{"text": "-- ------------------------------------------------------------ [ DeBruijn.idr ]\n-- Module : DeBruijn.idr\n-- Copyright : (c) 2015,2016 See CONTRIBUTORS.md\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\n||| Data structure to compute de Bruijn indices.\n|||\n||| Thanks to christiansen's Galois tutorials for the accessor and\n||| mutator functions for environments/object store.\nmodule Toolkit.Data.List.DeBruijn\n\nimport public Decidable.Equality\n\nimport public Data.List.Elem\n\nimport public Toolkit.Data.DList\n\n%default total\n\n-- A reverse cons operator.\ninfixr 6 +=\n\nnamespace List\n\n ||| Proof that the given list (`xs`) contains the given element\n ||| (`x`).\n |||\n |||\n public export\n Contains : List a -> a -> Type\n Contains xs x = Elem x xs\n\n ||| Append `x` to the head of `xs`.\n public export\n (+=) : List a -> a -> List a\n (+=) xs x = x :: xs\n\n\n||| A De Bruijn Index.\n|||\n||| @T The type of type's collected.\n||| @ctxt The collection of types.\n||| @t The element collected at the current position.\npublic export\nIndex : (type : Type)\n -> (ctxt : List type)\n -> (t : type)\n -> Type\nIndex _ ctxt t = Elem t ctxt\n\n\n||| Sometimes it is bettern to think that we have this thing called an\n||| environment and not a `DList`.\n|||\n||| @t The Type for Types in our environment.\n||| @obj How we interpret the types in our DSL. Either this is a\n||| dependent type or a function that computes a type.\n||| @ctxt The typing context.\npublic export\nEnv : (t : Type) -> (obj : t -> Type) -> (ctxt : List t) -> Type\nEnv ty obj ctxt = DList ty obj ctxt\n\n||| Add an object from our typing environment.\n||| @env The typing environment.\nexport\nextend : {t : ty}\n -> (env : Env ty e ctxt)\n -> (obj : e t)\n -> Env ty e (t::ctxt)\nextend env obj = obj :: env\n\n||| Read an object from our typing environment.\n|||\n||| @idx The typing context.\n||| @env The typing environment.\nexport\nread : (idx : Index ty ctxt t)\n -> (env : Env ty e ctxt)\n -> e t\nread Here (obj::store) = obj\nread (There x) (obj::store) = read x store\n\n||| Add an object to our typnig environment.\n|||\n||| @idx The typing context.\n||| @obj The object to add.\n||| @env The environment to which the object is added.\nexport\nupdate : (idx : Index ty ctxt t )\n -> (obj : e t)\n -> (env : Env ty e ctxt)\n -> Env ty e ctxt\nupdate Here obj (_ :: store) = obj :: store\nupdate (There x) obj (obj' :: store) = obj' :: update x obj store\n\nnamespace KV\n\n\n public export\n indexEmpty : {k : String}\n -> (t ** Index (String, type) [] (k, t))\n -> Void\n indexEmpty (MkDPair fst snd) impossible\n\n public export\n notInIndex : (keyContra : (k = a) -> Void)\n -> (index : List (String, type))\n -> (kvContra : (t : type ** Index (String, type) xs (k, t)) -> Void)\n -> (prf : (t : type ** Index (String, type) ((a, b) :: xs) (k, t)))\n -> Void\n notInIndex keyContra index kvContra (MkDPair b Here) = keyContra Refl\n notInIndex keyContra index kvContra (MkDPair fst (There x)) = kvContra (_ ** x)\n\n public export\n isIndex : DecEq type\n => (k : String)\n -> (ctxt : List (String, type))\n -> Dec (t : type ** Index (String, type) ctxt (k,t))\n isIndex k [] = No indexEmpty\n isIndex k ((a,b) :: xs) with (decEq k a)\n isIndex a ((a,b) :: xs) | (Yes Refl) = Yes (b ** Here)\n isIndex k ((a,b) :: xs) | (No contra) with (isIndex k xs)\n isIndex k ((a,b) :: xs) | (No contra) | (Yes (MkDPair fst snd))\n = Yes (_ ** There snd)\n isIndex k ((a,b) :: xs) | (No contra) | (No f) = No (notInIndex contra xs f)\n\nnamespace Renaming\n\n public export\n weaken : (func : Contains old type\n -> Contains new type)\n -> (Contains (old += type') type\n -> Contains (new += type') type)\n\n weaken func Here = Here\n weaken func (There rest) = There (func rest)\n\n public export\n interface Rename (type : Type) (term : List type -> type -> Type) | term where\n rename : {old, new : List type}\n -> (f : {ty : type} -> Contains old ty\n -> Contains new ty)\n -> ({ty : type} -> term old ty\n -> term new ty)\n\n var : {ty : type}\n -> {ctxt : List type}\n -> Elem ty ctxt\n -> term ctxt ty\n\n\n weakens : {old, new : List type}\n -> (f : {ty : type}\n -> Contains old ty\n -> term new ty)\n -> ({ty,type' : type}\n -> Contains (old += type') ty\n -> term (new += type') ty)\n weakens f Here = var Here\n weakens f (There rest) = rename There (f rest)\n\nnamespace Substitution\n\n namespace General\n public export\n interface Rename type term\n => Substitute (type : Type) (term : List type -> type -> Type) | term where\n\n subst : {old, new : List type}\n -> (f : {ty : type}\n -> Contains old ty\n -> term new ty)\n -> ({ty : type}\n -> term old ty\n -> term new ty)\n\n namespace Single\n\n apply : {type : Type}\n -> {term : List type -> type -> Type}\n -> Rename type term\n => {ctxt : List type}\n -> {typeA : type}\n -> {typeB : type}\n -> (this : term ctxt typeB)\n -> (idx : Contains (ctxt += typeB) typeA)\n -> term ctxt typeA\n apply this Here = this\n apply this (There rest) = var rest\n\n export\n subst : {type : Type}\n -> {term : List type -> type -> Type}\n -> Rename type term\n => Substitute type term\n => {ctxt : List type}\n -> {typeA : type}\n -> {typeB : type}\n -> (this : term ctxt typeB)\n -> (inThis : term (ctxt += typeB) typeA)\n -> term ctxt typeA\n subst {ctxt} {typeA} {typeB} this inThis\n = subst (apply this) inThis\n\n namespace Double\n\n public export\n apply : {type : Type}\n -> {term : List type -> type -> Type}\n -> Rename type term\n => {ctxt : List type}\n -> {typeA, typeB, typeC : type}\n -> (this : term ctxt typeA)\n -> (andThis : term ctxt typeB)\n -> (idx : Contains ((ctxt += typeA) += typeB) typeC)\n -> term ctxt typeC\n apply this andThis Here = andThis\n apply this andThis (There Here) = this\n apply this andThis (There (There x)) = var x\n\n public export\n subst : {type : Type}\n -> {term : List type -> type -> Type}\n -> Rename type term\n => Substitute type term\n => {ctxt : List type}\n -> {typeA, typeB, typeC : type}\n -> (this : term ctxt typeA)\n -> (andThis : term ctxt typeB)\n -> (inThis : term ((ctxt += typeA) += typeB) typeC)\n -> term ctxt typeC\n subst {ctxt} {typeA} {typeB} {typeC} this andThis inThis\n = General.subst (apply this andThis) inThis\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "b37fb67fef5998146bf4be30c1f733f8c7244a2e", "size": 7469, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/List/DeBruijn.idr", "max_stars_repo_name": "gallais/linear-circuits", "max_stars_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-11-29T17:20:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T21:41:44.000Z", "max_issues_repo_path": "src/Toolkit/Data/List/DeBruijn.idr", "max_issues_repo_name": "gallais/linear-circuits", "max_issues_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Toolkit/Data/List/DeBruijn.idr", "max_forks_repo_name": "gallais/linear-circuits", "max_forks_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-09T19:49:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T19:49:11.000Z", "avg_line_length": 31.6483050847, "max_line_length": 92, "alphanum_fraction": 0.4959164547, "num_tokens": 1999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5544704649604272, "lm_q2_score": 0.6261241772283034, "lm_q1q2_score": 0.3471673636707423}} {"text": "-- --------------------------------------------------------------- [ BTree.idr ]\n-- Module : BTree.idr\n-- Copyright : (c) 2017 See CONTRIBUTORS.md\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\n||| Implementation of a Binary Tree as a Red-Black Binary Search Tree.\n|||\n||| The underlying Red-Black Tree is a Key-Value Tree, this library\n||| just wraps this up as a simple Binary tree for values i.e. keys.\nmodule Data.RedBlack.BTree\n\nimport Data.RedBlack.Tree\n\n%default total\n%access export\n\n-- ------------------------------------------------------------- [ Definitions ]\n\n||| A Binary Search Tree.\n|||\n||| @ty The type of the elements in the tree.\ndata BTree : (ty : Type) -> Type\n where\n MkTree : {a : Type} -> RBTree n B a Unit -> BTree a\n\n-- --------------------------------------------------------------------- [ API ]\n\n||| Return an empty BTree.\nempty : Ord a => BTree a\nempty = MkTree empty\n\n||| Insert an element into the Tree.\ninsert : (Ord a) => a -> BTree a -> BTree a\ninsert a (MkTree t) = case Tree.insert a () t of\n (_ ** t') => MkTree t'\n\n||| Does the tree contain the given element?\ncontains : (Ord a) => a -> BTree a -> Bool\ncontains a (MkTree t) = isJust (Tree.lookup a t)\n\n||| How many nodes are in the tree?\nsize : BTree a -> Nat\nsize (MkTree t) = Tree.size t\n\n||| Construct an ordered list containing the elements of the tree.\ntoList : BTree a -> List a\ntoList (MkTree t) = map fst $ Tree.toList t\n\n||| Construct a tree from a list of elements.\nfromList : (Ord a) => List a -> BTree a\nfromList xs = (foldl (\\t,k => BTree.insert k t) empty xs)\n\n-- --------------------------------------------------------------- [ Instances ]\n\nFoldable BTree where\n foldr f i (MkTree t) = foldr (\\x,_,p => f x p) i t\n\n-- Eq a => Eq (BTree a) where\n-- (==) (MkTree t) (MkTree t') = t == t'\n\nShow a => Show (BTree a) where\n show s = \"{ \" ++ (unwords . intersperse \",\" . map show . BTree.toList $ s) ++ \" }\"\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "93b880bb355ccec61dc133f7587595d1cb7d13be", "size": 2068, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/RedBlack/BTree.idr", "max_stars_repo_name": "witt3rd/idris-containers", "max_stars_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 99, "max_stars_repo_stars_event_min_datetime": "2015-03-01T20:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:17:39.000Z", "max_issues_repo_path": "Data/RedBlack/BTree.idr", "max_issues_repo_name": "witt3rd/idris-containers", "max_issues_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2015-03-23T19:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T13:05:44.000Z", "max_forks_repo_path": "Data/RedBlack/BTree.idr", "max_forks_repo_name": "witt3rd/idris-containers", "max_forks_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-06-02T17:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T14:51:07.000Z", "avg_line_length": 31.8153846154, "max_line_length": 84, "alphanum_fraction": 0.503384913, "num_tokens": 539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5964331462646255, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.34670843128633855}} {"text": "module Effect.Memory\n\nimport Effects\nimport Control.IOExcept\n\n%access public\n\nabstract\ndata MemoryChunk : Nat -> Nat -> Type where\n CH : Ptr -> MemoryChunk size initialized\n\nabstract\ndata RawMemory : Effect where\n Allocate : (n : Nat) ->\n RawMemory () () (\\v => MemoryChunk n 0)\n Free : RawMemory () (MemoryChunk n i) (\\v => ())\n Initialize : Bits8 ->\n (size : Nat) ->\n so (i + size <= n) ->\n RawMemory () (MemoryChunk n i) (\\v => MemoryChunk n (i + size))\n Peek : (offset : Nat) ->\n (size : Nat) ->\n so (offset + size <= i) ->\n RawMemory (Vect size Bits8)\n (MemoryChunk n i) (\\v => MemoryChunk n i) \n Poke : (offset : Nat) ->\n (Vect size Bits8) ->\n so (offset <= i && offset + size <= n) ->\n RawMemory () (MemoryChunk n i) (\\v => MemoryChunk n (max i (offset + size))) \n Move : (src : MemoryChunk src_size src_init) ->\n (dst_offset : Nat) ->\n (src_offset : Nat) ->\n (size : Nat) ->\n so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->\n so (src_offset + size <= src_init) ->\n RawMemory () (MemoryChunk dst_size dst_init)\n (\\v => MemoryChunk dst_size (max dst_init (dst_offset + size))) \n GetRawPtr : RawMemory (MemoryChunk n i) (MemoryChunk n i) (\\v => MemoryChunk n i) \n\nprivate\ndo_malloc : Nat -> IOExcept String Ptr\ndo_malloc size with (fromInteger (cast size) == size)\n | True = do ptr <- ioe_lift $ mkForeign (FFun \"malloc\" [FInt] FPtr) (fromInteger $ cast size)\n fail <- ioe_lift $ nullPtr ptr\n if fail then ioe_fail \"Cannot allocate memory\"\n else return ptr\n | False = ioe_fail \"The target architecture does not support adressing enough memory\"\n\nprivate\ndo_memset : Ptr -> Nat -> Bits8 -> Nat -> IO ()\ndo_memset ptr offset c size\n = mkForeign (FFun \"idris_memset\" [FPtr, FInt, FByte, FInt] FUnit)\n ptr (fromInteger $ cast offset) c (fromInteger $ cast size)\n\nprivate\ndo_free : Ptr -> IO ()\ndo_free ptr = mkForeign (FFun \"free\" [FPtr] FUnit) ptr\n\nprivate\ndo_memmove : Ptr -> Ptr -> Nat -> Nat -> Nat -> IO ()\ndo_memmove dest src dest_offset src_offset size\n = mkForeign (FFun \"idris_memmove\" [FPtr, FPtr, FInt, FInt, FInt] FUnit)\n dest src (fromInteger $ cast dest_offset) (fromInteger $ cast src_offset) (fromInteger $ cast size)\n\nprivate\ndo_peek : Ptr -> Nat -> (size : Nat) -> IO (Vect size Bits8)\ndo_peek _ _ Z = return (Prelude.Vect.Nil)\ndo_peek ptr offset (S n)\n = do b <- mkForeign (FFun \"idris_peek\" [FPtr, FInt] FByte) ptr (fromInteger $ cast offset)\n bs <- do_peek ptr (S offset) n\n Prelude.Monad.return (Prelude.Vect.(::) b bs)\n\nprivate\ndo_poke : Ptr -> Nat -> Vect size Bits8 -> IO ()\ndo_poke _ _ [] = return ()\ndo_poke ptr offset (b::bs)\n = do mkForeign (FFun \"idris_poke\" [FPtr, FInt, FByte] FUnit) ptr (fromInteger $ cast offset) b\n do_poke ptr (S offset) bs\n\ninstance Handler RawMemory (IOExcept String) where\n handle () (Allocate n) k\n = do ptr <- do_malloc n\n k () (CH ptr)\n handle {-{res = MemoryChunk _ offset}-} (CH ptr) (Initialize {i} c size _) k\n = ioe_lift (do_memset ptr i c size) $> k () (CH ptr)\n handle (CH ptr) (Free) k\n = ioe_lift (do_free ptr) $> k () ()\n handle (CH ptr) (Peek offset size _) k\n = do res <- ioe_lift (do_peek ptr offset size)\n k res (CH ptr)\n handle (CH ptr) (Poke offset content _) k\n = do ioe_lift (do_poke ptr offset content)\n k () (CH ptr)\n handle (CH dest_ptr) (Move (CH src_ptr) dest_offset src_offset size _ _) k\n = do ioe_lift (do_memmove dest_ptr src_ptr dest_offset src_offset size)\n k () (CH dest_ptr)\n handle chunk (GetRawPtr) k\n = k chunk chunk\n\nRAW_MEMORY : Type -> EFFECT\nRAW_MEMORY t = MkEff t RawMemory\n\nallocate : (n : Nat) -> \n Eff m () [RAW_MEMORY ()] (\\v => [RAW_MEMORY (MemoryChunk n 0)])\nallocate size = Allocate size\n\ninitialize : {i : Nat} ->\n {n : Nat} ->\n Bits8 ->\n (size : Nat) ->\n so (i + size <= n) ->\n Eff m () [RAW_MEMORY (MemoryChunk n i)] \n (\\v => [RAW_MEMORY (MemoryChunk n (i + size))])\ninitialize c size prf = Initialize c size prf\n\nfree : Eff m () [RAW_MEMORY (MemoryChunk n i)] (\\v => [RAW_MEMORY ()])\nfree = Free\n\npeek : {i : Nat} ->\n (offset : Nat) ->\n (size : Nat) ->\n so (offset + size <= i) ->\n { [RAW_MEMORY (MemoryChunk n i)] } Eff m (Vect size Bits8) \npeek offset size prf = Peek offset size prf\n\npoke : {n : Nat} ->\n {i : Nat} ->\n (offset : Nat) ->\n Vect size Bits8 ->\n so (offset <= i && offset + size <= n) ->\n Eff m () [RAW_MEMORY (MemoryChunk n i)] \n (\\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])\npoke offset content prf = Poke offset content prf\n\nprivate\ngetRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff m (MemoryChunk n i) \ngetRawPtr = GetRawPtr\n\nprivate\nmove' : {dst_size : Nat} ->\n {dst_init : Nat} ->\n {src_init : Nat} ->\n (src_ptr : MemoryChunk src_size src_init) ->\n (dst_offset : Nat) ->\n (src_offset : Nat) ->\n (size : Nat) ->\n so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->\n so (src_offset + size <= src_init) ->\n Eff m () [RAW_MEMORY (MemoryChunk dst_size dst_init)]\n (\\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])\nmove' src_ptr dst_offset src_offset size dst_bounds src_bounds\n = Move src_ptr dst_offset src_offset size dst_bounds src_bounds\n\ndata MoveDescriptor = Dst | Src\n\nmove : {dst_size : Nat} ->\n {dst_init : Nat} ->\n {src_size : Nat} ->\n {src_init : Nat} ->\n (dst_offset : Nat) ->\n (src_offset : Nat) ->\n (size : Nat) ->\n so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->\n so (src_offset + size <= src_init) ->\n Eff m ()\n [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)\n , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]\n (\\v =>\n [ Dst ::: RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))\n , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)])\nmove dst_offset src_offset size dst_bounds src_bounds\n = do src_ptr <- Src :- getRawPtr\n Dst :- move' src_ptr dst_offset src_offset size dst_bounds src_bounds\n return () \n\n", "meta": {"hexsha": "cb82aa21e9dc961cec735df9dbeb4aaee2622fe9", "size": 6697, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Effect/Memory.idr", "max_stars_repo_name": "edwinb/Eff-new", "max_stars_repo_head_hexsha": "e906e2d22a1606de015086bd92acc6f4e0e40ec1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-02-25T02:12:17.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-13T12:00:40.000Z", "max_issues_repo_path": "Effect/Memory.idr", "max_issues_repo_name": "edwinb/Eff-new", "max_issues_repo_head_hexsha": "e906e2d22a1606de015086bd92acc6f4e0e40ec1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Effect/Memory.idr", "max_forks_repo_name": "edwinb/Eff-new", "max_forks_repo_head_hexsha": "e906e2d22a1606de015086bd92acc6f4e0e40ec1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0511363636, "max_line_length": 113, "alphanum_fraction": 0.5677168882, "num_tokens": 1834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3463209979119566}} {"text": "singleton : Vector xs t -> \n Vector (1::xs) t\nsingleton t = [t]\n\ninvSingleton : Vector (1::xs) t -> \n Vector xs t\ninvSingleton [t] = t\n\n", "meta": {"hexsha": "8aef4dd71629ad688f8b82736f373be73a64b2a6", "size": 161, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "proposal/code/singleton.idr", "max_stars_repo_name": "RossMeikleham/MSci-Project", "max_stars_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-20T11:17:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-20T11:17:45.000Z", "max_issues_repo_path": "proposal/code/singleton.idr", "max_issues_repo_name": "RossMeikleham/MSci-Project", "max_issues_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proposal/code/singleton.idr", "max_forks_repo_name": "RossMeikleham/MSci-Project", "max_forks_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.8888888889, "max_line_length": 35, "alphanum_fraction": 0.5217391304, "num_tokens": 47, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.61878043374385, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.34548181972574304}} {"text": "module LightClick.Types.Usage\n\nimport Data.List\nimport Data.Vect\n\nimport Toolkit.Data.DList\nimport Toolkit.Data.DVect\n\nimport LightClick.Error\n\nimport LightClick.Types\nimport LightClick.Types.Equality\n\n%default total\n\npublic export\nPortList : (p : Nat)\n -> (names : Vect p String)\n -> Type\nPortList = DVect String (Ty . PORT)\n\nnamespace PortList\n\n public export\n data Division : (0 pred : (label : String) -> Ty (PORT label) -> Type)\n\n -> {ps : Vect p String}\n -> {ns : Vect n String}\n -> {names : Vect o String}\n\n -> (pos : PortList p ps)\n -> (neg : PortList n ns)\n -> (orig : PortList o names)\n -> Type\n where\n Empty : Division pred Nil Nil Nil\n\n Pos : {0 pred : (label : String) -> Ty (PORT label) -> Type}\n -> {pos : PortList p ps}\n -> {neg : PortList n ns}\n -> {orig : PortList o os}\n\n -> {label : String}\n -> {port : Ty (PORT label)}\n\n -> (prf : pred label port)\n -> (rest : Division pred pos neg orig)\n -> Division pred (port::pos) neg (port::orig)\n\n Neg : {0 pred : (label : String) -> Ty (PORT label) -> Type}\n -> {pos : PortList p ps}\n -> {neg : PortList n ns}\n -> {orig : PortList o os}\n\n -> {label : String}\n -> {port : Ty (PORT label)}\n\n -> (prf : Not (pred label port))\n\n -> (rest : Division pred pos neg orig)\n -> Division pred pos (port::neg) (port::orig)\n\n public export\n data State : (pred : (label : String) -> (port : Ty (PORT label)) -> Type)\n -> (ports : PortList p names)\n -> Type\n where\n\n MkState : {0 pred : (label : String) -> Ty (PORT label) -> Type}\n\n -> {os : Vect o String}\n -> {orig : PortList o os}\n\n -> (ps : Vect p String)\n -> (pos : PortList p ps)\n\n -> (ns : Vect n String)\n -> (neg : PortList n ns)\n\n -> (division : Division pred pos neg orig)\n\n -> State pred orig\n\n export\n state : (0 pred : (label : String) -> (port : Ty (PORT label)) -> Type)\n\n -> (dec : (label : String) -> (port : Ty (PORT label)) -> Dec (pred label port))\n -> (ports : PortList p ps)\n -> State pred ports\n state pred _ [] = MkState Nil Nil Nil Nil Empty\n\n state pred dec ((TyPort l d s w t u) :: ports) with (dec l (TyPort l d s w t u))\n state pred dec ((TyPort l d s w t u) :: ports) | (Yes prf) with (state pred dec ports)\n state pred dec ((TyPort l d s w t u) :: ports) | (Yes prf) | (MkState xs pos ns neg division)\n = MkState (l::xs) ((TyPort l d s w t u)::pos) ns neg (Pos prf division)\n\n state pred dec ((TyPort l d s w t u) :: ports) | (No contra) with (state pred dec ports)\n state pred dec ((TyPort l d s w t u) :: ports) | (No contra) | (MkState xs pos ns neg division)\n = MkState xs pos (l::ns) ((TyPort l d s w t u)::neg) (Neg contra division)\n\nnamespace Free\n\n namespace Port\n public export\n data Free : (l : String) -> (port : Ty (PORT l)) -> Type where\n FreePort : (label : String)\n -> (use : TyRig)\n -> (contra : Not (use = None))\n -> Free (label) (TyPort label dir sense ety type use)\n\n used : Free l (TyPort l d s w t None) -> Void\n used (FreePort l None contra) = contra Refl\n\n export\n free : (label : String)\n -> (type : Ty (PORT label))\n -> Dec (Free label type)\n free l (TyPort l d s w t None) = No used\n free l (TyPort l d s w t One) = Yes (FreePort l One (negEqSym noneNotOne))\n free l (TyPort l d s w t Tonne) = Yes (FreePort l Tonne (negEqSym noneNotTonne))\n\n namespace Types\n\n export\n free : (type : Ty m) -> List String\n free TyLogic = Nil\n free (TyArray type length) = Nil\n free (TyStruct kvs) = Nil\n free (TyUnion kvs) = Nil\n free TyUnit = Nil\n free TyConn = Nil\n free TyGate = Nil\n free (TyPort label dir sense wty type usage) with (free label (TyPort label dir sense wty type usage))\n free (TyPort label dir sense wty type usage) | Yes (FreePort label usage contra)\n = [label]\n free (TyPort label dir sense wty type usage) | No contra\n = Nil\n free (TyModule ports) with (state Port.Free Port.free ports)\n free (TyModule ports) | (MkState ps pos ns neg division) = toList ps\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "64a2f77e544aedf6909a5e02f3602c4aa4c0bd6e", "size": 4657, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/LightClick/Types/Usage.idr", "max_stars_repo_name": "border-patrol/lightclick", "max_stars_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-11-03T11:33:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:11:38.000Z", "max_issues_repo_path": "src/LightClick/Types/Usage.idr", "max_issues_repo_name": "border-patrol/lightclick", "max_issues_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LightClick/Types/Usage.idr", "max_forks_repo_name": "border-patrol/lightclick", "max_forks_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7957746479, "max_line_length": 106, "alphanum_fraction": 0.5202920335, "num_tokens": 1281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.34489500800221506}} {"text": "data SnocList ty = Empty | Snoc (Main.SnocList ty) ty\n\nreverseSnoc : Main.SnocList ty -> List ty\nreverseSnoc Empty = []\nreverseSnoc (Snoc xs x) = x :: reverseSnoc xs\n", "meta": {"hexsha": "f18f91e9d89a081cd73b279fa07de4b689203259", "size": 166, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/typedd-book/chapter10/ReverseSnoc.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "tests/typedd-book/chapter10/ReverseSnoc.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "tests/typedd-book/chapter10/ReverseSnoc.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 27.6666666667, "max_line_length": 53, "alphanum_fraction": 0.7108433735, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.6370307944803831, "lm_q1q2_score": 0.3433489092862711}} {"text": "module Sub08Apply108x63\r\n\r\nimport ProofColDivSeqBase\r\nimport ProofColDivSeqPostulate\r\n\r\n%default total\r\n-- %language ElabReflection\r\n\r\n\r\n-- 3(36x+21) --F[5,-2]->B[1,-2]--> 3(16x+9)\r\nfb108x63To48x27 :\r\n (o:Nat) -> P (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))))))) 2\r\n -> P (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))))) 2\r\nfb108x63To48x27 o prf =\r\n let prf2 = lvDown (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))))))) 2\r\n prf in\r\n let prf3 = fb108x63To48x27' o prf2 in lvDown (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))))) 3 prf3\r\n\r\n\r\nexport\r\napply108x63 : P (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))))))) 2\r\n -> (m : Nat **\r\n (LTE (S m)\r\n (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))))))),\r\n P m 2))\r\napply108x63 {o} col = let col2 = fb108x63To48x27 o col in ((S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))))))))\r\n ** (lte108x63 o, col2)) where\r\n lte108x63 : (o:Nat) -> LTE (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))\r\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))))))\r\n (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))))))))))\r\n lte108x63 Z = (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) LTEZero\r\n lte108x63 (S o) = let lemma = lte108x63 o in\r\n rewrite (sym (plusSuccRightSucc o o)) in\r\n rewrite (sym (plusSuccRightSucc (plus o o) (S (plus o o)))) in\r\n rewrite (sym (plusSuccRightSucc (plus o o) (plus o o))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (S (S (plus (plus o o) (plus o o))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (S (plus (plus o o) (plus o o)))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (plus (plus o o) (plus o o))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))) in\r\n\r\n rewrite (sym (plusSuccRightSucc (plus o o) o)) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (S (S (plus (plus o o) o)))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (S (plus (plus o o) o))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (plus (plus o o) o)))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (S (S (S (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (S (S (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (S (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (plus (plus o o) o))) (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o)))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o)))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o)))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o)))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o)))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o))))))\r\n (S (S (plus (plus (plus (plus o o) o) (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o) (S (plus (plus o o) o)))))))))\r\n (S (S (plus (plus (plus (plus o o) o)\r\n (S (plus (plus o o) o)))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (plus (plus o o)\r\n o)))))))))) in\r\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) lemma\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "c744081472871ec3fc8820f2de8fdc7d4c29181c", "size": 27937, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program/Sub08Apply108x63.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program/Sub08Apply108x63.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program/Sub08Apply108x63.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 103.4703703704, "max_line_length": 472, "alphanum_fraction": 0.3127393779, "num_tokens": 7222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.4493926344647597, "lm_q1q2_score": 0.3431039798747331}} {"text": "module Crypto.Hash.MerkleDamgard\n\nimport Crypto.Hash.Interfaces\nimport Data.Bits\nimport Data.DPair\nimport Data.Fin\nimport Data.Fin.Extra\nimport Data.List\nimport Data.Nat\nimport Data.Nat.Factor\nimport Data.Vect\nimport Utils.Misc\nimport Utils.Bytes\nimport Data.Stream\n\npublic export\nrecord MerkleDamgard (internal_state_nbyte : Nat) (0 block_nbyte : Nat) (0 word_type : Type) where\n constructor MkMerkleDamgard\n hash_values : Vect internal_state_nbyte word_type\n buffer_nbyte : Nat\n buffer_nbyte_constraint : LT buffer_nbyte block_nbyte\n buffer : Vect buffer_nbyte Bits8\n npassed_blocks : Nat\n\nexport\nmk_merkle_damgard : (init_hash_values : Vect internal_state_nbyte word_type) ->\n {auto 0 prf : LTE 1 block_nbyte} ->\n MerkleDamgard internal_state_nbyte block_nbyte word_type\nmk_merkle_damgard x {prf = LTESucc prf'} = MkMerkleDamgard x 0 (LTESucc LTEZero) [] 0\n\npublic export\npad_lemma : {residue_nbyte, length_nbyte, residue_max_nbyte, block_nbyte : Nat}\n -> LTE 1 block_nbyte\n -> (residue_max_nbyte + 1 + length_nbyte = block_nbyte)\n -> LTE residue_nbyte residue_max_nbyte\n -> (plus residue_nbyte (S (plus (minus residue_max_nbyte residue_nbyte) length_nbyte))) = block_nbyte\npad_lemma remilia flandre sakuya =\n rewrite sym flandre in\n rewrite sym $ plusSuccRightSucc residue_nbyte (plus (minus residue_max_nbyte residue_nbyte) length_nbyte) in\n rewrite plusAssociative residue_nbyte (minus residue_max_nbyte residue_nbyte) length_nbyte in\n rewrite plusCommutative residue_nbyte (minus residue_max_nbyte residue_nbyte) in\n rewrite plusMinusLte residue_nbyte residue_max_nbyte sakuya in\n rewrite plusCommutative residue_max_nbyte 1 in\n Refl\n\npublic export\npad_over_lemma : {residue_nbyte, length_nbyte, residue_max_nbyte, block_nbyte : Nat}\n -> (residue_max_nbyte + 1 + length_nbyte = block_nbyte)\n -> LT residue_nbyte block_nbyte\n -> plus residue_nbyte (S (plus (plus (minus block_nbyte residue_nbyte) residue_max_nbyte) length_nbyte)) = (plus block_nbyte (plus block_nbyte 0))\npad_over_lemma flandre cirno =\n rewrite sym $ plusSuccRightSucc residue_nbyte (plus (plus (minus block_nbyte residue_nbyte) residue_max_nbyte) length_nbyte) in\n rewrite plusAssociative residue_nbyte (plus (minus block_nbyte residue_nbyte) residue_max_nbyte) length_nbyte in\n rewrite plusAssociative residue_nbyte (minus block_nbyte residue_nbyte) residue_max_nbyte in\n rewrite plusCommutative residue_nbyte (minus block_nbyte residue_nbyte) in\n rewrite plusMinusLte residue_nbyte block_nbyte (lteSuccLeft cirno) in\n rewrite sym $ plusAssociative block_nbyte residue_max_nbyte length_nbyte in\n rewrite plusSuccRightSucc block_nbyte (plus residue_max_nbyte length_nbyte) in\n rewrite plusZeroRightNeutral block_nbyte in\n rewrite flandre' in\n Refl\n where\n flandre' : S (plus residue_max_nbyte length_nbyte) = block_nbyte\n flandre' = rewrite sym flandre in rewrite plusCommutative residue_max_nbyte 1 in Refl\n\npublic export\npad_residue : {residue_nbyte, length_nbyte, residue_max_nbyte, block_nbyte : _}\n -> (0 _ : LTE 1 block_nbyte)\n -> (0 _ : (residue_max_nbyte + 1 + length_nbyte = block_nbyte))\n -> (0 _ : LTE residue_nbyte residue_max_nbyte)\n -> Vect residue_nbyte Bits8\n -> Vect length_nbyte Bits8\n -> Vect block_nbyte Bits8\npad_residue remilia flandre sakuya residue b_length =\n replace_vect (pad_lemma remilia flandre sakuya) $\n residue\n ++ [0b10000000]\n ++ replicate (minus residue_max_nbyte residue_nbyte) 0\n ++ b_length\n\npublic export\npad_over_residue : {residue_nbyte, length_nbyte, residue_max_nbyte, block_nbyte : _}\n -> (0 _ : LTE 1 block_nbyte)\n -> (0 _ : residue_max_nbyte + 1 + length_nbyte = block_nbyte)\n -> (0 _ : LT residue_max_nbyte residue_nbyte)\n -> (0 _ : LT residue_nbyte block_nbyte)\n -> Vect residue_nbyte Bits8\n -> Vect length_nbyte Bits8\n -> Vect (2 * block_nbyte) Bits8\npad_over_residue remilia flandre rumia cirno residue b_length =\n replace_vect (pad_over_lemma flandre cirno) $\n residue\n ++ [0b10000000]\n ++ replicate (minus block_nbyte residue_nbyte + residue_max_nbyte) 0\n ++ b_length\n\npublic export\npad_theorem : {residue_nbyte, length_nbyte, residue_max_nbyte, block_nbyte : _}\n -> (0 _ : LTE 1 block_nbyte)\n -> (0 _ : residue_max_nbyte + 1 + length_nbyte = block_nbyte)\n -> (0 _ : LT residue_nbyte block_nbyte)\n -> Vect residue_nbyte Bits8\n -> Vect length_nbyte Bits8\n -> Either (Vect block_nbyte Bits8) (Vect (block_nbyte + block_nbyte) Bits8)\npad_theorem remilia flandre cirno input b_length =\n case isLTE residue_nbyte residue_max_nbyte of\n Yes sakuya => Left $ pad_residue remilia flandre sakuya input b_length\n No rumia => Right $ replace_vect (cong (plus block_nbyte) (plusZeroRightNeutral block_nbyte)) $ pad_over_residue remilia flandre (notLTEImpliesGT rumia) cirno input b_length\n", "meta": {"hexsha": "f037e0452c327b7e28f6bf009d0819d95ec9c283", "size": 4836, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Crypto/Hash/MerkleDamgard.idr", "max_stars_repo_name": "octeep/idris2-tls", "max_stars_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_stars_repo_licenses": ["ISC"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-23T15:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T11:00:15.000Z", "max_issues_repo_path": "src/Crypto/Hash/MerkleDamgard.idr", "max_issues_repo_name": "octeep/idris2-tls", "max_issues_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_issues_repo_licenses": ["ISC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Crypto/Hash/MerkleDamgard.idr", "max_forks_repo_name": "octeep/idris2-tls", "max_forks_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_forks_repo_licenses": ["ISC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3669724771, "max_line_length": 177, "alphanum_fraction": 0.7772952854, "num_tokens": 1412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105587468141, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3430989362222371}} {"text": "import Data.Nat\nimport Data.Vect\nimport Language.Reflection\n\n%language ElabReflection\n\nfc : FC\nfc = EmptyFC\n\nquoteTest : TTImp -> TTImp -> List Decl\nquoteTest f arg = `[ myFunc : ~(IApp fc f arg) ]\n\naxes : (n : Nat) -> {auto gt : GT n 0} -> {auto lte : LTE n 4} -> Vect n String\naxes 1 = [\"x\"]\naxes 2 = \"y\" :: axes 1\naxes 3 = \"z\" :: axes 2\naxes 4 = \"w\" :: axes 3\naxes (S (S (S (S (S _))))) {lte} = absurd lte\n\nmkPoint : (n : Nat) -> {auto gt : GT n 0} -> {auto lte : LTE n 4} -> Decl\nmkPoint n\n = let type = \"Point\" ++ show n ++ \"D\" in\n let mkMainUN = NS (MkNS [\"Main\"]) . UN . Basic in\n IRecord emptyFC Nothing Public\n (MkRecord emptyFC (mkMainUN type) [] (mkMainUN (\"Mk\" ++ type))\n (toList $ map (\\axis => MkIField emptyFC MW ExplicitArg (UN (Field axis)) `(Double)) (axes n)))\n\nlogDecls : TTImp -> Elab (Int -> Int)\nlogDecls v\n = do declare [IClaim EmptyFC MW Public []\n (MkTy EmptyFC EmptyFC `{ Main.foo }\n `(Int -> Int -> Int) )]\n\n declare `[ foo x y = x + y ]\n\n declare [ mkPoint 3 ]\n\n declare `[ multBy : Int -> Int\n multBy x = x * ~(v) ]\n declare `[ myplus : Nat -> Nat -> Nat\n myplus Z y = y\n myplus (S k) y = S (myplus k y) ]\n check `( multBy )\n\nmkMult : Int -> Int\nmkMult = %runElab logDecls `(4)\n\npoint : Point3D\npoint = MkPoint3D 1.0 2.0 3.0\n", "meta": {"hexsha": "2ea8a6481e4edc3621eb79590e785724617d6778", "size": 1427, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/reflection004/refdecl.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/idris2/reflection004/refdecl.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/idris2/reflection004/refdecl.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.54, "max_line_length": 103, "alphanum_fraction": 0.5248773651, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3422771357906906}} {"text": "module ConcurrentImp\n\nimport Expr\nimport Logic\nimport Maps\nimport SmallStepExpr\n\n%access public export\n\n%default total\n\ndata Com : Type where\n CSkip : Com\n CAss : Id -> AExp -> Com\n CSeq : Com -> Com -> Com\n CIf : BExp -> Com -> Com -> Com\n CWhile : BExp -> Com -> Com\n CPar : Com -> Com -> Com\n\nSKIP : Com\nSKIP = CSkip\n\ninfix 5 ::=\n\n(::=) : Id -> AExp -> Com\n(::=) = CAss\n\n(>>=) : Com -> (() -> Com) -> Com\n(>>=) c f = CSeq c (f ())\n\nWHILE : BExp -> Com -> Com\nWHILE = CWhile\n\nsyntax IFB [b] THEN [c1] ELSE [c2] FI = CIf b c1 c2\n\nsyntax PAR [c1] WITH [c2] END = CPar c1 c2\n\ndata CStep : (Com, State) -> (Com, State) -> Type where\n CS_AssStep : AStep st a a' -> CStep (i ::= a, st) (i ::= a', st)\n CS_Ass : CStep (i ::= ANum n, st) (SKIP, t_update i n st)\n CS_SeqStep : CStep (c1, st) (c1', st') ->\n CStep ((do c1; c2), st) ((do c1'; c2), st')\n CS_SeqFinish : CStep ((do SKIP; c2), st) (c2, st)\n CS_IfStep : BStep st b b' -> CStep (CIf b c1 c2, st) (CIf b' c1 c2, st)\n CS_IfTrue : CStep (CIf BTrue c1 c2, st) (c1, st)\n CS_IfFalse : CStep (CIf BFalse c1 c2, st) (c2, st)\n CS_While : CStep (WHILE b c, st) (CIf b (do c; WHILE b c) SKIP, st)\n CS_Par1 : CStep (c1, st) (c1', st') ->\n CStep (CPar c1 c2, st) (CPar c1' c2, st')\n CS_Par2 : CStep (c2, st) (c2', st') ->\n CStep (CPar c1 c2, st) (CPar c1 c2', st')\n CS_ParDone : CStep (CPar SKIP SKIP, st) (SKIP, st)\n\nCMultiStep : Relation (Com, State)\nCMultiStep = Multi CStep\n\nsyntax [t] \"/\" [st] \"-+>*\" [t'] \"/\" [st'] = Multi CStep (t, st) (t', st')\n\npar_loop : Com\npar_loop =\n PAR\n Y ::= 1\n WITH\n WHILE (Y == 0) $ do\n X ::= X + 1\n END\n\npar_loop_example_0 : (st' : State ** ( ConcurrentImp.par_loop / Expr.empty_state\n -+>* SKIP / st'\n , st' X = 2 ))\npar_loop_example_0 = (updatedState ** (execution, Refl))\nwhere updatedState : State\n updatedState = t_update Y 1 $\n t_update X 2 $\n t_update X 1 $\n empty_state\n execution : CMultiStep (ConcurrentImp.par_loop, Expr.empty_state)\n (SKIP, updatedState)\n execution = MultiStep (CS_Par2 CS_While) $\n MultiStep (CS_Par2 (CS_IfStep (BS_Eq1 AS_Id))) $\n MultiStep (CS_Par2 (CS_IfStep BS_Eq)) $\n MultiStep (CS_Par2 CS_IfTrue) $\n MultiStep (CS_Par2\n (CS_SeqStep (CS_AssStep (AS_Plus1 AS_Id)))) $\n MultiStep (CS_Par2 (CS_SeqStep (CS_AssStep AS_Plus))) $\n MultiStep (CS_Par2 (CS_SeqStep CS_Ass)) $\n MultiStep (CS_Par2 CS_SeqFinish) $\n MultiStep (CS_Par2 CS_While) $\n MultiStep (CS_Par2 (CS_IfStep (BS_Eq1 AS_Id))) $\n MultiStep (CS_Par2 (CS_IfStep BS_Eq)) $\n MultiStep (CS_Par2 CS_IfTrue) $\n MultiStep (CS_Par2\n (CS_SeqStep (CS_AssStep (AS_Plus1 AS_Id)))) $\n MultiStep (CS_Par2 (CS_SeqStep (CS_AssStep AS_Plus))) $\n MultiStep (CS_Par2 (CS_SeqStep CS_Ass)) $\n MultiStep (CS_Par2 CS_SeqFinish) $\n MultiStep (CS_Par1 CS_Ass) $\n MultiStep (CS_Par2 CS_While) $\n MultiStep (CS_Par2 (CS_IfStep (BS_Eq1 AS_Id))) $\n MultiStep (CS_Par2 (CS_IfStep BS_Eq)) $\n MultiStep (CS_Par2 CS_IfFalse) $\n MultiStep CS_ParDone $\n MultiRefl\n\npar_body_n__Sn : (n : Nat) -> (st : State) -> (st X = n, st Y = 0) ->\n ConcurrentImp.par_loop / st -+>*\n ConcurrentImp.par_loop / (t_update X (S n) st)\npar_body_n__Sn n st (x_prf, y_prf) =\n MultiStep (CS_Par2 CS_While) $\n MultiStep (CS_Par2 (CS_IfStep (BS_Eq1 AS_Id))) $\n rewrite y_prf in\n MultiStep (CS_Par2 (CS_IfStep BS_Eq)) $\n MultiStep (CS_Par2 CS_IfTrue) $\n MultiStep (CS_Par2\n (CS_SeqStep (CS_AssStep (AS_Plus1 AS_Id)))) $\n MultiStep (CS_Par2 (CS_SeqStep (CS_AssStep AS_Plus))) $\n MultiStep (CS_Par2 (CS_SeqStep CS_Ass)) $\n MultiStep (CS_Par2 CS_SeqFinish) $\n rewrite plusCommutative (st X) 1 in\n rewrite x_prf in\n MultiRefl\n\npar_body_any_X_helper : (n : Nat) ->\n ( st' : State\n ** ( ConcurrentImp.par_loop / Expr.empty_state\n -+>* ConcurrentImp.par_loop / st'\n , st' X = n\n , st' Y = 0 ))\npar_body_any_X_helper Z = (empty_state ** (MultiRefl, Refl, Refl))\npar_body_any_X_helper (S k) =\n let (st ** (s, x_prf, y_prf)) = par_body_any_X_helper k\n in ( t_update X (S k) st\n ** ( multi_trans s $\n MultiStep (CS_Par2 CS_While) $\n MultiStep (CS_Par2 (CS_IfStep (BS_Eq1 AS_Id))) $\n MultiStep (CS_Par2 (CS_IfStep BS_Eq)) $\n rewrite y_prf in\n MultiStep (CS_Par2 CS_IfTrue) $\n MultiStep (CS_Par2\n (CS_SeqStep (CS_AssStep (AS_Plus1 AS_Id)))) $\n MultiStep (CS_Par2 (CS_SeqStep (CS_AssStep AS_Plus))) $\n MultiStep (CS_Par2 (CS_SeqStep CS_Ass)) $\n MultiStep (CS_Par2 CS_SeqFinish) $\n rewrite plusCommutative (st X) 1 in\n rewrite x_prf in\n MultiRefl\n , Refl\n , y_prf ))\n\npar_body_any_X : (n : Nat) ->\n (st' : State ** ( ConcurrentImp.par_loop / Expr.empty_state\n -+>* SKIP / st'\n , st' X = n ))\npar_body_any_X n =\n let (st ** (s, x_prf, _)) = par_body_any_X_helper n\n in (t_update Y 1 st ** ( multi_trans s $\n MultiStep (CS_Par1 CS_Ass) $\n MultiStep (CS_Par2 CS_While) $\n MultiStep (CS_Par2 (CS_IfStep (BS_Eq1 AS_Id))) $\n MultiStep (CS_Par2 (CS_IfStep BS_Eq)) $\n MultiStep (CS_Par2 CS_IfFalse) $\n MultiStep CS_ParDone $\n MultiRefl\n , x_prf ))\n", "meta": {"hexsha": "cf2230b66088178a1f63f3a994a79a4327706352", "size": 6131, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ConcurrentImp.idr", "max_stars_repo_name": "minhnhdo/programming-language-foundations-in-idris", "max_stars_repo_head_hexsha": "0881c34307afa8c90cda2290bf72910be4a1ea57", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ConcurrentImp.idr", "max_issues_repo_name": "minhnhdo/programming-language-foundations-in-idris", "max_issues_repo_head_hexsha": "0881c34307afa8c90cda2290bf72910be4a1ea57", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ConcurrentImp.idr", "max_forks_repo_name": "minhnhdo/programming-language-foundations-in-idris", "max_forks_repo_head_hexsha": "0881c34307afa8c90cda2290bf72910be4a1ea57", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1575757576, "max_line_length": 80, "alphanum_fraction": 0.5242211711, "num_tokens": 1951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6001883592602051, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3420189278723405}} {"text": "module Main\nimport Data.Vect\n\n\ninfixr 5 .+.\ndata Schema = SString\n | SInt\n | SChar\n | (.+.) Schema Schema\n\nSchemaType : Schema -> Type\nSchemaType SString = String\nSchemaType SChar = Char\nSchemaType SInt = Int\nSchemaType (x .+. y) = (SchemaType x, SchemaType y)\n\nrecord DataStore where\n constructor MkData\n schema:Schema\n size:Nat\n items:Vect size (SchemaType schema)\n\n\naddToStore : (store:DataStore) -> SchemaType (schema store) -> DataStore\naddToStore (MkData schema size items) newitem = MkData schema _ (addToData items)\n where\n addToData : Vect old (SchemaType schema) -> Vect (S old) (SchemaType schema)\n addToData [] = [newitem]\n addToData (x :: xs) = newitem :: x :: xs\n\nsumInputs : Integer -> String -> Maybe (String, Integer)\nsumInputs tot inp = let val = cast inp in\n if val < 0\n then Nothing\n else let newVal = tot + val in\n Just (\"Subtotal: \" ++ show newVal ++ \"\\n\", newVal)\n\ndata Command : Schema -> Type where\n SetSchema : (newschema : Schema) -> Command schema\n Add : SchemaType schema -> Command schema\n Get : Integer -> Command schema\n GetAll : Command schema\n Size : Command schema\n --Search : String -> Command schema\n Quit : Command schema\n\nparsePrefix : (schema : Schema) -> String -> Maybe (SchemaType schema, String)\nparsePrefix SString input = getQuoted (unpack input) where\n getQuoted : List Char -> Maybe (String, String)\n getQuoted ('\"' :: xs) = case span (/= '\"') xs of\n (quoted, '\"' :: rest) => Just (pack quoted, ltrim (pack rest))\n _ => Nothing\n getQuoted _ = Nothing\nparsePrefix SChar input = case unpack input of\n (c :: rest ) => Just (c, ltrim (pack rest))\n _ => Nothing\nparsePrefix SInt input = case span isDigit input of\n (\"\", rest) => Nothing\n (num,rest) => Just (cast num, ltrim rest)\nparsePrefix (leftSchema .+. rightSchema) input = case parsePrefix leftSchema input of\n Nothing => Nothing\n Just (l_val, input') => case parsePrefix rightSchema input' of\n Nothing => Nothing\n Just (r_val, input'') => Just ((l_val,r_val), input'')\n\nparseSchema : List String -> Maybe Schema\nparseSchema (\"String\" :: xs)\n = case xs of\n [] => Just SString\n _ => case parseSchema xs of\n Nothing => Nothing\n Just right_schema => Just (SString .+. right_schema)\nparseSchema (\"Char\" :: xs)\n = case xs of\n [] => Just SChar\n _ => case parseSchema xs of\n Nothing => Nothing\n Just right_schema => Just (SChar .+. right_schema)\nparseSchema (\"Int\" :: xs)\n = case xs of\n [] => Just SInt\n _ => case parseSchema xs of\n Nothing => Nothing\n Just right_schema => Just (SInt .+. right_schema)\nparseSchema _ = Nothing\n\n\n\nparseBySchema : (schema:Schema) -> String -> Maybe (SchemaType schema)\nparseBySchema schema input = case parsePrefix schema input of\n Just (res,\"\") => Just res\n Just _ => Nothing\n Nothing => Nothing\n\nsetSchema : (store : DataStore) -> Schema -> Maybe DataStore\nsetSchema store schema = case size store of\n Z => Just (MkData schema _ [])\n S k => Nothing\n\nparseCommand : (schema:Schema) -> (cmd : String) -> (args : String) -> Maybe (Command schema)\nparseCommand schema \"add\" rest = case parseBySchema schema rest of\n Nothing => Nothing\n Just restok => Just (Add restok)\n--parseCommand schema \"search\" str = Just (Search str)\nparseCommand schema \"list\" _ = Just GetAll\nparseCommand schema \"get\" val = case all isDigit (unpack val) of\n False => Just GetAll\n True => Just (Get (cast val))\nparseCommand schema \"quit\" \"\" = Just Quit\nparseCommand schema \"size\" \"\" = Just Size\nparseCommand schema \"schema\" rest = case parseSchema (words rest) of\n Nothing => Nothing\n Just schemaok => Just (SetSchema schemaok)\nparseCommand _ _ _ = Nothing\n\nparse : (schema:Schema) -> (input : String) -> Maybe (Command schema)\nparse schema input = case span (/= ' ') input of\n (cmd, args) => parseCommand schema cmd (ltrim args)\n\ndisplay : SchemaType schema -> String\ndisplay {schema = SString} item = item\ndisplay {schema = SInt} item = show item\ndisplay {schema = SChar} item = show item\ndisplay {schema = (x .+. y)} (left, right) = display left ++ \", \" ++ display right\n\ngetEntry : (pos : Integer) -> (store : DataStore) -> Maybe (String, DataStore)\ngetEntry pos store = let store_items = items store in\n case integerToFin pos (size store) of\n Nothing => Just (\"Out of range\\n\", store)\n Just id => Just (display (index id store_items) ++ \"\\n\", store)\n\nstringify : SchemaType schema -> String\nstringify schemaType = (display schemaType) ++ \"\\n\"\n\ngetAll : (store:DataStore) -> Maybe (String, DataStore)\ngetAll store = let stringified = map stringify (items store)\n in Just (show stringified, store)\n\n{-searchEntryHelper : (searchStr : String) -> (store : Vect n String) -> (currentResults : List (Nat,String)) -> List (Nat, String)\nsearchEntryHelper searchStr [] res = res\nsearchEntryHelper {n = S k} searchStr (x :: xs) res =\n let newResults =\n case Strings.isInfixOf searchStr x of\n True => (k,x) :: res\n False => res\n in searchEntryHelper searchStr xs newResults\n\nsearchEntry : (value : String) -> (store : DataStore) -> Maybe (String, DataStore)\nsearchEntry value store @ (MkData size items) = let search_result = searchEntryHelper value items Nil in\n Just (\"Search results \" ++ show (search_result) ++ \"\\n\", store)\n-}\n\nprocessCmd : (store:DataStore) -> (command : Command (schema store)) -> Maybe (String, DataStore)\nprocessCmd store (SetSchema schema') = case setSchema store schema' of\n Nothing => Just (\"Can't update schema\\n\", store)\n Just store' => Just (\"OK\\n\", store')\nprocessCmd store (Add value) = Just (\"ID \" ++ show (size store) ++ \"\\n\", addToStore store value)\nprocessCmd store (Get pos) = getEntry pos store\nprocessCmd store GetAll = getAll store\nprocessCmd store Quit = Nothing\nprocessCmd store Size = Just (\"Size \" ++ show (size store) ++ \"\\n\", store)\n--processCmd store (Search value) = searchEntry value store\n\nprocessInput : DataStore -> String -> Maybe (String, DataStore)\nprocessInput store input = case parse (schema store) input of\n Just cmd => processCmd store cmd --cmd store\n Nothing => Just (\"Invalid command\\n\", store)\n\nmain : IO ()\nmain = replWith (MkData (SString .+. SString .+. SInt) _ []) \"Command: \" processInput\n", "meta": {"hexsha": "b84cf32d768c4ddb328e2619a8ec31f27732de2c", "size": 7497, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "datastoreSchema.idr", "max_stars_repo_name": "janschultecom/idris-examples", "max_stars_repo_head_hexsha": "c0bf0105d69f07492c6b99f14e9ca3c4cd7443c8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-05T15:26:06.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-05T15:26:06.000Z", "max_issues_repo_path": "datastoreSchema.idr", "max_issues_repo_name": "janschultecom/idris-examples", "max_issues_repo_head_hexsha": "c0bf0105d69f07492c6b99f14e9ca3c4cd7443c8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "datastoreSchema.idr", "max_forks_repo_name": "janschultecom/idris-examples", "max_forks_repo_head_hexsha": "c0bf0105d69f07492c6b99f14e9ca3c4cd7443c8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8421052632, "max_line_length": 137, "alphanum_fraction": 0.5620915033, "num_tokens": 1692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.34159470414198595}} {"text": "module Scheme.Eval\n\nimport Data.Vect\nimport Data.SortedMap\nimport Control.ST\n\nimport Scheme.Core\n\n%default total\n%access public export\n\nSErr : Type\nSErr = String\n\nSEvalResult : Type\nSEvalResult = Either SErr SExp\n\ndata Arity : Type where\n AConst : Arity\n AFixed : Nat -> Arity\n AVar : Arity\n\nShow Arity where\n show AConst = \"AConst\"\n show (AFixed n) = \"AFixed \" ++ show n\n show AVar = \"AVar\"\n\ndata SFun : Arity -> Type where\n MkSFConst : SExp -> SFun AConst\n MkSFFixed : (Vect n SExp -> SEvalResult) -> SFun (AFixed n)\n MkSFVar : (List SExp -> SEvalResult) -> SFun AVar\n\nShow SExp => Show (SFun ar) where\n show (MkSFConst x) = show x\n show {ar} _ = \"# List SExp -> ST m SEvalResult [env ::: State SEnv]\napply {env} t argList = do\n MkSEnv defs <- read env\n case lookup t defs of\n Nothing => pure $ Left \"Undefined function\"\n Just (AConst ** MkSFConst _ ) => pure $ Left $ \"Can't apply constant \" ++ t\n Just (AFixed n ** MkSFFixed func) => do\n case decEq n (length argList) of\n Yes prf => pure $ func $ replace {P = \\u => Vect u SExp} (sym prf) $ fromList argList\n No _ => pure $ Left $ \"Need \" ++ show n ++ \" argument(s), got \" ++ show (length argList)\n Just (AVar ** MkSFVar func) => pure $ func argList\n\neval : SExp -> ST m SEvalResult [env ::: State SEnv, qql ::: State Nat]\n\n-- Terminals (Unit, Vect, Bool, Char, Str, Num)\neval SEUnit = pure $ Right $ SEUnit\neval (SEVect xs) = pure $ Right $ SEVect xs\neval (SEBool b ) = pure $ Right $ SEBool b\neval (SEChar c ) = pure $ Right $ SEChar c\neval (SEStr s ) = pure $ Right $ SEStr s\neval (SENum sn ) = pure $ Right $ SENum sn\n\n-- Symbols\neval {env} {qql} (SESymbol t) = do\n n <- read qql\n case n of\n -- Outside a quasiquote symbols should consult with environment\n Z => do MkSEnv defs <- read env\n case lookup t defs of\n Nothing => pure $ Left $ \"Unbound symbol \" ++ t\n Just (AConst ** MkSFConst body) => pure $ Right body\n Just (ar ** _ ) => pure $ Left \"God bless you\" -- FIXME consider arity\n -- Inside a quasiquote symbols evaluate to themselves\n S _ => pure $ Right $ SESymbol t\n\n-- Special forms\neval {env} (SECons (SESymbol \"define\") (SECons (SESymbol name) (SECons x SEUnit))) = do\n MkSEnv defs <- read env\n case !(eval x) of\n Left err => pure $ Left err\n Right res => do\n write env $ MkSEnv $ insert name (AConst ** MkSFConst res) defs\n pure $ Right $ SEUnit\n\neval {env} (SECons (SESymbol \"define\") (SECons (SECons (SESymbol name) args) (SECons x SEUnit))) = do\n MkSEnv defs <- read env\n case !(eval x) of\n Left err => pure $ Left err\n Right res => do\n ?definingFunctions\n\neval (SECons (SESymbol \"quote\") x) = pure $ Right x\n\neval {qql} (SECons (SESymbol \"quasiquote\") x) = do\n n <- read qql\n update qql S\n res <- eval x\n write qql n\n pure res\n\neval {qql} (SECons (SESymbol \"unquote\") x) = do\n n <- read qql\n case n of\n Z => pure $ Left \"Unquote only works inside a quasiquote\"\n S k => do write qql k\n res <- eval x\n write qql n\n pure res\n\n-- Generic cons i.e. function application\neval {env} {qql} (SECons x y) = do\n n <- read qql\n case n of\n -- Outside a quasiquote\n Z => do\n case x of\n SESymbol f => call $ apply f $ fst $ listify y\n _ => pure $ Left \"Not a function\"\n -- Inside a quasiquote evaluate to itself deeply\n S k => do\n exr <- eval x\n eyr <- eval y\n case (exr, eyr) of\n (Left xErr, _ ) => pure $ Left xErr\n (_ , Left yErr) => pure $ Left yErr\n (Right xr , Right yr ) => pure $ Right $ SECons xr yr\n\n-- Everything else doesn't exist yet\neval _ = pure $ Left \"Not yet implemented\"\n\nnamespace StdLib\n\n -- Type predicates\n isSymbol : Vect 1 SExp -> SExp\n isSymbol [SESymbol _] = SEBool True\n isSymbol _ = SEBool False\n\n isList : Vect 1 SExp -> SExp\n isList [x] = case snd $ listify x of\n Nothing => SEBool True\n _ => SEBool False\n\n isVect : Vect 1 SExp -> SExp\n isVect [SEVect _] = SEBool True\n isVect _ = SEBool False\n\n isBool : Vect 1 SExp -> SExp\n isBool [SEBool _] = SEBool True\n isBool _ = SEBool False\n\n isChar : Vect 1 SExp -> SExp\n isChar [SEChar _] = SEBool True\n isChar _ = SEBool False\n\n isStr : Vect 1 SExp -> SExp\n isStr [SEStr _] = SEBool True\n isStr _ = SEBool False\n\n isNum : Vect 1 SExp -> SExp\n isNum [SENum _] = SEBool True\n isNum _ = SEBool False\n\n -- String/Symbol conversion\n symbolToString : Vect 1 SExp -> SEvalResult\n symbolToString [SESymbol t] = Right $ SEStr t\n symbolToString _ = Left $ \"Expected a symbol\"\n\n stringToSymbol : Vect 1 SExp -> SEvalResult\n stringToSymbol [SEStr s] = Right $ SESymbol s\n stringToSymbol _ = Left $ \"Expected a string\"\n\n -- Numeric\n plusBin' : SExp -> SExp -> SEvalResult\n plusBin' (SENum (SNExactInt x)) (SENum (SNExactInt y)) = Right $ SENum $ SNExactInt $ x + y\n plusBin' _ _ = Left $ \"Expected only numbers\"\n\n plusVar : List SExp -> SEvalResult\n plusVar [] = Right $ SENum $ SNExactInt 0\n plusVar (x :: xs) = do\n w <- plusVar xs\n plusBin' x w\n\n defaultEnv : SEnv\n defaultEnv = MkSEnv $\n insert \"symbol?\" (AFixed 1 ** MkSFFixed (pure . isSymbol)) $\n insert \"list?\" (AFixed 1 ** MkSFFixed (pure . isList)) $\n insert \"vector?\" (AFixed 1 ** MkSFFixed (pure . isVect)) $\n insert \"bool?\" (AFixed 1 ** MkSFFixed (pure . isBool)) $\n insert \"char?\" (AFixed 1 ** MkSFFixed (pure . isChar)) $\n insert \"string?\" (AFixed 1 ** MkSFFixed (pure . isStr)) $\n insert \"number?\" (AFixed 1 ** MkSFFixed (pure . isNum)) $\n insert \"symbol->string\" (AFixed 1 ** MkSFFixed symbolToString) $\n insert \"string->symbol\" (AFixed 1 ** MkSFFixed stringToSymbol) $\n insert \"+\" (AVar ** MkSFVar plusVar) $\n empty\n\n", "meta": {"hexsha": "f7928359c4dd5a61ef54303c047d2c769eb44de2", "size": 6298, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Scheme/Eval.idr", "max_stars_repo_name": "cmcmA20/descheme", "max_stars_repo_head_hexsha": "2392b45acaac6f12491fcafb223482f314218fc6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Scheme/Eval.idr", "max_issues_repo_name": "cmcmA20/descheme", "max_issues_repo_head_hexsha": "2392b45acaac6f12491fcafb223482f314218fc6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Scheme/Eval.idr", "max_forks_repo_name": "cmcmA20/descheme", "max_forks_repo_head_hexsha": "2392b45acaac6f12491fcafb223482f314218fc6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9695431472, "max_line_length": 108, "alphanum_fraction": 0.5822483328, "num_tokens": 1951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6113819591324416, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3413510516332889}} {"text": "module System.Random.SplitMix32\n\nimport System.Random\nimport Data.IORef\n\n||| Generator for splitmix PRNG\nexport\ndata SMGen\n = MkGen\n Bits32 -- seed\n Bits32 -- gamma (odd)\n\n||| Create a SMGen with specific seed and gamma (gamma is forced to be odd)\nexport\nmakeSMGen : Int -> Int -> SMGen\nmakeSMGen seed gamma = MkGen (cast seed) (cast gamma `prim__or_Bits32` 1)\n\n{-\n================\nHelper Functions\n================\n-}\n\nsuccBits32 : Bits32 -> Bits32\nsuccBits32 x = if x == 0xffffffff\n then x\n else x + 1\n\nneg : Bits32 -> Bits32\nneg x = cast $ the Int 0x100000000 - cast x\n\nxor : Bits32 -> Bits32 -> Bits32\nxor = prim__xor_Bits32\n\nand : Bits32 -> Bits32 -> Bits32\nand = prim__and_Bits32\n\nshiftR : Bits32 -> Bits32 -> Bits32\nshiftR = prim__shr_Bits32\n\nm1 : Bits32\nm1 = 0x55555555\n\nm2 : Bits32\nm2 = 0x33333333\n\nm4 : Bits32\nm4 = 0x0f0f0f0f\n\npopCount : Bits32 -> Bits32\npopCount x0 = -- feel free to add this as a primitive\n let x1 = (x0 `shiftR` 1) `and` m1\n x2 = (x1 `and` m2) + ((x1 `shiftR` 2) `and` m2)\n x3 = (x2 + (x2 `shiftR` 4)) `and` m4\n x4 = x3 + (x3 `shiftR` 8)\n x5 = x4 + (x4 `shiftR` 16)\n x6 = x5 + (x5 `shiftR` 32)\n in x6 `and` 0x7f\n\nshiftXor : Bits32 -> Bits32 -> Bits32\nshiftXor n w = w `xor` (w `shiftR` n)\n\nshiftXorMult : Bits32 -> Bits32 -> Bits32 -> Bits32\nshiftXorMult n k w = shiftXor n w * k\n\nmix32 : Bits32 -> Bits32\nmix32 z0 =\n let z1 = shiftXorMult 16 0x85ebca6b z0\n z2 = shiftXorMult 13 0xc2b2ae35 z1\n z3 = shiftXor 16 z2\n in z3\n\nmix32variant13 : Bits32 -> Bits32\nmix32variant13 z0 =\n let z1 = shiftXorMult 16 0x69ad6ccb z0\n z2 = shiftXorMult 13 0xcd9ab5b3 z1\n z3 = shiftXor 16 z2\n in z3\n\nmixGamma : Bits32 -> Bits32\nmixGamma z0 =\n let z1 = mix32variant13 z0 `xor` 1\n n = popCount (z1 `xor` (z1 `shiftR` 1))\n in if n >= 12\n then z1\n else z1 `xor` 0xaaaaaaaa\n\n{-\n==========\nOperations\n==========\n-}\n\n||| Return the next Bits32 and the updated SMGen\nexport\nnextBits32 : SMGen -> (Bits32, SMGen)\nnextBits32 (MkGen seed gamma) = (mix32 seed', MkGen seed' gamma)\n where\n seed' : Bits32\n seed' = seed + gamma\n\n||| Return the next Bits32 in range (lo, hi) inclusive and the updated SMGen\nexport\nnextBits32Range : (Bits32, Bits32) -> SMGen -> (Bits32, SMGen)\nnextBits32Range (lo, hi) = mapFst (+ lo) . nextBits32R (succBits32 $ cast $ the Int (cast hi - cast lo))\n where\n nextBits32R : Bits32 -> SMGen -> (Bits32, SMGen)\n nextBits32R 0 gen0 = (0, snd (nextBits32 gen0))\n nextBits32R range gen0 =\n let t = assert_total prim__mod_Bits32 (neg range) range\n go : Bits64 -> SMGen -> (Bits32, SMGen)\n go m gen = if (the Bits32 $ cast m) < t\n then (the Bits32 $ cast $ m `prim__shr_Bits64` 32, gen)\n else\n let (x, gen') = nextBits32 gen\n m' = the Bits64 $ cast x * cast range\n in go m' gen'\n xgen : (Bits32, SMGen)\n xgen = nextBits32 gen0\n in go (cast $ fst xgen) (snd xgen)\n\n\n||| Return the next Bits64 and the updated SMGen\nexport\nnextBits64 : SMGen -> (Bits64, SMGen)\nnextBits64 gen0 =\n let (bottom, gen1) = nextBits32 gen0\n (top, gen2) = nextBits32 gen1\n in (cast top `prim__shl_Bits64` 32 + cast bottom, gen2)\n\n||| Return the next Int and the updated SMGen\nexport\nnextInt : SMGen -> (Int, SMGen)\nnextInt gen =\n let (bits64, gen') = nextBits64 gen\n in (if bits64 >= 0x7fffffffffffffff\n then negate $ cast $ bits64 + 0x7fffffffffffffff\n else cast bits64\n , gen')\n\n{-\n=========\nSplitting\n=========\n-}\n\n||| Return an unrelated SMGen and the updated SMGen\nexport\nsplitSMGen : SMGen -> (SMGen, SMGen)\nsplitSMGen (MkGen seed gamma) =\n (MkGen seed'' gamma, MkGen (mix32 seed') (mixGamma seed''))\n where\n seed' : Bits32\n seed' = seed + gamma\n seed'' : Bits32\n seed'' = seed + gamma\n\n{-\n==========\nGeneration\n==========\n-}\n\n||| Deterministically create a new SMGen from a seed\nexport\nmkSMGen : Bits32 -> SMGen\nmkSMGen seed = MkGen (mix32 seed) goldenGamma -- different from haskell version \n where\n goldenGamma : Bits32\n goldenGamma = 0x9e3779b9\n\ntheSMGen : IORef SMGen\ntheSMGen = unsafePerformIO $ do\n init <- cast <$> randomRIO (the Int 0, 0xffffffff)\n newIORef (mkSMGen init)\n\n||| Randomly create an SMGen\nexport\nnewSMGen : HasIO io => io SMGen\nnewSMGen = do\n (newThe, new) <- splitSMGen <$> readIORef theSMGen\n writeIORef theSMGen newThe\n pure new", "meta": {"hexsha": "1ed4df8e289f1d2ab280daab9469c59d684d8cdf", "size": 4528, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/System/Random/SplitMix32.idr", "max_stars_repo_name": "Z-snails/idris2splitmix", "max_stars_repo_head_hexsha": "e3236e4427a04851ff428094c87cf50a858a2f0e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/System/Random/SplitMix32.idr", "max_issues_repo_name": "Z-snails/idris2splitmix", "max_issues_repo_head_hexsha": "e3236e4427a04851ff428094c87cf50a858a2f0e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/System/Random/SplitMix32.idr", "max_forks_repo_name": "Z-snails/idris2splitmix", "max_forks_repo_head_hexsha": "e3236e4427a04851ff428094c87cf50a858a2f0e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7431693989, "max_line_length": 104, "alphanum_fraction": 0.6168286219, "num_tokens": 1566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370308082623216, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.33839673647680535}} {"text": "\nimport Data.Vect\n\ndata CopK : Type where\n Nil : CopK\n (::) : (head : Type -> Type) -> (tail : CopK) -> CopK\n\ndata ElemK : (value : (Type -> Type)) -> CopK -> Type where\n Here : ElemK head (head :: tail)\n There : (later : ElemK x xs) -> ElemK x ( y :: xs) \n\nfoo : CopK\nfoo = List :: (Vect 3) :: Maybe :: Nil\n\nx : ElemK Maybe Main.foo \nx = There (There Here)\n", "meta": {"hexsha": "7ee28b8b6c15e4ddb3a6b3e2d896bfcc5e3613f9", "size": 362, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "copk.idr", "max_stars_repo_name": "janschultecom/seo-router", "max_stars_repo_head_hexsha": "5efc13c8abe678c12767f9a7b9fe1d8b47ee0ce1", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-08-20T21:17:24.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-20T21:17:24.000Z", "max_issues_repo_path": "copk.idr", "max_issues_repo_name": "janschultecom/seo-router", "max_issues_repo_head_hexsha": "5efc13c8abe678c12767f9a7b9fe1d8b47ee0ce1", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "copk.idr", "max_forks_repo_name": "janschultecom/seo-router", "max_forks_repo_head_hexsha": "5efc13c8abe678c12767f9a7b9fe1d8b47ee0ce1", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2941176471, "max_line_length": 59, "alphanum_fraction": 0.5662983425, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7025300573952052, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.3375507132661684}} {"text": "||| Dependent sorted maps\n|||\n||| Mostly copied from Data.SortedMap, but with some changes\nmodule Extra.Data.DepMap\n\nimport Decidable.Equality\n\n||| Used to report errors when key lookups don't agree\npublic export\ndata BadKey : (k : Type) -> (Ord k, DecEq k) => Type where\n KeyIsBad : (Ord k, DecEq k)\n => (x : k) -> (y : k)\n -> (compare x y = EQ)\n -> Not (x = y)\n -> BadKey k\n\n-- Multiplicities are very intentional here, I just haven't gotten around to\n-- \"linear\"-izing the rest of the library\ndata Tree : Nat -> (k : Type) -> (k -> Type) -> Type where\n Leaf : (x : k) -> (1 _ : p x) -> Tree Z k p\n Branch2 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S n) k p\n Branch3 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S n) k p\n\nbranch4 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S (S n)) k p\nbranch4 a b c d e f g =\n Branch2 (Branch2 a b c) d (Branch2 e f g)\n\nbranch5 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S (S n)) k p\nbranch5 a b c d e f g h i =\n Branch2 (Branch2 a b c) d (Branch3 e f g h i)\n\nbranch6 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S (S n)) k p\nbranch6 a b c d e f g h i j k =\n Branch3 (Branch2 a b c) d (Branch2 e f g) h (Branch2 i j k)\n\nbranch7 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S (S n)) k p\nbranch7 a b c d e f g h i j k l m =\n Branch3 (Branch3 a b c d e) f (Branch2 g h i) j (Branch2 k l m)\n\nmerge1 :\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree (S n) k p) -> k ->\n (1 _ : Tree (S n) k p) ->\n Tree (S (S n)) k p\nmerge1 a b (Branch2 c d e) f (Branch2 g h i) = branch5 a b c d e f g h i\nmerge1 a b (Branch2 c d e) f (Branch3 g h i j k) = branch6 a b c d e f g h i j k\nmerge1 a b (Branch3 c d e f g) h (Branch2 i j k) = branch6 a b c d e f g h i j k\nmerge1 a b (Branch3 c d e f g) h (Branch3 i j k l m) = branch7 a b c d e f g h i j k l m\n\nmerge2 :\n (1 _ : Tree (S n) k p) -> k ->\n (1 _ : Tree n k p) -> k ->\n (1 _ : Tree (S n) k p) ->\n Tree (S (S n)) k p\nmerge2 (Branch2 a b c) d e f (Branch2 g h i) = branch5 a b c d e f g h i\nmerge2 (Branch2 a b c) d e f (Branch3 g h i j k) = branch6 a b c d e f g h i j k\nmerge2 (Branch3 a b c d e) f g h (Branch2 i j k) = branch6 a b c d e f g h i j k\nmerge2 (Branch3 a b c d e) f g h (Branch3 i j k l m) = branch7 a b c d e f g h i j k l m\n\nmerge3 :\n (1 _ : Tree (S n) k p) -> k ->\n (1 _ : Tree (S n) k p) -> k ->\n (1 _ : Tree n k p) ->\n Tree (S (S n)) k p\nmerge3 (Branch2 a b c) d (Branch2 e f g) h i = branch5 a b c d e f g h i\nmerge3 (Branch2 a b c) d (Branch3 e f g h i) j k = branch6 a b c d e f g h i j k\nmerge3 (Branch3 a b c d e) f (Branch2 g h i) j k = branch6 a b c d e f g h i j k\nmerge3 (Branch3 a b c d e) f (Branch3 g h i j k) l m = branch7 a b c d e f g h i j k l m\n\ntreeLookup : (Ord k, DecEq k) => (x : k) -> Tree n k p -> Either (BadKey k) (Maybe (p x))\ntreeLookup k (Leaf k' v) with (KeyIsBad k k')\n treeLookup k (Leaf k' v) | err with (compare k k')\n treeLookup k (Leaf k' v) | err | EQ with (decEq k k')\n treeLookup k (Leaf k v) | err | EQ | Yes Refl = Right $ Just v\n treeLookup k (Leaf k' v) | err | EQ | No bad = Left $ err Refl bad\n treeLookup k (Leaf k' v) | err | _ = Right Nothing\ntreeLookup k (Branch2 t1 k' t2) =\n if k <= k' then\n treeLookup k t1\n else\n treeLookup k t2\ntreeLookup k (Branch3 t1 k1 t2 k2 t3) =\n if k <= k1 then\n treeLookup k t1\n else if k <= k2 then\n treeLookup k t2\n else\n treeLookup k t3\n\ntreeInsert' : Ord k\n => (x : k) -> p x\n -> Tree n k p\n -> Either (Tree n k p) (Tree n k p, k, Tree n k p)\ntreeInsert' k v (Leaf k' v') =\n case compare k k' of\n LT => Right (Leaf k v, k, Leaf k' v')\n EQ => Left (Leaf k v)\n GT => Right (Leaf k' v', k', Leaf k v)\ntreeInsert' k v (Branch2 t1 k' t2) =\n if k <= k' then\n case treeInsert' k v t1 of\n Left t1' => Left (Branch2 t1' k' t2)\n Right (a, b, c) => Left (Branch3 a b c k' t2)\n else\n case treeInsert' k v t2 of\n Left t2' => Left (Branch2 t1 k' t2')\n Right (a, b, c) => Left (Branch3 t1 k' a b c)\ntreeInsert' k v (Branch3 t1 k1 t2 k2 t3) =\n if k <= k1 then\n case treeInsert' k v t1 of\n Left t1' => Left (Branch3 t1' k1 t2 k2 t3)\n Right (a, b, c) => Right (Branch2 a b c, k1, Branch2 t2 k2 t3)\n else\n if k <= k2 then\n case treeInsert' k v t2 of\n Left t2' => Left (Branch3 t1 k1 t2' k2 t3)\n Right (a, b, c) => Right (Branch2 t1 k1 a, b, Branch2 c k2 t3)\n else\n case treeInsert' k v t3 of\n Left t3' => Left (Branch3 t1 k1 t2 k2 t3')\n Right (a, b, c) => Right (Branch2 t1 k1 t2, k2, Branch2 a b c)\n\ntreeInsert : Ord k\n => (x : k) -> p x\n -> Tree n k p\n -> Either (Tree n k p) (Tree (S n) k p)\ntreeInsert k v t =\n case treeInsert' k v t of\n Left t' => Left t'\n Right (a, b, c) => Right (Branch2 a b c)\n\ndelType : Nat -> (k : Type) -> (k -> Type) -> Type\ndelType Z k p = ()\ndelType (S n) k p = Tree n k p\n\ntreeDelete : Ord k => (n : Nat) -> k -> Tree n k p -> Either (Tree n k p) (delType n k p)\ntreeDelete _ k (Leaf k' v) =\n if k == k' then\n Right ()\n else\n Left (Leaf k' v)\ntreeDelete (S Z) k (Branch2 t1 k' t2) =\n if k <= k' then\n case treeDelete Z k t1 of\n Left t1' => Left (Branch2 t1' k' t2)\n Right () => Right t2\n else\n case treeDelete Z k t2 of\n Left t2' => Left (Branch2 t1 k' t2')\n Right () => Right t1\ntreeDelete (S Z) k (Branch3 t1 k1 t2 k2 t3) =\n if k <= k1 then\n case treeDelete Z k t1 of\n Left t1' => Left (Branch3 t1' k1 t2 k2 t3)\n Right () => Left (Branch2 t2 k2 t3)\n else if k <= k2 then\n case treeDelete Z k t2 of\n Left t2' => Left (Branch3 t1 k1 t2' k2 t3)\n Right () => Left (Branch2 t1 k1 t3)\n else\n case treeDelete Z k t3 of\n Left t3' => Left (Branch3 t1 k1 t2 k2 t3')\n Right () => Left (Branch2 t1 k1 t2)\ntreeDelete (S (S n)) k (Branch2 t1 k' t2) =\n if k <= k' then\n case treeDelete (S n) k t1 of\n Left t1' => Left (Branch2 t1' k' t2)\n Right t1' =>\n case t2 of\n Branch2 a b c => Right (Branch3 t1' k' a b c)\n Branch3 a b c d e => Left (branch4 t1' k' a b c d e)\n else\n case treeDelete (S n) k t2 of\n Left t2' => Left (Branch2 t1 k' t2')\n Right t2' =>\n case t1 of\n Branch2 a b c => Right (Branch3 a b c k' t2')\n Branch3 a b c d e => Left (branch4 a b c d e k' t2')\ntreeDelete (S (S n)) k (Branch3 t1 k1 t2 k2 t3) =\n if k <= k1 then\n case treeDelete (S n) k t1 of\n Left t1' => Left (Branch3 t1' k1 t2 k2 t3)\n Right t1' => Left (merge1 t1' k1 t2 k2 t3)\n else if k <= k2 then\n case treeDelete (S n) k t2 of\n Left t2' => Left (Branch3 t1 k1 t2' k2 t3)\n Right t2' => Left (merge2 t1 k1 t2' k2 t3)\n else\n case treeDelete (S n) k t3 of\n Left t3' => Left (Branch3 t1 k1 t2 k2 t3')\n Right t3' => Left (merge3 t1 k1 t2 k2 t3')\n\ntreeToList : Tree n k p -> List (DPair k p)\ntreeToList = treeToList' (:: [])\n where\n -- explicit quantification to avoid conflation with {n} from treeToList\n treeToList' : {0 n : Nat} -> (DPair k p -> List (DPair k p)) -> Tree n k p -> List (DPair k p)\n treeToList' cont (Leaf k v) = cont (k ** v)\n treeToList' cont (Branch2 t1 _ t2) = treeToList' (:: treeToList' cont t2) t1\n treeToList' cont (Branch3 t1 _ t2 _ t3) = treeToList' (:: treeToList' (:: treeToList' cont t3) t2) t1\n\nexport\ndata DepMap : (k : Type) -> (k -> Type) -> Type where\n Empty : DepMap k p\n M : (n : Nat) -> Tree n k p -> DepMap k p\n\nexport\nempty : DepMap k p\nempty = Empty\n\nexport\nlookup : (Ord k, DecEq k)\n => (x : k)\n -> DepMap k p\n -> Either (BadKey k) (Maybe (p x))\nlookup _ Empty = Right Nothing\nlookup k (M _ t) = treeLookup k t\n\nexport\ninsert : Ord k\n => (x : k) -> p x\n -> DepMap k p\n -> DepMap k p\ninsert k v Empty = M Z (Leaf k v)\ninsert k v (M _ t) =\n case treeInsert k v t of\n Left t' => (M _ t')\n Right t' => (M _ t')\n\nexport\nsingleton : Ord k => (x : k) -> p x -> DepMap k p\nsingleton k v = insert k v empty\n\nexport\ninsertFrom : (Ord k, Foldable f) => f (DPair k p) -> DepMap k p -> DepMap k p\ninsertFrom = flip $ foldl $ flip insert'\n where insert' : DPair k p -> DepMap k p -> DepMap k p\n insert' (k ** v) = insert k v\n\nexport\ndelete : Ord k => k -> DepMap k p -> DepMap k p\ndelete _ Empty = Empty\ndelete k (M Z t) =\n case treeDelete Z k t of\n Left t' => (M _ t')\n Right () => Empty\ndelete k (M (S n) t) =\n case treeDelete (S n) k t of\n Left t' => (M _ t')\n Right t' => (M _ t')\n\nexport\nfromList : Ord k => List (DPair k p) -> DepMap k p\nfromList l = foldl (flip insert') empty l\n where insert' : DPair k p -> DepMap k p -> DepMap k p\n insert' (k ** v) = insert k v\n\nexport\ntoList : DepMap k p -> List (DPair k p)\ntoList Empty = []\ntoList (M _ t) = treeToList t\n\n||| Gets the keys of the map.\nexport\nkeys : DepMap k p -> List k\nkeys = map fst . toList\n\n-- Not really that possible\n-- ||| Gets the values of the map. Could contain duplicates.\n-- export\n-- values : DepMap k v -> List v\n-- values = map snd . toList\n\nexport\nnull : DepMap k p -> Bool\nnull Empty = True\nnull (M _ _) = False\n\ntreeMap : ((x : k) -> a x -> b x) -> Tree n k a -> Tree n k b\ntreeMap f (Leaf k v) = Leaf k (f k v)\ntreeMap f (Branch2 t1 k t2) = Branch2 (treeMap f t1) k (treeMap f t2)\ntreeMap f (Branch3 t1 k1 t2 k2 t3)\n = Branch3 (treeMap f t1) k1 (treeMap f t2) k2 (treeMap f t3)\n\ntreeTraverse : Applicative f\n => ((x : k) -> a x -> f (b x))\n -> Tree n k a\n -> f (Tree n k b)\ntreeTraverse f (Leaf k v) = Leaf k <$> f k v\ntreeTraverse f (Branch2 t1 k t2) =\n Branch2\n <$> treeTraverse f t1\n <*> pure k\n <*> treeTraverse f t2\ntreeTraverse f (Branch3 t1 k1 t2 k2 t3) =\n Branch3\n <$> treeTraverse f t1\n <*> pure k1\n <*> treeTraverse f t2\n <*> pure k2\n <*> treeTraverse f t3\n\n||| Not a Functor, but close enough\n||| Still a functor from the category of Idris endofunctors to Idris tho?\nexport\nmap : ({x : k} -> a x -> b x) -> DepMap k a -> DepMap k b\nmap _ Empty = Empty\nmap f (M n t) = M n (treeMap (\\k, v => f v) t)\n\n||| Not a traversable, but close enough\nexport\ntraverse : Applicative f\n => ({x : k} -> a x -> f (b x))\n -> DepMap k a -> f (DepMap k b)\ntraverse _ Empty = pure Empty\ntraverse f (M n t) = M n <$> treeTraverse (\\k, v => f v) t\n\n||| Merge two maps. When encountering duplicate keys, using a function to\n||| combine the values.\n-- TODO: this could totally have better linearity\nexport\nmergeWith : (Ord k, DecEq k)\n => ({x : k} -> p x -> p x -> p x)\n -> DepMap k p\n -> DepMap k p\n -> Either (BadKey k) (DepMap k p)\nmergeWith f x y = flip insertFrom x <$> traverse go (toList y)\n where go : DPair k p -> Either (BadKey k) (DPair k p)\n go (a ** v) with (lookup a x)\n go (a ** v) | Left bad = Left bad\n go (a ** v) | Right Nothing = Right (a ** v)\n go (a ** v) | Right (Just v') = Right (a ** f v v')\n\n||| Left-biased merge\n-- TODO: lift DecEq requirement? idk\n-- would require a lot of work, so prob not\nmergeLeft : (Ord k, DecEq k)\n => DepMap k p\n -> DepMap k p\n -> Either (BadKey k) (DepMap k p)\nmergeLeft = mergeWith (\\x, y => x)\n", "meta": {"hexsha": "46309240530f5f9d857023ac5e27372a0370dc0d", "size": 11580, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Extra/Data/DepMap.idr", "max_stars_repo_name": "mb64/idris2-extras", "max_stars_repo_head_hexsha": "cc7251c2003d66885c775767dd3a13a193f5b710", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-01-26T13:44:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-06T12:12:17.000Z", "max_issues_repo_path": "Extra/Data/DepMap.idr", "max_issues_repo_name": "mb64/idris2-extras", "max_issues_repo_head_hexsha": "cc7251c2003d66885c775767dd3a13a193f5b710", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Extra/Data/DepMap.idr", "max_forks_repo_name": "mb64/idris2-extras", "max_forks_repo_head_hexsha": "cc7251c2003d66885c775767dd3a13a193f5b710", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.88, "max_line_length": 105, "alphanum_fraction": 0.5544905009, "num_tokens": 4473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863695, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.33720053003063605}} {"text": "module Utils.Bytes\n\nimport Syntax.WithProof\nimport Data.Bits\nimport Data.DPair\nimport Data.Fin\nimport Data.Fin.Extra\nimport Data.Nat\nimport Data.List\nimport Data.Vect\nimport Data.Nat.Factor\nimport Data.Nat.Order.Properties\nimport Utils.Misc\n\nweakenN' : {m : Nat} -> (0 n : Nat) -> Fin m -> Fin (n + m)\nweakenN' n m' = rewrite plusCommutative n m in weakenN n m'\n\nfix_fin : (m : Nat) -> (n : Nat) -> (S m) = n -> S (S (S (S (S (S (S (S (mult m 8)))))))) = mult n 8\nfix_fin m n prf = rewrite sym prf in Refl\n\nexport\nto_le : (FiniteBits a, Cast a Bits8) => {n : _} -> {auto 0 no0 : NonZero n} -> {auto 0 prf : n * 8 = (bitSize {a})} -> a -> Vect n Bits8\nto_le x = let (S m) = n; nmeq = Refl in map (go nmeq x) Fin.range\n where\n go : {m : Nat} -> ((S m) = n) -> a -> Fin (S m) -> Bits8\n go nmeq b i = cast $ shiftR b (bitsToIndex $ coerce prf $ coerce (fix_fin m n nmeq) $ weakenN' 7 $ i * 8)\n\nexport\nto_be : (FiniteBits a, Cast a Bits8) => {n : _} -> {auto 0 no0 : NonZero n} -> {auto 0 prf : n * 8 = (bitSize {a})} -> a -> Vect n Bits8\nto_be = reverse . to_le\n\nexport\nfrom_le : (FiniteBits a, Cast Bits8 a) => {n : _} -> {auto 0 no0 : NonZero n} -> {auto 0 prf : n * 8 = (bitSize {a})} -> Vect n Bits8 -> a\nfrom_le p = let (S m) = n; nmeq = Refl in foldl (.|.) zeroBits $ zipWith (go nmeq) p Fin.range\n where\n go : {m : Nat} -> ((S m) = n) -> Bits8 -> Fin (S m) -> a\n go nmeq b i = shiftL (cast b) (bitsToIndex $ coerce prf $ coerce (fix_fin m n nmeq) $ weakenN' 7 $ i * 8)\n\nexport\nfrom_be : (FiniteBits a, Cast Bits8 a) => {n : _} -> {auto 0 no0 : NonZero n} -> {auto 0 prf : n * 8 = (bitSize {a})} -> Vect n Bits8 -> a\nfrom_be = from_le . reverse\n\nexport\nset_bit_to : Bits a => Bool -> Index {a} -> a -> a\nset_bit_to False _ x = x\nset_bit_to True pos x = setBit x pos\n\nexport\nto_bools_be' : FiniteBits a => (n : Fin (S (bitSize {a}))) -> a -> Vect (finToNat n) Bool\nto_bools_be' FZ x = []\nto_bools_be' (FS wit) x = testBit x (bitsToIndex wit) :: (replace_vect finToNatWeakenNeutral $ to_bools_be' (weaken wit) x)\n\nexport\nto_bools_be : FiniteBits a => a -> Vect (bitSize {a}) Bool\nto_bools_be x = replace_vect finToNatLastIsBound $ to_bools_be' {a = a} Fin.last x\n\nexport\nle_to_integer : Foldable t => t Bits8 -> Integer\nle_to_integer = go . toList\n where\n go : List Bits8 -> Integer\n go v = foldr (.|.) 0 $ zipWith shiftL (cast {to=Integer} <$> v) ((*8) <$> [0..(length v)])\n\nexport\nbe_to_integer : Foldable t => t Bits8 -> Integer\nbe_to_integer = le_to_integer . reverse . toList\n\nexport\ninteger_to_le : (n : Nat) -> Integer -> Vect n Bits8\ninteger_to_le n v = (cast . shiftR v) <$> (((*8) . finToNat) <$> Fin.range)\n\nexport\ninteger_to_be : (n : Nat) -> Integer -> Vect n Bits8\ninteger_to_be n = reverse . integer_to_le n\n\nexport\nto_digit : Bool -> Char\nto_digit False = '0'\nto_digit True = '1'\n\nexport\nshow_bin : FiniteBits a => a -> String\nshow_bin = pack . toList . map to_digit . to_bools_be\n\n||| if 0-15, then return the corresponding hex char\n||| otherwise returns a '?'\nexport\nhex_lower : Bits8 -> Char\nhex_lower 0 = '0'\nhex_lower 1 = '1'\nhex_lower 2 = '2'\nhex_lower 3 = '3'\nhex_lower 4 = '4'\nhex_lower 5 = '5'\nhex_lower 6 = '6'\nhex_lower 7 = '7'\nhex_lower 8 = '8'\nhex_lower 9 = '9'\nhex_lower 10 = 'a'\nhex_lower 11 = 'b'\nhex_lower 12 = 'c'\nhex_lower 13 = 'd'\nhex_lower 14 = 'e'\nhex_lower 15 = 'f'\nhex_lower _ = '?'\n\nexport\nshow_hex : Bits8 -> String\nshow_hex x = strCons (hex_lower (div x 16)) $ strCons (hex_lower (mod x 16)) $ \"\"\n\n||| takes a list of bytes and show them using `show_hex` interspersed by a whitespace\nexport\nxxd : Foldable t => t Bits8 -> String\nxxd = concat . intersperse \" \" . map show_hex . toList\n\nexport\nstring_to_ascii : (x : String) -> List Bits8\nstring_to_ascii = map (cast . ord) . unpack\n\nexport\nascii_to_string : List Bits8 -> String\nascii_to_string = pack . map cast\n\nmaybe_a_a : Lazy a -> Maybe a -> a\nmaybe_a_a a Nothing = Force a\nmaybe_a_a _ (Just a) = a\n\nexport\nshiftL' : FiniteBits a => a -> Nat -> a\nshiftL' x i = maybe_a_a zeroBits $ do\n i' <- natToFin i _\n Just $ shiftL x (bitsToIndex i')\n\nexport\nshiftR' : FiniteBits a => a -> Nat -> a\nshiftR' x i = maybe_a_a zeroBits $ do\n i' <- natToFin i _\n Just $ shiftR x (bitsToIndex i')\n\nexport\nrotl : FiniteBits a => {n : Nat} -> {auto prf : ((S n) = bitSize {a})} -> Fin (S n) -> a -> a\nrotl FZ x = x\nrotl (FS i) x = (shiftL x $ bitsToIndex (coerce prf $ FS i)) .|. (shiftR x $ bitsToIndex $ invFin $ coerce prf $ weaken i)\n\nexport\nrotr : FiniteBits a => {n : Nat} -> {auto prf : ((S n) = bitSize {a})} -> Fin (S n) -> a -> a\nrotr FZ x = x\nrotr (FS i) x = (shiftR x $ bitsToIndex (coerce prf $ FS i)) .|. (shiftL x $ bitsToIndex $ invFin $ coerce prf $ weaken i)\n", "meta": {"hexsha": "21b213230632f8587a0ee45856c7a50ff83465cf", "size": 4677, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Utils/Bytes.idr", "max_stars_repo_name": "octeep/idris2-tls", "max_stars_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_stars_repo_licenses": ["ISC"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-23T15:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T11:00:15.000Z", "max_issues_repo_path": "src/Utils/Bytes.idr", "max_issues_repo_name": "octeep/idris2-tls", "max_issues_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_issues_repo_licenses": ["ISC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Utils/Bytes.idr", "max_forks_repo_name": "octeep/idris2-tls", "max_forks_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_forks_repo_licenses": ["ISC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.389261745, "max_line_length": 139, "alphanum_fraction": 0.6294633312, "num_tokens": 1707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.3371914375474175}} {"text": "module Quantities.SIBaseUnits\n\nimport Quantities.Core\nimport Quantities.SIPrefixes\nimport Quantities.SIBaseQuantities\n\n%default total\n%access public export\n\nMetre : ElemUnit Length\nMetre = MkElemUnit \"m\" 1\nMeter : ElemUnit Length\nMeter = Metre\nM : ElemUnit Length\nM = Meter\n\nCentimetre : Unit Length\nCentimetre = centi Metre\nCentimeter : Unit Length\nCentimeter = Centimetre\nCm : Unit Length\nCm = Centimetre\n\nKilometre : Unit Length\nKilometre = kilo Metre\nKilometer : Unit Length\nKilometer = Kilometre\nKm : Unit Length\nKm = Kilometre\n\nGram : ElemUnit Mass\nGram = MkElemUnit \"g\" 0.001\nG : ElemUnit Mass\nG = Gram\n\nKilogram : Unit Mass\nKilogram = kilo Gram\nKg : Unit Mass\nKg = Kilogram\n\nSecond : ElemUnit Time\nSecond = MkElemUnit \"s\" 1\nS : ElemUnit Time\nS = Second\n\nAmpere : ElemUnit ElectricCurrent\nAmpere = MkElemUnit \"A\" 1\nA : ElemUnit ElectricCurrent\nA = Ampere\n\nKelvin : ElemUnit Temperature\nKelvin = MkElemUnit \"K\" 1\nK : ElemUnit Temperature\nK = Kelvin\n\nMole : ElemUnit AmountOfSubstance\nMole = MkElemUnit \"mol\" 1\nMol : ElemUnit AmountOfSubstance\nMol = Mole\n\nCandela : ElemUnit LuminousIntensity\nCandela = MkElemUnit \"cd\" 1\nCd : ElemUnit LuminousIntensity\nCd = Candela\n", "meta": {"hexsha": "4ad1dc794e53eb2ce2d6b254c6271b67905a297f", "size": 1171, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Quantities/SIBaseUnits.idr", "max_stars_repo_name": "timjb/quantities", "max_stars_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 112, "max_stars_repo_stars_event_min_datetime": "2015-01-18T13:52:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T14:15:46.000Z", "max_issues_repo_path": "Quantities/SIBaseUnits.idr", "max_issues_repo_name": "timjb/quantities", "max_issues_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-04T08:51:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-17T09:52:29.000Z", "max_forks_repo_path": "Quantities/SIBaseUnits.idr", "max_forks_repo_name": "timjb/quantities", "max_forks_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-04-28T23:49:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T17:28:34.000Z", "avg_line_length": 18.0153846154, "max_line_length": 36, "alphanum_fraction": 0.7694278395, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953506426082, "lm_q2_score": 0.5774953651858117, "lm_q1q2_score": 0.33350088841246134}} {"text": "module TypedContainers.In\n\nimport Data.List\nimport Data.List.Elem\nimport Data.DPair\n\n%default total\n\nlemma0 : ([x] = [y]) -> (x = y)\nlemma0 Refl = Refl\n\nlemma1 : {0 xs : List a} -> {0 ys : List a} -> ((x :: xs) = (y :: ys)) -> (xs = ys)\nlemma1 Refl = Refl\n\nlemma2 : {0 xs : List a} -> {0 ys : List a} -> ((x :: xs) = (y :: ys)) -> (x = y)\nlemma2 Refl = Refl\n\npublic export\ndata In : (a -> Bool) -> List a -> Type where\n MkIn : (x : a) -> (f x = True) -> (xs : List a) -> In f (x :: xs)\n MkInCons : (x : a) -> (0 xs : List a) -> In f xs -> In f (x :: xs)\n\npublic export\ninFilter : (f : a -> Bool) -> (g : a -> Bool) -> ((x : a) -> (g x = True) -> f x = True) -> (l : List a) -> In g l -> In g (filter f l)\ninFilter f g p1 [] p2 impossible\ninFilter f g p1 (x :: xs) (MkIn x p2 xs) =\n let p3 = p1 x p2 in\n rewrite p3 in MkIn x p2 (filter f xs) {f = g}\ninFilter f g p1 (x :: xs) (MkInCons x xs p2) =\n let r = inFilter f g p1 xs p2 in\n let MkDPair p2 p3 : DPair Bool (f x ===) = MkDPair (f x) Refl in\n case p2 of\n True => rewrite p3 in MkInCons x (filter f xs) r\n False => rewrite p3 in r\n\nfromFilter : {f : a -> Bool} -> {l : List a} -> {lEq : l' === filter f l} -> Elem x l' -> (f x = True)\nfromFilter (Here {x, xs}) = case l of\n [] impossible\n y :: ys =>\n let (MkDPair p0 p1) : DPair Bool ((f y) ===) = MkDPair (f y) Refl in\n case p0 of\n True =>\n let p2 : (y :: filter f ys = filter f (y :: ys)) = rewrite p1 in Refl in\n let p3 : (x :: xs = y :: filter f ys) = rewrite p2 in lEq in\n let p4 = lemma2 p3 in\n rewrite p4 in p1\n False =>\n let p2 : (filter f ys = filter f (y :: ys)) = rewrite p1 in Refl in\n let p3 : (x :: xs = filter f ys) = rewrite p2 in lEq in\n fromFilter {f, l = ys, lEq = p3} (Here {x, xs})\nfromFilter (There p {x, y, xs}) =\n case l of\n [] impossible\n z :: zs =>\n let (MkDPair p0 p1) : DPair Bool ((f z) ===) = MkDPair (f z) Refl in\n case p0 of\n True =>\n let p2 : (z :: filter f zs = filter f (z :: zs)) = rewrite p1 in Refl in\n let p3 : (y :: xs = z :: filter f zs) = rewrite p2 in lEq in\n let p4 = lemma1 p3 in\n fromFilter {f, lEq = p4} p\n False =>\n let p2 : (filter f zs = filter f (z :: zs)) = rewrite p1 in Refl in\n let p3 : (y :: xs = filter f zs) = rewrite p2 in lEq in\n fromFilter {f, lEq = p3} (There p {x, y, xs})\n\nextractIn' : {f : a -> Bool} -> {g : a -> Bool} -> {l : List a} -> {l' : List a} -> {lEq : l' = filter g l} -> In f l' -> DPair a (\\x => (f x = True, g x = True))\nextractIn' (MkIn x p0 xs) =\n let p1 = Here {x, xs} in\n let p2 = fromFilter {f = g, l, l' = x :: xs, lEq} p1 in\n MkDPair x (p0, p2)\nextractIn' (MkInCons x xs rec) =\n case l of\n [] impossible\n y :: ys =>\n let (MkDPair p2 p3) : DPair Bool ((g y) ===) = MkDPair (g y) Refl in\n case p2 of\n True =>\n let p4 : (y :: filter g ys = filter g (y :: ys)) = rewrite p3 in Refl in\n let p5 : (x :: xs = y :: filter g ys) = rewrite p4 in lEq in\n extractIn' {f, g, l = ys, l' = xs, lEq = lemma1 p5} rec\n False =>\n let p4 : (filter g ys = filter g (y :: ys)) = rewrite p3 in Refl in\n let p5 : (x :: xs = filter g ys) = rewrite p4 in lEq in\n extractIn' {f, g, l = ys, l' = x :: xs, lEq = p5} (MkInCons x xs rec)\n\npublic export\nextractIn : {f : a -> Bool} -> {g : a -> Bool} -> {l : List a} -> In f (filter g l) -> DPair a (\\x => (f x = True, g x = True))\nextractIn = extractIn' {lEq = Refl}\n\noutFilter' : {0 f : a -> Bool} -> {g : a -> Bool} -> (xxs : List a) -> (pl : yys = filter g xxs) -> In f yys -> In f xxs\noutFilter' [] pl (MkIn _ _ _) impossible\noutFilter' [] pl (MkInCons _ _ _) impossible\noutFilter' (x :: xs) pl (MkIn y py ys) with (g x)\n outFilter' (x :: xs) pl (MkIn y py ys) | True =\n let pl' = lemma2 pl in\n let px : (f x = True) = rewrite sym pl' in py in\n MkIn x px xs\n outFilter' (x :: xs) pl (MkIn y py ys) | False = MkInCons x xs $ outFilter' {f, g} xs pl (MkIn {f} y py ys)\noutFilter' (x :: xs) pl (MkInCons y ys py) with (g x)\n outFilter' (x :: xs) pl (MkInCons y ys py) | True = MkInCons x xs $ outFilter' {f, g} xs (lemma1 pl) py\n outFilter' (x :: xs) pl (MkInCons y ys py) | False = MkInCons x xs $ outFilter' {f, g} xs pl (MkInCons y ys py)\n\npublic export\noutFilter : {g : a -> Bool} -> {l : List a} -> In f (filter g l) -> In f l\noutFilter p = outFilter' {f, g} l Refl p\n", "meta": {"hexsha": "c65f30248a0fb20e885118cb203b8e77c0af3a22", "size": 4457, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypedContainers/In.idr", "max_stars_repo_name": "L-as/idris-rbtree", "max_stars_repo_head_hexsha": "1c9bab3c5f54ab431c379bf54cec5b548e09f0d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-08-25T15:48:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-10T05:31:53.000Z", "max_issues_repo_path": "TypedContainers/In.idr", "max_issues_repo_name": "L-as/idris-rbtree", "max_issues_repo_head_hexsha": "1c9bab3c5f54ab431c379bf54cec5b548e09f0d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypedContainers/In.idr", "max_forks_repo_name": "L-as/idris-rbtree", "max_forks_repo_head_hexsha": "1c9bab3c5f54ab431c379bf54cec5b548e09f0d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.6542056075, "max_line_length": 162, "alphanum_fraction": 0.5223244335, "num_tokens": 1725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.33129662141100197}} {"text": "\nmodule NoRegression\n\nimport Data.Vect\n\ndata Dep : (n : Nat) -> (a : Type) -> Vect n a -> Type where\n MkDep : Dep n a v\n\ndpairParse : ( n : Nat\n ** a : Type\n ** v : Vect n a\n ** Dep n a v\n )\ndpairParse = (_ ** _ ** [\"a\", \"b\"] ** MkDep)\n", "meta": {"hexsha": "0755b682fa766315812307919f30d9d43b0b778d", "size": 291, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/perf005/NoRegression.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "idris2/tests/idris2/perf005/NoRegression.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "idris2/tests/idris2/perf005/NoRegression.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 19.4, "max_line_length": 60, "alphanum_fraction": 0.4295532646, "num_tokens": 92, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.32966068415638444}} {"text": "---\npandoc-minted:\nlanguage: idris\n---\n\n= Explosives in Cyberspace\n\n[Link](https://adventofcode.com/2016/day/9)\n\nWandering around a secure area, you come across a datalink port to a new part of\nthe network. After briefly scanning it for interesting files, you find one file\nin particular that catches your attention. It's compressed with an experimental\nformat, but fortunately, the documentation for the format is nearby.\n\nThe format compresses a sequence of characters. Whitespace is ignored. To\nindicate that some sequence should be repeated, a marker is added to the file,\nlike `(10x2)`. To decompress this marker, take the subsequent `10` characters\nand repeat them `2` times. Then, continue reading the file *after* the repeated\ndata. The marker itself is not included in the decompressed output.\n\nIf parentheses or other characters appear within the data referenced by a\nmarker, that's okay - treat it like normal data, not a marker, and then resume\nlooking for markers after the decompressed section.\n\nFor example:\n\n- `ADVENT` contains no markers and decompresses to itself with no changes,\n resulting in a decompressed length of `6`.\n- `A(1x5)BC` repeats only the `B` a total of `5` times, becoming `ABBBBBC` for a\n decompressed length of `7`.\n- `(3x3)XYZ1 becomes `XYZXYZXYZ` for a decompressed length of `9`.\n- `A(2x2)BCD(2x2)EFG` doubles the `BC` and `EF`, becoming `ABCBCDEFEFG` for a\n decompressed length of `11`.\n- `(6x1)(1x3)A` simply becomes `(1x3)A` - the `(1x3)` looks like a marker, but\n because it's within a data section of another marker, it is not treated any\n differently from the A that comes after it. It has a decompressed length of\n `6`.\n- `X(8x2)(3x3)ABCY` becomes `X(3x3)ABC(3x3)ABCY` (for a decompressed length of\n `18`), because the decompressed data from the `(8x2)` marker (the `(3x3)ABC`)\n is skipped and not processed further.\n\n\n== Module Declaration and Imports\n\n> ||| Day 9: Explosives in Cyberspace\n> module Data.Advent.Day09\n\nImport the [generic `Day`\nstructure](https://github.com/yurrriq/advent-of-idris/blob/master/src/Data/Advent/Day.idr),\ninspired by [Steve Purcell Haskell\nsolution](https://github.com/purcell/adventofcode2016).\n\n> import public Data.Advent.Day\n\n\n== Data Types\n\nEnsure both the type and data constructors are\n[exported](http://docs.idris-lang.org/en/latest/tutorial/modules.html#meaning-for-data-types)\nfor all the following data types.\n\n> %access public export\n\nTODO: describe this\n\n> data Block = Seq Nat String (List Block)\n> | Str String\n\n\n== Parsers\n\n> %access private\n>\n> notSpace : Parser Char\n> notSpace = satisfy (not . isSpace)\n\nEnsure the type constructors of the following parsers are\n[exported](http://docs.idris-lang.org/en/latest/tutorial/modules.html#meaning-for-data-types).\n\n> %access export\n>\n> partial block : Parser Block\n> block = go <|>| Str . pack <$> some letter \n> \"a repeated sequence or plain string\"\n> where\n> go = do len <- char '(' *> integer <* char 'x'\n> reps <- fromIntegerNat <$> integer <* char ')'\n> rest <- pack <$> ntimes len notSpace\n> case parse (some block <* eof) rest of\n> Right subBlocks => pure $ Seq reps rest subBlocks\n> Left err => fail err\n\n\n== Part One\n\n\\begin{quote}\n What is the \\textit{decompressed length} of the file (your puzzle input)?\n Don't count whitespace.\n\\end{quote}\n\nTODO: describe this\n\n> partOne : Block -> Nat\n> partOne (Seq n str _) = n * length str\n> partOne (Str str) = length str\n>\n> %default partial\n>\n> namespace PartOne\n>\n> ex : String -> Either String Nat\n> ex str = sum . map partOne <$> parse (some block <* newline) str\n>\n> ex1 : Either String Nat\n> ex1 = ex \"ADVENT\"\n>\n> ex2 : Either String Nat\n> ex2 = ex \"A(1x5)BC\"\n>\n> ex3 : Either String Nat\n> ex3 = ex \"(3x3)XYZ\"\n>\n> ex4 : Either String Nat\n> ex4 = ex \"A(2x2)BCD(2x2)EFG\"\n>\n> ex5 : Either String Nat\n> ex5 = ex \"(6x1)(1x3)A\"\n>\n> ex6 : Either String Nat\n> ex6 = ex \"X(8x2)(3x3)ABCY\"\n\n\n== Part Two\n\nApparently, the file actually uses *version two* of the format.\n\nIn version two, the only difference is that markers within decompressed data\n*are* decompressed. This, the documentation explains, provides much more\nsubstantial compression capabilities, allowing many-gigabyte files to be stored\nin only a few kilobytes.\n\nFor example:\n\n- `(3x3)XYZ` still becomes `XYZXYZXYZ`, as the decompressed section contains no\n markers.\n- `X(8x2)(3x3)ABCY` becomes `XABCABCABCABCABCABCY`, because the decompressed\n data from the `(8x2)` marker is then further decompressed, thus triggering the\n `(3x3)` marker twice for a total of six `ABC` sequences.\n- `(27x12)(20x12)(13x14)(7x10)(1x12)A` decompresses into a string of `A`\n repeated `241920` times.\n- `(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN` becomes `445`\n characters long.\n\nUnfortunately, the computer you brought probably doesn't have enough memory to\nactually decompress the file; you'll have to *come up with another way* to get\nits decompressed length.\n\n\\begin{quote}\n What is the \\textit{decompressed length} of the file\n using this improved format?\n\\end{quote}\n\nTODO: describe this\n\n> partTwo : Block -> Nat\n> partTwo (Seq n _ bs) = n * sum (partTwo <$> bs)\n> partTwo (Str str) = length str\n\n\n== Main\n\n> namespace Main\n>\n> main : IO ()\n> main = runDay $ MkDay 9 (some block <* newline)\n> (pure . show . sum . map partOne)\n> (pure . show . sum . map partTwo)\n", "meta": {"hexsha": "cafc23d1e2a3a42a1b7ba938402a802ab4417546", "size": 5527, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Data/Advent/Day09.lidr", "max_stars_repo_name": "yurrriq/advent-of-code", "max_stars_repo_head_hexsha": "ee83efa138322b5dbbda9f4aeac75481a9cd49fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-11-04T10:32:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-05T07:36:22.000Z", "max_issues_repo_path": "src/Data/Advent/Day09.lidr", "max_issues_repo_name": "yurrriq/aoc19", "max_issues_repo_head_hexsha": "ee83efa138322b5dbbda9f4aeac75481a9cd49fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Data/Advent/Day09.lidr", "max_forks_repo_name": "yurrriq/aoc19", "max_forks_repo_head_hexsha": "ee83efa138322b5dbbda9f4aeac75481a9cd49fe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-26T19:27:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-26T19:27:21.000Z", "avg_line_length": 31.0505617978, "max_line_length": 94, "alphanum_fraction": 0.6947711236, "num_tokens": 1583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6150878414043814, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.329132537402819}} {"text": "module NoDeclaration\n\nidentity : (a : Type) -> a -> a\nidentity _ x = x\n\nidNat = identity Nat\n\ndouble = (S 1 *)\n\ntest : idNat (double 3) === 6\ntest = Refl\n\nunwords : List String -> String\nunwords [] = \"\"\nunwords [x] = x\nunwords (x::xs) = x ++ \" \" ++ unwords xs\n\nhelloWorld = unwords [\"hello\", \"world\"]\n\ntest' : NoDeclaration.helloWorld === \"hello world\"\ntest' = Refl\n\ncat x y = unwords [x, show {ty = Nat} y]\n", "meta": {"hexsha": "10c0b7d0950542aa0606f09da2adfbfd4514a213", "size": 408, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic063/NoDeclaration.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/tests/idris2/basic063/NoDeclaration.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/tests/idris2/basic063/NoDeclaration.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 17.0, "max_line_length": 50, "alphanum_fraction": 0.6078431373, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5736784074525098, "lm_q1q2_score": 0.3291069151772477}} {"text": "|||\nmodule Toolkit.Data.Graph.EdgeBounded.HasMinDegree\n\nimport Decidable.Equality\n\nimport Data.String\nimport Data.List.Elem\nimport Data.List.Quantifiers\n\nimport Toolkit.Decidable.Do\nimport Toolkit.Decidable.Informative\n\nimport Toolkit.Data.Nat\nimport Toolkit.Data.Pair\nimport Toolkit.Data.List.Size\nimport Toolkit.Data.List.Occurs.Does\n\nimport Toolkit.Data.Graph.EdgeBounded\n\nimport public Toolkit.Data.Graph.EdgeBounded.DegreeCommon\n\n%default total\n\nnamespace Out\n\n public export\n HasMinDegreeOut : (v : Nat)\n -> (es : Edges)\n -> (d : Nat)\n -> Type\n HasMinDegreeOut v\n = AtLeast.Occurs (Pair Nat Nat) (IsFirst v)\n\n\n export\n hasMinDegreeOut : (v : Nat)\n -> (es : Edges)\n -> (d : Nat)\n -> DecInfo (Maybe HasDegree.Error)\n (HasMinDegreeOut v es d)\n\n hasMinDegreeOut v es d\n = embed (maybe Nothing (\\x => Just $ MkError v O x))\n (AtLeast.occurs (isFirst v) es d)\n\nnamespace In\n\n public export\n HasMinDegreeIn : (v : Nat)\n -> (es : Edges)\n -> (d : Nat)\n -> Type\n HasMinDegreeIn v\n = AtLeast.Occurs (Pair Nat Nat) (IsSecond v)\n\n export\n hasMinDegreeIn : (v : Nat)\n -> (es : Edges)\n -> (d : Nat)\n -> DecInfo (Maybe HasDegree.Error)\n (HasMinDegreeIn v es d)\n hasMinDegreeIn v es d\n = embed (maybe Nothing (\\x => Just $ MkError v I x))\n (AtLeast.occurs (isSecond v) es d)\n\nnamespace Error\n public export\n data Kind = WrongIN\n | WrongOUT\n | WrongLeafSrcIN\n | WrongLeafSrcOUT\n | WrongLeafSnkIN\n | WrongLeafSnkOUT\n\npublic export\nrecord Error type where\n constructor MkError\n vertex : Vertex type\n kind : Error.Kind\n error : Maybe HasDegree.Error\n\nnamespace Raw\n\n public export\n data ExpDegrees : (v : Vertex type) -> (i,o : Nat) -> Type where\n Node : ExpDegrees (Node d k j i) j i\n Src : ExpDegrees (Leaf d SRC k j) 0 j\n Bsrc : ExpDegrees (Leaf d BI k j) 0 j\n Snk : ExpDegrees (Leaf d SNK k j) j 0\n Bsnk : ExpDegrees (Leaf d BI k j) j 0\n\n public export\n data HasExactDegree : (v : Vertex type)\n -> (es : Edges)\n -> (i,o : Nat)\n -> (exp : ExpDegrees v i o)\n -> Type\n where\n HDN : (din : HasExactDegreeIn v es i)\n -> (dout : HasExactDegreeOut v es o)\n -> HasExactDegree (Node d v i o) es i o Node\n\n HDLS : (din : HasExactDegreeIn v es 0)\n -> (dout : HasExactDegreeOut v es o)\n -> HasExactDegree (Leaf d SRC v o) es 0 o Src\n\n HDLT : (din : HasExactDegreeIn v es i)\n -> (dout : HasExactDegreeOut v es 0)\n -> HasExactDegree (Leaf d SNK v i) es i 0 Snk\n\n HDLBS : (din : HasExactDegreeIn v es 0)\n -> (dout : HasExactDegreeOut v es k)\n -> HasExactDegree (Leaf d BI v k) es 0 k Bsrc\n\n HDLBT : (din : HasExactDegreeIn v es k)\n -> (dout : HasExactDegreeOut v es 0)\n -> HasExactDegree (Leaf d BI v k) es k 0 Bsnk\n\n{-\n\n leafBiAsSrcOutWrong : (HasExactDegreeOut k es o -> Void)\n -> HasExactDegree (Leaf d BI k o) es 0 o Bsrc -> Void\n leafBiAsSrcOutWrong f (HDLBS din dout) = f dout\n\n leafBiAsSrcInWrong : (HasExactDegreeIn k es 0 -> Void)\n -> HasExactDegree (Leaf d BI k o) es 0 o Bsrc -> Void\n leafBiAsSrcInWrong f (HDLBS din dout) = f din\n\n leafBiAsSnkOutWrong : (HasExactDegreeOut k es 0 -> Void)\n -> HasExactDegree (Leaf d BI k o) es o 0 Bsnk -> Void\n leafBiAsSnkOutWrong f (HDLBT din dout) = f dout\n\n leafBiAsSnkInWrong : (HasExactDegreeIn k es o -> Void)\n -> HasExactDegree (Leaf d BI k o) es o 0 Bsnk -> Void\n leafBiAsSnkInWrong f (HDLBT din dout) = f din\n-}\n export\n hasExactDegree : (v : Vertex type)\n -> (exp : ExpDegrees v i o)\n -> (es : Edges)\n -> DecInfo (HasExactDegree.Error type)\n (HasExactDegree v es i o exp)\n{-\n hasExactDegree (Node d k i o) Node es with (hasExactDegreeIn k es i)\n hasExactDegree (Node d k i o) Node es | (Yes pI) with (hasExactDegreeOut k es o)\n hasExactDegree (Node d k i o) Node es | (Yes pI) | (Yes pO)\n = Yes (HDN pI pO)\n hasExactDegree (Node d k i o) Node es | (Yes pI) | (No msg contra)\n = No (MkError (Node d k i o) WrongOUT msg)\n (\\(HDN pI pO) => contra pO)\n\n hasExactDegree (Node d k i o) Node es | (No msg contra)\n = No (MkError (Node d k i o) WrongIN msg)\n (\\(HDN pI pO) => contra pI)\n\n hasExactDegree (Leaf d SRC k o) Src es with (hasExactDegreeIn k es 0)\n hasExactDegree (Leaf d SRC k o) Src es | (Yes pI) with (hasExactDegreeOut k es o)\n hasExactDegree (Leaf d SRC k o) Src es | (Yes pI) | (Yes pO)\n = Yes (HDLS pI pO)\n hasExactDegree (Leaf d SRC k o) Src es | (Yes pI) | (No msg contra)\n = No (MkError (Leaf d SRC k o) WrongOUT msg)\n (\\(HDLS pI pO) => contra pO)\n\n hasExactDegree (Leaf d SRC k o) Src es | (No msg contra)\n = No (MkError (Leaf d SRC k o) WrongIN msg)\n (\\(HDLS pI pO) => contra pI)\n\n hasExactDegree (Leaf d BI k o) Bsrc es with (hasExactDegreeIn k es 0)\n hasExactDegree (Leaf d BI k o) Bsrc es | (Yes pI) with (hasExactDegreeOut k es o)\n hasExactDegree (Leaf d BI k o) Bsrc es | (Yes pI) | (Yes pO)\n = Yes (HDLBS pI pO)\n hasExactDegree (Leaf d BI k o) Bsrc es | (Yes pI) | (No msg contra)\n = No (MkError (Leaf d BI k o) WrongLeafSrcOUT msg)\n (leafBiAsSrcOutWrong contra)\n\n hasExactDegree (Leaf d BI k o) Bsrc es | (No msg contra)\n = No (MkError (Leaf d BI k o) WrongLeafSrcIN msg)\n (leafBiAsSrcInWrong contra)\n\n hasExactDegree (Leaf d SNK k i) Snk es with (hasExactDegreeIn k es i)\n hasExactDegree (Leaf d SNK k i) Snk es | (Yes pI) with (hasExactDegreeOut k es 0)\n hasExactDegree (Leaf d SNK k i) Snk es | (Yes pI) | (Yes pO)\n = Yes (HDLT pI pO)\n hasExactDegree (Leaf d SNK k i) Snk es | (Yes pI) | (No msg contra)\n = No (MkError (Leaf d SNK k i) WrongLeafSnkOUT msg)\n (\\(HDLT pI pO) => contra pO)\n\n hasExactDegree (Leaf d SNK k i) Snk es | (No msg contra)\n = No (MkError (Leaf d SNK k i) WrongLeafSnkIN msg)\n (\\(HDLT pI pO) => contra pI)\n\n hasExactDegree (Leaf d BI k i) Bsnk es with (hasExactDegreeIn k es i)\n hasExactDegree (Leaf d BI k i) Bsnk es | (Yes pO) with (hasExactDegreeOut k es 0)\n hasExactDegree (Leaf d BI k i) Bsnk es | (Yes pO) | (Yes pI)\n = Yes (HDLBT pO pI)\n hasExactDegree (Leaf d BI k i) Bsnk es | (Yes pO) | (No msg contra)\n = No (MkError (Leaf d SNK k i) WrongLeafSnkOUT msg)\n (leafBiAsSnkOutWrong contra)\n\n hasExactDegree (Leaf d BI k i) Bsnk es | (No msg contra)\n = No (MkError (Leaf d SNK k i) WrongLeafSnkIN msg)\n (leafBiAsSnkInWrong contra)\n-}\n{-\npublic export\ndata HasExactDegree : (v : Vertex type) -> (es : Edges) -> Type where\n R : (exp : ExpDegrees v i o)\n -> (prf : HasExactDegree v es i o exp)\n -> HasExactDegree v es\n\n\nbiLeafWrong : (HasExactDegree (Leaf d BI k j) es j 0 Bsnk -> Void)\n -> (HasExactDegree (Leaf d BI k j) es 0 j Bsrc -> Void)\n -> HasExactDegree (Leaf d BI k j) es -> Void\nbiLeafWrong f g (R Bsrc prf) = g prf\nbiLeafWrong f g (R Bsnk prf) = f prf\n\nexport\nhasExactDegree : (v : Vertex type)\n -> (es : Edges)\n -> DecInfo (HasExactDegree.Error type)\n (HasExactDegree v es)\n\nhasExactDegree (Node d k j i) es with (hasExactDegree (Node d k j i) Node es)\n hasExactDegree (Node d k j i) es | (Yes prf)\n = Yes (R Node prf)\n hasExactDegree (Node d k j i) es | (No msg contra)\n = No msg\n (\\(R Node prf) => contra prf)\n\nhasExactDegree (Leaf d SRC k j) es with (hasExactDegree (Leaf d SRC k j) Src es)\n hasExactDegree (Leaf d SRC k j) es | (Yes prf)\n = Yes (R Src prf)\n hasExactDegree (Leaf d SRC k j) es | (No msg contra)\n = No msg\n (\\(R Src prf) => contra prf)\n\nhasExactDegree (Leaf d SNK k j) es with (hasExactDegree (Leaf d SNK k j) Snk es)\n hasExactDegree (Leaf d SNK k j) es | (Yes prf)\n = Yes (R Snk prf)\n hasExactDegree (Leaf d SNK k j) es | (No msg contra)\n = No msg (\\(R Snk prf) => contra prf)\n\nhasExactDegree (Leaf d BI k j) es with (hasExactDegree (Leaf d BI k j) Bsrc es)\n hasExactDegree (Leaf d BI k j) es | (Yes prf)\n = Yes (R Bsrc prf)\n\n hasExactDegree (Leaf d BI k j) es | (No msgi contra) with (hasExactDegree (Leaf d BI k j) Bsnk es)\n hasExactDegree (Leaf d BI k j) es | (No msgi contra) | (Yes prf)\n = Yes (R Bsnk prf)\n\n hasExactDegree (Leaf d BI k j) es | (No msgi contra) | (No msg f)\n = No msg (biLeafWrong f contra)\n-}\n-- [ EOF ]\n", "meta": {"hexsha": "253f4c5e4b5b1c6fd655d88d9c2a89c332ddb76f", "size": 9108, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/Graph/EdgeBounded/HasMinDegree.idr", "max_stars_repo_name": "gallais/linear-circuits", "max_stars_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Toolkit/Data/Graph/EdgeBounded/HasMinDegree.idr", "max_issues_repo_name": "gallais/linear-circuits", "max_issues_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Toolkit/Data/Graph/EdgeBounded/HasMinDegree.idr", "max_forks_repo_name": "gallais/linear-circuits", "max_forks_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.578125, "max_line_length": 100, "alphanum_fraction": 0.5738910848, "num_tokens": 2922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.32828840484027955}} {"text": "infixl 7 <><\n\npublic export\n(<><) : SnocList a -> List a -> SnocList a\nsx <>< [] = sx\nsx <>< (x :: xs) = (sx :< x) <>< xs\n", "meta": {"hexsha": "2579f1e6bbe8f93b3ea4f10da01e5848baaec0ec", "size": 122, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/pretty002/SnocList.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/tests/idris2/pretty002/SnocList.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/tests/idris2/pretty002/SnocList.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 17.4285714286, "max_line_length": 42, "alphanum_fraction": 0.4590163934, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.6224593312018546, "lm_q1q2_score": 0.3282330904745325}} {"text": "module piAutomata\n\nimport tipos\nimport Data.SortedMap\n\n%access public export\n\ncalcAExp : AExp -> Int\ncalcAExp (Sum (N n1) (N n2)) = n1 + n2\ncalcAExp (Sub (N n1) (N n2)) = n1 - n2\ncalcAExp (Div (N n1) (N n2)) = n1 `div` n2\ncalcAExp (Mul (N n1) (N n2)) = n1 * n2\n\ncalcBExp : BExp -> Bool\ncalcBExp (Not (Boo b)) = not b\ncalcBExp (Equal (N n1) (N n2)) = n1 == n2\ncalcBExp (GE (N n1) (N n2)) = n1 >= n2\ncalcBExp (LE (N n1) (N n2)) = n1 <= n2\ncalcBExp (LT (N n1) (N n2)) = n1 < n2\ncalcBExp (GT (N n1) (N n2)) = n1 > n2\ncalcBExp (And (Boo b1) (Boo b2)) = (&&) b1 b2\ncalcBExp (OR (Boo b1) (Boo b2)) = (||) b1 b2\n\ntransforma:Maybe a -> a\ntransforma (Just v) = v\n\n-- retorna o maior Loc da lista de Locs\nmaxList: List Loc -> Int\nmaxList [] = 0\nmaxList (x :: xs) = auxiliar x xs where\n auxiliar: Loc -> List Loc -> Int\n auxiliar (L x) [] = x\n auxiliar x (l :: ls) = if x > l then auxiliar x ls else auxiliar l ls\n\n-- retorna o maior Loc do mapa + 1\ngetLocPlus1FromMap: SortedMap Loc Val -> Loc\ngetLocPlus1FromMap map = L ((maxList (keys map)) + 1)\n\n-- Retorna um stored com a adição de uma nova location como chave e um valor v\nextendStored: SortedMap Loc Val -> Val -> SortedMap Loc Val\nextendStored map v = insert (getLocPlus1FromMap map) (v) map\n\ngetLocFromValBindable: Bindable -> Val\ngetLocFromValBindable (BindLoc x) = ValLoc x\n\n-- Atualiza segundo ambiente com os valores do primeiro, e cria novas chave-valor caso nao exista\n-- ex: addIntersectionNewEnv ([ (ValId \"k\", L 3) , (ValId \"y\", L 4) , (ValId \"z\", L 5)]) ([ (ValId \"x\", L 1) , (ValId \"y\", L 2) , (ValId \"z\", L 3)])\naddIntersectionNewEnv: List (Id,Bindable)-> List (Id,Bindable) -> SortedMap Id Bindable\naddIntersectionNewEnv [] env = fromList env\naddIntersectionNewEnv ( (key,value) :: e) env = addIntersectionNewEnv e (toList (insert key value (fromList env)))\n\n-- deleta todos as chave-valor da memoria dada uma lista de chaves (Loc)\ndeleteLocsStore: List Loc -> SortedMap Loc Val -> SortedMap Loc Val\ndeleteLocsStore [] store = store\ndeleteLocsStore (x :: xs) store = deleteLocsStore xs (delete x store)\n\npushExpsInCtrl : Actuals -> List Ctrl -> List Ctrl\npushExpsInCtrl (Act []) list = list\npushExpsInCtrl (Act (x::xs)) list = pushExpsInCtrl (Act xs) ((CtExp x)::list)\n\ngetCmdFromClosure : Id -> (SortedMap Id Bindable) -> Ctrl\ngetCmdFromClosure id env = let (bindClosure) = lookup id env in case bindClosure of\n Just (BindClos (Clos (f, b, e))) => CtCmd b\n\ngetFormalsFromClosure : Id -> (SortedMap Id Bindable) -> Formals\ngetFormalsFromClosure id env = let (bindClosure) = lookup id env in case bindClosure of\n Just (BindClos (Clos (f, b, e))) => f\n\ngetEnvFromClosure : Id -> (SortedMap Id Bindable) -> (SortedMap Id Bindable)\ngetEnvFromClosure id env = let (bindClosure) = lookup id env in case bindClosure of\n Just (BindClos (Clos (f, b, e))) => e\n\ngetExpsFromListVal: List Val -> Nat -> List Val -> List Val\ngetExpsFromListVal list Z l = reverse l\ngetExpsFromListVal (x::xs) (S tam) l = getExpsFromListVal xs (tam) (x::l)\n\nremoveActuals: Nat -> List Val -> List Val\nremoveActuals Z list = list\nremoveActuals (S tam) (x::xs) = removeActuals tam xs\n\ngetLocFromValLoc: Val -> Loc\ngetLocFromValLoc (ValLoc l) = l\n\nmatch: Formals -> List Val -> SortedMap Id Bindable -> SortedMap Id Bindable\nmatch (Form []) (val::vals) e = empty\nmatch (Form (id::ids)) [] e = empty\nmatch (Form []) [] e = e\nmatch (Form (id::ids)) (val::vals) e = case val of\n ValInt x => let env = insert id (BindInt x) e in match (Form ids) (vals) env\n ValLoc l => let env = insert id (BindLoc l) e in match (Form ids) (vals) env\n\nlookup': Maybe Bindable -> SortedMap Loc Val -> Val\nlookup' (Just (BindLoc loc)) sto = transforma (lookup loc sto)\nlookup' Nothing sto = ValNop\n\ninserir : Maybe Bindable -> Val -> SortedMap Loc Val -> SortedMap Loc Val\ninserir (Just (BindLoc loc)) v stored = insert loc v stored\ninserir Nothing v stored = stored\n\ngetCmdFromRec : Id -> (SortedMap Id Bindable) -> Ctrl\ngetCmdFromRec id env = let (bindRec) = lookup id env in case bindRec of\n Just (BindRec (Rec (f, b, e, e'))) => CtCmd b\n\ngetFormalsFromRec : Id -> (SortedMap Id Bindable) -> Formals\ngetFormalsFromRec id env = let (bindRec) = lookup id env in case bindRec of\n Just (BindRec (Rec (f, b, e, e'))) => f\n\ngetEnv1FromRec : Id -> (SortedMap Id Bindable) -> (SortedMap Id Bindable)\ngetEnv1FromRec id env = let (bindRec) = lookup id env in case bindRec of\n Just (BindRec (Rec (f, b, e, e'))) => e\n\ngetEnv2FromRec : Id -> (SortedMap Id Bindable) -> (SortedMap Id Bindable)\ngetEnv2FromRec id env = let (bindRec) = lookup id env in case bindRec of\n Just (BindRec (Rec (f, b, e, e'))) => e'\n\nreclose : SortedMap Id Bindable -> SortedMap Id Bindable\nreclose env = let list = toList env in recloseAux list where\n recloseAux : List (Id, Bindable) -> SortedMap Id Bindable\n recloseAux [] = empty\n recloseAux (x::[]) = case x of\n ((ValID w), (BindClos (Clos (f, b, e)))) => let env' = insert (ValID w) (BindClos (Clos (f, b, e))) empty in insert (ValID w) (BindRec (Rec (f,b,e, env'))) empty\n ((ValID w), (BindRec (Rec (f,b,e', e'')))) => let env' = insert (ValID w) (BindRec (Rec (f,b,e', e''))) empty in insert (ValID w) (BindRec (Rec (f,b,e', env'))) empty\n (id, b) => insert id b empty\n recloseAux (x::xs) = Data.SortedMap.fromList ((Data.SortedMap.toList (reclose (Data.SortedMap.fromList [x]))) ++ (Data.SortedMap.toList (reclose (Data.SortedMap.fromList xs))))\n\nunfold : SortedMap Id Bindable -> SortedMap Id Bindable\nunfold e = reclose(e)\n\nprocess: (List Ctrl, List Val, SortedMap Id Bindable , SortedMap Loc Val, List Loc) -> List (List Ctrl, List Val, SortedMap Id Bindable , SortedMap Loc Val, List Loc) -> ((List Ctrl, List Val, SortedMap Id Bindable , SortedMap Loc Val, List Loc), List (List Ctrl, List Val, SortedMap Id Bindable , SortedMap Loc Val, List Loc))\n\n-- Stop Case\nprocess ([],[], env, stored, listLoc) list = (([],[], env, stored, listLoc), ([],[], env, stored, listLoc)::list)\n\n-- Aritmetic Expression\nprocess ( (CtExp (AExpR (Sum n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlSum :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (AExpR (Sum n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\n\nprocess ( (CtExp (AExpR (Sub n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlSub :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (AExpR (Sub n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (AExpR (Mul n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlMul :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (AExpR (Mul n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (AExpR (Div n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlDiv :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (AExpR (Div n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (AExpR (N n ))) ::xs , listVal, env, stored, listLoc) (list) = process (xs , ValInt n :: listVal, env, stored, listLoc) (( (CtExp (AExpR (N n ))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlSum)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValInt (calcAExp (Sum (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlSum)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlSub)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValInt (calcAExp (Sub (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlSub)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlMul)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValInt (calcAExp (Mul (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlMul)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlDiv)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValInt (calcAExp (Div (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlDiv)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\n\n-- Boolean Expression\nprocess ( (CtExp (BExpR (Not b))) ::xs , listVal, env, stored, listLoc) (list) = process ( (CtExp (BExpR b)) :: (CtExpOp CtrlNot :: xs) , listVal, env, stored, listLoc) (( (CtExp (BExpR (Not b))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (Equal n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlEq :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (Equal n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (GE n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlGE :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (GE n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (LE n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlLE :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (LE n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (LT n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlLT :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (LT n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (GT n1 n2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (AExpR n1) :: (CtExp (AExpR n2) :: (CtExpOp CtrlGT :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (GT n1 n2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (And b1 b2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (BExpR b1) :: (CtExp (BExpR b2) :: (CtExpOp CtrlAnd :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (And b1 b2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (OR b1 b2))) ::xs , listVal, env, stored, listLoc) (list) = process ((CtExp (BExpR b1) :: (CtExp (BExpR b2) :: (CtExpOp CtrlOR :: xs)) ), listVal, env, stored, listLoc) (( (CtExp (BExpR (OR b1 b2))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (BExpR (Boo b))) ::xs , listVal, env, stored, listLoc) (list) = process (xs , ValBool b :: listVal, env, stored, listLoc) (( (CtExp (BExpR (Boo b))) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlNot) :: xs , (ValBool b) :: restoLista, env, stored, listLoc) (list) = process (xs , ValBool (calcBExp (Not (Boo b))) :: restoLista , env, stored, listLoc) (( (CtExpOp CtrlNot) :: xs , (ValBool b) :: restoLista, env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlEq)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (Equal (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlEq)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlGE)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (GE (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlGE)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlLE)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (LE (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlLE)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlLT)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (LT (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlLT)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlGT)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (GT (N val2) (N val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlGT)::xs , (ValInt val1) :: (ValInt val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlAnd)::xs , (ValBool val1) :: (ValBool val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (And (Boo val2) (Boo val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlAnd)::xs , (ValBool val1) :: (ValBool val2 :: restoLista), env, stored, listLoc)::list)\nprocess ( (CtExpOp CtrlOR)::xs , (ValBool val1) :: (ValBool val2 :: restoLista), env, stored, listLoc) (list) = process (xs, (ValBool (calcBExp (OR (Boo val2) (Boo val1)))) ::restoLista, env, stored, listLoc) (( (CtExpOp CtrlOR)::xs , (ValBool val1) :: (ValBool val2 :: restoLista), env, stored, listLoc)::list)\n\n--Commands\nprocess ( (CtCmd (Assign (ValID c1) c2)) ::xs , listVal, env, stored, listLoc) (list) = process (CtExp c2 ::(CtCmdOp CtrlAssign::xs), ValId c1::listVal, env, stored, listLoc) (( (CtCmd (Assign (ValID c1) c2)) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtExp (AExpR (IdA (ValID c1)) )) ::xs , listVal, env, stored, listLoc) (list) = let loc = lookup (ValID c1) env in case loc of\n Nothing => process ([], listVal, env, stored, listLoc) (list)\n Just (BindLoc l) => process (xs, (lookup' (Just (BindLoc l)) (stored))::listVal, env, stored, listLoc) (( (CtExp (AExpR (IdA (ValID c1)) )) ::xs , listVal, env, stored, listLoc)::list)\n Just (BindInt k) => process (xs, (ValInt k)::listVal, env, stored, listLoc) (( (CtExp (AExpR (IdA (ValID c1)) )) ::xs , listVal, env, stored, listLoc)::list)\n\nprocess ( (CtExp (BExpR (IdB (ValID c1)) )) ::xs , listVal, env, stored, listLoc) (list) = let loc = lookup (ValID c1) env in case loc of\n Nothing => process ([], listVal, env, stored, listLoc) (list)\n Just (BindLoc l) => process (xs, (lookup' (Just (BindLoc l)) (stored))::listVal, env, stored, listLoc) (( (CtExp (BExpR (IdB (ValID c1)) )) ::xs , listVal, env, stored, listLoc)::list)\n Just (BindInt k) => process (xs, (ValInt k)::listVal, env, stored, listLoc) (( (CtExp (BExpR (IdB (ValID c1)) )) ::xs , listVal, env, stored, listLoc)::list)\n\nprocess ( (CtCmd (Loop b c)) ::xs , listVal, env, stored, listLoc) (list) = process (CtExp (BExpR b) ::(CtCmdOp CtrlLoop::xs), ValCmd (Loop b c)::listVal, env, stored, listLoc) (( (CtCmd (Loop b c)) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtCmd (Cond b c1 c2)) ::xs , listVal, env, stored, listLoc) (list) = process (CtExp (BExpR b) ::(CtCmdOp CtrlCond::xs), ValCmd (Cond b c1 c2)::listVal, env, stored, listLoc) (( (CtCmd (Cond b c1 c2)) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtCmd (CSeq c1 c2)) ::xs , listVal, env, stored, listLoc) (list) = process (CtCmd c1::(CtCmd c2::xs), listVal, env, stored, listLoc) (( (CtCmd (CSeq c1 c2)) ::xs , listVal, env, stored, listLoc)::list)\nprocess ( (CtCmd NOP) ::xs, listVal, env, stored, listLoc) (list) = process ( xs, listVal, env, stored, listLoc) (list)\n\nprocess ( (CtCmdOp CtrlAssign :: xs , v1 :: (ValId v2 ::listVal), env, stored, listLoc)) (list) = process (xs, listVal, env, (inserir (lookup (ValID v2) env) (v1) stored), listLoc) (( (CtCmdOp CtrlAssign :: xs , v1 :: (ValId v2 ::listVal), env, stored, listLoc))::list)\nprocess ( (CtCmdOp CtrlLoop :: xs , ValBool True :: (ValCmd (Loop b2 c) :: listVal), env, stored, listLoc)) (list) = process (CtCmd c ::(CtCmd (Loop b2 c)::xs), listVal, env, stored, listLoc) (( (CtCmdOp CtrlLoop :: xs , ValBool True :: (ValCmd (Loop b2 c) :: listVal), env, stored, listLoc))::list)\nprocess ( (CtCmdOp CtrlLoop :: xs , ValBool False :: (ValCmd (Loop b2 c) :: listVal), env, stored, listLoc)) (list) = process (xs, listVal, env, stored, listLoc) (( (CtCmdOp CtrlLoop :: xs , ValBool False :: (ValCmd (Loop b2 c) :: listVal), env, stored, listLoc))::list)\nprocess ( (CtCmdOp CtrlCond :: xs , ValBool True :: (ValCmd (Cond b2 c1 c2) :: listVal), env, stored, listLoc)) (list) = process (CtCmd c1 ::xs, listVal, env, stored, listLoc) (( (CtCmdOp CtrlCond :: xs , ValBool True :: (ValCmd (Cond b2 c1 c2) :: listVal), env, stored, listLoc))::list)\nprocess ( (CtCmdOp CtrlCond :: xs , ValBool False :: (ValCmd (Cond b2 c1 c2) :: listVal), env, stored, listLoc)) (list) = process (CtCmd c2 ::xs, listVal, env, stored, listLoc) (( (CtCmdOp CtrlCond :: xs , ValBool False :: (ValCmd (Cond b2 c1 c2) :: listVal), env, stored, listLoc))::list)\n\n--Declarations\nprocess ( CtExp (Ref exp) :: xs , listVal, env, stored, listLoc) (list) = process (CtExp exp ::(CtExpOp CtrlRef::xs), listVal, env, stored, listLoc) (( CtExp (Ref exp) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtCmd (Blk d c) :: xs , listVal, env, stored, listLoc) (list) = process ( CtDec d :: (CtCmdOp CtrlBlkDec :: (CtCmd c :: (CtCmdOp CtrlBlkCmd::xs))), ValListLoc listLoc :: listVal, env, stored, []) (( CtCmd (Blk d c) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtDec (Bind (ValID x) exp) :: xs , listVal, env, stored, listLoc) (list) = process ( CtExp exp :: (CtDecOp CtrlBind::xs), ValId x ::listVal, env, stored, listLoc) (( CtDec (Bind (ValID x) exp) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtExp (DeRef (ValID x)) :: xs , listVal, env, stored, listLoc) (list) = process ( xs, ( getLocFromValBindable (transforma (lookup (ValID x) env)))::listVal, env, stored, listLoc) (( CtExp (DeRef (ValID x)) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtExp (ValRef (ValID x)) :: xs , listVal, env, stored, listLoc) (list) = process ( xs, (lookup' (Just (BindLoc (getLocFromValLoc (lookup' (lookup (ValID x) env) stored))) ) stored)::listVal, env, stored, listLoc) (( CtExp (ValRef (ValID x)) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtDec (DSeq a b) :: xs , listVal, env, stored, listLoc) (list) = process (CtDec a :: (CtDec b :: xs), listVal, env, stored, listLoc) (( CtDec (DSeq a b) :: xs , listVal, env, stored, listLoc)::list)\n\nprocess ( CtExpOp CtrlRef :: xs , v :: listVal, env, stored, listLoc) (list) = process (xs, ValLoc (getLocPlus1FromMap stored) ::listVal, env, extendStored stored v, getLocPlus1FromMap stored ::listLoc) (( CtExpOp CtrlRef :: xs , v :: listVal, env, stored, listLoc)::list)\nprocess ( CtCmdOp CtrlBlkDec :: xs , ValEnv e :: listVal, env, stored, listLoc) (list) = process (xs, ValEnv env ::listVal, addIntersectionNewEnv (toList e) (toList env), stored, listLoc) (( CtCmdOp CtrlBlkDec :: xs , ValEnv e :: listVal, env, stored, listLoc)::list)\nprocess ( CtCmdOp CtrlBlkCmd :: xs , ValEnv e :: (ValListLoc l :: listVal), env, stored, listLoc) (list) = process (xs, listVal, e, deleteLocsStore listLoc stored, l) (( CtCmdOp CtrlBlkCmd :: xs , ValEnv e :: (ValListLoc l :: listVal), env, stored, listLoc)::list)\nprocess ( CtDecOp CtrlBind :: xs , ValLoc l :: (ValId w :: (ValEnv e :: listVal)), env, stored, listLoc) (list) = process (xs, ValEnv (insert (ValID w) (BindLoc l) (e)) ::listVal, env, stored, listLoc) (( CtDecOp CtrlBind :: xs , ValLoc l :: (ValId w :: (ValEnv e :: listVal)), env, stored, listLoc)::list)\nprocess ( CtDecOp CtrlBind :: xs , ValLoc l :: (ValId w :: listVal), env, stored, listLoc) (list) = process (xs, ValEnv (insert (ValID w) (BindLoc l) (empty)) ::listVal, env, stored, listLoc) (( CtDecOp CtrlBind :: xs , ValLoc l :: (ValId w :: listVal), env, stored, listLoc)::list)\nprocess ( CtDecOp CtrlBind :: xs , ValInt n :: (ValId w :: (ValEnv e :: listVal)), env, stored, listLoc) (list) = process (xs, ValEnv (insert (ValID w) (BindInt n) (e)) ::listVal, env, stored, listLoc) (( CtDecOp CtrlBind :: xs , ValInt n :: (ValId w :: (ValEnv e :: listVal)), env, stored, listLoc)::list)\nprocess ( CtDecOp CtrlBind :: xs , ValInt n :: (ValId w :: listVal), env, stored, listLoc) (list) = process (xs, ValEnv (insert (ValID w) (BindInt n) (empty)) ::listVal, env, stored, listLoc) (( CtDecOp CtrlBind :: xs , ValInt n :: (ValId w :: listVal), env, stored, listLoc)::list)\n\n--Abstractions\nprocess ( CtDec (BindF (ValID x) abs) :: xs , listVal, env, stored, listLoc) (list) = process ( CtAbs abs :: (CtDecOp CtrlBindF::xs), ValId x ::listVal, env, stored, listLoc) (( CtDec (BindF (ValID x) abs) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtAbs (Abstr f c) :: xs , listVal, env, stored, listLoc) (list) = process (xs, ValClos (Clos (f,c, env))::listVal, env, stored, listLoc) (( CtAbs (Abstr f c) :: xs , listVal, env, stored, listLoc)::list)\nprocess ( CtCmd (Call id (Act listExp)) :: xs , listVal, env, stored, listLoc) (list) = process ((pushExpsInCtrl (Act listExp) ((CtCmdOp (CtrlCall id (Prelude.List.length listExp)))::xs)), listVal, env, stored, listLoc) (( CtCmd (Call id (Act listExp)) :: xs , listVal, env, stored, listLoc)::list)\n\nprocess ( CtDecOp CtrlBindF :: xs , ValClos cls :: (ValId w :: listVal), env, stored, listLoc) (list) = process (xs, ValEnv (insert (ValID w) (BindClos cls) (empty)) ::listVal, env, stored, listLoc) (( CtDecOp CtrlBindF :: xs , ValClos cls :: (ValId w :: listVal), env, stored, listLoc)::list)\nprocess ( CtCmdOp (CtrlCall id tam)::xs , listVal, env, stored, listLoc) (list) = let e = toList env in case e of\n (((ValID w), (BindClos (Clos (f, b, e))))::l) => process ((getCmdFromClosure id env)::((CtCmdOp CtrlBlkCmd)::xs), ValEnv env :: (ValListLoc listLoc:: (removeActuals tam listVal) ), addIntersectionNewEnv ( Data.SortedMap.toList (match (getFormalsFromClosure id env) (getExpsFromListVal (listVal) (tam) ([]) ) empty) ) ( Data.SortedMap.toList (addIntersectionNewEnv (Data.SortedMap.toList (getEnvFromClosure id env)) (Data.SortedMap.toList env)) ) , stored, []) (( CtCmdOp (CtrlCall id tam)::xs , listVal, env, stored, listLoc)::list)\n (((ValID w), (BindRec (Rec (f,b,e', e''))))::l) => process ((getCmdFromRec id env)::((CtCmdOp CtrlBlkCmd)::xs), ValEnv env :: (ValListLoc listLoc:: (removeActuals tam listVal) ), addIntersectionNewEnv ( Data.SortedMap.toList (match (getFormalsFromRec id env) (getExpsFromListVal (listVal) (tam) ([]) ) empty) ) (Data.SortedMap.toList (addIntersectionNewEnv (Data.SortedMap.toList (unfold (getEnv2FromRec id env))) ( Data.SortedMap.toList (addIntersectionNewEnv (Data.SortedMap.toList (getEnv1FromRec id env)) (Data.SortedMap.toList env)) ))) , stored, []) (( CtCmdOp (CtrlCall id tam)::xs , listVal, env, stored, listLoc)::list)\n\nprocess ( CtDec (Rbnd (ValID x) (Abstr f c)) :: xs , listVal, env, stored, listLoc) (list) = process ( xs, ValEnv (unfold (insert (ValID x) (BindClos (Clos (f, c, env))) empty)) ::listVal, env, stored, listLoc) (( CtDec (Rbnd (ValID x) (Abstr f c)) :: xs , listVal, env, stored, listLoc)::list)\n", "meta": {"hexsha": "160124cb9ecc1c5f3f2f6ebe8ebc46edae632968", "size": 23046, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/piAutomata.idr", "max_stars_repo_name": "RonaldCamp/ImpCompiler", "max_stars_repo_head_hexsha": "b7690dd0bffc97be52f0e64f8e8dead1f240fb87", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-15T03:36:44.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-13T22:38:30.000Z", "max_issues_repo_path": "src/piAutomata.idr", "max_issues_repo_name": "RonaldCamp/ImpCompiler", "max_issues_repo_head_hexsha": "b7690dd0bffc97be52f0e64f8e8dead1f240fb87", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-04-15T03:44:40.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-09T23:51:29.000Z", "max_forks_repo_path": "src/piAutomata.idr", "max_forks_repo_name": "RonaldCamp/ImpCompiler", "max_forks_repo_head_hexsha": "b7690dd0bffc97be52f0e64f8e8dead1f240fb87", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-15T03:46:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-15T03:46:13.000Z", "avg_line_length": 107.1906976744, "max_line_length": 630, "alphanum_fraction": 0.6572941074, "num_tokens": 8216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.6297746074044134, "lm_q1q2_score": 0.3271813365706012}} {"text": "||| Spec: https://webassembly.github.io/spec/core/valid/types.html#block-types\nmodule WebAssembly.Validation.Types.BlockTypes\n\nimport WebAssembly.Structure\nimport WebAssembly.Validation.Conventions\n\n-------------------------------------------------------------------------------\n-- Validation Rules\n-------------------------------------------------------------------------------\n\n||| Valid blocks\npublic export\ndata ValidBlockType : Context -> BlockType -> FuncType -> Type where\n ||| Proof that a BlockType is valid for some given type-index\n |||\n ||| C.types[typeidx] = functype\n |||-----------------------------------\n ||| C ⊢ typeidx : functype\n |||\n MkValidTypeIdxBlock : (c : Context) -> (i : TypeIdx)\n -> {auto in_bounds: InBounds i (types c)}\n -> ValidBlockType c (BlockTypeTypeIdx i) (index i (types c))\n ||| Proof that a BlockType without result-type is valid\n |||\n |||-------------------------------------\n ||| C ⊢ [] : [] -> []\n |||\n MkValidBlockWithoutResult : (c : Context) -> ValidBlockType c BlockTypeEmpty ([] ->> [])\n ||| Proof that a BlockType with some result-type is valid\n |||\n |||-------------------------------------\n ||| C ⊢ [valtype] : [] -> [valtype]\n |||\n MkValidBlockWithResult : (c : Context) -> (t : ValType) -> ValidBlockType c (BlockTypeSingelton t) ([] ->> [t])\n\n-------------------------------------------------------------------------------\n-- Type Inference\n-------------------------------------------------------------------------------\n\n||| If the typeIndex is not present in the context, the block is invalid\ntotal\ntypeidx_out_of_bounds : (c : Context) -> (i : TypeIdx)\n -> (out_of_bounds: InBounds i (types c) -> Void)\n -> ValidBlockType c (BlockTypeTypeIdx i) ft\n -> Void\ntypeidx_out_of_bounds c i out_of_bounds (MkValidTypeIdxBlock c i {in_bounds}) = out_of_bounds in_bounds\n\n||| If the typeIndex is not present in the context, no type can be inferred\ntotal\ntypeidx_out_of_bounds2 : (c : Context) -> (i : TypeIdx)\n -> (out_of_bounds: InBounds i (types c) -> Void)\n -> (ft ** ValidBlockType c (BlockTypeTypeIdx i) ft)\n -> Void\ntypeidx_out_of_bounds2 c i out_of_bounds (x ** pf) = typeidx_out_of_bounds c i out_of_bounds pf\n\n\n||| Infer the FuncType of some BlockType\ntotal public export\ninferBlockType : (c : Context)\n -> (bt : BlockType)\n -> Dec (ft ** ValidBlockType c bt ft)\ninferBlockType c BlockTypeEmpty = Yes $ ([] ->> [] ** MkValidBlockWithoutResult c)\ninferBlockType c (BlockTypeSingelton vt) = Yes $ ([] ->> [vt] ** MkValidBlockWithResult c vt)\ninferBlockType c (BlockTypeTypeIdx i) = case inBounds i (types c) of\n No out_of_bounds => No $ typeidx_out_of_bounds2 c i out_of_bounds\n Yes in_bounds => Yes $ ((index i (types c)) ** MkValidTypeIdxBlock c i)\n\n-------------------------------------------------------------------------------\n-- Type Checking\n-------------------------------------------------------------------------------\n\n||| The bounds-proof does not affect the result of the index-function\ntotal\nindex_proof_irrelevant : {i : TypeIdx, a : Type, xs : List a}\n -> (prfA : InBounds i xs)\n -> (prfB: InBounds i xs)\n -> (index i xs {ok = prfA}) = (index i xs {ok = prfB})\nindex_proof_irrelevant InFirst InFirst = Refl\nindex_proof_irrelevant (InLater prfA') (InLater prfB') = index_proof_irrelevant prfA' prfB'\n\n||| If the FuncType in the context does not match the expected FuncType,\n||| the block is invalid.\ntotal\ncheck_failed : (c : Context) -> (i : TypeIdx)\n -> {auto prfA : InBounds i (types c)}\n -> ((ft = index i (types c)) -> Void)\n -> ValidBlockType c (BlockTypeTypeIdx i) ft -> Void\ncheck_failed {prfA} c i contra (MkValidTypeIdxBlock c i {in_bounds=prfB}) = contra (rewrite index_proof_irrelevant prfA prfB in Refl)\n\n||| If the expected type does not match the actual type, the check fails\ntotal\nvaltype_without_result_check_failed : (contra : (ft = ([] ->> [])) -> Void) -> ValidBlockType c BlockTypeEmpty ft -> Void\nvaltype_without_result_check_failed contra (MkValidBlockWithoutResult c) = contra Refl\n\n||| If the expected type does not match the actual type, the check fails\ntotal\nvaltype_with_result_check_failed : (contra : (ft = ([] ->> [vt])) -> Void) -> ValidBlockType c (BlockTypeSingelton vt) ft -> Void\nvaltype_with_result_check_failed contra (MkValidBlockWithResult c vt) = contra Refl\n\n||| Typecheck a BlockType\ntotal public export\ncheckBlockType : (c : Context)\n -> (bt : BlockType)\n -> (ft : FuncType) \n -> Dec (ValidBlockType c bt ft)\ncheckBlockType c BlockTypeEmpty ft = case decEq ft ([] ->> []) of\n No contra => No (valtype_without_result_check_failed contra)\n Yes Refl => Yes $ MkValidBlockWithoutResult c\ncheckBlockType c (BlockTypeSingelton vt) ft = case decEq ft ([] ->> [vt]) of\n No contra => No (valtype_with_result_check_failed contra)\n Yes Refl => Yes $ MkValidBlockWithResult c vt\ncheckBlockType c (BlockTypeTypeIdx i) ft = case inBounds i (types c) of\n No out_of_bounds => No $ typeidx_out_of_bounds c i out_of_bounds\n Yes in_bounds => case decEq ft (index i (types c)) of\n No contra => No (check_failed c i contra)\n Yes Refl => Yes $ MkValidTypeIdxBlock c i\n", "meta": {"hexsha": "33568c856256383e2a6692863612517a74f0c56f", "size": 5226, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "WebAssembly/Validation/Types/BlockTypes.idr", "max_stars_repo_name": "RaoulSchaffranek/idris-webassembly", "max_stars_repo_head_hexsha": "ce77f5a5b612aad85eefe2374d22456d7d1edbb5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-07T16:03:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-07T16:03:42.000Z", "max_issues_repo_path": "WebAssembly/Validation/Types/BlockTypes.idr", "max_issues_repo_name": "RaoulSchaffranek/idris-webassembly", "max_issues_repo_head_hexsha": "ce77f5a5b612aad85eefe2374d22456d7d1edbb5", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WebAssembly/Validation/Types/BlockTypes.idr", "max_forks_repo_name": "RaoulSchaffranek/idris-webassembly", "max_forks_repo_head_hexsha": "ce77f5a5b612aad85eefe2374d22456d7d1edbb5", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.6666666667, "max_line_length": 133, "alphanum_fraction": 0.607347876, "num_tokens": 1371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.5039061705290806, "lm_q1q2_score": 0.32642951928381064}} {"text": "module Flexidisc.Record.Endo\n\nimport Flexidisc.RecordContent\nimport public Flexidisc.Record.Type\n\n%default total\n%access export\n\n\n||| Update a row at a given `Row`, can change its type.\n|||\n||| Complexity is _O(n)_\n|||\n||| @ xs the record\n||| @ loc the proof that the row is in it\n||| @ f the update function\nupdateByLabel : (xs : Record k header) -> (loc : Row query a header) ->\n (f : a -> a) ->\n Record k header\nupdateByLabel (Rec xs nub) (R loc) f =\n rewrite sym (changeWithSameTypeIsUnchanged loc) in\n Rec (update xs loc f) (changeValuePreservesNub nub)\n\n||| Update a row at a given `Row`, can change its type.\n|||\n||| Complexity is _O(n)_\n|||\n||| @ query the row name\n||| @ xs the record\n||| @ loc the proof that the row is in it\n||| @ f the update function\nupdate : (query : k) -> (f : a -> a) -> (xs : Record k header) ->\n {auto loc : Row query a header} ->\n Record k header\nupdate _ f xs {loc} = updateByLabel xs loc f\n\n||| Replace a row, can change its type\n|||\n||| Complexity is _O(n)_\n|||\n||| @ xs the record\n||| @ loc the proof that the row is in it\n||| @ new the new value for the row\nsetByLabel : (xs : Record k header) -> (loc : Row query ty header) ->\n (new : ty) ->\n Record k header\nsetByLabel xs loc = updateByLabel xs loc . const\n\n||| Update a row, the update can change the row type.\n|||\n||| Complexity is _O(n)_\n|||\n||| @ query the row name\n||| @ xs the record\n||| @ loc the proof that the row is in it\n||| @ new the new value for the row\nset : (query : k) -> (new : ty) -> (xs : Record k header) ->\n {auto loc : Row query ty header} ->\n Record k header\nset _ new xs {loc} = updateByLabel xs loc (const new)\n", "meta": {"hexsha": "88bd0b50e805cb1b2de4055411a0f0b50e9e0e36", "size": 1760, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Flexidisc/Record/Endo.idr", "max_stars_repo_name": "berewt/flexidisc", "max_stars_repo_head_hexsha": "8a0c367244229be5d417c04588d8d41b6030dba2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-02T09:51:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-03T05:15:49.000Z", "max_issues_repo_path": "src/Flexidisc/Record/Endo.idr", "max_issues_repo_name": "LIST-LUXEMBOURG/flexidisc", "max_issues_repo_head_hexsha": "f5a9cdc81554359e324b64400d8479494cd45a8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Flexidisc/Record/Endo.idr", "max_forks_repo_name": "LIST-LUXEMBOURG/flexidisc", "max_forks_repo_head_hexsha": "f5a9cdc81554359e324b64400d8479494cd45a8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8524590164, "max_line_length": 71, "alphanum_fraction": 0.5954545455, "num_tokens": 526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804478040617, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.32629315447128954}} {"text": "module Parsers\n{-\nParsing is the conversion of input, say a list of characters or a string,\nto structured data, if the input is of the appropriate form. We implement here\nthe idea of _combinator parsing_, where we build parsers from basic ones by\ncombining and transforming parsers.\n\nThis allows us to parse relatively complex languages with a small amount of code.\nBetter still, even the code to enable this is small (at least provided we do not\naddress issues of efficiency and error messages).\n-}\n\n%access public export\n\n{- The result of parsing, either consuming some input and generating a result\nwith type `a` as well as the rest of the input, or reporting that parsing failed.\n-}\ndata ParseResult : Type -> Type where\n Success : {a: Type} -> (result : a) -> (rest: List Char) -> ParseResult a\n Failed : {a: Type} -> ParseResult a\n\n-- A parser, which takes input and gives a result (plus unconsumed input)\nParser: Type -> Type\nParser a = (List Char) -> ParseResult a\n\n-- A helper method\nparseChars : {a: Type} -> Parser a -> List Char -> ParseResult a\nparseChars p xs = p xs\n\n-- A helper that allows giving a string as method to parse: the most user-friendly method\nparse : {a: Type} -> Parser a -> String -> ParseResult a\nparse p s = parseChars p (unpack s)\n\n-- A parser that checks if a character satisfies a predicate and returns it.\ncharPred : (Char -> Bool) -> Parser Char\ncharPred p l = (case l of\n [] => Failed\n (x :: xs) =>\n if (p x) then (Success x xs) else Failed)\n\n-- A parser matching a specific character\ncharLit : Char -> Parser Char\ncharLit c = charPred (\\x => x == c)\n\n{- Given a parser `p` for type `a` and a function `f: a -> b` gives a parser for type `b`;\nthis succeeds if `p` succeeds, and the result for type `b` is obtained by applying `f`\nto the result of `p`\n-}\nmap : {a: Type} -> {b: Type} -> Parser a -> (a -> b) -> Parser b\nmap p f cs = (case (p cs) of\n (Success result rest) => Success (f result) rest\n Failed => Failed)\n\n{- Given parsers `p` for type `a` and `q` for type `b`, returns a parser which\nparses the input on `a`, and if this succeeds parses the rest with `q`. A success\nis where both parses succeed, and the result is the pair of results.\n-}\n(++) : {a : Type} -> {b: Type} -> Parser a -> Parser b -> Parser (Pair a b)\n(++) p q l = (case p l of\n (Success result1 rest1) =>\n (case (q rest1) of\n (Success result2 rest2) => Success ((result1, result2)) rest2\n Failed => Failed)\n Failed => Failed)\n\n\n{- A parser that matches a list of characters, e.g. [`l`, `e`, `t`]. This means\nthe input should begin with this. This could have been reursively implemented\nwith `charLit` and `(++)` instead.\n-}\ncharsLit: (List Char) -> Parser (List Char)\ncharsLit [] l = Success [] l\ncharsLit (x :: xs) [] = Failed\ncharsLit (x :: xs) (a :: bs) =\n (case charLit x (a :: bs) of\n (Success result1 rest) => (case (charsLit xs bs) of\n (Success result2 rest) => Success (result1 :: result2) rest\n Failed => Failed)\n Failed => Failed)\n\n\n-- A parser matching a string, e.g. \"let\"\nS: String -> Parser String\nS s = map (charsLit (unpack s)) pack\n\n{- Given two parsers `p` and `q` for type `a`, tries to parse with `p` and, if this fails,\ntries to parse with `q`.\n-}\n(||) : {a: Type} -> Parser a -> Parser a -> Parser a\n(||) p q l = (case (p l) of\n (Success result rest) => Success result rest\n Failed => q l)\n\n-- recursive helper for `rep` method.\nrepParse: {a: Type} -> Parser a -> (inp: List Char) -> (accum: List a) -> ParseResult (List a)\nrepParse p inp accum = case (p inp) of\n (Success result rest) => repParse p rest (result :: accum)\n Failed => Success accum inp\n\n-- helper for `rep` method\nrepRev : {a: Type} -> Parser a -> Parser (List a)\nrepRev p l = repParse p l []\n\n{- Given a parser `p`, returns a new parser that matches 0 or more\nmatches for `p` and returns a list of successful matches\n-}\nrep : {a: Type} -> Parser a -> Parser (List a)\nrep p = map (repRev p) reverse\n\n{- Given a parser `p`, returns a new parser that matches 1 or more\nmatches for `p` and returns a list of successful matches\n-}\nrep1 : {a: Type} -> Parser a -> Parser (List a)\nrep1 p = map (p ++ (repRev p)) (\\pair => (case pair of\n (a, b) => a:: reverse(b)))\n\n-- Helper: given the digits of a natural number from the list of digits from right to left\nnatFromRev : List Char -> Nat -> Nat\nnatFromRev [] n = 0\nnatFromRev (x :: xs) n =\n let\n d : Nat = n * cast( (ord x) - (ord '0'))\n in\n d + (natFromRev xs (10 * n))\n\n-- Given the digits of a natural number, returns the number.\nnatFromChars : (List Char) -> Nat\nnatFromChars l = natFromRev (reverse l) 1\n\n-- Parser to return a (literal) natural number, e.g. \"231\" -> 231\nnat : Parser Nat\nnat = map (rep1 (charPred isDigit)) (natFromChars)\n\n-- Parser checking if al input is consumed.\neof : Parser Unit\neof [] = Success () []\neof (x :: xs) = Failed\n\n-- Given a parser `p` for type `a` and a predicate\nfilter : {a: Type} -> Parser a -> (a -> Bool) -> Parser a\nfilter p pred l = case p l of\n (Success result rest) =>\n if pred result then Success result rest else Failed\n Failed => Failed\n\ninfix 10 +>\n\n-- Like (++) but drops the second matched term\n(+>) : {a : Type} -> {b: Type} -> Parser a -> Parser b -> Parser a\n(+>) p q l = (case p l of\n (Success result1 rest1) => (case (q rest1) of\n (Success result2 rest2) => Success result1 rest2\n Failed => Failed)\n Failed => Failed)\n\ninfix 11 <+\n\n-- Like (++) but drops the first matched term\n(<+) : {a : Type} -> {b: Type} -> Parser a -> Parser b -> Parser b\n(<+) p q l = (case p l of\n (Success result1 rest1) => (case (q rest1) of\n (Success result2 rest2) => Success result2 rest2\n Failed => Failed)\n Failed => Failed)\n\n{- Given a parser `p` for type `a` and a character `c`, matches for 1 or more\nmatches for `p` separated by `c`\n-}\nrepSep: {a: Type} -> Parser a -> Char -> Parser (List a)\nrepSep p c =\n map((p +> (charLit c)) ++ (repSep p c))(\n \\pair => (case pair of\n (x, ys) => x :: ys)) || map(p)(\\n => n ::[])\n\n{- Given a parser `p`, returns a parser that allows spaces before and after the match\n-}\npad : {a: Type} -> Parser a -> Parser a\npad p = rep(S \" \") <+ p +> rep(S \" \")\n\n-- Parses a string with spaces allowed before and after\nSS : String -> Parser String\nSS s = pad (S s)\n\n{- Given a parser `p` for type `a` and a character `c`, matches for 1 or more\nmatches for `p` separated by `c`, allowing spaces before and after `c`\n-}\nrepSepTrim: {a: Type} -> Parser a -> Char -> Parser (List a)\nrepSepTrim p c =\n map((p +> (pad(charLit c))) ++ (repSepTrim p c))(\n \\pair => (case pair of\n (x, ys) => x :: ys)) || map(p)(\\n => n ::[])\n\n{- The mutual block is a typical example of parsing: parsers for arithmetic\nexpressions involving + and * and parenthesis with the usual precedence,\ncalculating the resulting natural number\n-}\nmutual\n -- A simple term: a literal natural number or an expression in parenthesis\n simpleTerm : Parser Nat\n simpleTerm = nat || ( (SS \"(\") <+ expression +> (SS \")\") )\n\n -- A product of simple terms, possibly with just one simple term\n term : Parser Nat\n term = map(repSepTrim simpleTerm '*')(foldl(*)(1))\n\n -- A sum of terms, possibly with just one term\n expression: Parser Nat\n expression = map(repSepTrim term '+')(foldl(+)(0))\n\n{- Combining parsers to allow dependence on context. Concretely, given\n * A parser `p` for type `a`\n * A function `parsers` from `a` to parsers of type `b`\n We get a parser for type `b`. Namely, the parser `p` is applied to the input.\n If this succeeds with result `x: a`, the parser `q = parsers x` is applied to the\n rest of the input.\n-}\nflatMapWithNext : {a : Type} -> {b: Type} -> Parser a -> (a -> Parser b) -> Parser b\nflatMapWithNext p parsers input =\n case p input of\n (Success result1 rest1) => (case (parsers result1) rest1 of\n (Success result2 rest) => Success result2 rest\n Failed => Failed)\n Failed => Failed\n\n{- Given a parser `p` for type `a` and a function `f: a -> Maybe b` gives a parser for type `b`;\nif `p` succeeds with result `x` and `f x = Just y`, then the parse is successful with result y;\nall other cases fail\n-}\nmapMaybe : {a : Type} -> {b: Type} -> Parser a -> (a -> Maybe b) -> Parser b\nmapMaybe p f s = case p s of\n (Success result rest) =>\n (case f result of\n Nothing => Failed\n (Just b) => Success b rest)\n Failed => Failed\n\n-- matches a letter\nletter: Parser Char\nletter = charPred (\\x => 'a' <= x && x <= 'z')\n", "meta": {"hexsha": "d4caf35338d05524363ebc9d294beae2f4d52230", "size": 9358, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Parsers.idr", "max_stars_repo_name": "anotherArka/LTS2019", "max_stars_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-01-16T18:03:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T16:28:41.000Z", "max_issues_repo_path": "Code/Parsers.idr", "max_issues_repo_name": "anotherArka/LTS2019", "max_issues_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2019-01-08T11:22:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-21T10:26:10.000Z", "max_forks_repo_path": "Code/Parsers.idr", "max_forks_repo_name": "anotherArka/LTS2019", "max_forks_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2019-01-08T05:56:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-31T03:58:00.000Z", "avg_line_length": 38.9916666667, "max_line_length": 96, "alphanum_fraction": 0.5816413764, "num_tokens": 2498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.32609275617109024}} {"text": "|||\n|||\n||| Module : Context.idr\n||| Copyright : (c) Jan de Muijnck-Hughes\n||| License : see LICENSE\n|||\nmodule Toolkit.DeBruijn.Context\n\nimport Decidable.Equality\n\nimport Data.DPair\nimport Data.Singleton\n\nimport Toolkit.Decidable.Informative\n\nimport Toolkit.Data.List.AtIndex\nimport Toolkit.Data.DList\nimport Toolkit.Data.DList.AtIndex\n\nimport Toolkit.DeBruijn.Context.Item\n\n%default total\n\n-- A reverse cons operator.\ninfixr 6 +=\n\nnamespace List\n ||| Append `x` to the head of `xs`.\n public export\n (+=) : List a -> a -> List a\n (+=) xs x = x :: xs\n\npublic export\nContext : (kind : Type) -> (types : List kind) -> Type\nContext kind = DList kind Item\n\nexport\nextend : (ctxt : Context kind types)\n -> (label : String)\n -> (type : kind)\n -> Context kind (types += type)\nextend ctxt label type\n = I label type :: ctxt\n\nexport\n(+=) : (ctxt : Context kind types)\n -> (label : String)\n -> (type : kind)\n -> Context kind (types += type)\n(+=) = extend\n\n||| A quantifier over the context that the given predicate holds.\n|||\n||| This is modelled after De Bruijn indices, and the underlying\n||| quantifier is `Any`.\n|||\npublic export\ndata Exists : (kind : Type)\n -> (pred : (type : kind) -> Type)\n -> (key : String)\n -> {types : List kind}\n -> (ctxt : Context kind types)\n -> Type\n where\n E : {ctxt : Context kind types}\n -> {pred : (type : kind) -> Type}\n -> (type : kind)\n -> (item : Item type)\n -> (prf : pred type)\n -> {loc : Nat}\n -> (locC : HoldsAtIndex kind Item (Holds kind pred key) ctxt loc)\n -> (locN : AtIndex type types loc)\n -> Exists kind pred key ctxt\n\nexport\ndeBruijn : {ctxt : Context kind types}\n -> (prf : Exists kind pred key ctxt)\n -> (type ** DPair Nat (AtIndex type types))\ndeBruijn (E type item prf locC locN)\n = (type ** _ ** locN)\n\nnamespace Exists\n public export\n data Error type = NotFound\n | NotSatisfied type\n\nisEmpty : Exists kind pred key [] -> Void\nisEmpty (E _ _ _ (Here x) _) impossible\nisEmpty (E _ _ _ (There contra later) _) impossible\n\nnotLater : (Holds kind pred key h -> Void)\n -> (Exists kind pred key t -> Void)\n -> Exists kind pred key (h :: t)\n -> Void\nnotLater f g (E type item prf (Here x) locN) = f x\nnotLater f g (E type item prf (There contra later) (There x)) = g (E type item prf later x)\n\nexport\nexists : {kind : Type}\n -> {types : List kind}\n -> {pred : (type : kind) -> Type}\n -> (func : (type : kind) -> DecInfo err (pred type))\n -> (key : String)\n -> (ctxt : Context kind types)\n -> DecInfo (Exists.Error err)\n (Exists kind pred key ctxt)\n\nexists f _ []\n = No NotFound\n isEmpty\nexists f key (head :: tail) with (holds f key head)\n exists f key ((I str x) :: tail) | (Yes (H prfK prf))\n = Yes (E _ (I str x) prf (Here (H prfK prf)) Here)\n\n exists f key (head :: tail) | (No msg contra) with (exists f key tail)\n exists f key (head :: tail) | (No msg contra) | (Yes (E type item prf locC locN))\n = Yes (E type item prf (There contra locC) (There locN))\n\n -- [ Note ]\n --\n -- we need to ensure that the 'correct' error message has been satisfied.\n exists f key (head :: tail) | (No (NotSatisfied x) contra) | (No msgR contraR)\n = No (NotSatisfied x)\n (notLater contra contraR)\n exists f key (head :: tail) | (No (WrongName x y) contra) | (No msgR contraR)\n = No msgR\n (notLater contra contraR)\n\n\nnamespace Lookup\n\n public export\n IsBound : {kind : Type}\n -> {types : List kind}\n -> (key : String)\n -> (ctxt : Context kind types)\n -> Type\n IsBound {kind} str ctxt\n = Exists kind Singleton\n str\n ctxt\n\n single : (item : kind)\n -> DecInfo () (Singleton item)\n single item = Yes (Val item)\n\n\n export\n lookup : {kind : Type}\n -> {types : List kind}\n -> (str : String)\n -> (ctxt : Context kind types)\n -> DecInfo (Exists.Error ())\n (IsBound str ctxt)\n lookup = exists single\n\n-- [ EOF ]\n", "meta": {"hexsha": "776e1eb54abdf5b03b177ed0e7445cf9ee4626a1", "size": 4273, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/DeBruijn/Context.idr", "max_stars_repo_name": "border-patrol/linear-circuits", "max_stars_repo_head_hexsha": "e6eb41dc07830d2e337acfad5b087fcc81479aa9", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-11-29T17:20:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T21:41:44.000Z", "max_issues_repo_path": "src/Toolkit/DeBruijn/Context.idr", "max_issues_repo_name": "border-patrol/linear-circuits", "max_issues_repo_head_hexsha": "e6eb41dc07830d2e337acfad5b087fcc81479aa9", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Toolkit/DeBruijn/Context.idr", "max_forks_repo_name": "border-patrol/linear-circuits", "max_forks_repo_head_hexsha": "e6eb41dc07830d2e337acfad5b087fcc81479aa9", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-09T19:49:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T19:49:11.000Z", "avg_line_length": 27.0443037975, "max_line_length": 91, "alphanum_fraction": 0.5604961385, "num_tokens": 1199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5467381667555714, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3240334503561457}} {"text": "{--\nCopyright 2021 Joel Berkeley\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n--}\n||| This module contains the `Tensor` object, an array of values of arbitrary type, along with a\n||| number of functions operating on numeric `Tensor`s.\nmodule Tensor\n\nimport Data.Vect\nimport Data.Vect.Elem\nimport Decidable.Equality\n\nimport Error\nimport public Primitive\nimport public Types\nimport Util\nimport XLA.Client.XlaBuilder\nimport XLA.Literal\n\n----------------------------- core definitions ----------------------------\n\n||| A `Tensor` is a symbolic value, which may refer to either to a scalar value or array of values,\n||| though the runtime representation will likely contain more than its value, and will depend on\n||| the specific backend.\n|||\n||| @shape The `Tensor` shape.\n||| @dtype The element type.\nexport\ndata Tensor : (0 shape : Shape {rank}) -> (0 dtype : Type) -> Type where\n MkTensor : RawTensor -> Tensor shape dtype\n\n||| Construct a `Tensor` from `Array` data.\nexport\nconst : Primitive dtype => {shape : _} -> Array shape {dtype} -> Tensor shape dtype\nconst xs = MkTensor $ const {rank=length shape} (rewrite lengthCorrect shape in xs)\n\n||| Evaluate a `Tensor`, returning its value as an `Array`.\nexport\neval : Primitive dtype => {shape : _} -> Tensor shape dtype -> IO $ Array shape {dtype}\neval (MkTensor raw) = eval raw\n\n||| Return a string representation of an unevaluated `Tensor`, detailing all enqueued operations.\n||| Useful for debugging.\nexport\ntoString : Tensor shape dtype -> IO String\ntoString (MkTensor raw) = toString raw\n\n||| A mutable tensor. That is, a tensor that can be modified in-place.\n|||\n||| We can do this in Idris with linearity. Linearity is offered by quantitative type theory*, which\n||| allows us to guarantee that a value is used at run time either never (erased), once (linear), or\n||| more. In-place mutation traditionally suffers from the problem that you have to reason about\n||| what state a value is in in a series of computations: whether it has been mutated and how. For\n||| example, in the following pseudo-code,\n|||\n||| ```\n||| a = 1\n||| a += 1\n||| b = f(a)\n||| ```\n|||\n||| We have to be aware of whether `a` was modified between its initialization and its use in the\n||| calculation of `b`. This problem is solved by simply defining a new variable, as\n|||\n||| ```\n||| a = 1\n||| a' = a + 1\n||| b = f(a')\n||| ```\n|||\n||| but this doesn't provide the same performance benefits of in-place mutation. The conundrum is\n||| (at least largely) solved with linear types, because you can require that the action of mutating\n||| a value \"uses it up\" such that the previous reference to it cannot be used any more. In the\n||| first example, the mutation `a += 1` would use up `a` and we wouldn't be able to use it in the\n||| construction of `b`, so the problem no longer exists.\n|||\n||| In order to ensure `Variable` is only used as a linear type, it is accessible only via the\n||| function `var`.\n|||\n||| *See http://www.type-driven.org.uk/edwinb\n|||\n||| @shape The `Variable` shape.\n||| @dtype The element type.\nexport\ndata Variable : (0 shape : Shape) -> (0 dtype : Type) -> Type where\n MkVariable : Primitive dtype => Array shape {dtype=dtype} -> Variable shape dtype\n\n||| Provides access to a linear `Variable` with initial contents `arr`. For example:\n|||\n||| ```idris\n||| addOne : (1 v : Variable [] Double) -> Variable [] Double\n||| addOne v = v += const {shape=[]} 1\n|||\n||| three : Tensor [] Double\n||| three = var 2.0 $ \\v => freeze $ addOne v\n||| ```\n|||\n||| @arr The initial contents of the `Variable`.\n||| @f A function which uses the `Variable`. The return value of `f` is returned by `var`.\nvar : Primitive dtype =>\n Array shape {dtype=dtype} -> (1 f : (1 v : Variable shape dtype) -> a) -> a\nvar arr f = f (MkVariable arr)\n\n||| Convert a `Variable` to a `Tensor`.\nfreeze : (1 _ : Variable shape dtype) -> Tensor shape dtype\n\n----------------------------- structural operations ----------------------------\n\n||| Get the `idx`-th row from a tensor. For example, `index 1 $ const [[1, 2], [3, 4], [5, 6]]`\n||| is equivalent to `const [3, 4]`.\n|||\n||| @idx The row to fetch.\nexport\nindex : (idx : Fin d) -> Tensor (d :: ds) dtype -> Tensor ds dtype\n\n||| Split a `Tensor` along the first axis at the specified index. For example,\n||| `split 1 const [[1, 2], [3, 4], [5, 6]]` is equivalent to\n||| `(const [[1, 2]], const [[3, 4], [5, 6]])`.\n|||\n||| @idx The index of the row at which to split the `Tensor`. The row with index `idx` in\n||| the input `Tensor` will appear in the result as the first row in the second `Tensor`.\nexport\nsplit : (idx : Nat) -> Tensor ((idx + rest) :: tl) dtype\n -> (Tensor (idx :: tl) dtype, Tensor (rest :: tl) dtype)\n\n||| Concatenate two `Tensor`s along their first axis. For example,\n||| `concat (const [[1, 2], [3, 4]]) (const [[5, 6]])` is equivalent to\n||| `const [[1, 2], [3, 4], [5, 6]]`.\nexport\nconcat : Tensor (n :: tl) dtype -> Tensor (m :: tl) dtype -> Tensor ((n + m) :: tl) dtype\n\n||| Add a dimension of length one at the specified `axis`. The new dimension will be at the\n||| specified axis in the new `Tensor` (as opposed to the original `Tensor`). For example,\n||| `expand 1 $ const [[1, 2], [3, 4], [5, 6]]` is equivalent to\n||| `const [[[1, 2]], [[3, 4]], [[5, 6]]]`.\nexport\nexpand :\n (axis : Fin (S rank)) -> Tensor {rank=rank} shape dtype -> Tensor (insertAt axis 1 shape) dtype\n\n||| Tranpose the last two axes of a tensor. For example, `(const [[1, 2], [3, 4]]).T` is equivalent\n||| to `const [[1, 3], [2, 4]]`.\nexport\n(.T) : forall shape, dtype . Tensor shape dtype ->\n let leading = init (init shape)\n m = last (init shape)\n n = last shape\n in Tensor (leading ++ [n, m]) dtype\n\n||| Cast the tensor elements to a new data type.\nexport\ncast_dtype : Cast dtype dtype' => Tensor shape dtype -> Tensor shape dtype'\n\n||| Construct a diagonal tensor from the specified value, where all off-diagonal elements are zero.\n||| For example, `the (Tensor [2, 2] Double) (diag 3)` is equivalent to\n||| `const [[3.0, 0.0], [0.0, 3.0]]`.\nexport\ndiag : Num dtype => Tensor [] dtype -> Tensor [n, n] dtype\n\n||| A `DimBroadcastable from to` proves that a dimension of size `from` can be broadcast to a\n||| dimension of size `to`.\npublic export\ndata DimBroadcastable : (0 from : Nat) -> (0 to : Nat) -> Type where\n ||| Proof that any dimension can be broadcast to itself. For example in shapes `[2, 3]` to\n ||| `[2, 3]`.\n Same : DimBroadcastable x x\n\n ||| Proof that a dimension of length one can be broadcast to any size. For example in shapes\n ||| `[2, 1]` to `[2, 3]`\n Stack : DimBroadcastable 1 _\n\n ||| Proof that any dimension can be broadcast to zero. For example in shapes `[2, 3]` to `[2, 0]`.\n Zero : DimBroadcastable _ 0\n\nnamespace Broadcastable\n ||| A `Broadcastable from to` constitutes proof that the shape `from` can be broadcast to the\n ||| shape `to`.\n public export\n data Broadcastable : (0 from : Shape) -> (0 to : Shape) -> Type where\n ||| Proof that a shape can be broadcast to itself. For example:\n |||\n ||| [] to []\n ||| [3, 4] to [3, 4]\n |||\n ||| Implementation note: we could have used `Broadcast [] []`, which would have resulted in more\n ||| atomic constructors for `Broadcastable`, but the author guesses that this implementation helps\n ||| the type checker avoid applications of `Match`.\n Same : Broadcastable x x\n\n ||| Proof that a dimension of size `f` can be broadcast to size `t` if these dimensions\n ||| are `DimBroadcastable f t`. For example:\n |||\n ||| [2, 3] to [2, 3]\n ||| [2, 1] to [2, 3]\n ||| [2, 1] to [2, 0]\n Match : {0 from, to : Shape {rank=r}}\n -> {auto 0 _ : DimBroadcastable f t}\n -> Broadcastable from to\n -> Broadcastable (f :: from) (t :: to)\n\n ||| Proof that broadcasting can add outer dimensions i.e. nesting. For example:\n |||\n ||| [3] to [1, 3]\n ||| [3] to [5, 3]\n Nest : Broadcastable f t -> Broadcastable f (_ :: t)\n\nempty : Primitive dtype => {shape : Shape} -> {auto isEmpty : Elem 0 shape} -> Tensor shape dtype\nempty = const (emptyArray shape) where\n emptyArray : (shape : _) -> {auto isEmpty : Elem Z shape} -> Array shape\n emptyArray {isEmpty = Here} (0 :: _) = []\n emptyArray {isEmpty = (There _)} (d :: ds) = replicate d (emptyArray ds)\n\n||| Broadcast a `Tensor` to a new compatible shape. For example,\n|||\n||| ```idris\n||| x : Tensor [2, 3] Double\n||| x = broadcast (const [4, 5, 6])\n||| ```\n|||\n||| is equivalent to\n|||\n||| ```idris\n||| x : Tensor [2, 3] Double\n||| x = const [[4, 5, 6], [4, 5, 6]]\n||| ```\nexport\nbroadcast : Primitive dtype => {from : _} -> {to : _} -> {auto prf : Broadcastable from to}\n -> Tensor from dtype -> Tensor to dtype\nbroadcast xs = case (isElem 0 to, toList from == toList to) of\n (Yes _, False) => empty\n _ =>\n let from_prf = lengthCorrect from\n to_prf = lengthCorrect to in\n rewrite sym to_prf in impl {fr=length from} {tr=length to} {tt=length to} []\n (rewrite to_prf in to) (rewrite from_prf in xs)\n {prf=rewrite to_prf in rewrite from_prf in prf}\n\n where\n impl : {fr, tr : _} -> {from : Shape {rank=fr}} -> {to : Shape {rank=tr}}\n -> {tl, tt : _} -> (to_leading : Vect tl Nat) -> (to_trailing : Vect tt Nat)\n -> {auto prf : Broadcastable from to_trailing} -> Tensor from dtype -> Tensor to dtype\n impl to_leading _ {prf=Same} (MkTensor raw) =\n MkTensor $ if (length to_leading == 0) then raw else broadcast raw to_leading\n impl {fr = (S r)} to_leading (th' :: tt') {prf=(Match _)} (MkTensor raw) =\n MkTensor $ broadcast (broadcastInDim raw (th' :: tt') (range (S r))) to_leading\n impl to_leading (th' :: tt') {prf=(Nest _)} xs = impl (to_leading ++ [th']) tt' xs\n\nscalarToAnyOk : (to : Shape) -> Broadcastable [] to\nscalarToAnyOk [] = Same\nscalarToAnyOk (_ :: xs) = Nest (scalarToAnyOk xs)\n\nnamespace Squeezable\n ||| A `Squeezable from to` constitutes proof that the shape `from` can be squeezed to the\n ||| shape `to`. Squeezing is the process of removing any number of dimensions of length one.\n public export\n data Squeezable : (0 from : Shape) -> (0 to : Shape) -> Type where\n ||| Proof that a shape can be squeezed to itself. For example:\n |||\n ||| [] to []\n ||| [3, 4] to [3, 4]\n Same : Squeezable x x\n\n ||| Proof that any dimensions (including those of length 1) can be preserved in the process of\n ||| squeezing. For example:\n |||\n ||| ...\n Match : Squeezable from to -> Squeezable (x :: from) (x :: to)\n\n ||| Proof that any dimensions of length one can be squeezed out. For example:\n |||\n ||| [1, 3, 1, 1, 4] to [3, 4]\n Nest : Squeezable from to -> Squeezable (1 :: from) to\n\n||| Remove dimensions of length one from a `Tensor` such that it has the desired shape. For example:\n|||\n||| ```idris\n||| x : Tensor [2, 1, 3, 1] Double\n||| x = const [[[[4], [5], [6]]], [[[7], [8], [9]]]]\n|||\n||| y : Tensor [2, 1, 3] Double\n||| y = squeeze x\n||| ```\n|||\n||| is equivalent to\n|||\n||| ```idris\n||| y : Tensor [2, 1, 3] Double\n||| y = const [[[4, 5, 6]], [[7, 8, 9]]]\n||| ```\nexport\nsqueeze : {auto 0 _ : Squeezable from to} -> Tensor from dtype -> Tensor to dtype\n\n||| A `Tensor` where every element has the specified value. For example,\n|||\n||| ```idris\n||| fives : Tensor [2, 3] Int\n||| fives = fill 5\n||| ```\n||| is equivalent to\n||| ```idris\n||| fives : Tensor [2, 3] Int\n||| fives = const [[5, 5, 5], [5, 5, 5]]\n||| ```\nexport\nfill : Primitive dtype => {shape : _} -> dtype -> Tensor shape dtype\nfill = broadcast {prf=scalarToAnyOk shape} . const\n\n----------------------------- numeric operations ----------------------------\n\ninfix 6 ==#, /=#\n\n||| Element-wise equality. For example, `const [1, 2] ==# const [1, 3]` is equivalent to\n||| `const [True, False]`.\nexport\n(==#) : Eq dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape Bool\n(MkTensor l) ==# (MkTensor r) = MkTensor (eq l r)\n\n||| Element-wise inequality. For example, `const [1, 2] /=# const [1, 3]` is equivalent to\n||| `const [False, True]`.\nexport\n(/=#) : Eq dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape Bool\n(MkTensor l) /=# (MkTensor r) = MkTensor (ne l r)\n\ninfix 6 <#, >#, <=#, >=#\n\n||| Element-wise less than. For example, `const [1, 2, 3] <# const [2, 2, 2]` is equivalent to\n||| `const [True, False, False]`.\nexport\n(<#) : Ord dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape Bool\n(MkTensor l) <# (MkTensor r) = MkTensor (lt l r)\n\n||| Element-wise greater than. For example, `const [1, 2, 3] ># const [2, 2, 2]` is equivalent to\n||| `const [False, False, True]`.\nexport\n(>#) : Ord dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape Bool\n(MkTensor l) ># (MkTensor r) = MkTensor (gt l r)\n\n||| Element-wise less than or equal. For example, `const [1, 2, 3] <=# const [2, 2, 2]` is\n||| equivalent to `const [True, True, False]`.\nexport\n(<=#) : Ord dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape Bool\n(MkTensor l) <=# (MkTensor r) = MkTensor (le l r)\n\n||| Element-wise greater than or equal. For example, `const [1, 2, 3] >=# const [2, 2, 2]` is\n||| equivalent to `const [False, True, True]`.\nexport\n(>=#) : Ord dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape Bool\n(MkTensor l) >=# (MkTensor r) = MkTensor (ge l r)\n\n-- see https://www.python.org/dev/peps/pep-0465/#precedence-and-associativity\ninfixl 9 @@\n\n||| Matrix multiplication. The tensors are contracted along the last axis of the first tensor and\n||| the first axis of the last tensor. For example:\n|||\n||| ```idris\n||| x : Tensor [2, 3] Double\n||| x = const [[-1, -2, -3], [0, 1, 2]]\n|||\n||| y : Tensor [3, 1] Double\n||| y = const [[4, 0, 5]]\n|||\n||| z : Tensor [2, 1] Double\n||| z = x @@ y\n||| ```\n|||\n||| is equivalent to\n|||\n||| ```idris\n||| z : Tensor [2, 1] Double\n||| z = const [-19, 10]\n||| ```\nexport\n(@@) : Num dtype => Tensor l dtype -> Tensor (S n :: tail') dtype ->\n {auto 0 _ : last l = S n} -> Tensor (init l ++ tail') dtype\n\n||| Element-wise addition. For example, `const [1, 2] + const [3, 4]` is equivalent to\n||| `const [4, 6]`.\nexport\n(+) : Num dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape dtype\n(MkTensor ll_raw) + (MkTensor rr_raw) = MkTensor (add ll_raw rr_raw)\n\n||| Element-wise negation. For example, `- const [1, -2]` is equivalent to `const [-1, 2]`.\nexport\nnegate : Neg dtype => Tensor shape dtype -> Tensor shape dtype\n\n||| Element-wise subtraction. For example, `const [3, 4] - const [4, 2]` is equivalent to\n||| `const [-1, 2]`.\nexport\n(-) : Neg dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape dtype\n\ninfixl 9 *#, /#\n\n||| Elementwise multiplication. For example, `const [2, 3] *# const [4, 5]` is equivalent to\n||| `const [8, 15]`.\nexport\n(*#) : Num dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape dtype\n(MkTensor l) *# (MkTensor r) = MkTensor (mul l r)\n\n||| Multiplication by a constant. For example, `const 2 * const [3, 5]` is equivalent to\n||| `const [6, 10]`.\nexport\n(*) : (Primitive dtype, Num dtype) => Tensor [] dtype -> {shape : _} -> Tensor shape dtype\n -> Tensor shape dtype\nl * r = (broadcast {prf=scalarToAnyOk shape} l) *# r\n\n||| Elementwise floating point division. For example, `const [2, 3] /# const [4, 5]` is equivalent to\n||| `const [0.5, 0.6]`.\nexport\n(/#) : Fractional dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape dtype\n\n||| Floating point division by a constant. For example, `const [3.4, -5.6] / const 2` is equivalent\n||| to `const [1.7, -2.8]`.\nexport\n(/) : Fractional dtype => Tensor shape dtype -> Tensor [] dtype -> Tensor shape dtype\n\ninfixr 9 ^\n\n-- todo we don't support complex yet\n||| Each element in `base` raised to the power of the corresponding element in `exponent`.\n||| example, `const [2, 25, -9] ^ const [3, -0.5, 0.5]` is equivalent to `const [8, 0.2, 3i]`.\n|||\n||| Note: The first root is used.\nexport\n(^) : Num dtype => Tensor shape dtype -> Tensor shape dtype -> Tensor shape dtype\n\n-- todo\n||| The element-wise natural exponential.\nexport\nexp : Tensor shape Double -> Tensor shape Double\n\ninfix 8 +=\ninfix 8 -=\ninfix 8 *=\ninfix 8 //=\n\n||| Element-wise in-place addition. It is in-place in the sense that the value in memory is mutated\n||| in-place. However, since the function is linear its `Variable`, you must still use the result to\n||| get the updated value. For example:\n|||\n||| ```idris\n||| addOne : (1 v : Variable [] Double) -> Variable [] Double\n||| addOne v = v += const {shape=[]} 1\n||| ```\n|||\n||| Other than the fact that it works on a `Variable`, and mutates the value in-place, it works\n||| exactly like `(+)` on a `Tensor`.\nexport\n(+=) : Num dtype => (1 v : Variable shape dtype) -> Tensor shape dtype -> Variable shape dtype\n\n||| Element-wise in-place subtraction. See `(+=)` and `(+)` for details.\nexport\n(-=) : Neg dtype => (1 v : Variable shape dtype) -> Tensor shape dtype -> Variable shape dtype\n\n||| Element-wise in-place multiplication. See `(+=)` and `(*)` for details.\nexport\n(*=) : Num dtype => (1 v : Variable shape dtype) -> Tensor shape dtype -> Variable shape dtype\n\n||| Element-wise in-place division. See `(+=)` and `(/)` for details.\nexport\n(//=) : Fractional dtype =>\n (1 v : Variable shape dtype) -> Tensor shape dtype -> Variable shape dtype\n\n-- todo\n||| The element-wise natural logarithm.\nexport\nlog : Tensor shape Double -> Tensor shape Double\n\n||| Reduce a `Tensor` along the specified `axis` to the smallest element along that axis, removing\n||| the axis in the process. For example, `reduce_min 1 $ const [[-1, 5, 10], [4, 5, 6]]` is\n||| equivalent to `const [-1, 5, 6]`.\nexport\nreduce_min : Num dtype => (axis : Fin (S r)) -> Tensor {rank=S r} shape dtype ->\n {auto 0 _ : IsSucc $ index axis shape} -> Tensor (deleteAt axis shape) dtype\n\n||| Reduce a `Tensor` along the specified `axis` to the sum of its components, removing the axis in\n||| the process. For example, `reduce_sum 1 $ const [[-1, 2, 3], [4, 5, -6]]` is equivalent to\n||| `const [3, 7, -3]`.\nexport\nreduce_sum : Num dtype => (axis : Fin (S r)) -> Tensor {rank=S r} shape dtype ->\n {auto 0 _ : IsSucc $ index axis shape} -> Tensor (deleteAt axis shape) dtype\n\n---------------------------- other ----------------------------------\n\n||| The determinant of a tensor (with respect to the last two axes). For example,\n||| `det $ const [[1, 2], [3, 4]]` is equivalent to `const -2`.\nexport\ndet : forall shape, dtype . Neg dtype => Tensor shape dtype ->\n let leading = init (init shape)\n m = last (init shape)\n n = last shape\n in {auto 0 isSquare : m = n} -> {auto 0 nonEmpty : IsSucc m} -> Tensor leading dtype\n\n||| Cholesky decomposition. Finds the lower triangular matrix `L` from `X` s.t. `X = L @@ L.T`.\nexport\ncholesky : Tensor [S n, S n] dtype -> Tensor [S n, S n] dtype\n\ninfix 9 \\\\\n\n||| Find `Y` from `A` and `X` s.t. `X = AY` where `A` is a lower triangular matrix.\nexport\n(\\\\) : Tensor [n, n] dtype -> Tensor (n :: tl) dtype -> Tensor (n :: tl) dtype\n\n||| Indicates an operation was impossible (at the attempted precision) due to a matrix being\n||| singular.\nexport\ndata SingularMatrixError = MkSingularMatrixError String\n\nexport\nError SingularMatrixError where\n format (MkSingularMatrixError msg) = msg\n\n||| The inverse of a matrix. For example, `inverse $ const [[1, 2], [3, 4]]` is equivalent to\n||| `const [[-2, -1], [-1.5, -0.5]]`.\nexport\ninverse : Tensor [S n, S n] Double -> Either SingularMatrixError $ Tensor [S n, S n] Double\n\n||| The product of all elements along the diagonal of a matrix. For example,\n||| `trace_product $ const [[2, 3], [4, 5]]` is equivalent to `const 10`.\nexport\ntrace_product : Num dtype => Tensor [S n, S n] dtype -> Tensor [] dtype\n\n||| Sum the elements along the diagonal of the input.\nexport\ntrace : Num dtype => Tensor [S n, S n] dtype -> Tensor [] dtype\n", "meta": {"hexsha": "a6d08c6e1e96c0ada0b4a84725530dc8d5fcc3cc", "size": 20377, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Tensor.idr", "max_stars_repo_name": "joelberkeley/spidr", "max_stars_repo_head_hexsha": "98cffe059ac5162a46942027658b6fe1dba5074d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2020-11-21T00:57:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T18:18:43.000Z", "max_issues_repo_path": "src/Tensor.idr", "max_issues_repo_name": "joelberkeley/spidr", "max_issues_repo_head_hexsha": "98cffe059ac5162a46942027658b6fe1dba5074d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 55, "max_issues_repo_issues_event_min_datetime": "2021-04-22T18:52:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:09:55.000Z", "max_forks_repo_path": "src/Tensor.idr", "max_forks_repo_name": "joelberkeley/spidr", "max_forks_repo_head_hexsha": "98cffe059ac5162a46942027658b6fe1dba5074d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-08-11T10:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-01T04:00:23.000Z", "avg_line_length": 38.0167910448, "max_line_length": 102, "alphanum_fraction": 0.6278156745, "num_tokens": 6191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.32378165597412156}} {"text": "module Main\n\ninterface Symantics (repr : Type -> Type) where\n int : Int -> repr Int\n bool : Bool -> repr Bool\n string : String -> repr String\n nil : repr (List a)\n not : repr Bool -> repr Bool\n (==) : Eq a => repr a -> repr a -> repr Bool\n (*) : Num a => repr a -> repr a -> repr a\n lam : (repr a -> repr b) -> repr (a -> b)\n app : repr (a -> b) -> repr a -> repr b\n foreach : Lazy (repr (List a)) -> (repr a -> repr (List b)) -> repr (List b)\n where' : repr Bool -> Lazy (repr (List a)) -> repr (List a) \n yield : repr a -> repr (List a)\n union_all : repr (List a) -> repr (List a) -> repr (List a)\n\nrecord Product where\n constructor MkProduct\n pid : Int\n name : String\n price : Int\n\nrecord Order where\n constructor MkOrder\n oid : Int\n opid : Int\n qty : Int\n \nrecord Sale where\n constructor MkSale\n spid : Int\n sname : String\n amount : Int\n\ninterface Symantics repr => SymSchema (repr : Type -> Type) where\n product : repr Int -> repr String -> repr Int -> repr Product\n pid : repr Product -> repr Int\n name : repr Product -> repr String\n price : repr Product -> repr Int\n products : Lazy (repr (List Product))\n \n order : repr Int -> repr Int -> repr Int -> repr Order\n oid : repr Order -> repr Int\n opid : repr Order -> repr Int\n qty : repr Order -> repr Int\n orders : Lazy (repr (List Order))\n \n sale : repr Int -> repr String -> repr Int -> repr Sale\n\nlistFive : Symantics r => r (List Int)\nlistFive = yield (int 5)\n\n-- products\ntablet : SymSchema r => r Product\ntablet = product (int 1) (string \"Tablet\") (int 500)\nlaptop : SymSchema r => r Product\nlaptop = product (int 2) (string \"Laptop\") (int 1000)\ndesktop : SymSchema r => r Product\ndesktop = product (int 3) (string \"Desktop\") (int 1000)\nrouter : SymSchema r => r Product\nrouter = product (int 4) (string \"Router\") (int 150)\nhdd : SymSchema r => r Product\nhdd = product (int 5) (string \"HDD\") (int 100)\nssd : SymSchema r => r Product\nssd = product (int 6) (string \"SSD\") (int 500)\n\n-- orders\no1 : SymSchema r => r Order\no1 = order (int 1) (int 1) (int 5)\no2 : SymSchema r => r Order\no2 = order (int 1) (int 2) (int 5)\no3 : SymSchema r => r Order\no3 = order (int 1) (int 4) (int 2)\no4 : SymSchema r => r Order\no4 = order (int 2) (int 5) (int 10)\no5 : SymSchema r => r Order\no5 = order (int 2) (int 6) (int 20)\no6 : SymSchema r => r Order\no6 = order (int 3) (int 2) (int 50)\n\n\ndata Evaluator a = R a\n\neval : Evaluator a -> a\neval (R a) = a\n\nSymantics Evaluator where\n int = R\n bool = R\n string = R\n not (R b) = R (not b)\n nil = R []\n (==) (R a) (R b) = R (a == b)\n (*) (R a) (R b) = R (a * b)\n lam f = R (\\a => eval (f (R a)))\n app (R f) (R a) = R (f a)\n foreach t f = \n case eval t of\n [] => R []\n (x :: xs) => R (eval (f (R x)) ++ (eval (foreach (R xs) f)))\n where' (R b) r = if b then r else R []\n yield (R x) = R [x]\n union_all (R as) (R bs) = R (as ++ bs)\n\nSymantics Evaluator => SymSchema Evaluator where\n product (R pid) (R name) (R price) = R (MkProduct pid name price)\n pid (R p) = R (pid p)\n name (R p) = R (name p)\n price (R p) = R (price p)\n products = R (map eval [tablet, laptop, desktop, router, hdd, ssd]) -- yield tablet `union_all` yield laptop\n\n order (R oid) (R opid) (R qty) = R (MkOrder oid opid qty)\n oid (R o) = R (oid o)\n opid (R o) = R (opid o)\n qty (R o) = R (qty o)\n orders = R (map eval [o1, o2, o3, o4, o5, o6])\n \n sale (R spid) (R sname) (R amount) = R (MkSale spid sname amount)\n\n-- eval (foreach products (\\p => yield (pid p)) `union_all` foreach orders (\\o => yield (opid o)))\n\n-- Q1\nq1 : SymSchema r => r Int -> r (List Order)\nq1 xoid = foreach orders $ \\o =>\n where' (oid o == xoid) $\n yield o\n\nq1_2 : SymSchema r => r (List Order)\nq1_2 = q1 (int 2) -- I'm not using `app` and `lam` anywhere. Is that a problem?\n\n-- eval q1_2\n\nq2 : SymSchema r => r Order -> r (List Sale)\nq2 o = foreach products $ \\p =>\n where' (not (not (pid p == opid o))) $\n yield $ sale (pid p) (name p) (price p * qty o)\n\n-- eval (q2 (order (int 2) (int 5) (int 10)))\nq3 : SymSchema r => r Int -> r (List Sale)\nq3 x = foreach (q1 x) $ \\y =>\n q2 y\n-- Still no app and lam... Oleg et. al. use app, but no lam either\n\n-- eval (q3 (int 2))\n\ndata Printer a = P String\n\nprint : Printer a -> String\nprint (P a) = a\n\nSymantics Printer where\n int i = P (show i)\n bool b = P (show b)\n string s = P s\n not (P b) = P (\"(NOT \" ++ b ++ \")\")\n nil = P \"[]\"\n (==) (P a) (P b) = P (a ++ \" == \" ++ b)\n (*) (P a) (P b) = P (\"(\" ++ a ++ \" * \" ++ b ++ \")\")\n lam f = P \"lam\"\n app (P f) (P a) = P \"app\"\n foreach t f =\n let ts : String = print t\n fs : String = print (f (P \"$arg\"))\n in P (\"FOREACH (\" ++ ts ++ \") \" ++ fs)\n where' (P b) r = P (\"WHERE \" ++ b ++ \" \" ++ (print r))\n yield (P x) = P (\"YIELD \" ++ x)\n union_all (P as) (P bs) = P (as ++ \" UNION ALL \" ++ bs)\n\nSymantics Printer => SymSchema Printer where\n product _ _ _ = P \"product\"\n pid (P x) = P (x ++ \".pid\")\n name (P x) = P (x ++ \".name\")\n price (P x) = P (x ++ \".price\")\n products = P \"products\"\n order x y z = P \"order\"\n oid (P x) = P (x ++ \".oid\")\n opid (P x) = P (x ++ \".pid\")\n qty (P x) = P (x ++ \".qty\")\n orders = P \"orders\"\n sale x y z = P $ \"(MkSale \" ++ print x ++ \" \" ++ print y ++ \" \" ++ print z ++ \")\"\n\n-- λΠ> print (q3 (int 2))\n-- \"FOREACH (FOREACH (orders) WHERE $arg.oid == 2 YIELD $arg) FOREACH (products) WHERE $arg.pid == $arg.pid YIELD (MkSale $arg.pid $arg.name ($arg.price * $arg.qty))\" : String\n\ndata ConstantFolder : (repr : Type -> Type) -> (a : Type) -> Type where\n Empty : ConstantFolder repr (List a)\n Unknown : (repr a) -> ConstantFolder repr a\n\ndyn : Symantics repr => ConstantFolder repr a -> repr a\ndyn Empty = nil\ndyn (Unknown x) = x\n\nSymantics r => Symantics (ConstantFolder r) where\n nil = Empty\n union_all Empty y = y\n union_all (Unknown x) y = Unknown (union_all x (dyn y))\n -- boilerplate\n int x = Unknown (int x)\n bool x = Unknown (bool x)\n string x = Unknown (string x)\n not b = Unknown (not (dyn b))\n lam f = Unknown (lam (\\x => dyn (f (Unknown x))))\n app x y = Unknown (app (dyn x) (dyn y))\n foreach t f = Unknown $ foreach (Delay (dyn t)) (\\x => dyn (f (Unknown x)))\n where' x y = Unknown (where' (dyn x) (dyn y))\n yield x = Unknown (yield (dyn x))\n (==) x y = Unknown (dyn x == dyn y)\n (*) x y = Unknown (dyn x * dyn y)\n\nSymSchema r => SymSchema (ConstantFolder r) where\n-- (Symantics (ConstantFolder r), SymSchema r) => SymSchema (ConstantFolder r) where\n product x y z = Unknown $ product (dyn x) (dyn y) (dyn z)\n pid = pid\n name = name\n price = price\n products = products\n order = order\n oid = oid\n opid = opid\n qty = qty\n orders = Unknown $ Force orders -- not sure I like this Force\n sale = sale\n\ncfp' : ConstantFolder Printer (List Int)\ncfp' = union_all nil (yield (int 2))\n\n-- print (dyn (union_all nil (yield (int 2))))\n\n-- From http://okmij.org/ftp/tagless-final/course/RR.hs\n-- \n-- {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}\n\n-- -- * Reflection-Reification pair\n\n-- module RR where\n\n-- class RR t repr where\n-- fwd :: repr a -> t repr a\n-- bwd :: t repr a -> repr a\n\n-- map1 :: (repr a -> repr b) -> (t repr a -> t repr b)\n-- map1 f = fwd . f . bwd\n\n-- map2 :: (repr a -> repr b -> repr c) ->\n-- (t repr a -> t repr b -> t repr c)\n-- map2 f e1 e2 = fwd (f (bwd e1) (bwd e2))\n\n\n-- -- * fwd is generally not surjective and bwd is not injective\n-- -- * bwd . fwd == id, fwd . bwd /= id\n\n-- -- * QUIZ\n-- -- * map1 looks like fmap of a Functor. Can it be defined or related\n-- -- * to Functor?\n\ninterface RR (t : (Type -> Type) -> Type -> Type) (repr : Type -> Type) where\n fwd : repr a -> t repr a\n bwd : t repr a -> repr a\n \n map1 : (repr a -> repr b) -> (t repr a -> t repr b)\n map1 f = fwd . f . bwd\n \n map2 : (repr a -> repr b -> repr c) -> (t repr a -> t repr b -> t repr c)\n map2 f e1 e2 = fwd (f (bwd e1) (bwd e2))\n\n-- print (q_3 (int 2))\n\ndata N2N : (repr : Type -> Type) -> (a : Type) -> Type where\n Unk : repr a -> N2N repr a -- no annotation\n Neg : repr Bool -> N2N repr Bool -- it is a negation\n\n-- instance Symantics repr => RR N2N repr where\n-- bwd (Unk e) = e\n-- bwd (Neg x) = neg x\n\n-- fwd = Unk\n\nSymantics repr => RR N2N repr where\n bwd (Unk e) = e\n bwd (Neg x) = not x\n \n fwd = Unk\n\n-- instance Symantics repr => Symantics (N2N repr) where\n-- lit = fwd . lit\n\n-- neg (Unk e) = Neg e -- we statically know we negated\n-- neg (Neg x) = Unk x\n\n-- -- and e1 e2 = Unk $ and (bwd e1) (bwd e2)\n-- and = map2 and\n-- or = map2 or\n\nSymantics repr => Symantics (N2N repr) where\n bool = fwd . bool\n\n not (Unk e) = Neg e -- we statically know we negated\n not (Neg x) = Unk x\n\n int = fwd . int\n string = fwd . string\n (==) = map2 (==)\n (*) = map2 (*)\n nil = fwd nil\n lam f = fwd (lam (\\x => bwd (f (fwd x))))\n app = map2 app\n foreach x f = fwd $ foreach (bwd x) (\\x => bwd (f (fwd x)))\n where' x y = fwd $ where' (bwd x) (bwd y)\n yield = map1 yield -- not sure..\n union_all = map2 union_all\n\n-- instance SymInput repr => SymInput (N2N repr) where\n-- wireX = fwd wireX\n-- wireY = fwd wireY\n-- wireZ = fwd wireZ\n\nSymSchema r => SymSchema (N2N r) where\n product x y z = fwd $ product (bwd x) (bwd y) (bwd z)\n pid = map1 pid\n name = map1 name\n price = map1 price\n products = fwd $ Force products\n order x y z = fwd $ order (bwd x) (bwd y) (bwd z)\n oid = map1 oid\n opid = map1 opid\n qty = map1 qty\n orders = fwd $ Force orders\n sale x y z = fwd $ sale (bwd x) (bwd y) (bwd z)\n\n-- -- * Observe the result\n-- -- A type-specific version of bwd\n-- obsN2N :: Symantics repr => N2N repr a -> repr a\n-- obsN2N = bwd\nobsN2N : Symantics repr => N2N repr a -> repr a\nobsN2N = bwd\n\n-- print (obsN2N (q3 (int 2)))\n", "meta": {"hexsha": "e59321a3744abacb010ff1ce7491743b3f46dc99", "size": 9807, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Main.idr", "max_stars_repo_name": "fehrenbach/furry-parakeet", "max_stars_repo_head_hexsha": "7e3fcef2c562316ff14471093fa0ebf5ce013c6a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Main.idr", "max_issues_repo_name": "fehrenbach/furry-parakeet", "max_issues_repo_head_hexsha": "7e3fcef2c562316ff14471093fa0ebf5ce013c6a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Main.idr", "max_forks_repo_name": "fehrenbach/furry-parakeet", "max_forks_repo_head_hexsha": "7e3fcef2c562316ff14471093fa0ebf5ce013c6a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9292035398, "max_line_length": 175, "alphanum_fraction": 0.5664321403, "num_tokens": 3482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370308082623217, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.32349180234697805}} {"text": "module Sub07Apply108x27\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\nimport ProofColDivSeqPostuProof\n\n%default total\n-- %language ElabReflection\n\n\n-- 3(36x+9) --F[5,-2]->C[4,-4]--> 3(32x+7)\nexport\napply108x27 : (Not . P) (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))))\n -> (m : Nat **\n (LTE (S m)\n (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))),\n (Not . P) m))\napply108x27 {o} col = ((S (S (S (S (S (S (S (plus (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))))))) ** (lte108x27 o, fc108x27To96x21 o col)) where\n lte108x27 : (o:Nat) -> LTE (S (S (S (S (S (S (S (S (plus (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))))))))\n (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))))\n lte108x27 Z = (lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) LTEZero\n lte108x27 (S o) = let lemma = lte108x27 o in\n rewrite (sym (plusSuccRightSucc o o)) in\n rewrite (sym (plusSuccRightSucc (plus o o) (S (plus o o)))) in\n rewrite (sym (plusSuccRightSucc (plus o o) (plus o o))) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (S (S (plus (plus o o) (plus o o))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (S (plus (plus o o) (plus o o)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (plus (plus o o) (plus o o))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))) in\n rewrite (sym (plusSuccRightSucc (plus o o) o)) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (S (plus (plus o o) o))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (plus (plus o o) o)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (plus (plus o o) o))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (plus (plus o o) o)) (S (S (S (S (S (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (plus (plus o o) o)) (S (S (S (S (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (plus (plus o o) o)) (S (S (S (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (plus (plus o o) o)) (S (S (S (plus (plus (plus o o) o) (plus (plus o o) o))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (plus (plus o o) o)) (S (S (plus (plus (plus o o) o) (plus (plus o o) o)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o)))) (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o)))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o)))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o)))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o) (plus (plus o o) o))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o)) (S (plus (plus (plus o o) o) (plus (plus o o) o))))))\n (S (plus (plus (plus (plus o o) o) (plus (plus o o) o))\n (S (plus (plus (plus o o) o)\n (plus (plus o o) o))))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (S (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (S (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) (plus o o))\n (plus (plus o o) (plus o o)))\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))\n (plus (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o o)))\n (plus (plus (plus o o)\n (plus o o))\n (plus (plus o o)\n (plus o\n o)))))) in\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "04ed891880e3094e5269d7ea5e8913ea747fc655", "size": 49676, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program2/Sub07Apply108x27.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program2/Sub07Apply108x27.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program2/Sub07Apply108x27.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 146.1058823529, "max_line_length": 391, "alphanum_fraction": 0.2169458088, "num_tokens": 8500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.41869690935568665, "lm_q1q2_score": 0.32316849144633186}} {"text": "module Data.HashSet\n\nimport Data.Vector\n\n%default total\n\npublic export\nHashCode : Type\nHashCode = Bits32\n\npublic export\ninterface (Eq a) => Hash a where\n hash : a -> HashCode\n\npublic export\nHash HashCode where\n hash = id\n\npublic export\nHash Int where\n hash = prim__zextInt_B32\n\npublic export\nimplementation (Hash a, Hash b) => Hash (a, b) where\n hash (x, y) = prim__xorB32 (997 * hash x) (991 * hash y)\n\nBitmap : Type\nBitmap = Bits32\n\nIndex : Type\nIndex = Nat\n\nCast Bits32 Nat where\n cast = cast . prim__zextB32_Int\n\nmutual\n data Node a\n = Empty\n | Key HashCode a\n | HashCollision HashCode (Vector a)\n | SubTrie Bitmap (NodeList a)\n\n NodeList : Type -> Type\n NodeList a = Vector (Node a)\n\nexport\nrecord HashSet a where\n constructor MkHashSet\n size : Nat\n root : NodeList a\n\nShow a => Show (Node a) where\n show Empty = \"E\"\n show (Key h a) = \"(K \" ++ show a ++ \")\"\n show (SubTrie bm l) = \"(S \" ++ show bm ++ \" \" ++ assert_total (show l) ++ \")\"\n show _ = \"*\"\n\nexport\nShow a => Show (HashSet a) where\n show (MkHashSet s r) = \"HashSet \" ++ show s ++ \" \" ++ show r\n\ninfixl 7 &\n(&) : Bits32 -> Bits32 -> Bits32\n(&) = prim__andB32\n\ninfixl 7 >>\n(>>) : Bits32 -> Bits32 -> Bits32\n(>>) = prim__lshrB32\n\ninfixl 7 <<\n(<<) : Bits32 -> Bits32 -> Bits32\n(<<) = prim__shlB32\n\n(-) : Bits32 -> Bits32 -> Bits32\n(-) x y = prim__zextInt_B32 (prim__zextB32_Int x - prim__zextB32_Int y)\n\nshiftMask : Bits32 -> Bits32 -> Bits32 -> Bits32\nshiftMask bits shift mask = (bits >> shift) & mask\n\npopcnt : Bits32 -> Bits32\npopcnt x =\n let x = x - shiftMask x 1 0x55555555\n x = (x & 0x33333333) + shiftMask x 2 0x33333333\n x = (x + (x >> 4)) & 0x0F0F0F0F\n x = x + (x >> 8)\n x = x + (x >> 16)\n in x & 0x0000003F\n\nnext5Bits : Bits32 -> HashCode -> HashCode\nnext5Bits level hashCode = shiftMask hashCode (5 * level) 0x1F\n\nbitAt : Bits32 -> Bits32 -> Bool\nbitAt pos bits = 1 == shiftMask bits pos 1\n\nsetBit : Bits32 -> Bits32 -> Bits32\nsetBit bitPos bits = prim__orB32 bits (1 << bitPos)\n\nnodeIndex : Bits32 -> Bits32 -> Index\nnodeIndex bitPos bitmap = cast (popcnt (bitmap & ((1 << bitPos) - 1)))\n\nnodeAt : Index -> NodeList a -> Node a\nnodeAt idx nodes = nodes !! idx\n\ninsertNode : Index -> NodeList a -> Node a -> NodeList a\ninsertNode idx nodes n = unsafeInsertAt idx n nodes\n\nreplaceNode : Index -> NodeList a -> Node a -> NodeList a\nreplaceNode idx nodes n = unsafeReplaceAt idx n nodes\n\n{-\n3.1 Search for a key Map Hash Array Mapped Trie (HAMT)\n\nCompute a full 32 bit hash for the key, take the most significant t bits and use them as an integer to index into the root hash table. One of three cases may be encountered. First, the entry is empty indicating that the key is not in the hash tree. Second the entry is a Key/Value pair and the key either matches the desired key indicating success or not, indicating failure. Third, the entry has a 32 bit map sub-hash table and a sub-trie pointer, Base, that points to an ordered list of the non-empty sub-hash table entries.\n\nTake the next 5 bits of the hash and use them as an integer to index into the bit Map. If this bit is a zero the hash table entry is empty indicating failure, otherwise, it’s a one, so count the one bits below it using CTPOP and use the result as the index into the non-empty entry list at Base. This process is repeated taking five more bits of the hash each time until a terminating key/value pair is found or the search fails. Typically, only a few iterations are required and it is important to note that the key is only compared once and that is with the terminating node key.\n-}\nexport\nmember : (Hash a) => a -> HashSet a -> Bool\nmember key (MkHashSet _ root) =\n let rootPos = cast (next5Bits 0 hashCode)\n in memberOf root rootPos 1\n where\n hashCode : HashCode\n hashCode = hash key\n memberOf : NodeList a -> Index -> Bits32 -> Bool\n memberOf nodes index nextLevel =\n case nodeAt index nodes of\n Empty => False\n Key existingHashCode existingKey =>\n existingHashCode == hashCode && existingKey == key\n HashCollision existingHashCode keys =>\n existingHashCode == hashCode && elem key keys\n SubTrie bitmap nodes =>\n let\n bitPos = next5Bits nextLevel hashCode\n bitVal = bitAt bitPos bitmap\n in\n if bitVal\n then assert_total (memberOf nodes (nodeIndex bitPos bitmap) (nextLevel + 1))\n else False\n\n{-\n3.2 Insertion\nThe initial steps required to add a new key to the hash tree are identical to the search. The search algorithm is followed until one of two failure modes is encoun- tered.\n\nEither an empty position is discovered in the hash table or a sub-hash table is found. In this case, if this is in the root hash table, the new key/value pair is simply substituted for the empty position. However, if in a sub-hash table then a new bit must be added to the bit map and the sub-hash table increased by one in size. A new sub-hash table must be allocated, the existing sub-table copied to it, the new key/value entry added in sub-hash sorted order and the old hash table made free.\n\nOr the key will collide with an existing one. In which case the existing key must be replaced with a sub-hash table and the next 5 bit hash of the existing key computed. If there is still a collision then this process is repeated until no collision occurs. The existing key is then inserted in the new sub-hash table and the new key added. Each time 5 more bits of the hash are used the probability of a collision reduces by a factor of 1 . Occasionally an entire 32 bit hash may be consumed and 32 a new one must be computed to differentiate the two keys.\n-}\ninsert' : (Hash a) => HashCode -> a -> HashSet a -> HashSet a\ninsert' hashCode key set@(MkHashSet size root) =\n case nodeAt rootPos root of\n Empty => insertRootNode (Key hashCode key)\n SubTrie bitmap nodes =>\n maybe set insertRootNode (insertIntoSubTrie bitmap nodes 1)\n node@(Key existingHashCode existingKey) =>\n if existingHashCode == hashCode\n then\n if existingKey == key\n then set\n else insertRootNode (collision existingKey)\n else\n maybe set insertRootNode (spawnSubTrie node existingHashCode 1)\n node@(HashCollision existingHashCode keys) =>\n if existingHashCode == hashCode\n then\n if elem key keys\n then set\n else insertRootNode (HashCollision hashCode (key :: keys))\n else\n maybe set insertRootNode (spawnSubTrie node existingHashCode 1)\n where\n rootPos : Index\n rootPos = cast (next5Bits 0 hashCode)\n insertRootNode : Node a -> HashSet a\n insertRootNode = MkHashSet (S size) . replaceNode rootPos root\n collision : a -> Node a\n collision existingKey = HashCollision hashCode (key :: singleton existingKey)\n mutual\n insertIntoSubTrie : Bitmap -> NodeList a -> Bits32 -> Maybe (Node a)\n insertIntoSubTrie bitmap nodes level =\n let\n bitPos = next5Bits level hashCode\n bitVal = bitAt bitPos bitmap\n nodePos = nodeIndex bitPos bitmap\n in\n if bitVal\n then SubTrie bitmap . replaceNode nodePos nodes <$> insertInto (nodeAt nodePos nodes) level\n else Just (SubTrie (setBit bitPos bitmap) (insertNode nodePos nodes (Key hashCode key)))\n\n insertInto : Node a -> Bits32 -> Maybe (Node a)\n insertInto (SubTrie bitmap nodes) level =\n assert_total (insertIntoSubTrie bitmap nodes (level + 1))\n insertInto node@(Key existingHashCode existingKey) level =\n if existingHashCode == hashCode\n then\n if existingKey == key\n then Nothing\n else Just (collision existingKey)\n else\n assert_total (spawnSubTrie node existingHashCode (level + 1))\n insertInto node@(HashCollision existingHashCode keys) level =\n if existingHashCode == hashCode\n then\n if elem key keys\n then Nothing\n else Just (HashCollision hashCode (key :: keys))\n else\n assert_total (spawnSubTrie node existingHashCode (level + 1))\n insertInto Empty _ = assert_unreachable\n\n spawnSubTrie : Node a -> HashCode -> Bits32 -> Maybe (Node a)\n spawnSubTrie node existingHashCode level =\n let bitPos = next5Bits level existingHashCode\n bitmap = setBit bitPos 0\n in insertIntoSubTrie bitmap (singleton node) level\n\nexport\ninsert : (Hash a) => a -> HashSet a -> HashSet a\ninsert key set = insert' (hash key) key set\n\nexport\nempty : HashSet a\nempty = MkHashSet 0 (replicate 32 Empty)\n\nexport\nlength : HashSet a -> Nat\nlength (MkHashSet size _) = size\n\nfold : (acc -> elem -> acc) -> acc -> HashSet elem -> acc\nfold f init (MkHashSet _ nodes) = foldNodes init nodes\n where\n mutual\n foldNodes : acc -> NodeList elem -> acc\n foldNodes acc nodes = foldl foldNode acc nodes\n foldNode : acc -> Node elem -> acc\n foldNode acc Empty = acc\n foldNode acc (Key _ k) = f acc k\n foldNode acc (HashCollision _ keys) = foldl f acc keys\n foldNode acc (SubTrie _ nodes) = assert_total (foldNodes acc nodes)\n\nexport\nFoldable HashSet where\n foldl = fold\n foldr = fold . flip\n\nexport\nfilter : (Eq elem, Hash elem) => (elem -> Bool) -> HashSet elem -> HashSet elem\nfilter f (MkHashSet _ nodes) = foldNodes empty nodes\n where\n mutual\n foldNodes : HashSet elem -> NodeList elem -> HashSet elem\n foldNodes acc nodes = foldl foldNode acc nodes\n foldNode : HashSet elem -> Node elem -> HashSet elem\n foldNode acc Empty = acc\n foldNode acc (Key hashCode k) = insertWithHashCode hashCode acc k\n foldNode acc (HashCollision hashCode keys) = foldl (insertWithHashCode hashCode) acc keys\n foldNode acc (SubTrie _ nodes) = assert_total (foldNodes acc nodes)\n insertWithHashCode : HashCode -> HashSet elem -> elem -> HashSet elem\n insertWithHashCode hc acc e = if f e then insert' hc e acc else acc\n\nexport\ninto : (Hash a, Foldable f) => HashSet a -> f a -> HashSet a\ninto = foldl (flip insert)\n\nexport\nfromList : (Hash a) => List a -> HashSet a\nfromList = foldl (flip insert) empty\n\nexport\nfoldM : Monad m => (acc -> elem -> m acc) -> acc -> HashSet elem -> m acc\nfoldM f acc (MkHashSet _ nodes) = foldNodes f acc nodes\n where\n mutual\n foldNodes : (Monad m) => (a -> elem -> m a) -> a -> NodeList elem -> m a\n foldNodes f acc nodes = loop (length nodes) acc\n where\n loop Z acc = pure acc\n loop (S k) acc = foldNode f acc (nodes !! k) >>= loop k\n foldNode : (Monad m) => (a -> elem -> m a) -> a -> Node elem -> m a\n foldNode f acc Empty = pure acc\n foldNode f acc (Key _ k) = f acc k\n foldNode f acc (HashCollision _ keys) = foldKeys f acc keys\n foldNode f acc (SubTrie _ nodes) = assert_total (foldNodes f acc nodes)\n foldKeys : (Monad m) => (a -> elem -> m a) -> a -> Vector elem -> m a\n foldKeys f acc keys = loop (length keys) acc\n where\n loop Z acc = pure acc\n loop (S k) acc = f acc (keys !! k) >>= loop k\n", "meta": {"hexsha": "184161cb31851e3942a90d7b2733a5f2561c267a", "size": 11105, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "rts/Data/HashSet.idr", "max_stars_repo_name": "alaendle/idris-cil", "max_stars_repo_head_hexsha": "37ec9a3cd783e67ba03369052ce6e177621fc147", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 146, "max_stars_repo_stars_event_min_datetime": "2015-07-27T12:33:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T22:26:35.000Z", "max_issues_repo_path": "rts/Data/HashSet.idr", "max_issues_repo_name": "alaendle/idris-cil", "max_issues_repo_head_hexsha": "37ec9a3cd783e67ba03369052ce6e177621fc147", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-09-21T15:08:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-20T13:55:12.000Z", "max_forks_repo_path": "rts/Data/HashSet.idr", "max_forks_repo_name": "alaendle/idris-cil", "max_forks_repo_head_hexsha": "37ec9a3cd783e67ba03369052ce6e177621fc147", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2015-09-21T12:24:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T21:10:06.000Z", "avg_line_length": 38.2931034483, "max_line_length": 581, "alphanum_fraction": 0.6704187303, "num_tokens": 2946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.44552953503957277, "lm_q1q2_score": 0.3229511171090675}} {"text": "module Circuits.Idealised.Types\n\nimport Decidable.Equality\n\nimport Data.List.Elem\n\nimport public Circuits.Common\n\n%default total\n\npublic export\ndata GateKind = AND | IOR | XOR\n | ANDN | IORN | XORN | JOIN\n\nexport\nShow GateKind where\n show AND = \"and\"\n show IOR = \"or\"\n show XOR = \"xor\"\n show ANDN = \"nand\"\n show IORN = \"nor\"\n show XORN = \"xnor\"\n show JOIN = \"join\"\n\npublic export\ndata Direction = INPUT | OUTPUT\n\nUninhabited (INPUT = OUTPUT) where\n uninhabited Refl impossible\n\nDecEq Direction where\n decEq INPUT INPUT = Yes Refl\n decEq INPUT OUTPUT = No absurd\n decEq OUTPUT INPUT = No (negEqSym absurd)\n decEq OUTPUT OUTPUT = Yes Refl\n\nexport\nShow Direction where\n show INPUT = \"input\"\n show OUTPUT = \"output\"\n\npublic export\ndata PortHasProperties : Direction -> DType -> (Direction, DType) -> Type\n where\n PortHas : PortHasProperties flow type (flow,type)\n\npublic export\ndata Ty : Type where\n TyUnit : Ty\n TyPort : (Direction, DType) -> Ty\n\n TyGate : Ty\n\nexport\nShow Ty where\n show TyUnit = \"()\"\n show (TyPort (d,t)) = concat [\"TyPort(\", show d, \",\", show t, \")\"]\n show TyGate = \"TyGate\"\n\n\nUninhabited (TyUnit = (TyPort x)) where\n uninhabited Refl impossible\n\nUninhabited (TyUnit = TyGate) where\n uninhabited Refl impossible\n\nUninhabited (TyPort x = TyGate) where\n uninhabited Refl impossible\n\nexport\nDecEq Ty where\n decEq TyUnit TyUnit = Yes Refl\n decEq TyUnit (TyPort x) = No absurd\n decEq TyUnit TyGate = No absurd\n\n decEq (TyPort x) TyUnit = No (negEqSym absurd)\n decEq (TyPort x) (TyPort y) with (decEq x y)\n decEq (TyPort x) (TyPort x) | (Yes Refl)\n = Yes Refl\n decEq (TyPort x) (TyPort y) | (No contra)\n = No (\\Refl => contra Refl)\n decEq (TyPort x) TyGate = No (absurd)\n\n decEq TyGate TyUnit = No (negEqSym absurd)\n decEq TyGate (TyPort x) = No (negEqSym absurd)\n decEq TyGate TyGate = Yes Refl\n\n\npublic export\ndata Used : (Ty, Usage) -> Type where\n IsUsed : Used (type, USED)\n\nUninhabited (Used (type,FREE)) where\n uninhabited IsUsed impossible\n\nexport\nused : (p : (Ty,Usage)) -> Dec (Used p)\nused (ty,USED) = Yes IsUsed\nused (ty,FREE) = No absurd\n\npublic export\ndata Use : (old : List (Ty, Usage))\n -> (prf : Elem (type,FREE) old)\n -> (new : List (Ty, Usage))\n -> Type\n where\n H : Use ((type,FREE) :: rest)\n Here\n ((type,USED) :: rest)\n T : Use old later new\n -> Use ((type',usage')::old) (There later) ((type',usage')::new)\n\nexport\nuse : (ctxt : List (Ty, Usage))\n -> (prf : Elem (type, FREE) ctxt)\n -> (DPair (List (Ty, Usage))\n (Use ctxt prf))\nuse ((type, FREE) :: xs) Here\n = (MkDPair ((type, USED) :: xs) H)\nuse ((y, z) :: xs) (There x) with (use xs x)\n use ((y, z) :: xs) (There x) | ((MkDPair fst snd))\n = (MkDPair ((y, z) :: fst) (T snd))\n\nexport\nuseAlt : {ctxt : List (Ty, Usage)}\n -> (prf : Elem (type, FREE) ctxt)\n -> (DPair (List (Ty, Usage))\n (Use ctxt prf))\nuseAlt {ctxt = ((type, FREE) :: xs)} Here\n = MkDPair ((type, USED) :: xs) H\nuseAlt {ctxt = (y :: xs)} (There x) with (useAlt x)\n useAlt {ctxt = ((y, z) :: xs)} (There x) | (MkDPair fst snd) = MkDPair ((y, z) :: fst) (T snd)\n\n-- [ EOF ]\n", "meta": {"hexsha": "5a39e38d8c44cebb049b6466861767dd0d96af3a", "size": 3228, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Circuits/Idealised/Types.idr", "max_stars_repo_name": "gallais/linear-circuits", "max_stars_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Circuits/Idealised/Types.idr", "max_issues_repo_name": "gallais/linear-circuits", "max_issues_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Circuits/Idealised/Types.idr", "max_forks_repo_name": "gallais/linear-circuits", "max_forks_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9111111111, "max_line_length": 96, "alphanum_fraction": 0.6121437423, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3225471630310558}} {"text": "module Parser\n\nimport Data.String\nimport Data.List \n\npublic export \nInput : Type \nInput = List Char \n\npublic export \ndata ParseResult a = Done (a, Input) | Error String\n\n-- To make a parser we need to take a function to maps from input to \n-- A parse result and feed it into the AParser constuctor \npublic export \ndata Parser : Type -> Type where \n AParser : (Input -> ParseResult a) -> Parser a\n\n%name Parser parser, parser2 \n\n-- To actually apply a parser we need to call the parse function\nexport \nparse : Parser a -> Input -> ParseResult a\nparse (AParser p) input = p input \n\nexport \ndoParse : Parser a -> String -> ParseResult a \ndoParse parser str = parse parser (unpack str)\n\nexport \neitherParse : Parser a -> String -> Either String a \neitherParse parser input = \n case doParse parser input of \n Done (a, rest) => Right a \n Error str => Left str\n\n-- This is a more general form of map, it takes a parser, applies it \n-- and the maps over both the result and the remaining input\nexport \ncontinue : Parser a -> ((a, Input) -> ParseResult b) -> Parser b \ncontinue parser f = AParser $ \\input => \n case parse parser input of \n Error str => Error str \n Done a => f a \n\npublic export \nFunctor ParseResult where \n map _ (Error str) = Error str \n map f (Done (a, input)) = Done (f a, input)\n\npublic export\nFunctor Parser where \n -- map : (a -> b) -> Parser a -> Parser b\n map f parser = AParser $ map f . parse parser\n\npublic export\nApplicative Parser where \n (<*>) parser1 parser2 =\n AParser $ \\input => \n case parse parser1 input of \n Error err => Error err \n Done (a, rest) => parse (map a parser2) rest\n\n pure a = AParser \\input => Done (a, input)\n\npublic export\nMonad Parser where \n -- (>>=) : Parser a -> (a -> Parser b) -> Parser b\n (>>=) parser f = continue parser (\\(a, rest) => parse (f a) rest) \n\n-- Defining Basic parsers \n\nexport\nend : ParseResult a \nend = Error \"End of Input\"\n\nexport\nfailure : Parser a \nfailure = AParser $ \\input => Error \"Always fails\"\n\nexport\nparseError : String -> Parser a \nparseError err = AParser $ \\input => Error err\n\nexport\npToken : Parser Char \npToken = AParser $ \\input => \n case input of \n [] => end \n (c :: cs) => Done (c, cs)\n\nexport\nvalidate : (a -> Bool) -> Parser a -> Parser a\nvalidate f parser = do \n result <- parser \n if f result \n then pure result\n else parseError \"Invalid Parse\"\n\nexport\npBool : (Char -> Bool) -> Parser Char\npBool f = validate f pToken\n\n-- parse a specific word \nexport \npTag : String -> Parser String \npTag tag = AParser $ go (unpack tag) []\n where \n go : List Char -> List Char -> Input -> ParseResult String\n go [] acc input = Done (pack . reverse $ acc, input)\n go (c :: cs) acc [] = end\n go (c :: cs) acc (n :: rest) = \n if c == n then go cs (n :: acc) rest\n else Error \"Did not match tag\"\n\n\n-- Apply a parser N times \n-- This should return a Vect \n-- There must be a better way to do this \nexport\npN : Parser a -> Nat -> Parser (List a)\npN parser n = go parser n []\n where \n go : Parser a -> Nat -> List a -> Parser (List a)\n go parser 0 xs = failure\n go parser (S k) acc = do\n parsed <- parser \n let newAcc = parsed :: acc\n case k of \n 0 => pure $ reverse newAcc\n k => go parser k newAcc\n\n\nexport\npChar : Char -> Parser Char \npChar c = pBool (==c)\n\nexport \npDigit : Parser Char \npDigit = pBool isDigit\n\nexport\nmany : Parser a -> Parser (List a)\nmany parser = AParser $ map reverse . go []\n where \n go : List a -> Input -> ParseResult (List a)\n go acc input = \n case parse parser input of \n Done (parsed, rest) => go (parsed :: acc) rest \n Error str => Done (acc, input)\n\nexport\nmanyString : Parser Char -> Parser String \nmanyString parser = map pack (many parser)\n\nexport\nor : Parser a -> Parser a -> Parser a \nor parser1 parser2 = AParser $ \\input =>\n case parse parser1 input of \n Done (result, rest) => Done (result, rest)\n Error _ => parse parser2 input\n\ninfixr 4 <^>\nexport \n(<^>) : Parser a -> Parser a -> Parser a\n(<^>) x y = or x y\n\nexport\nwhile : (Char -> Bool) -> Parser String \nwhile f = manyString (pBool f)\n\nexport\nuntil : (Char -> Bool) -> Parser String \nuntil f = while (not . f)\n\nexport\npWhiteSpace : Parser String \npWhiteSpace = while isSpace\n\nexport\n-- Parse until it encounters whitespace \n-- Doesn't consume the whitespace\npWord : Parser String \npWord = until isSpace\n\nexport\nmapM : (a -> Maybe b) -> Parser a -> Parser b \nmapM f parser = do\n parsed <- parser \n case f parsed of \n Nothing => parseError \"Invalid mapM\"\n Just a => pure a \n\nexport \npInteger : Parser Integer \npInteger = mapM parseInteger (while validChar)\n where validChar : Char -> Bool \n validChar '+' = True\n validChar '-' = True\n validChar c = isDigit c\n\nexport\npNat : Parser Nat \npNat = map stringToNatOrZ (while isDigit)\n\nexport\nandThen : Parser a -> Parser b -> Parser (a,b)\nandThen parser1 parser2 = do\n parsed1 <- parser1\n parsed2 <- parser2\n pure (parsed1, parsed2)\n\ninfixl 3 <&>\nexport \n(<&>) : Parser a -> Parser b -> Parser (a,b)\n(<&>) x y = andThen x y \n\nexport\nthenDrop : Parser a -> Parser b -> Parser a \nthenDrop parser1 parser2 = map fst (andThen parser1 parser2)\n\ninfixl 3 :>\nexport \n(:>) : Parser a -> Parser b -> Parser a \n(:>) x y = thenDrop x y \n\nexport \nsepBy : Parser a -> Parser b -> Parser (List a)\nsepBy parser1 parser2 = do \n most <- many (thenDrop parser1 parser2)\n AParser $ (\\input => \n case parse parser1 input of \n Done (result, rest) => Done (most ++ [result], rest)\n Error str => Done (most, input))\n\nexport \n-- Matches the end of the file\ntheEnd : Parser ()\ntheEnd = AParser $ \\input => \n if input == [] then Done ((), [])\n else Error \"Expected End of File\"\n\nexport\n-- Parses a word and consume whitespace\npWord' : Parser String \npWord' = pWord :> pWhiteSpace\n\nexport \nignore : Parser a -> Parser () \nignore parser = map (\\i => ()) parser\n\nexport \noneOf : List (Parser a) -> Parser a\noneOf parsers = foldl (<^>) (parseError \"No opertion found\") parsers\n\nexport \nignoreThen : Parser a -> Parser b -> Parser b \nignoreThen parser1 parser2 = map snd (parser1 <&> parser2)\n\n\n\n-- Parses a line as text and consumes the newline \n-- TODO make this work on windows style newlines\nexport \nline : Parser String \nline = (until (=='\\n')) `thenDrop` (pChar '\\n')\n\nexport \npLines : Parser a -> Parser (List a)\npLines parser = sepBy parser line\n\ninfixl 3 <: \nexport \n(<:) : Parser a -> Parser b -> Parser b\n(<:) x y = ignoreThen x y \n", "meta": {"hexsha": "419d196067a16c1779c1049413178bf28bd448b9", "size": 6537, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Parser.idr", "max_stars_repo_name": "Stinners/Advent2021", "max_stars_repo_head_hexsha": "39a964633bd1eec22102eca9588d90be5f0a8c52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Parser.idr", "max_issues_repo_name": "Stinners/Advent2021", "max_issues_repo_head_hexsha": "39a964633bd1eec22102eca9588d90be5f0a8c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Parser.idr", "max_forks_repo_name": "Stinners/Advent2021", "max_forks_repo_head_hexsha": "39a964633bd1eec22102eca9588d90be5f0a8c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6847826087, "max_line_length": 69, "alphanum_fraction": 0.6409668043, "num_tokens": 1840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3225471630310558}} {"text": "module LightClick.Connection\n\nimport Data.Vect\n\nimport Toolkit.Decidable.Informative\nimport Toolkit.Data.Rig\n\nimport LightClick.Types\nimport LightClick.Types.Equality\nimport LightClick.Types.Compatibility\n\n%default total\n\nnamespace Port\n\n public export\n data Compatible : (left : Ty (PORT l))\n -> (right : Ty (PORT r))\n -> Type\n where\n IsSafe : (flow : Safe dl dr)\n -> (sens : Sensitivity.Compatible sl sr)\n -> (wtype : WireType.Compatible wl wr)\n -> (dtype : Data.Compatible tl tr)\n -> Port.Compatible (TyPort l dl sl wl tl ul)\n (TyPort r dr sr wr tr ur)\n\n directionUnsafe : (Safe dir x -> Void)\n -> Compatible (TyPort l dir sense wty type usage) (TyPort r x y z t w)\n -> Void\n directionUnsafe contra (IsSafe flow sens wtype dtype) = contra flow\n\n sensitivityInCompatible : (Compatible sense y -> Void)\n -> Compatible (TyPort l dir sense wty type usage) (TyPort r x y z t w)\n -> Void\n sensitivityInCompatible contra (IsSafe flow sens wtype dtype) = contra sens\n\n wireTypesInCompatible : (Compatible wty z -> Void)\n -> Compatible (TyPort l dir sense wty type usage) (TyPort r x y z t w)\n -> Void\n wireTypesInCompatible contra (IsSafe flow sens wtype dtype) = contra wtype\n\n dataTypeInCompatible : (Compatible type t -> Void)\n -> Compatible (TyPort l dir sense wty type usage) (TyPort r x y z t w) -> Void\n dataTypeInCompatible contra (IsSafe flow sens wtype dtype) = contra dtype\n\n public export\n data Error = InCompatSensitivity Sensitivity.Error\n | InCompatDirection Direction.Safe.Error\n | InCompatWTypes Wire.Error\n | InCompatDTypes Data.Error\n\n\n\n export\n compatible : (left : Ty (PORT l))\n -> (right : Ty (PORT r))\n -> DecInfo Port.Error\n (Compatible left right)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) with (safe dx dy)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) with (compatible sx sy)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) | (Yes prfS) with (compatible wx wy)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) | (Yes prfS) | (Yes prfW) with (compatible tx ty)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) | (Yes prfS) | (Yes prfW) | (Yes prfT)\n = Yes (IsSafe prfD prfS prfW prfT)\n\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) | (Yes prfS) | (Yes prfW) | (No msg contra)\n = No (InCompatDTypes msg) (dataTypeInCompatible contra)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) | (Yes prfS) | (No msg contra)\n = No (InCompatWTypes msg) (wireTypesInCompatible contra)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (Yes prfD) | (No msg contra)\n = No (InCompatSensitivity msg) (sensitivityInCompatible contra)\n compatible (TyPort l dx sx wx tx ux) (TyPort r dy sy wy ty uy) | (No msg contra)\n = No (InCompatDirection msg) (directionUnsafe contra)\n\nnamespace Fanout\n\n namespace PortList\n\n public export\n data Compatible : (input : Ty (PORT s))\n -> (fan : DVect String (Ty . PORT) n names)\n -> Type\n where\n Empty : PortList.Compatible i Nil\n Cons : {x : Ty (PORT s)}\n -> {rest : DVect String (Ty . PORT) n names}\n -> Port.Compatible i x\n -> PortList.Compatible i rest\n -> PortList.Compatible i (x::rest)\n\n headNotCompat : {xs : DVect String (Ty . PORT) n names}\n -> (Port.Compatible i x -> Void)\n -> PortList.Compatible i (x `DVect.(::)` xs)\n -> Void\n headNotCompat contra (Cons prf rest) = contra prf\n\n restNotCompat : {xs : DVect String (Ty . PORT) n names}\n -> (Compatible i xs -> Void)\n -> Compatible i (x `DVect.(::)` xs)\n -> Void\n restNotCompat contra (Cons prf rest) = contra rest\n\n public export\n data Error = PListError Nat (Ty (PORT s)) Port.Error\n\n export\n compatible : (input : Ty (PORT s))\n -> (ports : DVect String (Ty . PORT) n names)\n -> DecInfo PortList.Error\n (PortList.Compatible input ports)\n compatible i Nil = Yes Empty\n compatible i (x :: xs) with (compatible i x)\n compatible i (x :: xs) | (Yes prfX) with (compatible i xs)\n compatible i (x :: xs) | (Yes prfX) | Yes prfXs = Yes (Cons prfX prfXs)\n\n compatible i (x :: xs) | (Yes prfX) | (No (PListError pos y err) contra)\n = No (PListError (S pos) y err) (restNotCompat contra)\n compatible i (x :: xs) | (No msg contra) = No (PListError Z x msg) (headNotCompat contra)\n\n\n public export\n data Compatible : (input : Ty (PORT s))\n -> (fan : DVect String (Ty . PORT) (S (S n)) names)\n -> Type\n where\n CompatFanout : PortList.Compatible input fan\n -> Compatible input fan\n\n notCompatFanout : (PortList.Compatible input (x :: (y :: fan)) -> Void)\n -> Fanout.Compatible input (x :: (y :: fan)) -> Void\n notCompatFanout contra (CompatFanout prf) = contra prf\n\n\n export\n compatible : (input : Ty (PORT s))\n -> (fan : DVect String (Ty . PORT) (S (S n)) names)\n -> DecInfo PortList.Error\n (Fanout.Compatible input fan)\n\n compatible input (x::y::fan) with (PortList.compatible input (x::y::fan))\n compatible input (x::y::fan) | Yes prf = Yes (CompatFanout prf)\n compatible input (x::y::fan) | No msg contra = No msg (notCompatFanout contra)\n\nnamespace Mux\n\n public export\n data Error = CtrlNotSafe (Ty (PORT s)) Port.Error\n | MuxNotSafe (PortList.Error)\n\n\n namespace PortList\n\n public export\n data Compatible : (ports : DVect String (Ty . PORT) n names)\n -> (o : Ty (PORT s))\n -> Type\n where\n Empty : Compatible Nil o\n Cons : {x : Ty (PORT s)}\n -> {rest : DVect String (Ty . PORT) n names}\n -> Port.Compatible x o\n -> PortList.Compatible rest o\n -> PortList.Compatible (x::rest) o\n\n headNotCompat : {xs : DVect String (Ty . PORT) n names}\n -> (Port.Compatible x o -> Void)\n -> PortList.Compatible (x `DVect.(::)` xs) o\n -> Void\n headNotCompat contra (Cons prf rest) = contra prf\n\n restNotCompat : {xs : DVect String (Ty . PORT) n names}\n -> (Compatible xs o -> Void)\n -> Compatible (x `DVect.(::)` xs) o\n -> Void\n restNotCompat contra (Cons prf rest) = contra rest\n\n\n export\n compatible : (ports : DVect String (Ty . PORT) n names)\n -> (o : Ty (PORT s))\n -> DecInfo PortList.Error\n (PortList.Compatible ports o)\n compatible Nil o = Yes Empty\n compatible (x :: xs) o with (compatible x o)\n compatible (x :: xs) o | (Yes prfX) with (compatible xs o)\n compatible (x :: xs) o | (Yes prfX) | Yes prfXs = Yes (Cons prfX prfXs)\n\n compatible (x :: xs) o | (Yes prfX) | (No (PListError pos y err) contra)\n = No (PListError (S pos) y err) (restNotCompat contra)\n compatible (x :: xs) o | (No msg contra) = No (PListError Z x msg) (headNotCompat contra)\n\n namespace Fanin\n\n public export\n data Compatible : (fan : DVect String (Ty . PORT) (S (S n)) names)\n -> (output : Ty (PORT s))\n -> Type\n where\n CompatFanin : PortList.Compatible fan output\n -> Compatible fan output\n\n notCompatFanin : (PortList.Compatible (x :: (y :: fan)) output -> Void)\n -> Fanin.Compatible (x :: (y :: fan)) output -> Void\n notCompatFanin contra (CompatFanin prf) = contra prf\n\n\n export\n compatible : (fan : DVect String (Ty . PORT) (S (S n)) names)\n -> (output : Ty (PORT s))\n -> DecInfo PortList.Error\n (Fanin.Compatible fan output)\n\n compatible (x::y::fan) output with (PortList.compatible (x::y::fan) output)\n compatible (x::y::fan) output | Yes prf = Yes (CompatFanin prf)\n compatible (x::y::fan) output | No msg contra = No msg (notCompatFanin contra)\n\n public export\n data Compatible : (fan : DVect String (Ty . PORT) (S (S n)) names)\n -> (ctrl : Ty (PORT c))\n -> (output : Ty (PORT o))\n -> Type\n where\n CompatMux : (fan : DVect String (Ty . PORT) (S (S n)) names)\n -> (ctrl : Ty (PORT c))\n -> (out : Ty (PORT o))\n -> (safeCTRL : Port.Compatible ctrl (Control.mkDual ctrl))\n -> (safeFanIn : Fanin.Compatible fan out)\n -> Compatible fan ctrl out\n\n\n faninNotCompat : (Fanin.Compatible fan output -> Void)\n -> Compatible fan ctrl output -> Void\n faninNotCompat contra (CompatMux f c o prfCtrl prfFanin) = contra prfFanin\n\n ctrlNotCompat : {fan : DVect String (Ty . PORT) (S (S n)) names}\n -> (Port.Compatible ctrl (Control.mkDual ctrl) -> Void)\n -> Compatible fan ctrl output\n -> Void\n ctrlNotCompat contra (CompatMux f c o prfCtrl prfFanin) = contra prfCtrl\n\n export\n compatible : (fanin : DVect String (Ty . PORT) (S (S n)) names)\n -> (ctrl : Ty (PORT c))\n -> (output : Ty (PORT o))\n -> DecInfo Mux.Error\n (Compatible fanin ctrl output)\n compatible fan ctrl output with (Fanin.compatible fan output)\n compatible fan ctrl output | (Yes prfFan) with (compatible ctrl (Control.mkDual ctrl))\n compatible fan ctrl output | (Yes prfFan) | Yes prfCtrl = Yes (CompatMux fan ctrl output prfCtrl prfFan)\n\n compatible fan ctrl output | (Yes prfFan) | No msg contra\n = No (CtrlNotSafe (Control.mkDual ctrl) msg) (ctrlNotCompat contra)\n compatible fan ctrl output | No msg contra\n = No (MuxNotSafe msg) (faninNotCompat contra)\n\n-- [ EOF ]\n", "meta": {"hexsha": "8db6e2add875885c008dedb016dd8f7fc4f43616", "size": 10566, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/LightClick/Connection.idr", "max_stars_repo_name": "border-patrol/lightclick", "max_stars_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-11-03T11:33:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:11:38.000Z", "max_issues_repo_path": "src/LightClick/Connection.idr", "max_issues_repo_name": "border-patrol/lightclick", "max_issues_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LightClick/Connection.idr", "max_forks_repo_name": "border-patrol/lightclick", "max_forks_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9534883721, "max_line_length": 133, "alphanum_fraction": 0.5598144993, "num_tokens": 2837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.3220103522577372}} {"text": "module ITree\nimport Control.Monad.State\n\n-- Based on https://arxiv.org/pdf/1906.00046.pdf\n\ndata ITree : (e : Type -> Type) -> (r : Type) -> Type where\n Ret : r -> ITree e r\n Tau : Inf (ITree e r) -> ITree e r\n Vis : e a -> (a -> Inf (ITree e r)) -> ITree e r\n\nimplementation Functor (ITree e) where\n map f (Ret x) = Ret $ f x\n map f (Tau tr) = Tau $ map f tr\n map f (Vis e k) = Vis e (\\x => map f (k x))\n\nimplementation Applicative (ITree e) where\n pure a = Ret a\n\n (Ret f) <*> tra = map f tra\n (Tau trf) <*> tra = Tau $ trf <*> tra\n (Vis e k) <*> tra = Vis e (\\x => k x <*> tra)\n\nimplementation Monad (ITree e) where\n (Ret r) >>= f = f r\n (Tau tr) >>= f = Tau $ tr >>= f\n (Vis e f') >>= f = Vis e (\\x => f' x >>= f)\n\ninterface Monad m => MonadIter (m : Type -> Type) where\n iter : (a -> m (Either a b)) -> a -> m b\n\nimplementation MonadIter (ITree e) where\n iter body a = do {\n ab <- body a;\n case ab of\n Left a => Tau $ iter body a\n Right b => Ret b\n }\n\nimplementation MonadIter m => MonadIter (StateT s m) where\n iter body a = ST $ \\s => iter (\\(a, s) =>\n do {\n (ab, s) <- runStateT (body a) s\n pure $ case ab of\n Left a => Left (a, s)\n Right b => Right (b, s)\n }) (a, s)\n\ninterp : MonadIter m => ({r : Type} -> e r -> m r) -> {r : Type} -> ITree e r -> m r\ninterp h = iter (\\tr => case tr of\n Ret r => pure $ Right r\n Tau tr => pure $ Left tr\n Vis e k => h e >>= (\\x => pure $ Left (k x)))\n\ndata IO' : Type -> Type where\n Input : IO' Nat\n Output : Nat -> IO' ()\n\n\nspin : ITree IO' ()\nspin = Tau spin\n\nkill9 : ITree IO' ()\nkill9 = Vis Input (\\x => if x == 9 then Ret () else kill9)\n\ndata StateE : (s : Type) -> Type -> Type where\n Get : StateE s s\n Put : s -> StateE s ()\n\n\nhandlerState : StateE s r -> StateT s (ITree e) r\nhandlerState Get = ST $ \\s => Ret (s, s)\nhandlerState (Put s') = ST $ \\s => Ret ((), s')\n\ninterpState : MonadIter m => ({r : Type} -> e r -> StateT s m r) -> ITree e r -> StateT s m r\ninterpState h = interp h\n", "meta": {"hexsha": "d35dd854d8c22861524c8d5ca18c853ea34be761", "size": 2160, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ITree.idr", "max_stars_repo_name": "STELIORD/idris-snippets", "max_stars_repo_head_hexsha": "f5ca6fa86370d24587040af9871ae850bbc630c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-11-21T22:28:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-05T18:25:18.000Z", "max_issues_repo_path": "src/ITree.idr", "max_issues_repo_name": "stjordanis/idris-snippets", "max_issues_repo_head_hexsha": "d92734b8624ae27be21a63fcb041077b38eaaecb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ITree.idr", "max_forks_repo_name": "stjordanis/idris-snippets", "max_forks_repo_head_hexsha": "d92734b8624ae27be21a63fcb041077b38eaaecb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-05-06T13:39:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T15:39:16.000Z", "avg_line_length": 28.4210526316, "max_line_length": 93, "alphanum_fraction": 0.4986111111, "num_tokens": 704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3219494999607148}} {"text": "module FLK_sos\n\nimport FLK_ast\nimport Data.SortedMap\n\n-- operational semanitcs for FLK\n-- TODO: Need way to have abstractions step\nmutual\n infixr 5 >==> -- read like => in SOS-land\n (>==>) : (CF a) -> (CF b) -> Type\n l >==> r = Step l r\n\n syntax \"[\" [ex1] \"=>\" [ex2] \"]\"=\n ex1 >- _ `Step` ex2 >- _\n\n syntax \"[\" [ex1] \",\" [env1] \"=>\" [ex2] \",\" [env2] \"]\"=\n ex1 >- env1 `Step` ex2 >- env2\n\n data Step : (CF a) -> (CF b) -> Type where\n PNot : [Prim1 Not (B b), e => B (not b), e]\n\n PrimStep : [b => b']\n -> [Prim1 o b, e => Prim1 o b', e]\n\n ArithOp : {o : Op2 Arith}\n -> [Prim2 o (N n1) (N n2), e => N (arithOp o n1 n2), e]\n\n RelOp : {o : Op2 Rel}\n -> [Prim2 o (N b1) (N b2), e => B (relop o b1 b2), e]\n\n GenOp : {o : Op2 Gen} -> {op1 : Exp Done} -> {op2 : Exp Done}\n -> [Prim2 o op1 op2, e => genOp o op1 op2, e]\n\n Prim2L : [b => b']\n -> [Prim2 o b re, e => Prim2 o b' re, e]\n\n Prim2R : {le : Exp Done}\n -> [b => b']\n -> [Prim2 o le b, e => Prim2 o le b', e]\n\n IfCase : [b => b']\n -> [If b t f, e' => If b' t f, e']\n\n IfT : [If (B True) t f, e => t, e]\n\n IfF : [If (B False) t f, e => f, e]\n\n ClosLam : [Abs ident exp, e => Clos e (Abs ident exp), e]\n\n AppFunT : [b => b']\n -> [App b exp, e => App b' exp, e]\n\n AppArgT : [arg => arg']\n -> [App (Clos env lam) arg, e => App (Clos env lam) arg', e]\n\n AppLam : {val : Exp Done}\n -> [App (Clos env (Abs ident body)) val, e => body, insert ident (Left val) env]\n\n IdTrans : {e : Env} -> {n : Ident}\n -> Sigma (Exp Done) (\\v => lookup n e = (Just (Left v)))\n -> [(Id n), e => v, e]\n\n IdRecTrans : {e : Env} -> {n : Ident}\n -> Sigma (Exp RecLam) (\\v => lookup n e = (Just (Right v)))\n -> [(Id n), e => v, e]\n\n RecTrans : [(Rec ident exp), e => exp, insert ident (Right $ Rec ident exp) e]\n\n syntax \"[[\" [str] \",\" [sub] \"]]\" = str++\" [\"++(show sub)++\"]\";\n\n instance Show (Step a b) where\n show PNot = \"PNot\"\n show (PrimStep w) = [[\"PrimStep\", w]]\n show ArithOp = \"ArithOp\"\n show RelOp = \"RelOp\"\n show GenOp = \"GenOp\"\n show (Prim2L t) = [[\"Prim2L\", t]]\n show (Prim2R s) = [[\"Prim2R\", s]]\n show (IfCase s) = [[\"IfCase\", s]]\n show IfT = \"IfT\"\n show IfF = \"IfF\"\n show ClosLam = \"ClosLam\"\n show (AppFunT s) = [[\"AppFunT\", s]]\n show (AppArgT z) = [[\"AppArgT\", z]]\n show AppLam = \"AppLam\"\n show (IdTrans x) = \"IdTrans\"\n show (IdRecTrans x) = \"IdRecTrans\"\n show RecTrans = \"RecTrans\"\n\n-- Simple rule application\ntestStep1 : Prim1 Not (B True) >- e >==> (B False) >- e\ntestStep1 = PNot\n\n-- Compose two rules\ntestStep : [(Prim1 Not (Prim1 Not (B False))), e => Prim1 Not (B True), e]\ntestStep {e=e} = PrimStep $ PNot {e=e}\n\ntakeStep : {state' : CF b} -> {rule : state >==> state'} -> (state : CF a) -> CF b\ntakeStep {state' = s} _ = s\n\ndefault : Exp a -> CF a\ndefault x = x >- emptyEnv\n\nopResolve : {e : Env}\n -> (op : Op2 a)\n -> (o1 : Exp Done)\n -> (o2 : Exp Done)\n -> Maybe (Sigma (Exp Done) (\\state => Step ((Prim2 op o1 o2) >- e) (state >- e)))\nopResolve EQ op1 op2 = Just ((genOp EQ op1 op2) ** GenOp)\nopResolve NEQ op1 op2 = Just ((genOp NEQ op1 op2) ** GenOp)\nopResolve Plus (N k) (N z) = Just ((N $ arithOp Plus k z) ** ArithOp)\nopResolve Minus (N k) (N z) = Just ((N $ arithOp Minus k z) ** ArithOp)\nopResolve LThan (N k) (N z) = Just ((B $ relop LThan k z) ** RelOp)\nopResolve LEThan (N k) (N z) = Just ((B $ relop LEThan k z) ** RelOp)\nopResolve GThan (N k) (N z) = Just ((B $ relop GThan k z) ** RelOp)\nopResolve GEThan (N k) (N z) = Just ((B $ relop GEThan k z) ** RelOp)\nopResolve x x1 x2 = Nothing\n\n\nmutual\n -- Evaluator based on operational semantics\n -- TODO: add printing, with effects and such\n goTill : Sigma Status (\\s => CF s) -> Sigma Status (\\s' => CF s')\n goTill (MkSigma Inter pf) with (search pf)\n goTill (MkSigma Inter pf) | Nothing = MkSigma Inter pf\n goTill (MkSigma Inter pf) | (Just (MkSigma x (MkSigma y z))) = goTill $ MkSigma x y\n goTill p@(MkSigma Done pf) = p\n goTill (MkSigma Lam pf) with (searchLam pf)\n goTill (MkSigma Lam pf) | Nothing = (MkSigma Lam pf)\n goTill (MkSigma Lam pf) | (Just (MkSigma x (MkSigma y z))) = goTill $ MkSigma x y\n goTill (MkSigma RecLam pf) = let (x ** (y ** z)) = recTrans pf in goTill (x ** y)\n\n\n -- Search rules for the semantics\n -- Forall states, we get\n -- Maybe (exists a Status such that there exists a state with\n -- that status that is transitioned to by the state)\n search : (start : CF Inter) -> Maybe (Sigma Status (\\s => (Sigma (CF s) (\\o => Step start o))))\n search ((App z w) >- y) = search_app y z w\n search ((If z w s) >- y) = search_if z w s y\n search ((Prim1 z w) >- y) = search_prim1 z w y\n search ((Prim2 z w s) >- y) = search_prim2 z w s y\n search ((Id x) >- y) with (idSteps x y)\n search ((Id x) >- y) | Nothing with (idRecSteps x y)\n search ((Id x) >- y) | Nothing | Nothing = Nothing\n search ((Id x) >- y) | Nothing | (Just (v ** pf)) =\n Just $ (RecLam ** (v >- y ** IdRecTrans (v ** pf)))\n search ((Id x) >- y) | Just (v ** pf) = Just $ (Done ** (v >- y ** IdTrans (v ** pf)))\n\n -- This is a macro that will do most of the intermediate computations needed for some common\n -- lemmas\n -- My understanding is that this sort of thing should be done with a high-level tactic\n -- involving reflection. I do not fully understand how to use this feature, so I am using the\n -- 'syntax' feature as a macro system of sorts\n syntax \"[[\" {state} \",\" {trans} \",\" [env] \",\" [ex] \",\" [newstate] \",\" [rule] \"]]\" =\n case (search $ ex >- env) of {\n Nothing => Nothing ;\n Just (status ** (state >- y' ** trans)) =>\n Just (Inter ** (newstate >- env ** rule));\n }\n\n -- transition intermediate-result composite expressions. wrapper for above macro\n syntax \"[[\" [env] \";\" [ex] \";\" [newstate] \";\" [rule] \"]]\" =\n [[ state, trans, env, ex, (newstate state), (rule trans)]]\n\n -- transition abstractions\n syntax \"<[\" [trans] \",\" [abs] \",\" [env] \",\" [state] \"]>\" =\n Just $ (_ ** (((state (Clos env abs)) >- env) ** trans ClosLam));\n -- transition rec expressions\n syntax \"<[\" [trans] \";\" [rec] \";\" [env] \";\" [state] \"]>\" =\n let (tag ** (newstate >- env' ** newtrans)) = recTrans (rec >- env) in\n Just $ (_ ** ((state newstate) >- env ** trans newtrans));\n\n search_prim2_rhs_7 : (z : Op2 y)\n -> (exp : Exp Done)\n -> (s : Exp b)\n -> (y : SortedMap String (Either (Exp Done) (Exp RecLam)))\n -> Maybe (Sigma Status (\\s2 => Sigma (CF s2)\n (\\o => Step ((Prim2 z exp s) >- y) o)))\n search_prim2_rhs_7 z exp (App x w) y = [[y; (App x w); Prim2 z exp; Prim2R]]\n search_prim2_rhs_7 z exp (Abs x w) y = <[Prim2R, (Abs x w), y, Prim2 z exp]>\n search_prim2_rhs_7 z exp (Rec x w) y = <[Prim2R; (Rec x w); y; Prim2 z exp]>\n search_prim2_rhs_7 z exp (If x w s) y = [[y; If x w s; Prim2 z exp; Prim2R]]\n search_prim2_rhs_7 z exp (Prim1 x w) y = [[y; Prim1 x w; Prim2 z exp; Prim2R]]\n search_prim2_rhs_7 z exp (Prim2 w s t) y = [[y; Prim2 w s t; Prim2 z exp; Prim2R]]\n search_prim2_rhs_7 z exp (Id x) y = [[y; Id x; Prim2 z exp; Prim2R]]\n search_prim2_rhs_7 z exp (N k) y with (opResolve {e=y} z exp (N k))\n search_prim2_rhs_7 z exp (N k) y | Nothing = Nothing\n search_prim2_rhs_7 z exp (N k) y | (Just (exp ** step)) = Just (Done ** (exp >- y ** step))\n search_prim2_rhs_7 z exp (B x) y with (opResolve {e=y} z exp (B x))\n search_prim2_rhs_7 z exp (B x) y | Nothing = Nothing\n search_prim2_rhs_7 z exp (B x) y | (Just (exp ** step)) = Just (Done ** (exp >- y ** step))\n search_prim2_rhs_7 z exp (Clos x w) y with (opResolve {e=y} z exp (Clos x w))\n search_prim2_rhs_7 z exp (Clos x w) y | Nothing = Nothing\n search_prim2_rhs_7 z exp (Clos x w) y | (Just (exp ** step)) = Just (Done ** (exp >- y ** step))\n\n search_prim2 : (z : Op2 y)\n -> (w : Exp a)\n -> (s : Exp b)\n -> (y : SortedMap String (Either (Exp Done) (Exp RecLam)))\n -> Maybe (Sigma Status (\\s1 => Sigma (CF s1)\n (\\o => Step ((Prim2 z w s) >- y) o)))\n search_prim2 z (App x w) s y = [[y; (App x w); \\st => Prim2 z st s; Prim2L]]\n search_prim2 z (Abs x w) s y = <[Prim2L, (Abs x w), y, \\st => Prim2 z st s]>\n search_prim2 z (Rec x w) s y = <[Prim2L; (Rec x w); y; \\st => Prim2 z st s]>\n search_prim2 z (If x w t) s y = [[y; If x w t; \\st => Prim2 z st s; Prim2L]]\n search_prim2 z (Prim1 x w) s y = [[y; Prim1 x w; \\st => Prim2 z st s; Prim2L]]\n search_prim2 z (Prim2 w t u) s y = [[y; Prim2 w t u; \\st => Prim2 z st s; Prim2L]]\n search_prim2 z (Id x) s y = [[y; Id x; \\st => Prim2 z st s; Prim2L]]\n search_prim2 z (N k) s y = search_prim2_rhs_7 z (N k) s y\n search_prim2 z (B x) s y = search_prim2_rhs_7 z (B x) s y\n search_prim2 z (Clos x w) s y = search_prim2_rhs_7 z (Clos x w) s y\n\n total\n searchLam : (start : CF Lam)\n -> Maybe (Sigma Status (\\s => (Sigma (CF s) (\\o => Step start o))))\n searchLam ((Abs x z) >- y) = <[ id , (Abs x z), y, id ]>\n\n total\n recTrans : (start : CF RecLam)\n -> (Sigma Status (\\s => (Sigma (CF s) (\\o => Step start o))))\n recTrans ((Rec x z) >- y) = (getTag z ** (z >- (insert x (Right $ Rec x z) y) ** RecTrans))\n\n\n total\n searchRec : (start : CF RecLam)\n -> Maybe (Sigma Status (\\s => (Sigma (CF s) (\\o => Step start o))))\n searchRec r = Just $ recTrans r\n\n search_if : (z : Exp a)\n -> (w : Exp b)\n -> (s : Exp c)\n -> (y : Env)\n -> Maybe (Sigma Status (\\s1 => Sigma (CF s1) (\\o => Step ((If z w s) >- y) o)))\n search_if (Abs x z) w s y = <[IfCase, (Abs x z), y, \\c => If c w s]> --Nothing\n search_if (Rec i b) w s y = <[IfCase; (Rec i b); y; \\c => If c w s]>\n search_if (N _) _ _ _ = Nothing\n search_if (Clos _ _) _ _ _ = Nothing\n search_if (B x) w s y = case x of\n True => let t = getTag w in\n Just (t ** (w >- y ** IfT))\n False => let t = getTag s in\n Just (t ** (s >- y ** IfF))\n search_if (App lam st) w s y = [[state, trans, y, App lam st, If state w s , IfCase trans]]\n search_if (If x z t) w s y = [[y; (If x z t); \\state => If state w s; IfCase]]\n search_if (Prim1 x z) w s y = [[y; (Prim1 x z); \\state => If state w s; IfCase]]\n search_if (Prim2 x z t) w s y = [[y; (Prim2 x z t); \\state => If state w s; IfCase]]\n search_if (Id x) w s y = [[y; (Id x); \\state => If state w s; IfCase]]\n\n search_prim1 : (z : Op1)\n -> (w : Exp a)\n -> (y : Env)\n -> Maybe (Sigma Status (\\s => Sigma (CF s) (\\o => Step ((Prim1 z w) >- y) o)))\n search_prim1 Not (Abs x z) y = <[PrimStep, (Abs x z), y, (Prim1 Not)]>\n search_prim1 Not (Rec x z) y = <[PrimStep; (Rec x z); y; (Prim1 Not)]>\n search_prim1 Not (N k) y = Nothing\n search_prim1 Not (Clos x z) y = Nothing\n search_prim1 Not (B x) y = Just $ (Done ** (B (not x) >- y ** PNot))\n search_prim1 Not (App x z) y = [[y; (App x z); Prim1 Not; PrimStep]]\n search_prim1 Not (If x z w) y = [[y; (If x z w); Prim1 Not; PrimStep]]\n search_prim1 Not (Prim1 x z) y = [[y; (Prim1 x z); Prim1 Not; PrimStep]]\n search_prim1 Not (Prim2 z w s) y = [[y; (Prim2 z w s); Prim1 Not; PrimStep]]\n search_prim1 Not (Id x) y = [[y; (Id x); Prim1 Not; PrimStep]]\n\n search_subst_env : (y : Env) -- Outer environment\n -> (x : Env) -- Closure environment\n -> (z : Exp Lam)\n -> (k : Exp Done)\n -> Maybe (Sigma Status\n (\\s => Sigma (CF s)\n (\\o => Step ((App (Clos x z) k) >- y) o)))\n search_subst_env y x (Abs iden w) k =\n Just $ (getTag w ** (w >- (insert iden (Left k) x) ** AppLam))\n\n search_app : (y : Env)\n -> (z : Exp a)\n -> (w : Exp b)\n -> Maybe (Sigma Status (\\s => Sigma (CF s) (\\o => Step ((App z w) >- y) o)))\n search_app y p@(Abs id body) w = <[AppFunT, (Abs id body), y, (\\clos => App clos w)]>\n search_app y (App e b) w = [[y; (App e b); \\s => App s w; AppFunT]]\n search_app y (If c t f) w = [[y; (If c t f); \\s => App s w; AppFunT]]\n search_app y (Prim1 op oa) w = [[y; (Prim1 op oa); \\s => App s w; AppFunT]]\n search_app y (Prim2 op o1 o2) w = [[y; (Prim2 op o1 o2); \\s => App s w; AppFunT]]\n search_app y (Id x) w = [[y; (Id x); \\s => App s w; AppFunT]]\n search_app y (N k) w = Nothing\n search_app y (B x) w = Nothing\n search_app y (Rec x z) w = <[AppFunT; (Rec x z); y; (\\clos => App clos w)]>\n search_app y (Clos x z) (Rec w s) = <[AppArgT; (Rec w s); y; (\\arg => App (Clos x z) arg)]>\n search_app y (Clos x z) (App e b) = [[y; App e b; App (Clos x z); AppArgT]]\n search_app y (Clos x z) (If c t f) = [[y; If c t f; App (Clos x z); AppArgT]]\n search_app y (Clos x z) (Prim1 op oa) = [[y; Prim1 op oa; App (Clos x z); AppArgT]]\n search_app y (Clos x z) (Prim2 op o1 o2) = [[y; Prim2 op o1 o2; App (Clos x z); AppArgT]]\n search_app y (Clos x z) (Id i) = [[y; Id i; App (Clos x z); AppArgT]]\n search_app y (Clos x z) p@(Abs _ _) = Just $ (Inter **\n (App (Clos x z) (Clos y p) >- y **\n AppArgT ClosLam))\n search_app y (Clos x z) p@(N k) = search_subst_env y x z p\n search_app y (Clos x z) p@(B w) = search_subst_env y x z p\n search_app y (Clos x z) p@(Clos w s) = search_subst_env y x z p\n", "meta": {"hexsha": "a75220a5ab147b984a9cf29864cac86efe41f3ad", "size": 14056, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "FLK_sos.idr", "max_stars_repo_name": "ezrosent/FLK-Semantics", "max_stars_repo_head_hexsha": "8198a567b2b96ee6658573e48359a195ba42151c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-21T09:46:31.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-21T15:37:59.000Z", "max_issues_repo_path": "FLK_sos.idr", "max_issues_repo_name": "ezrosent/FLK-Semantics", "max_issues_repo_head_hexsha": "8198a567b2b96ee6658573e48359a195ba42151c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "FLK_sos.idr", "max_forks_repo_name": "ezrosent/FLK-Semantics", "max_forks_repo_head_hexsha": "8198a567b2b96ee6658573e48359a195ba42151c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.8533333333, "max_line_length": 100, "alphanum_fraction": 0.5114541833, "num_tokens": 4995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.32165324685182645}} {"text": "module Main\n\nimport Effect.StdIO\nimport VectMissing\n\n-----------------------------------------------------------------------\n-- GAME STATE\n-----------------------------------------------------------------------\n\n\n{- First, the game state, HState, where the type specifies how many guesses\nare left and how many missing letters there are still to get. -}\n\ndata HState : Nat -> Nat -> Type where\n MkH : (word : String) ->\n (guesses : Nat) ->\n (got : List Char) ->\n (missing : Vect m Char) ->\n HState guesses m\n\ninstance Default (HState 0 0) where\n default = MkH \"\" 0 [] []\n\ninstance Show (HState guesses m) where\n show (MkH w _ got missing)\n = let w' = pack (map showGot (unpack w)) in\n w' ++ \"\\n\\n\" ++ show guesses ++ \" guesses left\"\n where showGot : Char -> Char\n showGot ' ' = '/'\n showGot c = if ((not (isAlpha c)) || (c `elem` got)) then c else '-'\n\n{- Initialise the state with the missing letters in a word -}\n\ntotal\nletters : String -> List Char\nletters x with (strM x)\n letters \"\" | StrNil = []\n letters (strCons y xs) | (StrCons y xs) \n = let xs' = assert_total (letters xs) in\n if ((not (isAlpha y)) || (y `elem` xs')) then xs' else y :: xs'\n\ninitState : (x : String) -> HState 6 (length (letters x))\ninitState w = let xs = letters w in\n MkH w _ [] (fromList (letters w))\n\n-----------------------------------------------------------------------\n-- RULES\n-----------------------------------------------------------------------\n\n{- Now, the rules of the game, written as an Effect. \nWe can think of the rules as giving a protocol that the game player and\nthe machine must follow for an implementation of the game to make sense.\n-}\n\ndata Hangman : Effect where\n\n-- Rule:\n-- Precondition: we can make a guess if we have one or more guess available \n-- (S g) and one or more letters are still missing (S w)\n\n-- Postcondition: return whether the character was in the word. If so, reduce\n-- the number of missing letters, if not, reduce the number of guesses left\n\n Guess : (x : Char) ->\n { HState (S g) (S w) ==>\n {inword} if inword then HState (S g) w\n else HState g (S w) }\n Hangman Bool\n\n-- The 'Won' operation requires that there are no missing letters\n\n Won : { HState g 0 ==> HState 0 0 } Hangman ()\n\n-- The 'Lost' operation requires that there are no guesses left\n\n Lost : { HState 0 w ==> HState 0 0 } Hangman ()\n\n-- Set up a new game, initialised with 6 guesses and the missing letters in\n-- the given word. Note that if there are no letters in the word, we won't\n-- be able to run 'Guess'!\n\n NewWord : (w : String) -> \n { h ==> HState 6 (length (letters w)) } Hangman ()\n\n-- Finally, allow us to get the current game state\n \n Get : { h } Hangman h\n\nHANGMAN : Nat -> Nat -> EFFECT\nHANGMAN g v = MkEff (HState g v) Hangman\n\n-----------------------------------------------------------------------\n-- IMPLEMENTATION OF THE RULES\n-----------------------------------------------------------------------\n\n{- This effect handler simply updates the game state as necessary for\neach operation. 'Guess' is slightly tricky, in that it needs to check\nwhether the letter is in the word, and branch accordingly (and if it\nis in the word, update the vector of missing letters to be the right\nlength). -}\n\nusing (m : Type -> Type)\n instance Handler Hangman m where\n handle (MkH w g got []) Won k = k () (MkH w 0 got [])\n handle (MkH w Z got m) Lost k = k () (MkH w 0 got [])\n\n handle st Get k = k st st\n handle st (NewWord w) k = k () (initState w)\n\n handle (MkH w (S g) got m) (Guess x) k =\n case isElem x m of\n Nothing => k False (MkH w _ got m)\n (Just p) => k True (MkH w _ (x :: got) (shrink m p))\n\n-----------------------------------------------------------------------\n-- USER INTERFACE \n-----------------------------------------------------------------------\n\n{- Finally, an implementation of the game which reads user input and calls\nthe operations we defined above when appropriate -}\n\ngame : { [HANGMAN (S g) (S w), STDIO] ==> [HANGMAN 0 0, STDIO] } Eff IO ()\ngame = do putStrLn (show !Get)\n putStr \"Enter guess: \"\n let guess = trim !getStr\n case choose (not (guess == \"\")) of\n (Left p) => processGuess (strHead' guess p)\n (Right p) => do putStrLn \"Invalid input!\"\n game\n where \n processGuess : Char -> { [HANGMAN (S g) (S w), STDIO] ==> \n [HANGMAN 0 0, STDIO] }\n Eff IO ()\n processGuess {g} {w} c\n = case !(Main.Guess c) of\n True => do putStrLn \"Good guess!\"\n case w of\n Z => Won \n (S k) => game\n False => do putStrLn \"No, sorry\"\n case g of\n Z => Lost\n (S k) => game\n\n{- It typechecks! Ship it! -}\n\nrunGame : { [HANGMAN 0 0, STDIO] } Eff IO ()\nrunGame = do NewWord \"sausage machine\"\n game\n\n{- I made a couple of mistakes while writing this. For example, the following \nwere caught by the type checker:\n\n* Forgetting to check the 'Won' state before continuing with 'game'\n* Accidentally checking the number of missing letters rather than the number\n of guesses when checking if 'Lost' was callable\n\n-}\n\nmain : IO ()\nmain = run runGame\n\n", "meta": {"hexsha": "c72e0013be6d42875998b4b648a742a203524224", "size": 5588, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Hangman/hangman.idr", "max_stars_repo_name": "silky/idris-demos", "max_stars_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-27T11:33:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T11:33:51.000Z", "max_issues_repo_path": "Hangman/hangman.idr", "max_issues_repo_name": "silky/idris-demos", "max_issues_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Hangman/hangman.idr", "max_forks_repo_name": "silky/idris-demos", "max_forks_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.282208589, "max_line_length": 80, "alphanum_fraction": 0.5173586256, "num_tokens": 1361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.32039813809445644}} {"text": "-- --------------------------------------------------------- [ Concurrency.idr ]\n-- Module : Chapter.Concurrency\n-- Description : Definitions from Chapter 15 of Edwin Brady's book,\n-- \"Type-Driven Development with Idris.\"\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Chapter.Concurrency\n\nimport System.Concurrency.Channels\nimport Chapter.Concurrency.ProcessLib\n\n-- import Control.Arrow\n-- import Control.Category\n-- import Data.Morphisms\n\n-- ------------------------------------ [ 15.1.1 Defining Concurrent Processes ]\n\n%access public export\n\ndata Message = Add Nat Nat\n\n-- ---------------------------------------- [ 15.1.2 Primitive Message Passing ]\n\nnamespace Unsafe\n\n %access export\n\n partial adder :IO ()\n adder = do Just chan <- listen 1\n | Nothing => adder\n Just msg <- unsafeRecv Message chan\n | Nothing => adder\n case msg of\n Add x y => do ok <- unsafeSend chan (x + y)\n adder\n\n partial main : IO ()\n main = do Just pid <- spawn adder\n | Nothing => putStrLn \"Spawn failed\"\n Just chan <- connect pid\n | Nothing => putStrLn \"Connection failed\"\n ok <- unsafeSend chan (Add 2 3)\n Just answer <- unsafeRecv Nat chan\n | Nothing => putStrLn \"Receive failed\"\n printLn answer\n\n-- ----------------------------------- [ 15.2.1 Describing Processes in a Type ]\n\nnamespace Safe\n\n %access public export\n\n data MessagePID = MkMessage PID\n\n data Process : Type -> Type where\n Request : MessagePID -> Message -> Process (Maybe Nat)\n Respond : ((msg : Message) -> Process Nat) -> Process (Maybe Message)\n Spawn : Process () -> Process (Maybe MessagePID)\n Loop : Inf (Process a) -> Process a\n\n Action : IO a -> Process a\n Pure : a -> Process a\n (>>=) : Process a -> (a -> Process b) -> Process b\n\n run : Fuel -> Process t -> IO (Maybe t)\n run Dry _ = pure Nothing\n run fuel (Action act) = pure (Just !act)\n run fuel (Pure val) = pure (Just val)\n run fuel (act >>= next) = do Just x <- run fuel act\n | Nothing => pure Nothing\n run fuel (next x)\n run (More fuel) (Loop act) = run fuel act\n run fuel (Spawn proc) = do Just pid <- spawn (run fuel proc *> pure ())\n | Nothing => pure Nothing\n pure (Just (Just (MkMessage pid)))\n -- TODO: encapsulate timeout\n run fuel (Respond calc) = do Just sender <- listen 1\n | Nothing => pure (Just Nothing)\n Just msg <- unsafeRecv Message sender\n | Nothing => pure (Just Nothing)\n Just res <- run fuel (calc msg)\n | Nothing => pure Nothing\n unsafeSend sender res\n pure (Just (Just msg))\n run fuel (Request (MkMessage proc) msg) =\n do Just chan <- connect proc\n | Nothing => pure (Just Nothing)\n if !(unsafeSend chan msg)\n then do Just x <- unsafeRecv Nat chan\n | Nothing => pure (Just Nothing)\n pure (Just (Just x))\n else pure (Just Nothing)\n\n partial runProc : Process () -> IO ()\n runProc proc = run forever proc *> pure ()\n\n adder : Process ()\n adder = do Respond go\n Loop adder\n where\n go : Message -> Process Nat\n go (Add x y) = Pure (x + y)\n\n partial main : Process ()\n main = do Just pid <- Spawn adder\n | Nothing => Action (putStrLn \"Spawn failed\")\n Just answer <- Request pid (Add 2 3)\n | Nothing => Action (putStrLn \"Request failed\")\n Action (printLn answer)\n\n -- NOTE: These two definitions type-check, but don't respond to messages.\n\n -- adderBad1 : Process ()\n -- adderBad1 = do Action $ putStrLn \"I'm out of the office today\"\n -- Loop adderBad1\n\n -- adderBad2 : Process ()\n -- adderBad2 = Loop adderBad2\n\nnamespace Stateful\n\n -- data AdderAction : Type where\n -- Add : Nat -> Nat -> AdderAction\n\n public export\n AdderType : Message -> Type\n AdderType (Add x y) = Nat\n\n export\n adder : Service AdderType ()\n adder = do Respond (\\(Add x y) => Pure (x + y))\n Loop adder\n\nnamespace ListProcessing\n\n %access public export\n\n data ListAction : Type where\n Length : List elem -> ListAction\n Append : List elem -> List elem -> ListAction\n\n ListType : ListAction -> Type\n ListType (Length xs) = Nat\n ListType (Append {elem} xs ys) = List elem\n\n %access export\n\n procList : Service ListType ()\n procList = do Respond go\n Loop procList\n where\n go : (msg : ListAction) -> Process ListType (ListType msg) Ready Ready\n go (Length xs) = Pure (length xs)\n go (Append xs ys) = Pure (xs ++ ys)\n\n procMain : Client ()\n procMain = do Just list <- Spawn procList\n | Nothing => Action (putStrLn \"Spawn failed\")\n len <- Request list (Length [1,2,3])\n Action (printLn len)\n app <- Request list (Append [1,2,3] [4,5,6])\n Action (printLn app)\n\nnamespace WordCounting\n\n %access public export\n\n record WCData where\n constructor MkWCData\n wordCount : Nat\n lineCount : Nat\n\n implementation Show WCData where\n show (MkWCData wc lc) = unlines [ \"Words: \" ++ show wc\n , \"Lines: \" ++ show lc\n ]\n\n data WC = CountFile String\n | GetData String\n\n implementation Show WC where\n show (CountFile fname) = \"CountFile \" ++ fname\n show (GetData fname) = \"GetData \" ++ fname\n\n WCType : WC -> Type\n WCType (CountFile _) = ()\n WCType (GetData _) = Maybe WCData\n\n private\n doCount : (content : String) -> WCData\n doCount content = MkWCData (length (lines content))\n (length (words content))\n\n -- doCount' : (content : String) -> WCData\n -- doCount' = applyMor $ arrow (length . lines) &&&\n -- arrow (length . words) >>>\n -- arrow (uncurry MkWCData)\n\n countFile : List (String, WCData) -> String ->\n Process WCType (List (String, WCData)) Sent Sent\n countFile files fname =\n do Right content <- Action (readFile fname)\n | Left _ => Pure files\n let count = doCount content\n Action (putStrLn (\"Counting complete for \" ++ fname))\n Pure ((fname, doCount content) :: files)\n\n wcService : (loaded : List (String, WCData)) ->\n Service WCType ()\n wcService loaded =\n do msg <- Respond go\n newLoaded <- case msg of\n Just (CountFile fname) => countFile loaded fname\n _ => Pure loaded\n Loop (wcService newLoaded)\n where\n go : (msg : WC) -> Process WCType (WCType msg) Ready Ready\n go (CountFile fname) = Pure ()\n go (GetData fname) = Pure (lookup fname loaded)\n\n procMain : Client ()\n procMain =\n do Just wc <- Spawn (wcService [])\n | Nothing => Action (putStrLn \"Spawn failed\")\n Action (putStrLn \"Counting test.txt\")\n let fname = \"/Users/mohacker/src/yurrriq/tdd-with-idris/README.org\"\n Request wc (CountFile fname)\n Action (putStrLn \"Processing\")\n Just wcdata <- Request wc (GetData fname)\n | Nothing => Action (putStrLn \"File error\")\n Action (printLn wcdata)\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "b51bb0c1b230981aa45b7551aaeff8f54e6ca8f1", "size": 7802, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Chapter/Concurrency.idr", "max_stars_repo_name": "yurrriq/tdd-with-idris", "max_stars_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-15T01:29:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-15T01:29:36.000Z", "max_issues_repo_path": "src/Chapter/Concurrency.idr", "max_issues_repo_name": "yurrriq/tdd-with-idris", "max_issues_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-11-21T23:42:45.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-01T05:43:10.000Z", "max_forks_repo_path": "src/Chapter/Concurrency.idr", "max_forks_repo_name": "yurrriq/tdd-with-idris", "max_forks_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4849785408, "max_line_length": 80, "alphanum_fraction": 0.526275314, "num_tokens": 1801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6224593171945417, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.318522768361264}} {"text": "module TypeTrans.AST\n\nimport Data.Vect\n\n-- Define Type Aliases\nRule : Type\nRule = String\n\nName : Type\nName = String\n\nValue : Type\nValue = String\n\nAssoc : Type\nAssoc = Bool\n\nPerformance : Type\nPerformance = Float\n\nCost : Type\nCost = Float\n\ndata Variant = Par | Seq | Stream | Tree \n\nimplementation Show Variant where\n show Par = \"Par\"\n show Seq = \"Seq\"\n show Stream = \"Stream\"\n show Tree = \"Tree\"\n\n\ndata TypeT = \n Vec Nat TypeT |\n Tuple (List TypeT) | \n IntT | \n ByteT | \n BitT | \n LongT | \n FloatT | \n DoubleT | \n BoolT | \n T1 | \n T2 | \n T3 \n\nimplementation Show TypeT where \n show (Vec i t) = \"Vec \" ++ show i ++ \" (\" ++ show t ++ \")\" \n show (Tuple xs) = \"Tuple \" ++ show xs \n show IntT = \"Int\"\n show ByteT = \"Byte\"\n show BitT = \"Bit\"\n show LongT = \"Long\"\n show FloatT = \"Float\"\n show DoubleT = \"Double\"\n show BoolT = \"Bool\"\n show T1 = \"T1\"\n show T2 = \"T2\"\n show T3 = \"T3\"\n\n\n-- Vector with description of its dimensions in the type\n--NVec : Vect n Nat -> TypeT -> TypeT\n--NVec Nil t = t\n--NVec (v::vs) t = Vec v (NVec vs t) \n\n\n-- Calculate the dimension of the given type\ngetDimension : TypeT -> Nat\ngetDimension (Vec i t) = (S Z) + getDimension t \ngetDimension _ = Z -- Non vector types have dimension 0\n\n\n\nmutual\n-- Argument is not a very good name. I mean something of type a as opposed to a -> b for the actions\n data Argument = \n Arg Name TypeT | \n Val Value TypeT | \n Res Action Argument |\n Let (List (Argument,Argument)) Argument -- let like this is not an action, it's only an action if I do \\x -> let ... x ... in ... i.e. Lambda x (let ...)\n\n implementation Show Argument where\n show (Arg n t) = \"Arg \" ++ n ++ \" \" ++ show t\n show (Val v t) = \"Val \" ++ v ++ \" \" ++ show t\n show (Res act arg) = \"Res \" ++ show act ++ \" \" ++ show arg\n show (Let xs arg) = \"Let \" ++ show xs ++ \" \" ++ show arg\n\n data Action = \n Opaque Name (List Argument) Argument TypeT (Performance,Cost) | -- [Type] is for constant args to map or fold, the first Type is the input arg, the last Type the return type\n OpaqueBin Assoc Name (List Argument) Argument Argument (Performance,Cost) |\n Map Variant Action | \n Fold Variant Action Argument | -- Argument here is the accumulator, and action must be a binary operation, not unary\n Compose (List Action) | \n -- Lambda (List Argument) (Action) ? \n Lambda (List Argument) Argument | -- (\\(x,y) -> map (g x) y) becomes Lambda [x,y] (Map g x) y so the last Argument is usually a Res\n Loop Action Action |\n Split Int | \n Merge Int | \n Distr Int Int |\n Group (List (Argument, List Rule)) | \n Ungroup (List (Argument, List Rule)) |\n Zip (List TypeT) | -- this should really only work on a set of vectors and return a Vec (Tuple [Type]) Int\n Unzip TypeT -- This should really only work on a Tuple [Vec Type Int]\n \n implementation Show Action where \n show (Opaque n xs arg t pc) = \"Opaque \" ++ n ++ \" \" ++ show xs ++ \" \" ++ \n show arg ++ \" \"++ show t ++ \" \" ++ show pc\n show (OpaqueBin a n xs arg1 arg2 pc) = \"Opaque \" ++ show a ++ \" \" ++ n ++ \" \" ++\n show arg1 ++ \" \" ++ show arg2 ++ \" \" ++ show pc\n show (Map v act) = \"Map \" ++ show v ++ \" \" ++ show act\n show (Fold v act arg) = \"Fold \" ++ show v ++ \" \" ++ show act ++ \" \" ++ show arg\n show (Compose xs) = \"Compose \" ++ show xs\n show (Lambda xs act) = \"Lambda \" ++ show xs ++ \" \" ++ show act\n show (Loop act1 act2) = \"Loop \" ++ show act1 ++ \" \" ++ show act2\n show (Split i) = \"Split \" ++ show i\n show (Merge i) = \"Merge \" ++ show i\n show (Distr i1 i2) = \"Distr \" ++ show i1 ++ \" \" ++ show i2\n show (Group xs) = \"Group \" ++ show xs\n show (Ungroup xs) = \"Ungroup \" ++ show xs\n show (Zip xs) = \"Zip \" ++ show xs\n show (Unzip t) = \"Unzip \" ++ show t\n\n\n-- We also need Zip, Unzip and Let\n--data FoldAction = deriving Show-- No need for return type as it's b -> a -> b\n\n\ndata Program = Prog Action Argument -- So actually Prog is identical to Res\n\nimplementation Show Program where\n show (Prog act arg) = \"Prog \" ++ show act ++ \" \" ++ show arg\n\n-- I also need to represent a while-loop \n-- We assume we have a loop primitive in the language\n-- let loop cond action v = (let res = action v in if (cond res) then res else loop cond action res) \n-- This becomes Loop (Opaque \"cond\" [] (Arg \"res\" T2) BoolT) (Opaque \"action\" [] (Arg \"v\" T1))\n-- and a way to extract values from a tuple, maybe a let?\n{-\n\nlet\n (err, p', p_avg) = fold (0, [], 0) sor p\nin\n map (stage3 p_avg) p'\n rather than simply (map stage3) $ (fold acc stage2) $ (map stage1) p\n this would be\n (\\(v_in,stage1,stage2) -> let (err, p', p_avg) = fold (0, [], 0) stage1 v_in in map (stage2 p_avg) p') $ map stage1 p\n The best way is to add a Lambda action\n\n\n(\\(x,y) -> map (g x) y) . (foldl f acc ) $ v -- [4,5,6]\n-}\n\n-- (Tuple [IntT,Vec IntT 3]) \n{-\np : Program \np = Prog (Compose [\n Lambda [Arg \"x\" IntT, Arg \"y\" (Vec 3 IntT)] \n (Map Seq (Opaque \"g\" [Arg \"x\" IntT] (Arg \"a1\" IntT) IntT (0,0)))\n ]\n ) {- (Arg \"y\" (Vec IntT 3)), \n Fold Seq (OpaqueBin True \"f\" [] (Arg \"acc\" (Tuple [IntT,Vec IntT 3])) (Arg \"a2\" IntT) (0,0)) (Arg \"acc\" (Tuple [IntT,Vec IntT 3]))\n ]) -} \n (Arg \"v\" (Vec 3 IntT)) \n\n-}\n", "meta": {"hexsha": "9e40dbf5ac9f7390aff527a92c58753ec395a3df", "size": 5405, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/TypeTrans/AST.idr", "max_stars_repo_name": "RossMeikleham/MSci-Project", "max_stars_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-20T11:17:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-20T11:17:45.000Z", "max_issues_repo_path": "src/TypeTrans/AST.idr", "max_issues_repo_name": "RossMeikleham/MSci-Project", "max_issues_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/TypeTrans/AST.idr", "max_forks_repo_name": "RossMeikleham/MSci-Project", "max_forks_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3652694611, "max_line_length": 179, "alphanum_fraction": 0.5715078631, "num_tokens": 1693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6584175005616829, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.3163555702734845}} {"text": "module Libraries.Data.IMaybe\n\n%default total\n\npublic export\ndata IMaybe : Bool -> Type -> Type where\n Nothing : IMaybe False a\n Just : a -> IMaybe True a\n\nexport\nFunctor (IMaybe b) where\n map f Nothing = Nothing\n map f (Just x) = Just (f x)\n\nexport\nfromJust : IMaybe True a -> a\nfromJust (Just x) = x\n", "meta": {"hexsha": "f383432dd87577053ac3e3eb50485fc2c8e08fd7", "size": 305, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Libraries/Data/IMaybe.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "src/Libraries/Data/IMaybe.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "src/Libraries/Data/IMaybe.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 16.9444444444, "max_line_length": 40, "alphanum_fraction": 0.6852459016, "num_tokens": 94, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.31630911332824757}} {"text": "module VISD.Common\n\nimport Control.Isomorphism\nimport Data.BoundedList\n\n%logging 1\n%default total\n%hide Prelude.Algebra.(<*>)\n%hide Prelude.Applicative.(<|>)\n%hide Prelude.Vect.reverse\n\n-- http://www.informatik.uni-marburg.de/~rendel/unparse/\n\n\n-- core definitions\n\ndata PartIso : Type -> Type -> Type where\n MkPartIso : (to : a -> Maybe b) ->\n (from : b -> Maybe a) ->\n (toFrom : (y : b) -> maybe () (\\x => to x = Just y) (from y)) ->\n (fromTo : (x : a) -> maybe () (\\y => from y = Just x) (to x)) ->\n PartIso a b\n\nclass PartIsoFunctor (f : Type -> Type -> Type) where\n (<$>) : PartIso a b -> f a c -> f b c\n\nclass PFunctor (f : Type -> Type -> Type) where\n (<*>) : f a c -> Lazy (f b c) -> f (a, b) c\n\nclass PAlternative (f : Type -> Type -> Type) where\n (<|>) : f a c -> Lazy (f a c) -> f a c\n empty : f a c\n\nclass (PartIsoFunctor d, PFunctor d, PAlternative d) => Syntax (d : Type -> Type -> Type) c where\n pure : Eq a => a -> d a c\n item : d c c\n\n\n-- helper functions\n\nipc_inverse : PartIso a b -> PartIso b a\nipc_inverse (MkPartIso f g tf ft) = MkPartIso g f ft tf\n\nipc_apply : PartIso a b -> a -> Maybe b\nipc_apply (MkPartIso f g ft ft) = f\n\nipc_unapply : PartIso a b -> b -> Maybe a\nipc_unapply = ipc_apply . ipc_inverse\n\n\n-- Inspect and other stuff\n\ndata Inspect : a -> Type where\n wi : {A : Type} -> (x : A) -> (y : A) -> (eq: x = y) -> Inspect x\n \ninspect : {A : Type} -> (x : A) -> Inspect x\ninspect x = wi x _ Refl\n\nmatch : {A : Type} -> {x : A} -> (y : A) -> {eq : x = y} -> Inspect x\nmatch y {eq} = wi _ y eq\n\n\nmaybe_assoc : (x : Maybe a) -> (f : a -> Maybe b) -> (g : b -> Maybe c) -> (x >>= (\\y => f y >>= g)) = (x >>= f >>= g)\nmaybe_assoc Nothing f g = Refl\nmaybe_assoc (Just x) f g = Refl\n\nmaybe_unbind : (f : a -> Maybe b) -> (g : b -> Maybe c) -> (x : a) -> {y : b} ->\n (f x = Just y) -> g y = Just x >>= f >>= g\nmaybe_unbind f g x eq = rewrite eq in Refl\n\n\n-- Algebra\n\ninfixr 1 >=>\n(>=>) : Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)\nf >=> g = \\x => f x >>= g\n\npId : PartIso a a\npId = MkPartIso (\\x => Just x) (\\x => Just x) (\\x => Refl) (\\x => Refl)\n\ninfixl 9 ..\n(..) : PartIso b c -> PartIso a b -> PartIso a c\n(MkPartIso gTo gFrom gTF gFT) .. (MkPartIso fTo fFrom fTF fFT) =\n MkPartIso\n (ipc_apply (MkPartIso fTo fFrom fTF fFT) >=> ipc_apply (MkPartIso gTo gFrom gTF gFT))\n (ipc_unapply (MkPartIso gTo gFrom gTF gFT) >=> ipc_unapply (MkPartIso fTo fFrom fTF fFT))\n tf ft\n where\n tf y with (inspect $ (gFrom y))\n | match Nothing {eq} = rewrite eq in ()\n | match (Just z) {eq} = rewrite eq in case (inspect $ fFrom z) of\n match Nothing {eq=eq1} => rewrite eq1 in ()\n match (Just n) {eq=eq1} => rewrite eq1 in\n rewrite (replace eq1 {P=(\\pz => maybe () (\\x => fTo x = Just z) pz)} (fTF z)) in\n (replace eq {P=(\\py => maybe () (\\x => gTo x = Just y) py)} (gTF y))\n ft x with (inspect $ (fTo x))\n | match Nothing {eq} = rewrite eq in ()\n | match (Just z) {eq} = rewrite eq in case (inspect $ gTo z) of\n match Nothing {eq=eq1} => rewrite eq1 in ()\n match (Just n) {eq=eq1} => rewrite eq1 in\n rewrite (replace eq1 {P=(\\pz => maybe () (\\x => gFrom x = Just z) pz)} (gFT z)) in\n (replace eq {P=(\\py => maybe () (\\y => fFrom y = Just x) py)} (fFT x))\n\ncommute : PartIso (a, b) (b, a)\ncommute = MkPartIso f f (\\(a,b) => Refl) (\\(a,b) => Refl) where\n f : (c, d) -> Maybe (d, c)\n f (a, b) = Just (b, a)\n\nunit : {a : Type} -> PartIso a (a, ())\nunit = MkPartIso f g tf ft where\n f : {a : Type} -> a -> Maybe (a, ())\n f a = Just (a, ())\n g : {a : Type} -> (a, ()) -> Maybe a\n g (a, ()) = Just a\n tf (a, ()) = Refl\n ft a = Refl\n\n-- *>, <*\n\ninfixl 3 *>\n(*>) : Syntax d c => d () c -> d a c -> d a c\np *> q = ipc_inverse unit .. commute <$> p <*> q\n\ninfixl 3 <*\n(<*) : Syntax d c => d a c -> d () c -> d a c\np <* q = ipc_inverse unit <$> p <*> q\n\n-- the following function can't be verified: there's no isomorphism\n-- when we are ignoring input; neither can it be changed, because it's\n-- quite important to be able to ignore input\n\nignore : a -> PartIso a ()\nignore x = MkPartIso f g tf ft where\n f : a -> Maybe ()\n f y = Just ()\n g : () -> Maybe a\n g () = Just x\n tf () = Refl\n ft y = believe_me (Just x = Just y)\n\n\n-- Parser\n\ndata Parser a c = MkParser (List c -> Maybe (a, List c))\n\nparse : Parser a c -> List c -> Maybe a\nparse (MkParser p) s = p s >>= pure . fst\n\ninstance PartIsoFunctor Parser where\n iso <$> (MkParser p) = MkParser pf\n where\n pf l = do\n (x, rest) <- p l\n y <- ipc_apply iso x\n return (y, rest)\n\ninstance PFunctor Parser where\n (MkParser p) <*> mkpq = MkParser pf\n where\n pf l = do\n (x, rest) <- p l\n case mkpq of\n (MkParser q) => do\n (y, ret) <- q rest\n return ((x, y), ret)\n\ninstance PAlternative Parser where\n (MkParser p) <|> mkpq = MkParser pf\n where\n pf l = case p l of\n Just x => Just x\n Nothing => case mkpq of\n (MkParser q) => q l\n empty = MkParser (\\s => Nothing)\n\ninstance Syntax Parser c where\n pure x = MkParser (\\s => Just (x, s))\n item = MkParser f\n where\n f [] = Nothing\n f (x :: xs) = Just (x, xs)\n\n\n-- Printer\n\ndata Printer a c = MkPrinter (a -> Maybe (List c))\n\ncompose : Printer a c -> a -> Maybe (List c)\ncompose (MkPrinter p) x = p x\n\ninstance PartIsoFunctor Printer where\n iso <$> (MkPrinter p) = MkPrinter (\\b => ipc_unapply iso b >>= p)\n\ninstance PFunctor Printer where\n (MkPrinter p) <*> mkpq = MkPrinter pf\n where\n pf (x, y) = do\n x' <- p x\n case mkpq of\n (MkPrinter q) => do\n y' <- q y\n return (x' ++ y')\n\ninstance PAlternative Printer where\n (MkPrinter p) <|> mkpq = MkPrinter $ \\s =>\n case (p s) of\n Nothing => case mkpq of\n (MkPrinter q) => q s\n x => x\n empty = MkPrinter (\\s => Nothing)\n\n\ninstance Syntax Printer c where\n pure x = MkPrinter (\\y =>\n if x == y\n then Just []\n else Nothing)\n item = MkPrinter (\\t => Just [t])\n\n\n-- Basic parsers/composers\n\nsat : Syntax d a => (a -> Bool) -> d a a\nsat {a} p = (MkPartIso check check verify verify) <$> item\n where\n check : a -> Maybe a\n check x = if p x then Just x else Nothing\n verify y with (inspect $ p y)\n | match False {eq=eq} = rewrite eq in ()\n | match True {eq=eq} = rewrite eq in\n rewrite eq in Refl\n\nval : (Syntax d a, Eq a) => a -> d a a\nval x = sat (== x)\n\n\n-- rep\n\nnilv : PartIso () (Vect 0 a)\nnilv = MkPartIso to from tf ft\n where\n to : () -> Maybe (Vect 0 a)\n to () = Just $ Vect.Nil {a=a}\n from : (Vect 0 a) -> Maybe ()\n from [] = Just () \n from _ = Nothing\n tf [] = Refl\n ft () = Refl\n\nconsv : PartIso (a, Vect n a) (Vect (S n) a)\nconsv = MkPartIso c1 c2 tf ft\n where\n c1 : (a, Vect n a) -> Maybe (Vect (S n) a)\n c1 (x, xs) = Just (x :: xs)\n c2 : (Vect (S n) a) -> Maybe (a, Vect n a)\n c2 (x :: xs) = Just (x, xs)\n tf (x :: xs) = Refl\n ft (a, b) = Refl\n\nrep : Syntax d c => (n : Nat) -> d a c -> d (Vect n a) c\nrep Z p = nilv <$> pure ()\nrep (S k) p = consv <$> p <*> rep k p\n\n\n-- up to\n\nbNil : PartIso () (BoundedList n a)\nbNil = MkPartIso to from tf ft\n where\n to : () -> Maybe (BoundedList n a)\n to () = Just []\n from : BoundedList n a -> Maybe ()\n from [] = Just ()\n from _ = Nothing\n tf [] = Refl\n tf (x::xs) impossible\n ft () = Refl\n\nbCons : PartIso (a, BoundedList n a) (BoundedList (S n) a)\nbCons = MkPartIso to from tf ft\n where\n to : (a, BoundedList n a) -> Maybe (BoundedList (S n) a)\n to (x, l) = Just $ x :: l\n from : BoundedList (S n) a -> Maybe (a, BoundedList n a)\n from [] = Nothing\n from (x :: xs) = Just (x, xs)\n tf [] = ()\n tf (x :: xs) = Refl\n ft (x, l) = Refl\n\nupTo : Syntax d c => (n: Nat) -> d a c -> d (BoundedList n a) c\nupTo Z _ = (bNil <$> pure ())\nupTo (S n) p = (bCons <$> (p <*> (upTo n p)))\n <|> (bNil <$> pure ())\n\nbounded : Syntax d c => (min,add: Nat) -> d a c -> d (Vect min a, BoundedList add a) c\nbounded min add p = rep min p <*> upTo add p\n\n\n-- maybe\n\njust : PartIso a (Maybe a)\njust = MkPartIso (Just . Just) id tf ft\n where\n tf Nothing = ()\n tf (Just x) = Refl\n ft _ = Refl\n\nnothing : PartIso () (Maybe a)\nnothing = MkPartIso to from tf ft\n where\n to : () -> Maybe (Maybe a)\n to x = Just Nothing\n from : Maybe a -> Maybe ()\n from (Just x) = Nothing\n from Nothing = Just ()\n tf (Just x) = ()\n tf Nothing = Refl\n ft () = Refl\n\nmaybe : Syntax d c => d a c -> d (Maybe a) c\nmaybe p = (just <$> p)\n <|> (nothing <$> pure ())\n\n\n-- many\n\nnil : PartIso () (List a)\nnil = MkPartIso c1 c2 tf ft\n where\n c1 : () -> Maybe (List a)\n c1 () = Just []\n c2 : List a -> Maybe ()\n c2 [] = Just ()\n c2 (x :: xs) = Nothing\n tf [] = Refl\n tf (x :: xs) = ()\n ft () = Refl\n\ncons : PartIso (a, List a) (List a)\ncons = MkPartIso c1 c2 tf ft\n where\n c1 : (a, List a) -> Maybe (List a)\n c1 (x, l) = Just $ x :: l\n c2 : List a -> Maybe (a, List a)\n c2 [] = Nothing\n c2 (x :: xs) = Just (x, xs)\n tf [] = ()\n tf (x :: xs) = Refl\n ft (x, l) = Refl\n\npartial many : Syntax d c => d a c -> d (List a) c\nmany p = (cons <$> (p <*> (many p)))\n <|> (nil <$> pure ())\n\n\n-- sepBy1\n\npartial sepBy1 : Syntax d c => d a c -> d b c -> b -> d (List a) c\nsepBy1 p s x = cons <$> (p <*> (many ((ignore x <$> s) *> p)))\n", "meta": {"hexsha": "dd0605fcebbc47f12db6cbe0ea9a4927dc39c573", "size": 9413, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/VISD/Common.idr", "max_stars_repo_name": "defanor/parcomb", "max_stars_repo_head_hexsha": "64e69395b6580cd0a9cc973cd2b3c8d04b5d1a89", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/VISD/Common.idr", "max_issues_repo_name": "defanor/parcomb", "max_issues_repo_head_hexsha": "64e69395b6580cd0a9cc973cd2b3c8d04b5d1a89", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/VISD/Common.idr", "max_forks_repo_name": "defanor/parcomb", "max_forks_repo_head_hexsha": "64e69395b6580cd0a9cc973cd2b3c8d04b5d1a89", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0747922438, "max_line_length": 118, "alphanum_fraction": 0.5278869648, "num_tokens": 3350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.3142309233341246}} {"text": "module Sub12Apply108x90\r\n\r\nimport ProofColDivSeqBase\r\nimport ProofColDivSeqPostulate\r\n\r\n%default total\r\n-- %language ElabReflection\r\n\r\n\r\n-- 3(36x+30) --F[5,-2]->B[1,-2]--> 3(16x+13)\r\nfb108x90To48x39 :\r\n (o:Nat) -> P (S (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))) (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))))))))) 2\r\n -> P (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))))))))) 2\r\nfb108x90To48x39 o prf =\r\n let prf2 = lvDown (S (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))) (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))))))))) 2\r\n prf in\r\n let prf3 = fb108x90To48x39' o prf2 in lvDown (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))))))))) 3 prf3\r\n\r\n\r\nexport\r\napply108x90 : P (S (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))) (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))))))))) 2\r\n -> (m : Nat **\r\n (LTE (S m)\r\n (S (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))))))))),\r\n P m 2))\r\napply108x90 {o} col = let col2 = fb108x90To48x39 o col in ((S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))))))))))))))))\r\n ** (lte108x90 o, col2)) where\r\n lte108x90 : (o:Nat) -> LTE (S (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))\r\n (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))))))))))))))))))\r\n (S (S (S (S (S (S (plus (plus (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))) (S (S (S (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))))))))))))\r\n lte108x90 Z = (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) LTEZero\r\n lte108x90 (S o) = let lemma = lte108x90 o in\r\n rewrite (sym (plusSuccRightSucc o o)) in\r\n rewrite (sym (plusSuccRightSucc (plus o o) (S (plus o o)))) in\r\n rewrite (sym (plusSuccRightSucc (plus o o) (plus o o))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (S (S (plus (plus o o) (plus o o))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (S (plus (plus o o) (plus o o)))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (S (plus (plus o o) (plus o o))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o)))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (S (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o)))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) (plus o o)) (plus (plus o o) (plus o o))) (plus (plus (plus o o) (plus o o))\r\n (plus (plus o o) (plus o o))))) in\r\n\r\n rewrite (sym (plusSuccRightSucc (plus o o) o)) in\r\n\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (S (S (S (plus (plus o o) o))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (S (S (plus (plus o o) o)))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus o o) o) (S (S (plus (plus o o) o))))) in\r\n\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (S (S (S (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (S (S (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (S (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))) (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))) in\r\n\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o))))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o)))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o)))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o)))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o)))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o)))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus o o) o) (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o) (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o)\r\n o)))))))))))) in\r\n\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o))))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o)))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o))))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o)))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o))))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o)))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o))))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o)))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o))))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o)))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o))))))))))))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))\r\n (S (S (S (plus (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o))))\r\n (S (S (plus (plus (plus o o) o)\r\n (S (S (plus (plus o o) o)))))))))))\r\n (S (S (S (plus (plus (plus (plus o\r\n o) o)\r\n (S (S (plus (plus o o)\r\n o))))\r\n (S (S (plus (plus (plus o o)\r\n o) (S (S (plus (plus o o)\r\n o)))))))))))) in\r\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) lemma\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "9872c21ef6196ea2458d15cb2b70193fad8e72e0", "size": 47143, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program/Sub12Apply108x90.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program/Sub12Apply108x90.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program/Sub12Apply108x90.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 130.9527777778, "max_line_length": 472, "alphanum_fraction": 0.1921388117, "num_tokens": 8061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.3138764736794522}} {"text": "module Control.Linear.LState\n\nimport Control.Linear\n\n%default total\n\nexport\ndata LState : (stateType : Type) -> (a : Type) -> Type where\n MkLState : (1 f : ((1 _ : stateType) -> (LPair a stateType))) -> LState stateType a\n\nexport\nFunctor (LState stateType) where\n map f (MkLState c) = MkLState (\\s => let (r # s') = c s in ((f r) # s'))\n\nexport\nApplicative (LState stateType) where\n pure x = MkLState (\\s => x # s)\n (MkLState cf) <*> (MkLState cv) = MkLState (\\s =>\n let (f # s') = cf s\n (r # s'') = cv s'\n in ((f r) # s''))\n\nexport\nLMonad (LState s) where\n (>>=) (MkLState f) c = MkLState (\\x => let (res # s') = f x in\n let (MkLState r2) = c res\n in r2 s')\n\nexport\nrun : (f : (1 state : s) -> (LPair a s)) -> LState s a\nrun f = MkLState f\n\nexport\nchange : (f : (1 state : s) -> s) -> LState s ()\nchange f = MkLState (\\state => (() # f state))\n\npublic export\ninterface SubState a b where\n liftSt : LState a r -> LState b r\n\nexport\nSubState a (a, b) where\n liftSt (MkLState f) = MkLState (\\(sa, sb) => let (res # sa') = f sa in\n (res # (sa', sb)))\n\nexport\nSubState a (b, a) where\n liftSt (MkLState f) = MkLState (\\(sb, sa) => let (res # sa') = f sa in\n (res # (sb, sa')))\n\nexport\nrunLState : (1 initState : stateType) -> (1 c : LState stateType r) -> LPair r stateType\nrunLState s (MkLState f) = f s\n\nexport\nexecLState : (1 initState : stateType) -> (1 c : LState stateType r) -> stateType\nexecLState s (MkLState f) = let (_ # finState) = f s in finState\n", "meta": {"hexsha": "f898e8e8253aeb9de47e83caac14690719910ca2", "size": 1775, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Control/Linear/LState.idr", "max_stars_repo_name": "ska80/idris-minisat", "max_stars_repo_head_hexsha": "e02c1810270107decec262c5c205552aa3f46f87", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Control/Linear/LState.idr", "max_issues_repo_name": "ska80/idris-minisat", "max_issues_repo_head_hexsha": "e02c1810270107decec262c5c205552aa3f46f87", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Control/Linear/LState.idr", "max_forks_repo_name": "ska80/idris-minisat", "max_forks_repo_head_hexsha": "e02c1810270107decec262c5c205552aa3f46f87", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6034482759, "max_line_length": 88, "alphanum_fraction": 0.4974647887, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.31365187232406144}} {"text": "module Reviewer\n\nimport Data.Nat\nimport Data.String\nimport Data.List\nimport Data.List.DeleteBy\nimport Data.List1\nimport System.Random.Node\nimport Text.PrettyPrint.Prettyprinter\nimport Text.PrettyPrint.Prettyprinter.Symbols\nimport Text.PrettyPrint.Prettyprinter.Render.Terminal\nimport Util\n\n%default total\n\nrecord Score login where\n constructor MkScore\n user : login\n partialScore : Nat\n combinedScore : Nat\n\nloginScore : Score login -> (login, Nat)\nloginScore (MkScore l s c) = (l, c)\n\n||| Get scored reviewers sorted from lowest to highest score.\n||| A low score indicates less review work (a better candidate for\n||| assigning a new PR to).\n|||\n||| The resulting `Score` contains both a partial score (the score\n||| based only on open reivews) and also a combined score (the score\n||| after negatively weighting closed reviews).\n|||\n||| Closed reviews are negatively scored because they are review requests\n||| that were not answered.\nscoredReviewers : Ord login =>\n (closedReviews : List login)\n -> (openReviews : List login)\n -> (candidates : List login)\n -> List (Score login)\nscoredReviewers closedReviews openReviews candidates =\n let closedReviewsWeighted = weightReviews 1 closedReviews\n openReviewsWeighted = weightReviews 4 openReviews\n allReviews = zipReviews openReviewsWeighted closedReviewsWeighted Subtract False\n in sort' $ zipReviews allReviews (weightReviews 0 candidates) Add True\n where\n -- The number of appearances is multiplied by the supplied weight which \n -- allows us to weight some lists more heavily than others.\n weightReviews : (weight : Nat) -> List login -> List (Score login)\n weightReviews weight reviews =\n let grouped = groupAllWith id reviews\n in grouped <&> (\\xs => let score = (* weight) . length $ forget xs in (MkScore (head xs) score score))\n\n -- Sort logins by the number of times each login was requested for review.\n sort' : List (Score login) -> List (Score login)\n sort' = sortBy $ compare `on` combinedScore\n\n data Op = Add | Subtract\n\n -- Add or subtract the scores for any equal logins.\n -- If `filterToSecondList` then no elements in the first list \n -- but not the second list will be kept.\n zipReviews : List (Score login) -> List (Score login) -> Op -> (filterToSecondList : Bool) -> List (Score login)\n zipReviews [] [] _ _ = []\n zipReviews [] ys Add _ = ys\n zipReviews [] ys Subtract _ = { combinedScore := 0 } <$> ys\n zipReviews xs [] _ True = []\n zipReviews xs [] _ False = xs\n zipReviews (x@(MkScore l1 s1 c1) :: xs) ys op filter =\n case (deleteBy' ((==) `on` user) x ys, filter) of\n ((Nothing , ys'), False) => (MkScore l1 s1 c1 ) :: zipReviews xs ys' op filter\n ((Nothing , ys'), True ) => zipReviews xs ys' op filter\n ((Just (MkScore _ _ c2'), ys'), _) => (MkScore l1 s1 (c1 `calc` c2')) :: zipReviews xs ys' op filter\n where\n calc : Nat -> Nat -> Nat\n calc k j with (op)\n _ | Add = k + j\n _ | Subtract = k `minus` j\n\n||| Choose reviewers that maintain harmony in the review world.\n||| Returns the logins of all reviewers that would work equally well.\n|||\n||| @ closedReviews The logins of each reviewer of each closed PR (duplicates intact).\n||| @ openReviews The logins of each reviewer of each open PR (duplicates intact).\n||| @ candidates The logins of all potential reviewers that should be considered.\n||| @ forcedReviewers The logins of all reviewers that are being forced (not chosen by harmony).\n||| @ author The author of the PR for which a reviewer is being picked.\nexport\nchooseReviewers : Ord login =>\n (closedReviews : List login)\n -> (openReviews : List login)\n -> (candidates : List login)\n -> (forcedReviewers : List login)\n -> (author : login)\n -> List (login, Nat)\nchooseReviewers closedReviews openReviews candidates forcedReviewers author = \n let remainingOptions = (nub candidates) \\\\ (author :: forcedReviewers)\n scoredOptions = scoredReviewers closedReviews openReviews remainingOptions\n in case scoredOptions of\n [] => []\n ((MkScore l s c) :: xs) => \n let rest = takeWhile ((== c) . combinedScore) xs \n rest' = loginScore <$> rest\n in (l, c) :: rest'\n\nexport\nrandomReviewer : HasIO io => List (login, Nat) -> io (Maybe login)\nrandomReviewer [] = pure Nothing\nrandomReviewer (x :: xs) = (Just . fst) <$> rndSelect (x :: xs)\n\n||| Produce a graph of relative review workload for all developers matching the given\n||| filter.\n||| @ closedReviews The logins of each reviewer of each closed PR (duplicates intact).\n||| @ openReviews The logins of each reviewer of each open PR (duplicates intact).\n||| @ candidates The logins of all potential reviewers that should be considered.\nexport\nreviewsGraph : Ord login => Pretty login =>\n (closedReviews : List login)\n -> (openReviews : List login)\n -> (candidates : List login)\n -> Doc AnsiStyle\nreviewsGraph closedReviews openReviews candidates =\n let scoredOptions = reverse $ scoredReviewers closedReviews openReviews (sort $ nub candidates)\n in case scoredOptions of\n [] => emptyDoc\n ((MkScore _ s c) :: _) =>\n let highScore = c + (s `minus` c)\n in header <+> graph (if highScore > 0 then highScore else 1) scoredOptions <+> line\n where\n yellowDot : Doc AnsiStyle\n yellowDot = annotate (color Yellow) \"·\"\n\n redDot : Doc AnsiStyle\n redDot = annotate (color Red) \"◦\"\n\n header : Doc AnsiStyle\n header = vsep [ emptyDoc\n , pretty \"Weighted review workload.\"\n , pretty \"4x the numbewr of open review requests\" <++> parens yellowDot\n , pretty \"1x the number of closed PRs with unanswered review requests\" <++> parens redDot\n , parens $ redDot <++> pretty \"overlayed on\" <++> yellowDot\n , emptyDoc\n , emptyDoc\n ]\n\n -- The \"detractor\" is an indication of the amount of the score that was taken\n -- away by the heuristic in `scoredReviewers` that weights closed reviews with\n -- unanswered review requests negatively.\n bar : (indentation : Nat) -> (score : Nat) -> (detractor : Nat) -> Doc AnsiStyle\n bar idt score detractor = indent (cast idt) . hcat $\n [ annotate (color Red) . pretty $ replicate detractor '◦'\n , annotate (color Yellow) . pretty $ replicate score '·'\n ]\n\n graphOne : (highScore : Nat) -> (Score login) -> Doc AnsiStyle\n graphOne highScore (MkScore user partialScore combinedScore) =\n let idt = highScore `minus` partialScore\n user = annotate italic $ pretty user\n detractor = (partialScore `minus` combinedScore)\n remainingSpace = highScore `minus` combinedScore\n -- we create a bar with the combinedScore and then fill in any\n -- remaining space with an indication of the detractor. We cap\n -- the detractor representation at the high score to make everything\n -- line up nicely. The detractor is just there to give some indication\n -- of review requests that did not count positively toward the score.\n in bar idt combinedScore (min remainingSpace detractor) <++> user\n\n graph : (highScore : Nat) -> List (Score login) -> Doc AnsiStyle\n graph highScore = vsep . map (graphOne highScore)\n\n", "meta": {"hexsha": "84b2f6bb97541e07fe039df18ac759ae379e8ca8", "size": 7831, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Reviewer.idr", "max_stars_repo_name": "mattpolzin/harmony", "max_stars_repo_head_hexsha": "2e7ddbcc4dc723ab24d82549f7c37c9b19c17592", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-08-31T00:07:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-27T19:20:51.000Z", "max_issues_repo_path": "src/Reviewer.idr", "max_issues_repo_name": "mattpolzin/harmony", "max_issues_repo_head_hexsha": "2e7ddbcc4dc723ab24d82549f7c37c9b19c17592", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2021-09-03T21:31:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T05:43:31.000Z", "max_forks_repo_path": "src/Reviewer.idr", "max_forks_repo_name": "mattpolzin/harmony", "max_forks_repo_head_hexsha": "2e7ddbcc4dc723ab24d82549f7c37c9b19c17592", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.0647058824, "max_line_length": 118, "alphanum_fraction": 0.6287830418, "num_tokens": 1862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.3131127704838877}} {"text": "module Lens.Reversible\n\nimport Data.Maybe\nimport Lens\nimport Lens.Uninhabited\nimport Lens.Util\nimport Map\n\n%default total\n\nmake_reversible : (k : Kind) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (Make k) s = Just s' -> transform_schema (reverse_lens (Make k)) s' = Just s\nmake_reversible KNull SNull _ Refl impossible\nmake_reversible KNull SBoolean _ Refl impossible\nmake_reversible KNull SNumber _ Refl impossible\nmake_reversible KNull SText _ Refl impossible\nmake_reversible KNull (SArray _ _) _ Refl impossible\nmake_reversible KNull (SObject _) _ Refl impossible\nmake_reversible (KPrimitive KBoolean) SNull SBoolean Refl = Refl\nmake_reversible (KPrimitive KBoolean) SBoolean _ Refl impossible\nmake_reversible (KPrimitive KBoolean) SNumber _ Refl impossible\nmake_reversible (KPrimitive KBoolean) SText _ Refl impossible\nmake_reversible (KPrimitive KBoolean) (SArray _ _) _ Refl impossible\nmake_reversible (KPrimitive KBoolean) (SObject _) _ Refl impossible\nmake_reversible (KPrimitive KNumber) SNull SNumber Refl = Refl\nmake_reversible (KPrimitive KNumber) SBoolean _ Refl impossible\nmake_reversible (KPrimitive KNumber) SNumber _ Refl impossible\nmake_reversible (KPrimitive KNumber) SText _ Refl impossible\nmake_reversible (KPrimitive KNumber) (SArray _ _) _ Refl impossible\nmake_reversible (KPrimitive KNumber) (SObject _) _ Refl impossible\nmake_reversible (KPrimitive KText) SNull SText Refl = Refl\nmake_reversible (KPrimitive KText) SBoolean _ Refl impossible\nmake_reversible (KPrimitive KText) SNumber _ Refl impossible\nmake_reversible (KPrimitive KText) SText _ Refl impossible\nmake_reversible (KPrimitive KText) (SArray _ _) _ Refl impossible\nmake_reversible (KPrimitive KText) (SObject _) _ Refl impossible\nmake_reversible KArray SNull (SArray True SNull) Refl = Refl\nmake_reversible KArray SBoolean _ Refl impossible\nmake_reversible KArray SNumber _ Refl impossible\nmake_reversible KArray SText _ Refl impossible\nmake_reversible KArray (SArray _ _) _ Refl impossible\nmake_reversible KArray (SObject _) _ Refl impossible\nmake_reversible KObject SNull (SObject Empty) Refl = Refl\nmake_reversible KObject SBoolean _ Refl impossible\nmake_reversible KObject SNumber _ Refl impossible\nmake_reversible KObject SText _ Refl impossible\nmake_reversible KObject (SArray _ _) _ Refl impossible\nmake_reversible KObject (SObject _) _ Refl impossible\n\ndestroy_reversible : (k : Kind) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (Destroy k) s = Just s' -> transform_schema (reverse_lens (Destroy k)) s' = Just s\ndestroy_reversible KNull SNull _ Refl impossible\ndestroy_reversible KNull SBoolean _ Refl impossible\ndestroy_reversible KNull SNumber _ Refl impossible\ndestroy_reversible KNull SText _ Refl impossible\ndestroy_reversible KNull (SArray _ _) _ Refl impossible\ndestroy_reversible KNull (SObject _) _ Refl impossible\ndestroy_reversible (KPrimitive KBoolean) SNull _ Refl impossible\ndestroy_reversible (KPrimitive KBoolean) SBoolean SNull Refl = Refl\ndestroy_reversible (KPrimitive KBoolean) SNumber _ Refl impossible\ndestroy_reversible (KPrimitive KBoolean) SText _ Refl impossible\ndestroy_reversible (KPrimitive KBoolean) (SArray _ _) _ Refl impossible\ndestroy_reversible (KPrimitive KBoolean) (SObject _) _ Refl impossible\ndestroy_reversible (KPrimitive KNumber) SNull _ Refl impossible\ndestroy_reversible (KPrimitive KNumber) SBoolean _ Refl impossible\ndestroy_reversible (KPrimitive KNumber) SNumber SNull Refl = Refl\ndestroy_reversible (KPrimitive KNumber) SText _ Refl impossible\ndestroy_reversible (KPrimitive KNumber) (SArray _ _) _ Refl impossible\ndestroy_reversible (KPrimitive KNumber) (SObject _) _ Refl impossible\ndestroy_reversible (KPrimitive KText) SNull _ Refl impossible\ndestroy_reversible (KPrimitive KText) SBoolean _ Refl impossible\ndestroy_reversible (KPrimitive KText) SNumber _ Refl impossible\ndestroy_reversible (KPrimitive KText) SText SNull Refl = Refl\ndestroy_reversible (KPrimitive KText) (SArray _ _) _ Refl impossible\ndestroy_reversible (KPrimitive KText) (SObject _) _ Refl impossible\ndestroy_reversible KArray SNull _ Refl impossible\ndestroy_reversible KArray SBoolean _ Refl impossible\ndestroy_reversible KArray SNumber _ Refl impossible\ndestroy_reversible KArray SText _ Refl impossible\ndestroy_reversible KArray (SArray False _) _ Refl impossible\ndestroy_reversible KArray (SArray True SNull) SNull Refl = Refl\ndestroy_reversible KArray (SArray True SBoolean) _ Refl impossible\ndestroy_reversible KArray (SArray True SNumber) _ Refl impossible\ndestroy_reversible KArray (SArray True SText) _ Refl impossible\ndestroy_reversible KArray (SArray True (SArray _ _)) _ Refl impossible\ndestroy_reversible KArray (SArray True (SObject _)) _ Refl impossible\ndestroy_reversible KArray (SObject _) _ Refl impossible\ndestroy_reversible KObject SNull _ Refl impossible\ndestroy_reversible KObject SBoolean _ Refl impossible\ndestroy_reversible KObject SNumber _ Refl impossible\ndestroy_reversible KObject SText _ Refl impossible\ndestroy_reversible KObject (SArray _ _) _ Refl impossible\ndestroy_reversible KObject (SObject (Update _ _ _)) _ Refl impossible\ndestroy_reversible KObject (SObject Empty) s' prf =\n rewrite sym $ justInjective prf in Refl\n\nadd_property_reversible : (k : Key) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (AddProperty k) s = Just s' -> transform_schema (reverse_lens (AddProperty k)) s' = Just s\nadd_property_reversible _ SNull _ Refl impossible\nadd_property_reversible _ SBoolean _ Refl impossible\nadd_property_reversible _ SNumber _ Refl impossible\nadd_property_reversible _ SText _ Refl impossible\nadd_property_reversible _ (SArray _ _) _ Refl impossible\nadd_property_reversible k (SObject m) s' prf with (get k m) proof prf1\n add_property_reversible k (SObject _) _ prf | (Just _) = absurd $ prf\n add_property_reversible k (SObject m) s' prf | Nothing =\n rewrite sym $ justInjective prf in\n rewrite update_eq m k (Just SNull) in\n rewrite update_shadow m k (Just SNull) Nothing in\n rewrite update_same m k Nothing prf1 in Refl\n\nremove_property_reversible : (k : Key) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (RemoveProperty k) s = Just s' -> transform_schema (reverse_lens (RemoveProperty k)) s' = Just s\nremove_property_reversible _ SNull _ Refl impossible\nremove_property_reversible _ SBoolean _ Refl impossible\nremove_property_reversible _ SNumber _ Refl impossible\nremove_property_reversible _ SText _ Refl impossible\nremove_property_reversible _ (SArray _ _) _ Refl impossible\nremove_property_reversible k (SObject m) s' prf with (get k m) proof prf1\n remove_property_reversible _ (SObject _) _ prf | Nothing = absurd $ prf\n remove_property_reversible _ (SObject _) _ prf | (Just SBoolean) = absurd $ prf\n remove_property_reversible _ (SObject _) _ prf | (Just SNumber) = absurd $ prf\n remove_property_reversible _ (SObject _) _ prf | (Just SText) = absurd $ prf\n remove_property_reversible _ (SObject _) _ prf | (Just (SArray _ _)) = absurd $ prf\n remove_property_reversible _ (SObject _) _ prf | (Just (SObject _)) = absurd $ prf\n remove_property_reversible k (SObject m) s' prf | (Just SNull) =\n rewrite sym $ justInjective prf in\n rewrite update_eq m k Nothing in\n rewrite update_shadow m k Nothing (Just SNull) in\n rewrite update_same m k (Just SNull) prf1 in Refl\n\nrename_property_reversible : (k, k' : Key) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (RenameProperty k k') s = Just s' -> transform_schema (reverse_lens (RenameProperty k k')) s' = Just s\nrename_property_reversible _ _ SNull _ Refl impossible\nrename_property_reversible _ _ SBoolean _ Refl impossible\nrename_property_reversible _ _ SNumber _ Refl impossible\nrename_property_reversible _ _ SText _ Refl impossible\nrename_property_reversible _ _ (SArray _ _) _ Refl impossible\nrename_property_reversible k k' (SObject m) s' prf with (get k m, get k' m) proof prf1\n rename_property_reversible _ _ (SObject _) _ prf | (Nothing, _) = absurd $ prf\n rename_property_reversible _ _ (SObject _) _ prf | (Just _, Just _) = absurd $ prf\n rename_property_reversible k k' (SObject m) s' prf | ((Just x), Nothing) =\n rewrite sym $ justInjective prf in\n rewrite update_eq (update k Nothing m) k' (Just x) in\n let va = cong fst prf1\n vb = cong snd prf1\n not_a_eq_b = get_neq $ tuple_eq prf1 uninhabited\n not_b_eq_a = \\p => not_a_eq_b $ sym p in\n rewrite update_permute m k' k (Just x) Nothing not_b_eq_a in\n rewrite ne_key k k' not_a_eq_b in\n rewrite beq_key k in\n rewrite update_permute m k k' Nothing (Just x) not_a_eq_b in\n rewrite update_shadow (update k Nothing m) k' (Just x) Nothing in\n rewrite update_permute m k' k Nothing Nothing not_b_eq_a in\n rewrite update_same m k' Nothing vb in\n rewrite update_shadow m k Nothing (Just x) in\n rewrite update_same m k (Just x) va in Refl\n\nhoist_property_reversible : (h, t : Key) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (HoistProperty h t) s = Just s' -> transform_schema (reverse_lens (HoistProperty h t)) s' = Just s\nhoist_property_reversible _ _ SNull _ Refl impossible\nhoist_property_reversible _ _ SBoolean _ Refl impossible\nhoist_property_reversible _ _ SNumber _ Refl impossible\nhoist_property_reversible _ _ SText _ Refl impossible\nhoist_property_reversible _ _ (SArray _ _) _ Refl impossible\nhoist_property_reversible h t (SObject m) s' prf with (get h m, get t m) proof prf1\n hoist_property_reversible _ _ (SObject _) _ prf | (Nothing, _) = absurd $ prf\n hoist_property_reversible _ _ (SObject _) _ prf | (Just SNull, _) = absurd $ prf\n hoist_property_reversible _ _ (SObject _) _ prf | (Just SBoolean, _) = absurd $ prf\n hoist_property_reversible _ _ (SObject _) _ prf | (Just SNumber, _) = absurd $ prf\n hoist_property_reversible _ _ (SObject _) _ prf | (Just SText, _) = absurd $ prf\n hoist_property_reversible _ _ (SObject _) _ prf | (Just (SArray _ _), _) = absurd $ prf\n hoist_property_reversible _ _ (SObject _) _ prf | (Just (SObject _), Just _) = absurd $ prf\n hoist_property_reversible h t (SObject m) s' prf | (Just (SObject hm), Nothing) with (get t hm) proof prf2\n hoist_property_reversible _ _ (SObject _) _ prf | (Just (SObject _), Nothing) | Nothing = absurd $ prf\n hoist_property_reversible h t (SObject m) s' prf | (Just (SObject hm), Nothing) | Just x =\n rewrite sym $ justInjective prf in\n let neq_ht = get_neq (tuple_eq prf1 uninhabited)\n neq_th = \\p => neq_ht (sym p) in\n rewrite update_permute m h t (Just (SObject (update t Nothing hm))) (Just x) neq_ht in\n rewrite ne_key t h neq_th in\n rewrite beq_key t in\n rewrite beq_key h in\n rewrite beq_key t in\n rewrite update_permute m t h (Just x) (Just (SObject (update t Nothing hm))) neq_th in\n rewrite update_shadow hm t Nothing (Just x) in\n rewrite update_permute (update t (Just x) m) t h Nothing (Just (SObject (update t Nothing hm))) neq_th in\n rewrite update_shadow m t (Just x) Nothing in\n rewrite update_shadow (update t Nothing m) h\n (Just (SObject (update t Nothing hm)))\n (Just (SObject (update t (Just x) hm))) in\n rewrite update_same m t Nothing (cong snd prf1) in\n rewrite update_same hm t (Just x) prf2 in\n rewrite update_same m h (Just (SObject hm)) (cong fst prf1) in Refl\n\nplunge_property_reversible : (h, t : Key) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (PlungeProperty h t) s = Just s' -> transform_schema (reverse_lens (PlungeProperty h t)) s' = Just s\nplunge_property_reversible _ _ SNull _ Refl impossible\nplunge_property_reversible _ _ SBoolean _ Refl impossible\nplunge_property_reversible _ _ SNumber _ Refl impossible\nplunge_property_reversible _ _ SText _ Refl impossible\nplunge_property_reversible _ _ (SArray _ _) _ Refl impossible\nplunge_property_reversible h t (SObject m) s' prf with (get t m, get h m, t == h) proof prf1\n plunge_property_reversible _ _ (SObject _) _ prf | (Nothing, _, _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Nothing, _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just SNull, _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just SBoolean, _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just SNumber, _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just SText, _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just (SArray _ _), _) = absurd $ prf\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just (SObject _), True) = absurd $ prf\n plunge_property_reversible h t (SObject m) s' prf | (Just tv, Just (SObject hm), False) with (get t hm) proof prf2\n plunge_property_reversible _ _ (SObject _) _ prf | (Just _, Just (SObject _), False) | Just _ = absurd $ prf\n plunge_property_reversible h t (SObject m) s' prf | (Just tv, Just (SObject hm), False) | Nothing =\n rewrite sym $ justInjective prf in\n let neq_th = bne_key t h $ cong snd $ cong snd $ prf1\n neq_ht = \\p => neq_th $ sym p in\n rewrite update_eq (update t Nothing m) h (Just (SObject (update t (Just tv) hm))) in\n rewrite update_permute m h t (Just (SObject (update t (Just tv) hm))) Nothing neq_ht in\n rewrite ne_key t h neq_th in\n rewrite beq_key t in\n rewrite beq_key t in\n rewrite update_shadow hm t (Just tv) Nothing in\n rewrite update_shadow (update h (Just (SObject (update t (Just tv) hm))) m) t Nothing (Just tv) in\n rewrite update_permute m t h (Just tv) (Just (SObject (update t (Just tv) hm))) neq_th in\n rewrite update_same m t (Just tv) (cong fst prf1) in\n rewrite update_shadow m h (Just (SObject (update t (Just tv) hm))) (Just (SObject (update t Nothing hm))) in\n rewrite update_same hm t Nothing prf2 in\n rewrite update_same m h (Just (SObject hm)) (cong fst $ cong snd prf1) in Refl\n\nwrap_reversible :\n (s : Schema) -> (s' : Schema) ->\n transform_schema Wrap s = Just s' -> transform_schema (reverse_lens Wrap) s' = Just s\nwrap_reversible SNull _ prf = rewrite sym $ justInjective prf in Refl\nwrap_reversible SBoolean _ prf = rewrite sym $ justInjective prf in Refl\nwrap_reversible SNumber _ prf = rewrite sym $ justInjective prf in Refl\nwrap_reversible SText _ prf = rewrite sym $ justInjective prf in Refl\nwrap_reversible (SArray _ _) _ prf = rewrite sym $ justInjective prf in Refl\nwrap_reversible (SObject _) _ prf = rewrite sym $ justInjective prf in Refl\n\nhead_reversible :\n (s : Schema) -> (s' : Schema) ->\n transform_schema Head s = Just s' -> transform_schema (reverse_lens Head) s' = Just s\nhead_reversible SNull _ Refl impossible\nhead_reversible SBoolean _ Refl impossible\nhead_reversible SNumber _ Refl impossible\nhead_reversible SText _ Refl impossible\nhead_reversible (SArray False _) _ prf = rewrite sym $ justInjective prf in Refl\nhead_reversible (SArray True _) _ Refl impossible\nhead_reversible (SObject _) _ Refl impossible\n\nconvert_reversible : (k, k' : PrimitiveKind) -> (m : List (PrimitiveValue, PrimitiveValue)) ->\n (s : Schema) -> (s' : Schema) ->\n transform_schema (Convert k k' m) s = Just s' -> transform_schema (reverse_lens (Convert k k' m)) s' = Just s\nconvert_reversible k k' m s s' prf with (validate_map k k' m) proof prf1\n convert_reversible KBoolean KBoolean _ _ _ prf | False = absurd $ prf\n convert_reversible KBoolean KNumber _ _ _ prf | False = absurd $ prf\n convert_reversible KBoolean KText _ _ _ prf | False = absurd $ prf\n convert_reversible KNumber KBoolean _ _ _ prf | False = absurd $ prf\n convert_reversible KNumber KNumber _ _ _ prf | False = absurd $ prf\n convert_reversible KNumber KText _ _ _ prf | False = absurd $ prf\n convert_reversible KText KBoolean _ _ _ prf | False = absurd $ prf\n convert_reversible KText KNumber _ _ _ prf | False = absurd $ prf\n convert_reversible KText KText _ _ _ prf | False = absurd $ prf\n convert_reversible KBoolean KBoolean _ SNull _ prf | True = absurd $ prf\n convert_reversible KBoolean KBoolean _ SBoolean SNull prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KBoolean m SBoolean SBoolean prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KBoolean KBoolean m prf1 in Refl\n convert_reversible KBoolean KBoolean _ SBoolean SNumber prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KBoolean _ SBoolean SText prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KBoolean _ SBoolean (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KBoolean _ SBoolean (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KBoolean _ SNumber _ prf | True = absurd $ prf\n convert_reversible KBoolean KBoolean _ SText _ prf | True = absurd $ prf\n convert_reversible KBoolean KBoolean _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KBoolean KBoolean _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KBoolean KNumber _ SNull _ prf | True = absurd $ prf\n convert_reversible KBoolean KNumber _ SBoolean SNull prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KNumber _ SBoolean SBoolean prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KNumber m SBoolean SNumber prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KBoolean KNumber m prf1 in Refl\n convert_reversible KBoolean KNumber _ SBoolean SText prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KNumber _ SBoolean (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KNumber _ SBoolean (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KNumber _ SNumber _ prf | True = absurd $ prf\n convert_reversible KBoolean KNumber _ SText _ prf | True = absurd $ prf\n convert_reversible KBoolean KNumber _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KBoolean KNumber _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KBoolean KText _ SNull _ prf | True = absurd $ prf\n convert_reversible KBoolean KText _ SBoolean SNull prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KText _ SBoolean SBoolean prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KText _ SBoolean SNumber prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KText m SBoolean SText prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KBoolean KText m prf1 in Refl\n convert_reversible KBoolean KText _ SBoolean (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KText _ SBoolean (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KBoolean KText _ SNumber _ prf | True = absurd $ prf\n convert_reversible KBoolean KText _ SText _ prf | True = absurd $ prf\n convert_reversible KBoolean KText _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KBoolean KText _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KNumber KBoolean _ SNull _ prf | True = absurd $ prf\n convert_reversible KNumber KBoolean _ SBoolean _ prf | True = absurd $ prf\n convert_reversible KNumber KBoolean _ SNumber SNull prf | True = absurd $ justInjective prf\n convert_reversible KNumber KBoolean m SNumber SBoolean prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KNumber KBoolean m prf1 in Refl\n convert_reversible KNumber KBoolean _ SNumber SNumber prf | True = absurd $ justInjective prf\n convert_reversible KNumber KBoolean _ SNumber SText prf | True = absurd $ justInjective prf\n convert_reversible KNumber KBoolean _ SNumber (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KNumber KBoolean _ SNumber (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KNumber KBoolean _ SText _ prf | True = absurd $ prf\n convert_reversible KNumber KBoolean _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KNumber KBoolean _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KNumber KNumber _ SNull _ prf | True = absurd $ prf\n convert_reversible KNumber KNumber _ SBoolean _ prf | True = absurd $ prf\n convert_reversible KNumber KNumber _ SNumber SNull prf | True = absurd $ justInjective prf\n convert_reversible KNumber KNumber _ SNumber SBoolean prf | True = absurd $ justInjective prf\n convert_reversible KNumber KNumber m SNumber SNumber prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KNumber KNumber m prf1 in Refl\n convert_reversible KNumber KNumber _ SNumber SText prf | True = absurd $ justInjective prf\n convert_reversible KNumber KNumber _ SNumber (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KNumber KNumber _ SNumber (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KNumber KNumber _ SText _ prf | True = absurd $ prf\n convert_reversible KNumber KNumber _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KNumber KNumber _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KNumber KText _ SNull _ prf | True = absurd $ prf\n convert_reversible KNumber KText _ SBoolean _ prf | True = absurd $ prf\n convert_reversible KNumber KText _ SNumber SNull prf | True = absurd $ justInjective prf\n convert_reversible KNumber KText _ SNumber SBoolean prf | True = absurd $ justInjective prf\n convert_reversible KNumber KText _ SNumber SNumber prf | True = absurd $ justInjective prf\n convert_reversible KNumber KText m SNumber SText prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KNumber KText m prf1 in Refl\n convert_reversible KNumber KText _ SNumber (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KNumber KText _ SNumber (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KNumber KText _ SText _ prf | True = absurd $ prf\n convert_reversible KNumber KText _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KNumber KText _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KText KBoolean _ SNull _ prf | True = absurd $ prf\n convert_reversible KText KBoolean _ SBoolean _ prf | True = absurd $ prf\n convert_reversible KText KBoolean _ SNumber _ prf | True = absurd $ prf\n convert_reversible KText KBoolean _ SText SNull prf | True = absurd $ justInjective prf\n convert_reversible KText KBoolean m SText SBoolean prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KText KBoolean m prf1 in Refl\n convert_reversible KText KBoolean _ SText SNumber prf | True = absurd $ justInjective prf\n convert_reversible KText KBoolean _ SText SText prf | True = absurd $ justInjective prf\n convert_reversible KText KBoolean _ SText (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KText KBoolean _ SText (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KText KBoolean _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KText KBoolean _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KText KNumber _ SNull _ prf | True = absurd $ prf\n convert_reversible KText KNumber _ SBoolean _ prf | True = absurd $ prf\n convert_reversible KText KNumber _ SNumber _ prf | True = absurd $ prf\n convert_reversible KText KNumber _ SText SNull prf | True = absurd $ justInjective prf\n convert_reversible KText KNumber _ SText SBoolean prf | True = absurd $ justInjective prf\n convert_reversible KText KNumber m SText SNumber prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KText KNumber m prf1 in Refl\n convert_reversible KText KNumber _ SText SText prf | True = absurd $ justInjective prf\n convert_reversible KText KNumber _ SText (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KText KNumber _ SText (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KText KNumber _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KText KNumber _ (SObject _) _ prf | True = absurd $ prf\n convert_reversible KText KText _ SNull _ prf | True = absurd $ prf\n convert_reversible KText KText _ SBoolean _ prf | True = absurd $ prf\n convert_reversible KText KText _ SNumber _ prf | True = absurd $ prf\n convert_reversible KText KText _ SText SNull prf | True = absurd $ justInjective prf\n convert_reversible KText KText _ SText SBoolean prf | True = absurd $ justInjective prf\n convert_reversible KText KText _ SText SNumber prf | True = absurd $ justInjective prf\n convert_reversible KText KText m SText SText prf | True =\n rewrite sym $ justInjective prf in\n rewrite flip_map_preserves_validity KText KText m prf1 in Refl\n convert_reversible KText KText _ SText (SArray _ _) prf | True = absurd $ justInjective prf\n convert_reversible KText KText _ SText (SObject _) prf | True = absurd $ justInjective prf\n convert_reversible KText KText _ (SArray _ _) _ prf | True = absurd $ prf\n convert_reversible KText KText _ (SObject _) _ prf | True = absurd $ prf\n\n\n||| Forwards and backwards compatibility requires schema transformations to be reversible\nlens_reversible : (l : Lens) -> (s : Schema) -> (s' : Schema) ->\n transform_schema l s = Just s' -> transform_schema (reverse_lens l) s' = Just s\nlens_reversible (Make k) s s' prf = make_reversible k s s' prf\nlens_reversible (Destroy k) s s' prf = destroy_reversible k s s' prf\nlens_reversible (AddProperty k) s s' prf = add_property_reversible k s s' prf\nlens_reversible (RemoveProperty k) s s' prf = remove_property_reversible k s s' prf\nlens_reversible (RenameProperty k k') s s' prf = rename_property_reversible k k' s s' prf\nlens_reversible (HoistProperty h t) s s' prf = hoist_property_reversible h t s s' prf\nlens_reversible (PlungeProperty h t) s s' prf = plunge_property_reversible h t s s' prf\nlens_reversible Wrap s s' prf = wrap_reversible s s' prf\nlens_reversible Head s s' prf = head_reversible s s' prf\nlens_reversible (LensIn _ _) SNull _ Refl impossible\nlens_reversible (LensIn _ _) SBoolean _ Refl impossible\nlens_reversible (LensIn _ _) SNumber _ Refl impossible\nlens_reversible (LensIn _ _) SText _ Refl impossible\nlens_reversible (LensIn _ _) (SArray _ _) _ Refl impossible\nlens_reversible (LensIn k l) (SObject m) s' prf with (get k m) proof prf1\n lens_reversible (LensIn k l) (SObject m) s' prf | Nothing = absurd $ prf\n lens_reversible (LensIn k l) (SObject m) s' prf | (Just s2) with (transform_schema l s2) proof prf2\n lens_reversible (LensIn k l) (SObject m) s' prf | (Just s2) | Nothing = absurd $ prf\n lens_reversible (LensIn k l) (SObject m) s' prf | (Just s2) | (Just s2') =\n rewrite sym $ justInjective prf in\n rewrite update_eq m k (Just s2') in\n rewrite lens_reversible l s2 s2' prf2 in\n rewrite update_shadow m k (Just s2') (Just s2) in\n rewrite update_same m k (Just s2) prf1 in Refl\nlens_reversible (LensMap _) SNull _ Refl impossible\nlens_reversible (LensMap _) SBoolean _ Refl impossible\nlens_reversible (LensMap _) SNumber _ Refl impossible\nlens_reversible (LensMap _) SText _ Refl impossible\nlens_reversible (LensMap l) (SArray e s2) s' prf with (transform_schema l s2) proof prf1\n lens_reversible (LensMap l) (SArray e s2) s' prf | Nothing = absurd $ prf\n lens_reversible (LensMap l) (SArray e s2) s' prf | (Just s2') =\n rewrite sym $ justInjective prf in\n rewrite lens_reversible l s2 s2' prf1 in Refl\nlens_reversible (LensMap _) (SObject _) _ Refl impossible\nlens_reversible (Convert k k' m) s s' prf = convert_reversible k k' m s s' prf\n", "meta": {"hexsha": "71deabb7b5a926174614a52730cc77ed939816b8", "size": 28512, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "spec/Lens/Reversible.idr", "max_stars_repo_name": "Actyx/cambria", "max_stars_repo_head_hexsha": "764b9dc7985fc4a2cca4900ce7e3b964cbbb424e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2021-09-01T16:29:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T15:39:15.000Z", "max_issues_repo_path": "spec/Lens/Reversible.idr", "max_issues_repo_name": "Actyx/cambria", "max_issues_repo_head_hexsha": "764b9dc7985fc4a2cca4900ce7e3b964cbbb424e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-08-31T16:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-03T09:48:25.000Z", "max_forks_repo_path": "spec/Lens/Reversible.idr", "max_forks_repo_name": "Actyx/cambria", "max_forks_repo_head_hexsha": "764b9dc7985fc4a2cca4900ce7e3b964cbbb424e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-12-02T01:43:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-19T21:17:03.000Z", "avg_line_length": 66.4615384615, "max_line_length": 123, "alphanum_fraction": 0.739127385, "num_tokens": 8124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.31153882595585264}} {"text": "module LightClick.Types.Equality\n\nimport public Toolkit.Decidable.Equality.Indexed\n\nimport public Toolkit.Decidable.Informative\n\nimport Toolkit.Data.Rig\n\nimport Toolkit.Data.Vect.Extra\n\nimport LightClick.Types.Meta\nimport LightClick.Types.Direction\nimport LightClick.Types.Sensitivity\nimport LightClick.Types.WireType\n\nimport LightClick.Types\n\n%default total\n\npublic export\nEquals : {a,b : MTy}\n -> (x : Ty a)\n -> (y : Ty b)\n -> Type\nEquals = Equals MTy Ty\n\n-- [ No's for Logic vs X]\nnamespace Logic\n export\n logicNotStruct : (Equals TyLogic (TyStruct xs)) -> Void\n logicNotStruct (Same _ _) impossible\n\n export\n logicNotUnion : (Equals TyLogic (TyUnion xs)) -> Void\n logicNotUnion (Same _ _ ) impossible\n\n export\n logicNotArray : (Equals TyLogic (TyArray x k)) -> Void\n logicNotArray (Same _ _) impossible\n\n-- [ No's for Array vs X]\nnamespace Array\n export\n arrayNotStruct : (Equals (TyArray x k) (TyStruct xs)) -> Void\n arrayNotStruct (Same _ _) impossible\n\n export\n arrayNotUnion : (Equals (TyArray x k) (TyUnion xs)) -> Void\n arrayNotUnion (Same _ _) impossible\n\n export\n arrayDiffIndicies : {k,j : Nat}\n -> (contra : (k = j) -> Void)\n -> (Equals (TyArray x k) (TyArray y j))\n -> Void\n arrayDiffIndicies contra (Same Refl Refl) {k = j} {j = j} = contra Refl\n\n export\n arrayDiffTypes : (contra : (x `Equals` y) -> Void)\n -> (Equals (TyArray x k) (TyArray y j))\n -> Void\n arrayDiffTypes contra (Same Refl Refl) = contra (Same Refl Refl)\n\n-- [ No's for 'Bodies' vs X]\nnamespace Body\n\n namespace Length\n export\n structNotUnion : (TyStruct xs `Equals` TyUnion ys) -> Void\n structNotUnion (Same _ _) impossible\n\n export\n structDifferBody : {xs : Vect (S n) (Pair String (Ty DATA))}\n -> {ys : Vect (S m) (Pair String (Ty DATA))}\n -> (contra : (xs = ys) -> Void)\n -> (TyStruct xs `Equals` TyStruct ys)\n -> Void\n structDifferBody contra (Same Refl Refl) = contra Refl\n\n export\n unionDifferBody : {xs : Vect (S n) (Pair String (Ty DATA))}\n -> {ys : Vect (S m) (Pair String (Ty DATA))}\n -> (contra : (xs = ys) -> Void)\n -> (TyUnion xs `Equals` TyUnion ys)\n -> Void\n unionDifferBody contra (Same Refl Refl) = contra Refl\n\n export\n modDifferBody : {xs : DVect String (Ty . PORT) (S n) ns}\n -> {ys : DVect String (Ty . PORT) (S m) ms}\n -> (contra : (xs = ys) -> Void)\n -> (TyModule xs `Equals` TyModule ys)\n -> Void\n modDifferBody contra (Same Refl Refl) = contra Refl\n\n\n-- [ No's for Ports]\nnamespace Ports\n export\n portDifferUsage : (contra : (ux = uy) -> Void)\n -> (TyPort lx dy sy wx ty ux `Equals` TyPort lx dy sy wx ty uy)\n -> Void\n portDifferUsage contra (Same Refl Refl) = contra Refl\n\n export\n portDifferType : (contra : (tx `Equals` ty) -> Void)\n -> (TyPort lx dy sy wx tx ux `Equals` TyPort lx dy sy wy ty uy)\n -> Void\n portDifferType contra (Same Refl Refl) = contra (Same Refl Refl)\n\n\n export\n portDifferWire : (contra : (wx = wy) -> Void)\n -> (TyPort lx dy sy wx tx ux `Equals` TyPort lx dy sy wy ty uy)\n -> Void\n portDifferWire contra (Same Refl Refl) = contra Refl\n\n export\n portDifferSens : (contra : (sx = sy) -> Void)\n -> (TyPort lx dy sx wx tx ux `Equals` TyPort lx dy sy wy ty uy)\n -> Void\n portDifferSens contra (Same Refl Refl) = contra Refl\n\n export\n portsDifferDir : (contra : (dx = dy) -> Void)\n -> (TyPort a dx sx wx tx ux `Equals` TyPort a dy sy wy ty uy)\n -> Void\n portsDifferDir contra (Same Refl Refl) = contra Refl\n\n export\n portsDifferLabel : (contra : (lx = ly) -> Void)\n -> (TyPort lx dx sx wx tx ux `Equals` TyPort ly dy sy wy ty uy)\n -> Void\n portsDifferLabel contra (Same Refl Refl) = contra Refl\n\n-- [ No's for Body ]\nnamespace Body\n namespace Length\n export\n dataBodyLengthsDiffer : {xs : Vect n (Pair String (Ty DATA))}\n -> {ys : Vect m (Pair String (Ty DATA))}\n -> (contra : (n = m) -> Void)\n -> (xs = ys)\n -> Void\n dataBodyLengthsDiffer contra Refl = contra Refl\n\n export\n dataBodyLengthsDiffer' : {xs : Vect (S n) (Pair String (Ty DATA))}\n -> {ys : Vect (S m) (Pair String (Ty DATA))}\n -> (contra : (xs = ys) -> Void)\n -> (xs = ys)\n -> Void\n dataBodyLengthsDiffer' contra Refl = contra Refl\n\n namespace Values\n\n namespace Names\n export\n modBodyDiffer : {n : Nat}\n -> {names : Vect (S n) String}\n -> {xs : DVect String (Ty . PORT) (S n) names}\n -> {ys : DVect String (Ty . PORT) (S n) names}\n -> (contra : (xs = ys) -> Void)\n -> (TyModule xs `Equals` TyModule ys)\n -> Void\n modBodyDiffer contra (Same Refl Refl) = contra Refl\n\n\n namespace Rest\n export\n restDataBodyDiffer : {xs : Vect n (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> (contra : (xs = ys) -> Void)\n -> (((ky, vy) :: xs) = ((ky, vy) :: ys))\n -> Void\n restDataBodyDiffer contra Refl = contra Refl\n\n export\n dataBodyDiffer : {xs : Vect n (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> (contra : (xs = ys) -> Void)\n -> (xs = ys)\n -> Void\n dataBodyDiffer contra Refl = contra Refl\n\n\n\n vRestDiffer : {xs : Vect n (Pair String (Ty DATA))}\n -> {ys : Vect m (Pair String (Ty DATA))}\n -> (contra : (xs = ys) -> Void)\n -> (((ky, vy) :: xs) = ((ky, vy) :: ys))\n -> Void\n vRestDiffer contra Refl = contra Refl\n\n export\n dVectElemDiffer : {n : Nat}\n -> {ns : Vect n String}\n -> {xrest : DVect String (Ty . PORT) n ns}\n -> {yrest : DVect String (Ty . PORT) n ns}\n -> {x : String}\n -> {ex : Ty (PORT x)}\n -> {ey : Ty (PORT x)}\n -> (contra : (ex `Equals` ey) -> Void)\n -> ((ex :: xrest) = (ey :: yrest))\n -> Void\n dVectElemDiffer contra Refl = contra (Same Refl Refl)\n\n export\n dVectBodyDiffer : {xrest : DVect String (Ty . PORT) n ns}\n -> {yrest : DVect String (Ty . PORT) n ns}\n -> (contra : (xrest = yrest) -> Void)\n -> ((ey :: xrest) = (ey :: yrest))\n -> Void\n dVectBodyDiffer contra Refl = contra Refl\n\n namespace Head\n export\n elemDataBodyDiffer : {xs : Vect n (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> {vx, vy : Ty DATA}\n -> (contra : (vx `Equals` vy) -> Void)\n -> (((ky, vx) :: xs) = ((ky, vy) :: ys))\n -> Void\n elemDataBodyDiffer contra Refl = contra (Same Refl Refl)\n\n export\n elemDataKeyDiffer : {xs : Vect n (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> {vx, vy : Ty DATA}\n -> (contra : (kx = ky) -> Void)\n -> (((kx, vx) :: xs) = ((ky, vy) :: ys))\n -> Void\n elemDataKeyDiffer contra Refl = contra Refl\n\n\nexport\ndecEq : (x : Ty i)\n -> (y : Ty j)\n -> (prf : i = j)\n -> Dec (Equals MTy Ty x y)\n\nnamespace Fields\n\n differentLengthLeft : {y : String}\n -> {z : Ty DATA}\n -> (y, z) `Vect.(::)` (x `Vect.(::)` xs) = (y, z) `Vect.(::)` Nil -> Void\n differentLengthLeft _ impossible\n\n differentLengthRight : {y : String}\n -> {z : Ty DATA}\n -> (y, z) `Vect.(::)` Nil = (y, z) `Vect.(::)` (x `Vect.(::)` xs) -> Void\n differentLengthRight _ impossible\n\n headTypeDiff : {xs : Vect m (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> {z,w : Ty DATA}\n -> (Equals MTy Ty z w -> Void)\n -> (y, z) `Vect.(::)` xs = (y, w) `Vect.(::)` ys\n -> Void\n headTypeDiff contra Refl = contra (Same Refl Refl)\n\n headLabelDiff : {xs : Vect m (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> (x = y -> Void)\n -> {z,w : Ty DATA}\n -> (x, z) `Vect.(::)` xs = (y, w) `Vect.(::)` ys\n -> Void\n headLabelDiff contra Refl = contra Refl\n\n fieldsAreNotEqual : {xs : Vect m (Pair String (Ty DATA))}\n -> {ys : Vect n (Pair String (Ty DATA))}\n -> (x `Vect.(::)` xs = y' `Vect.(::)` ys -> Void)\n -> (y, z) `Vect.(::)` (x `Vect.(::)` xs) = (y, z) `Vect.(::)` (y' `Vect.(::)` ys)\n -> Void\n fieldsAreNotEqual contra Refl = contra Refl\n\n export\n decEq : (xs : Vect (S n) (Pair String (Ty DATA)))\n -> (ys : Vect (S m) (Pair String (Ty DATA)))\n -> Dec (xs = ys)\n decEq {n} xs {m} ys with (shape xs ys)\n decEq {n = n} ((x, z) :: xs) {m = m} ((y, w) :: ys) | Both with (decEq x y)\n decEq {n = n} ((y, z) :: xs) {m = m} ((y, w) :: ys) | Both | (Yes Refl) with (Equality.decEq z w Refl)\n decEq {n = n} ((y, z) :: xs) {m = m} ((y, z) :: ys) | Both | (Yes Refl) | (Yes (Same Refl Refl)) with (shape xs ys)\n decEq {n = 0} ((y, z) :: []) {m = 0} ((y, z) :: []) | Both | (Yes Refl) | (Yes (Same Refl Refl)) | Empty = Yes Refl\n\n decEq {n = (S len)} ((y, z) :: (x :: xs)) {m = 0} ((y, z) :: []) | Both | (Yes Refl) | (Yes (Same Refl Refl)) | LH = No differentLengthLeft\n decEq {n = 0} ((y, z) :: []) {m = (S len)} ((y, z) :: (y' :: ys)) | Both | (Yes Refl) | (Yes (Same Refl Refl)) | RH = No differentLengthRight\n\n decEq {n = (S len)} ((y, z) :: (x :: xs)) {m = (S len)} ((y, z) :: (y' :: ys)) | Both | (Yes Refl) | (Yes (Same Refl Refl)) | Both with (Fields.decEq (x::xs) (y'::ys))\n decEq {n = (S len)} ((y, z) :: (x :: xs)) {m = (S len)} ((y, z) :: (x :: xs)) | Both | (Yes Refl) | (Yes (Same Refl Refl)) | Both | (Yes Refl) = Yes Refl\n decEq {n = (S len)} ((y, z) :: (x :: xs)) {m = (S len)} ((y, z) :: (y' :: ys)) | Both | (Yes Refl) | (Yes (Same Refl Refl)) | Both | (No contra) = No (fieldsAreNotEqual contra)\n\n decEq {n = n} ((y, z) :: xs) {m = m} ((y, w) :: ys) | Both | (Yes Refl) | (No contra) = No (headTypeDiff contra)\n decEq {n = n} ((x, z) :: xs) {m = m} ((y, w) :: ys) | Both | (No contra) = No (headLabelDiff contra)\n\nnamespace Port\n\n export\n decEq : (x : Ty (PORT a))\n -> (y : Ty (PORT b))\n -> Dec (Equals x y)\n decEq (TyPort a dx sx wx tx ux) (TyPort b dy sy wy ty uy) with (decEq a b)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dy sy wy ty uy) | (Yes Refl) with (decEq dx dy)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sy wy ty uy) | (Yes Refl) | (Yes Refl) with (decEq sx sy)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sx wy ty uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) with (decEq wx wy)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sx wx ty uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes Refl) with (decEq tx ty Refl)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sx wx tx uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes (Same Refl Refl)) with (decEq ux uy)\n decEq (TyPort a dx sx wx tx uy) (TyPort a dx sx wx tx uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes (Same Refl Refl)) | (Yes Refl) = Yes (Same Refl Refl)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sx wx tx uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes (Same Refl Refl)) | (No contra) = No (portDifferUsage contra)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sx wx ty uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (No contra) = No (portDifferType contra)\n\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sx wy ty uy) | (Yes Refl) | (Yes Refl) | (Yes Refl) | (No contra) = No (portDifferWire contra)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dx sy wy ty uy) | (Yes Refl) | (Yes Refl) | (No contra) = No (portDifferSens contra)\n decEq (TyPort a dx sx wx tx ux) (TyPort a dy sy wy ty uy) | (Yes Refl) | (No contra) = No (portsDifferDir contra)\n decEq (TyPort a dx sx wx tx ux) (TyPort b dy sy wy ty uy) | (No contra) = No (portsDifferLabel contra)\n\n\nnamespace Ports\n\n export\n decEq : {n :Nat}\n -> {ns : _}\n -> (xs : DVect String (Ty . PORT) n ns)\n -> (ys : DVect String (Ty . PORT) n ns)\n -> Dec (xs = ys)\n decEq [] [] = Yes Refl\n decEq (x :: xs) (y :: ys) with (Port.decEq x y)\n decEq (x :: xs) (x :: ys) | (Yes (Same Refl Refl)) with (Ports.decEq xs ys)\n decEq (x :: xs) (x :: xs) | (Yes (Same Refl Refl)) | (Yes Refl) = Yes Refl\n decEq (x :: xs) (y :: ys) | (Yes (Same Refl Refl)) | (No contra) = No (dVectBodyDiffer contra)\n decEq (x :: xs) (y :: ys) | (No contra) = No (dVectElemDiffer contra)\n\n-- [ Body ]\n\n-- [ Logic Types]\ndecEq TyLogic TyLogic Refl = Yes (Same Refl Refl)\ndecEq TyLogic (TyArray x k) Refl = No logicNotArray\ndecEq TyLogic (TyStruct xs) Refl = No logicNotStruct\ndecEq TyLogic (TyUnion xs) Refl = No logicNotUnion\n\n-- [ Array Types ]\ndecEq (TyArray x k) TyLogic Refl = No (negEqSym logicNotArray)\n\ndecEq (TyArray x i) (TyArray y j) Refl with (decEq i j)\n decEq (TyArray x i) (TyArray y i) Refl | (Yes Refl) with (decEq x y Refl)\n decEq (TyArray x i) (TyArray x i) Refl | (Yes Refl) | (Yes (Same Refl Refl))\n = Yes (Same Refl Refl)\n decEq (TyArray x i) (TyArray y i) Refl | (Yes Refl) | (No contra)\n = No (arrayDiffTypes contra)\n decEq (TyArray x i) (TyArray y j) Refl | (No contra)\n = No (arrayDiffIndicies contra)\n\ndecEq (TyArray x k) (TyStruct xs) Refl = No arrayNotStruct\ndecEq (TyArray x k) (TyUnion xs) Refl = No arrayNotUnion\n\n-- [ Structs ]\ndecEq (TyStruct xs) TyLogic Refl = No (negEqSym logicNotStruct)\ndecEq (TyStruct xs) (TyArray type length) Refl = No (negEqSym arrayNotStruct)\n\ndecEq (TyStruct xs) (TyStruct ys) Refl with (Fields.decEq xs ys)\n decEq (TyStruct xs) (TyStruct xs) Refl | (Yes Refl) = Yes (Same Refl Refl)\n decEq (TyStruct xs) (TyStruct ys) Refl | (No contra) = No (structDifferBody contra)\n\ndecEq (TyStruct xs) (TyUnion kvs) Refl = No structNotUnion\n\n-- [ Unions ]\ndecEq (TyUnion xs) TyLogic Refl = No (negEqSym logicNotUnion)\ndecEq (TyUnion xs) (TyArray type length) Refl = No (negEqSym arrayNotUnion)\ndecEq (TyUnion xs) (TyStruct kvs) Refl = No (negEqSym structNotUnion)\n\ndecEq (TyUnion xs) (TyUnion ys) Refl with (Fields.decEq xs ys)\n decEq (TyUnion xs) (TyUnion xs) Refl | (Yes Refl) = Yes (Same Refl Refl)\n decEq (TyUnion xs) (TyUnion ys) Refl | (No contra) = No (unionDifferBody contra)\n\n-- [ Unit ]\ndecEq TyUnit TyUnit Refl = Yes (Same Refl Refl)\n\n-- [ Gates ]\ndecEq TyGate TyGate Refl = Yes (Same Refl Refl)\n\n-- [ Connections ]\n\ndecEq TyConn TyConn Refl = Yes (Same Refl Refl)\n\n-- [ Ports ]\ndecEq (TyPort l dx sx wx tx ux) (TyPort l dy sy wy ty uy) Refl = Port.decEq (TyPort l dx sx wx tx ux) (TyPort l dy sy wy ty uy)\n\ndecEq (TyModule xs) (TyModule ys) Refl with (Ports.decEq xs ys)\n decEq (TyModule xs) (TyModule xs) Refl | (Yes Refl) = Yes (Same Refl Refl)\n decEq (TyModule xs) (TyModule ys) Refl | (No contra) = No (modBodyDiffer contra)\n\n\n\nDecEqIdx MTy Ty where\n decEq x y prf = Equality.decEq x y prf\n\n\n-- [ EOF ]\n", "meta": {"hexsha": "2bc0a19780dafdec8ecc045512abfa33a7dfff91", "size": 16055, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/LightClick/Types/Equality.idr", "max_stars_repo_name": "border-patrol/lightclick", "max_stars_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-11-03T11:33:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:11:38.000Z", "max_issues_repo_path": "src/LightClick/Types/Equality.idr", "max_issues_repo_name": "border-patrol/lightclick", "max_issues_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LightClick/Types/Equality.idr", "max_forks_repo_name": "border-patrol/lightclick", "max_forks_repo_head_hexsha": "1f52fc27674f244c399e5e579403e8075f982a37", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1375, "max_line_length": 192, "alphanum_fraction": 0.5252569293, "num_tokens": 5072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.3103112427114114}} {"text": "-- ----------------------------------------------------------------- [ Key.idr ]\n-- Module : Keys\n-- Description : Types for Cryptographic Keys\n-- Copyright : (c) Jan de Muijnck-Hughes\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Crypto.Std.Key\n\nimport Crypto.Common\nimport Data.Bits\n\n||| Keys are vectors of bits.\n||| \n||| @ v The Visibility of the key with respect to the owner.\n||| @ s The setting in which the key is to be used.\n||| @ l The length of the key in bits.\ndata Key : (v : Visibility) -> (s : Setting) -> (l : Nat) -> Type where\n ||| PKE Encryption keys.\n MkEncKey : Bits n -> Key Public Asymm n\n\n ||| PKE Decryption keys\n MkDecKey : Bits n -> Key Private Asymm n\n\n ||| DS Signing keys.\n MkSignKey : Bits n -> Key Private Sign n\n\n ||| DS Verifying keys.\n MkVerifyKey : Bits n -> Key Public Sign n\n\n ||| Symmetric keys \n MkSymmKey : Bits n -> Key Private Symm n\n\n||| Key pairs\n||| \n||| @ s The setting in which the key is to be used.\n||| @ l The length of the key in bits.\ndata KeyPair : (s : Setting) -> (l : Nat) -> Type where\n ||| Key pair for PKE.\n ||| \n ||| @ pub The public key.\n ||| @ priv The private key.\n MkAsymmKeyPair : (pub : Key Public Asymm n)\n -> (priv : Key Private Asymm n)\n -> KeyPair Asymm n\n\n ||| Key pair for DS.\n ||| \n ||| @ sig The signing key.\n ||| @ ver The verifying key.\n MkSignKeyPair : (sig : Key Private Sign n)\n -> (ver : Key Public Sign n)\n -> KeyPair Sign n\n\n\ndata TDESKeyOption = KeyOption1 | KeyOption2 | KeyOption3\n\n||| Representation of a Triple DES\n|||\n||| @ s The setting in ehich the key is to be used.\n||| @ n The length of each key\n||| @ option The Keying option used.\ndata TDESKey : (s : Setting) -> (n : Nat) -> (option : TDESKeyOption)-> Type where\n ||| \n MkTDESKey : (key1 : Bits n)\n -> (key2 : Bits n)\n -> (key3 : Bits n)\n -> (opt : TDESKeyOption)\n -> TDESKey Symm n opt\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "1cf82e3368f53a5f3a2555ab7a1ac94b3c46aa05", "size": 2125, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Crypto/Std/Key.idr", "max_stars_repo_name": "silky/idris-crypto-types", "max_stars_repo_head_hexsha": "aed6375fbe7202a1c9aae45904b036017d90e8bc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-27T11:33:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T11:33:38.000Z", "max_issues_repo_path": "src/Crypto/Std/Key.idr", "max_issues_repo_name": "silky/idris-crypto-types", "max_issues_repo_head_hexsha": "aed6375fbe7202a1c9aae45904b036017d90e8bc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Crypto/Std/Key.idr", "max_forks_repo_name": "silky/idris-crypto-types", "max_forks_repo_head_hexsha": "aed6375fbe7202a1c9aae45904b036017d90e8bc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3571428571, "max_line_length": 82, "alphanum_fraction": 0.5251764706, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.30474230844932787}} {"text": "module Flexidisc.Function\n\nimport Flexidisc.TaggedValue\n\n%default total\n%access public export\n\ninfixr 8 |->\ninfix 7 ~~\n\n||| A wrapper for functions to allow definition of typeclasses\nrecord (|->) (a : Type) (b : Type) where\n constructor F\n unwrap : (a -> b)\n\n\nFunctor ((|->) a) where\n map g (F f) = F (g . f)\n\nApplicative ((|->) a) where\n pure x = F (const x)\n (<*>) (F f) (F x) = F (\\y => f y (x y))\n\n(~~) : (l : k) -> (a -> b) -> TaggedValue l (a |-> b)\n(~~) l f = l := F f\n", "meta": {"hexsha": "7a615ed62bdaaae893fc238a5caa7ec1516d72d7", "size": 481, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Flexidisc/Function.idr", "max_stars_repo_name": "berewt/flexidisc", "max_stars_repo_head_hexsha": "8a0c367244229be5d417c04588d8d41b6030dba2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-02T09:51:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-03T05:15:49.000Z", "max_issues_repo_path": "src/Flexidisc/Function.idr", "max_issues_repo_name": "LIST-LUXEMBOURG/flexidisc", "max_issues_repo_head_hexsha": "f5a9cdc81554359e324b64400d8479494cd45a8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Flexidisc/Function.idr", "max_forks_repo_name": "LIST-LUXEMBOURG/flexidisc", "max_forks_repo_head_hexsha": "f5a9cdc81554359e324b64400d8479494cd45a8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.5, "max_line_length": 62, "alphanum_fraction": 0.5550935551, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.3039365556728161}} {"text": "-- ------------------------------------------------------ [ Tree.idr ]\n-- Module : Tree.idr\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\n-- http://www.cs.kent.ac.uk/people/staff/smk/redblack/Untyped.hs\nmodule Data.RedBlack.Tree\n\nimport Debug.Error\n%language ElabReflection\n\n%default total\n%access export\n\n-- ------------------------------------------------------------- [ Definitions ]\npublic export\ndata Colour = R | B\n\n||| The core tree key-value data structure used to represent an\n||| Red-Black Tree.\n|||\n||| This structure doesn't encode the invariants of the tree and is\n||| *simply* a container. This structure ideally shouldn't be exposed\n||| to the user at all. This structure should be used to build other\n||| data structures. See the modules alongside this for appropriate\n||| interfaces for using the tree.\n|||\n||| @keyTy The type associated with the key.\n||| @valTy The type associated with the value.\npublic export\ndata Tree : (colour : Colour)\n -> (keyTy : Type)\n -> (valTy : Type)\n -> Type\n where\n ||| An empty Tree node.\n Empty : Tree B k v\n\n ||| A Key Value node in the Tree.\n |||\n ||| @key The key.\n ||| @val The value associated with the key.\n ||| @left The left child of the Node\n ||| @right THe right child of the Node.\n Node : (c3 : Colour)\n -> (key : k)\n -> (val : v)\n -> (left : Tree c1 k v)\n -> (right : Tree c2 k v)\n -> Tree c3 k v\n\n%name Tree t, tree\n\npublic export\ndata RBInvariant : (blackHeight : Nat)\n -> (colour : Colour)\n -> (valid : Bool)\n -> (tree : Tree colour k v)\n -> Type\n where\n ||| A tree of height zero.\n RBEmpty : RBInvariant 0 B True Empty\n ||| A balanced black tree.\n |||\n ||| @left The invariant of the left child.\n ||| @right The invariant of the right child.\n BNode : (left : RBInvariant n _ True l)\n -> (right : RBInvariant n _ True r)\n -> RBInvariant (S n) B True (Node B k v l r)\n ||| A balanced red tree.\n |||\n ||| @left The invariant of the left child.\n ||| @right The invariant of the right child.\n RNode : (left : RBInvariant n B True l)\n -> (right : RBInvariant n B True r)\n -> RBInvariant n R True (Node R k v l r)\n\n ||| A red tree with a red left child.\n |||\n ||| @left The invariant of the left child.\n ||| @right The invariant of the right child.\n LBad : (left : RBInvariant n R True l)\n -> (right : RBInvariant n B True r)\n -> RBInvariant n R False (Node R k v l r)\n\n ||| A red tree with a red right child.\n |||\n ||| @left The invariant of the left child.\n ||| @right The invariant of the right child.\n RBad : (left : RBInvariant n B True l)\n -> (right : RBInvariant n R True r)\n -> RBInvariant n R False (Node R k v l r)\n\n%name RBInvariant inv\n\n||| An Red-Black Tree.\n|||\n||| Modelled using subset to separate the invariants from the tree\n||| implementation itself.\n|||\n||| @blackHeight The height of the Tree.\n||| @keyTy The type associated with the keys.\n||| @valueTy The type associated with the values.\npublic export\nRBTree : (blackHeight : Nat)\n -> (colour : Colour)\n -> (keyTy : Type)\n -> (valueTy : Type)\n -> Type\nRBTree n c k v = Subset (Tree c k v) (RBInvariant n c True)\n\nprivate\nInsTree : (blackHeight : Nat)\n -> (colour : Colour)\n -> (keyTy : Type)\n -> (valueTy : Type)\n -> (valid : Bool)\n -> Type\nInsTree n c k v valid = Subset (Tree c k v) (RBInvariant n c valid)\n\n-- --------------------------------------------------------------- [ Insertion ]\n\nprivate\nbalance : k -> v -> RBTree n c1 k v -> RBTree n c2 k v -> (c3 ** RBTree (S n) c3 k v)\nbalance {n} y vy (Element (Node _ x vx a b) (RNode pf_l_l pf_l_r))\n (Element (Node _ z vz c d) (RNode pf_r_l pf_r_r)) =\n let t = (Node R y vy (Node B x vx a b) (Node B z vz c d))\n pf = RNode (BNode pf_l_l pf_l_r) (BNode pf_r_l pf_r_r)\n in (R ** Element t pf)\nbalance {n} x vx (Element a pf_a) (Element b pf_b) =\n let t = (Node B x vx a b)\n pf = BNode pf_a pf_b\n in (B ** Element t pf)\n\nprivate\nrecolorRight : (Ord k) => k -> v -> RBTree n c k v -> InsTree n R k v False -> (c' ** valid ** InsTree (S n) c' k v valid)\n\nrecolorRight g vg (Element (Node R u vu t5 t4) (RNode pf_5 pf_4))\n (Element (Node R p vp t3 tn) (RBad pf_3 pf_n)) =\n (R ** True ** Element (Node R g vg (Node B u vu t5 t4) (Node B p vp t3 tn))\n (RNode (BNode pf_5 pf_4) (BNode pf_3 pf_n)))\n\nrecolorRight g vg (Element (Node R u vu t5 t4) (RNode pf_5 pf_4))\n (Element (Node R p vp tn t3) (LBad pf_n pf_3)) =\n (R ** True ** Element (Node R g vg (Node B u vu t4 t5) (Node B p vp tn t3))\n (RNode (BNode pf_4 pf_5) (BNode pf_n pf_3)))\n\nrecolorRight g vg (Element (Node B u vu t5 t4) (BNode pf_5 pf_4))\n (Element (Node R p vp t3 (Node R n vn t2 t1)) (RBad pf_3 (RNode pf_2 pf_1))) =\n (B ** True ** Element (Node B p vp (Node R g vg (Node B u vu t5 t4) t3)\n (Node R n vn t2 t1))\n (BNode (RNode (BNode pf_5 pf_4) pf_3) (RNode pf_2 pf_1)))\n\nrecolorRight g vg (Element Empty RBEmpty)\n (Element (Node R p vp t3 (Node R n vn t2 t1)) (RBad pf_3 (RNode pf_2 pf_1))) =\n (B ** True ** Element (Node B p vp (Node R g vg Empty t3)\n (Node R n vn t2 t1))\n (BNode (RNode RBEmpty pf_3) (RNode pf_2 pf_1)))\n\nrecolorRight g vg (Element (Node B u vu t5 t4) (BNode pf_5 pf_4))\n (Element (Node R p vp (Node R n vn t3 t2) t1) (LBad (RNode pf_3 pf_2) pf_1)) =\n (B ** True ** Element (Node B n vn (Node R g vg (Node B u vu t5 t4) t3)\n (Node R p vp t2 t1))\n (BNode (RNode (BNode pf_5 pf_4) pf_3) (RNode pf_2 pf_1)))\n\nrecolorRight g vg (Element Empty RBEmpty)\n (Element (Node R p vp (Node R n vn t3 t2) t1) (LBad (RNode pf_3 pf_2) pf_1)) =\n (B ** True ** Element (Node B n vn (Node R g vg Empty t3)\n (Node R p vp t2 t1))\n (BNode (RNode RBEmpty pf_3) (RNode pf_2 pf_1)))\n\nprivate\nrecolorLeft : (Ord k) => k -> v -> InsTree n R k v False -> RBTree n c k v -> (c' ** valid ** InsTree (S n) c' k v valid)\n\nrecolorLeft g vg (Element (Node R p vp tn t3) (LBad pf_n pf_3))\n (Element (Node R u vu t4 t5) (RNode pf_4 pf_5)) =\n (R ** True ** Element (Node R g vg (Node B p vp tn t3)\n (Node B u vu t4 t5))\n (RNode (BNode pf_n pf_3) (BNode pf_4 pf_5)))\n\nrecolorLeft g vg (Element (Node R p vp t1 tn) (RBad pf_1 pf_n))\n (Element (Node R u vu t4 t5) (RNode pf_4 pf_5)) =\n (R ** True ** Element (Node R g vg (Node B p vp t1 tn)\n (Node B u vu t4 t5))\n (RNode (BNode pf_1 pf_n) (BNode pf_4 pf_5)))\n\nrecolorLeft g vg (Element (Node R p vp (Node R n vn t1 t2) t3) (LBad (RNode pf_1 pf_2) pf_3))\n (Element (Node B u vu t4 t5) (BNode pf_4 pf_5)) =\n (B ** True ** Element (Node B p vp (Node R n vn t1 t2)\n (Node R g vg t3 (Node B u vu t4 t5)))\n (BNode (RNode pf_1 pf_2) (RNode pf_3 (BNode pf_4 pf_5))))\n\nrecolorLeft g vg (Element (Node R p vp (Node R n vn t1 t2) t3) (LBad (RNode pf_1 pf_2) pf_3))\n (Element Empty RBEmpty) =\n (B ** True ** Element (Node B p vp (Node R n vn t1 t2)\n (Node R g vg t3 Empty))\n (BNode (RNode pf_1 pf_2) (RNode pf_3 RBEmpty)))\n\nrecolorLeft g vg (Element (Node R p vp t1 (Node R n vn t2 t3)) (RBad pf_1 (RNode pf_2 pf_3)))\n (Element (Node B u vu t4 t5) (BNode pf_4 pf_5)) =\n (B ** True ** Element (Node B n vn (Node R p vp t1 t2)\n (Node R g vg t3 (Node B u vu t4 t5)))\n (BNode (RNode pf_1 pf_2) (RNode pf_3 (BNode pf_4 pf_5))))\n\nrecolorLeft g vg (Element (Node R p vp t1 (Node R n vn t2 t3)) (RBad pf_1 (RNode pf_2 pf_3)))\n (Element Empty RBEmpty) =\n (B ** True ** Element (Node B n vn (Node R p vp t1 t2)\n (Node R g vg t3 Empty))\n (BNode (RNode pf_1 pf_2) (RNode pf_3 RBEmpty)))\n\nprivate\nins : Ord k => k -> v -> RBTree n c k v -> (c' ** valid ** InsTree n c' k v valid)\nins x vx (Element Empty RBEmpty) = (R ** True ** Element (Node R x vx Empty Empty) (RNode RBEmpty RBEmpty))\nins x vx t@(Element (Node _ y _ _ _) _) = insWith x vx t (compare x y)\n where\n addValid : (c ** InsTree n c k v True) -> (c ** valid ** InsTree n c k v valid)\n addValid (c ** t) = (c ** True ** t)\n\n insWith : Ord k => k -> v -> RBTree n c k v -> Ordering -> (c' ** valid ** InsTree n c' k v valid)\n\n insWith x vx (Element Empty RBEmpty) _ = -- unreachable, but make totality checker happy\n (R ** True ** Element (Node R x vx Empty Empty) (RNode RBEmpty RBEmpty))\n\n insWith x vx (Element n@(Node B y vy a b) pf) EQ =\n (B ** True ** Element n pf)\n insWith x vx t@(Element (Node B y vy a b) (BNode pf_a pf_b)) LT =\n let t_a = assert_smaller t (Element a pf_a)\n in case ins x vx t_a of\n (_ ** True ** t_a') => addValid (balance y vy t_a' (Element b pf_b))\n (R ** False ** t_a') => recolorLeft y vy t_a' (Element b pf_b)\n (B ** False ** (Element _ _)) impossible\n insWith x vx t@(Element (Node B y vy a b) (BNode pf_a pf_b)) GT =\n let t_b = assert_smaller t (Element b pf_b)\n in case ins x vx t_b of\n (_ ** True ** t_b') => addValid (balance y vy (Element a pf_a) t_b')\n (R ** False ** t_b') => recolorRight y vy (Element a pf_a) t_b'\n (B ** False ** (Element _ _)) impossible\n\n insWith x vx (Element n@(Node R y vy a b) pf) EQ =\n (R ** True ** Element n pf)\n insWith x vx t@(Element (Node R y vy a b) (RNode pf_a pf_b)) LT =\n let t_a = assert_smaller t (Element a pf_a)\n in case ins x vx t_a of\n (B ** True ** Element a' pf_a') => (R ** True ** Element (Node R y vy a' b) (RNode pf_a' pf_b))\n (R ** True ** Element a' pf_a') => (R ** False ** Element (Node R y vy a' b) (LBad pf_a' pf_b))\n (R ** False ** t_a') => error \"impossible\"\n (B ** False ** Element _ _) impossible\n insWith x vx t@(Element (Node R y vy a b) (RNode pf_a pf_b)) GT =\n let t_b = assert_smaller t (Element b pf_b)\n in case ins x vx t_b of\n (B ** True ** Element b' pf_b') => (R ** True ** Element (Node R y vy a b') (RNode pf_a pf_b'))\n (R ** True ** Element b' pf_b') => (R ** False ** Element (Node R y vy a b') (RBad pf_a pf_b'))\n (R ** False ** t_b') => error \"impossible\"\n (B ** False ** Element _ _) impossible\n\n-- --------------------------------------- [ Public API for working with Trees ]\n\n||| An empty tree\nempty : RBTree 0 B k v\nempty = Element Empty RBEmpty\n\n||| Insert a key value pair into the tree, returning a the new tree\n||| and possibly its new height.\ninsert : Ord k => k -> v -> RBTree n B k v -> (n' : Nat ** RBTree n' B k v)\ninsert x vx s =\n case ins x vx s of\n (B ** True ** t) => (_ ** t)\n (R ** True ** Element (Node R k v l r) (RNode pf_l pf_r)) =>\n (_ ** Element (Node B k v l r) (BNode pf_l pf_r))\n (B ** False ** Element _ _) impossible\n (R ** False ** Element (Node R k v l r) (RBad pf_l pf_r)) =>\n (_ ** Element (Node B k v l r) (BNode pf_l pf_r))\n (R ** False ** Element (Node R k v l r) (LBad pf_l pf_r)) =>\n (_ ** Element (Node B k v l r) (BNode pf_l pf_r))\n\n||| Find a value in the tree.\nlookup : (Ord k) => k -> RBTree n B k v -> Maybe v\nlookup key (Element t _) = lookup' key t\n where\n lookup' : (Ord k) => k -> Tree c k v -> Maybe v\n lookup' key Empty = Nothing\n lookup' key (Node _ key' value' l r) with (compare key key')\n lookup' key (Node _ key' value' l r) | LT = lookup' key l\n lookup' key (Node _ key' value' l r) | EQ = Just value'\n lookup' key (Node _ key' value' l r) | GT = lookup' key r\n\n||| Perform a right fold over the tree.\nfoldr : (step : k -> v -> p -> p)\n -> (init : p)\n -> RBTree n B k v\n -> p\nfoldr step init (Element t _) = foldr' step init t\n where\n foldr' : (k -> v -> p -> p) -> p -> Tree c k v -> p\n foldr' step' init' Empty = init'\n foldr' step' init' (Node _ key val l r) = foldr' step' (step' key val (foldr' step' init' r)) l\n\n||| Construct a AVL Tree from an association list.\nfromList : (Ord k) => List (k, v) -> (n : Nat ** RBTree n B k v)\nfromList xs = go xs empty\n where go : (Ord k) => List (k, v) -> RBTree n B k v -> (n' : Nat ** RBTree n' B k v)\n go [] t = (0 ** Element Empty RBEmpty)\n go ((k, v) :: xs) t = case insert k v t of\n (_ ** t') => go xs t'\n\n||| Flatten the tree to an association list.\ntoList : RBTree n B k v -> List (k, v)\ntoList = foldr (\\k,v,xs => (k, v) :: xs) []\n\n||| Size of the tree.\nsize : RBTree n B k v -> Nat\nsize t = Tree.foldr (\\_,_,res => S res) Z t\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "5e0ba7d39c84645606401019cfad9f78dbea605c", "size": 13345, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/RedBlack/Tree.idr", "max_stars_repo_name": "witt3rd/idris-containers", "max_stars_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 99, "max_stars_repo_stars_event_min_datetime": "2015-03-01T20:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:17:39.000Z", "max_issues_repo_path": "Data/RedBlack/Tree.idr", "max_issues_repo_name": "witt3rd/idris-containers", "max_issues_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2015-03-23T19:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T13:05:44.000Z", "max_forks_repo_path": "Data/RedBlack/Tree.idr", "max_forks_repo_name": "witt3rd/idris-containers", "max_forks_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-06-02T17:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T14:51:07.000Z", "avg_line_length": 42.5, "max_line_length": 122, "alphanum_fraction": 0.5342075684, "num_tokens": 4221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.303177902916776}} {"text": "module Libraries.Data.DList\n\n%default total\n\n-- Do not re-export the type so that it does not get unfolded in goals\n-- and error messages!\nexport\nDList : Type -> Type\nDList a = List a -> List a\n\nexport\nNil : DList a\nNil = id\n\nexport\n(::) : a -> DList a -> DList a\n(::) a as = (a ::) . as\n\nexport\nsnoc : DList a -> a -> DList a\nsnoc as a = as . (a ::)\n\nexport\nappendR : DList a -> List a -> DList a\nappendR as bs = as . (bs ++)\n\nexport\nappendL : List a -> DList a -> DList a\nappendL as bs = (as ++) . bs\n\nexport\n(++) : DList a -> DList a -> DList a\n(++) = (.)\n\nexport\nreify : DList a -> List a\nreify as = as []\n\n-- NB: No Functor instance because it's too expensive to reify, map, put back\n-- Consider using a different data structure if you need mapping (e.g. a rope)\n", "meta": {"hexsha": "ccb04b23d0c099efc9c4399b5e0debaba22d60e9", "size": 768, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Libraries/Data/DList.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "src/Libraries/Data/DList.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "src/Libraries/Data/DList.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 18.7317073171, "max_line_length": 78, "alphanum_fraction": 0.625, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.30315015734251366}} {"text": "module Solutions.DPair\n\nimport Control.Monad.State\n\nimport Data.DPair\nimport Data.Either\nimport Data.HList\nimport Data.List\nimport Data.List1\nimport Data.Singleton\nimport Data.String\nimport Data.Vect\n\nimport Text.CSV\n\nimport System.File\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Dependent Pairs\n--------------------------------------------------------------------------------\n\n-- 1\n\nfilterVect : (a -> Bool) -> Vect m a -> (n ** Vect n a)\nfilterVect f [] = (_ ** [])\nfilterVect f (x :: xs) = case f x of\n True => let (_ ** ys) = filterVect f xs in (_ ** x :: ys)\n False => filterVect f xs\n\n-- 2\n\nmapMaybeVect : (a -> Maybe b) -> Vect m a -> (n ** Vect n b)\nmapMaybeVect f [] = (_ ** [])\nmapMaybeVect f (x :: xs) = case f x of\n Just v => let (_ ** vs) = mapMaybeVect f xs in (_ ** v :: vs)\n Nothing => mapMaybeVect f xs\n\n-- 3\n\ndropWhileVect : (a -> Bool) -> Vect m a -> Exists (\\n => Vect n a)\ndropWhileVect f [] = Evidence _ []\ndropWhileVect f (x :: xs) = case f x of\n True => dropWhileVect f xs\n False => Evidence _ (x :: xs)\n\n-- 4\n\nvectLength : Vect n a -> Singleton n\nvectLength [] = Val 0\nvectLength (x :: xs) = let Val k = vectLength xs in Val (S k)\n\ndropWhileVect' : (a -> Bool) -> Vect m a -> (n ** Vect n a)\ndropWhileVect' f xs =\n let Evidence _ ys = dropWhileVect f xs\n Val n = vectLength ys\n in (n ** ys)\n\n--------------------------------------------------------------------------------\n-- Use Case: Nucleic Acids\n--------------------------------------------------------------------------------\n\n-- 1\n\ndata BaseType = DNABase | RNABase\n\ndata Nucleobase' : BaseType -> Type where\n Adenine' : Nucleobase' b\n Cytosine' : Nucleobase' b\n Guanine' : Nucleobase' b\n Thymine' : Nucleobase' DNABase\n Uracile' : Nucleobase' RNABase\n\nRNA' : Type\nRNA' = List (Nucleobase' RNABase)\n\nDNA' : Type\nDNA' = List (Nucleobase' DNABase)\n\nAcid1 : Type\nAcid1 = (b ** List (Nucleobase' b))\n\nrecord Acid2 where\n constructor MkAcid2\n baseType : BaseType\n sequence : List (Nucleobase' baseType)\n\ndata Acid3 : Type where\n SomeRNA : RNA' -> Acid3\n SomeDNA : DNA' -> Acid3\n\nnb12 : Acid1 -> Acid2\nnb12 (fst ** snd) = MkAcid2 fst snd\n\nnb21 : Acid2 -> Acid1\nnb21 (MkAcid2 bt seq) = (bt ** seq)\n\nnb13 : Acid1 -> Acid3\nnb13 (DNABase ** snd) = SomeDNA snd\nnb13 (RNABase ** snd) = SomeRNA snd\n\nnb31 : Acid3 -> Acid1\nnb31 (SomeRNA xs) = (RNABase ** xs)\nnb31 (SomeDNA xs) = (DNABase ** xs)\n\n-- 2\n\ndata Dir = Sense | Antisense\n\ndata Nucleobase : BaseType -> Dir -> Type where\n Adenine : Nucleobase b d\n Cytosine : Nucleobase b d\n Guanine : Nucleobase b d\n Thymine : Nucleobase DNABase d\n Uracile : Nucleobase RNABase d\n\nRNA : Dir -> Type\nRNA d = List (Nucleobase RNABase d)\n\nDNA : Dir -> Type\nDNA d = List (Nucleobase DNABase d)\n\n-- 3\n\ninverse : Dir -> Dir\ninverse Sense = Antisense\ninverse Antisense = Sense\n\ncomplementBase : (b : BaseType)\n -> Nucleobase b dir\n -> Nucleobase b (inverse dir)\ncomplementBase DNABase Adenine = Thymine\ncomplementBase RNABase Adenine = Uracile\ncomplementBase _ Cytosine = Guanine\ncomplementBase _ Guanine = Cytosine\ncomplementBase _ Thymine = Adenine\ncomplementBase _ Uracile = Adenine\n\ncomplement : (b : BaseType)\n -> List (Nucleobase b dir)\n -> List (Nucleobase b $ inverse dir)\ncomplement b = map (complementBase b)\n\ntranscribeBase : Nucleobase DNABase Antisense -> Nucleobase RNABase Sense\ntranscribeBase Adenine = Uracile\ntranscribeBase Cytosine = Guanine\ntranscribeBase Guanine = Cytosine\ntranscribeBase Thymine = Adenine\n\ntranscribe : DNA Antisense -> RNA Sense\ntranscribe = map transcribeBase\n\ntranscribeAny : (dir : Dir) -> DNA dir -> RNA Sense\ntranscribeAny Antisense = transcribe\ntranscribeAny Sense = transcribe . complement _\n\n-- 4\n\nrecord NucleicAcid where\n constructor MkNucleicAcid\n baseType : BaseType\n dir : Dir\n sequence : List (Nucleobase baseType dir)\n\n-- 5\n\nreadAnyBase : {0 dir : _} -> Char -> Maybe (Nucleobase b dir)\nreadAnyBase 'A' = Just Adenine\nreadAnyBase 'C' = Just Cytosine\nreadAnyBase 'G' = Just Guanine\nreadAnyBase _ = Nothing\n\nreadRNABase : {0 dir : _} -> Char -> Maybe (Nucleobase RNABase dir)\nreadRNABase 'U' = Just Uracile\nreadRNABase c = readAnyBase c\n\nreadDNABase : {0 dir : _} -> Char -> Maybe (Nucleobase DNABase dir)\nreadDNABase 'T' = Just Thymine\nreadDNABase c = readAnyBase c\n\nreadRNA : String -> Maybe (dir : Dir ** RNA dir)\nreadRNA str = case forget $ split ('-' ==) str of\n [\"5´\",s,\"3´\"] => MkDPair Sense <$> traverse readRNABase (unpack s)\n [\"3´\",s,\"5´\"] => MkDPair Antisense <$> traverse readRNABase (unpack s)\n _ => Nothing\n\nreadDNA : String -> Maybe (dir : Dir ** DNA dir)\nreadDNA str = case forget $ split ('-' ==) str of\n [\"5´\",s,\"3´\"] => MkDPair Sense <$> traverse readDNABase (unpack s)\n [\"3´\",s,\"5´\"] => MkDPair Antisense <$> traverse readDNABase (unpack s)\n _ => Nothing\n\n-- 6\n\npreSuf : Dir -> (String,String)\npreSuf Sense = (\"5´-\", \"-3´\")\npreSuf Antisense = (\"3´-\", \"-5´\")\n\nencodeBase : Nucleobase c d -> Char\nencodeBase Adenine = 'A'\nencodeBase Cytosine = 'C'\nencodeBase Guanine = 'G'\nencodeBase Thymine = 'T'\nencodeBase Uracile = 'U'\n\nencode : (dir : Dir) -> List (Nucleobase b dir) -> String\nencode dir seq =\n let (pre,suf) = preSuf dir\n in pre ++ pack (map encodeBase seq) ++ suf\n\n-- 7\n\npublic export\ndata InputError : Type where\n UnknownBaseType : String -> InputError\n InvalidSequence : String -> InputError\n\nreadAcid : (b : BaseType)\n -> String\n -> Either InputError (d ** List $ Nucleobase b d)\nreadAcid b str =\n let err = InvalidSequence str\n in case b of\n DNABase => maybeToEither err $ readDNA str\n RNABase => maybeToEither err $ readRNA str\n\ntoAcid : (b : BaseType) -> (d ** List $ Nucleobase b d) -> NucleicAcid\ntoAcid b (d ** seq) = MkNucleicAcid b d seq\n\ngetNucleicAcid : IO (Either InputError NucleicAcid)\ngetNucleicAcid = do\n baseString <- getLine\n case baseString of\n \"DNA\" => map (toAcid _) . readAcid DNABase <$> getLine\n \"RNA\" => map (toAcid _) . readAcid RNABase <$> getLine\n _ => pure $ Left (UnknownBaseType baseString)\n\nprintRNA : RNA Sense -> IO ()\nprintRNA = putStrLn . encode _\n\ntranscribeProg : IO ()\ntranscribeProg = do\n Right (MkNucleicAcid b d seq) <- getNucleicAcid\n | Left (InvalidSequence str) => putStrLn $ \"Invalid sequence: \" ++ str\n | Left (UnknownBaseType str) => putStrLn $ \"Unknown base type: \" ++ str\n case b of\n DNABase => printRNA $ transcribeAny d seq\n RNABase => case d of\n Sense => printRNA seq\n Antisense => printRNA $ complement _ seq\n\n--------------------------------------------------------------------------------\n-- Use Case: CSV Files with a Schema\n--------------------------------------------------------------------------------\n\n-- A lot of code was copy-pasted from the chapter's text and is, therefore\n-- not very interesting. I tried to annotate the new parts with some hints\n-- for better understanding. Also, instead of grouping code by exercise number,\n-- I organized it thematically.\n\n\n\n-- *** Types ***\n\n\n\n-- I used an indexed type here to make sure, data\n-- constructor `Optional` takes only non-nullary types\n-- as arguments. As noted in exercise 3, having a nesting\n-- of nullary types does not make sense without a way to\n-- distinguish between a `Nothing` and a `Just Nothing`,\n-- both of which would be encoded as the empty string.\n-- For `Finite`, we have to add `n` as an argument to the\n-- data constructor, so we can use it to decode values\n-- of type `Fin n`.\ndata ColType0 : (nullary : Bool) -> Type where\n I64 : ColType0 b\n Str : ColType0 b\n Boolean : ColType0 b\n Float : ColType0 b\n Natural : ColType0 b\n BigInt : ColType0 b\n Finite : Nat -> ColType0 b\n Optional : ColType0 False -> ColType0 True\n\n-- This is the type used in schemata, where nullary types\n-- are explicitly allowed.\nColType : Type\nColType = ColType0 True\n\nSchema : Type\nSchema = List ColType\n\n-- The only interesting new parts are the last two\n-- lines. They should be pretty self-explanatory.\nIdrisType : ColType0 b -> Type\nIdrisType I64 = Int64\nIdrisType Str = String\nIdrisType Boolean = Bool\nIdrisType Float = Double\nIdrisType Natural = Nat\nIdrisType BigInt = Integer\nIdrisType (Finite n) = Fin n\nIdrisType (Optional t) = Maybe $ IdrisType t\n\nRow : Schema -> Type\nRow = HList . map IdrisType\n\nrecord Table where\n constructor MkTable\n schema : Schema\n size : Nat\n rows : Vect size (Row schema)\n\ndata Error : Type where\n ExpectedEOI : (pos : Nat) -> String -> Error\n ExpectedLine : Error\n InvalidCell : (row, col : Nat) -> ColType0 b -> String -> Error\n NoNat : String -> Error\n OutOfBounds : (size : Nat) -> (index : Nat) -> Error\n ReadError : (path : String) -> FileError -> Error\n UnexpectedEOI : (pos : Nat) -> String -> Error\n UnknownCommand : String -> Error\n UnknownType : (pos : Nat) -> String -> Error\n WriteError : (path : String) -> FileError -> Error\n\n-- Oh, the type of `Query` is a nice one. :-)\n-- `PrintTable`, on the other hand, is trivial.\n-- The save and load commands are special: They will\n-- already have carried out their tasks after parsing.\n-- This allow us to keep `applyCommand` pure.\ndata Command : (t : Table) -> Type where\n PrintSchema : Command t\n PrintSize : Command t\n PrintTable : Command t\n Load : Table -> Command t\n Save : Command t\n New : (newSchema : Schema) -> Command t\n Prepend : Row (schema t) -> Command t\n Get : Fin (size t) -> Command t\n Delete : Fin (size t) -> Command t\n Quit : Command t\n Query : (ix : Fin (length $ schema t))\n -> (val : IdrisType $ indexList (schema t) ix)\n -> Command t\n\n\n\n-- *** Core Functionality ***\n\n\n\n-- Compares two values for equality.\neq : (c : ColType0 b) -> IdrisType c -> IdrisType c -> Bool\neq I64 x y = x == y\neq Str x y = x == y\neq Boolean x y = x == y\neq Float x y = x == y\neq Natural x y = x == y\neq BigInt x y = x == y\neq (Finite k) x y = x == y\neq (Optional z) (Just x) (Just y) = eq z x y\neq (Optional z) Nothing Nothing = True\neq (Optional z) _ _ = False\n\n-- Note: It would have been quite a bit easier to type and\n-- implement this, had we used a heterogeneous vector instead\n-- of a heterogeneous list for encoding table rows. However,\n-- I still think it's pretty cool that this type checks!\neqAt : (ts : Schema)\n -> (ix : Fin $ length ts)\n -> (val : IdrisType $ indexList ts ix)\n -> (row : Row ts)\n -> Bool\neqAt (x :: _) FZ val (v :: _) = eq x val v\neqAt (_ :: xs) (FS y) val (_ :: vs) = eqAt xs y val vs\neqAt [] _ _ _ impossible\n\n-- Most new commands don't change the table,\n-- so their cases are trivial. The exception is\n-- `Load`, which replaces the table completely.\napplyCommand : (t : Table) -> Command t -> Table\napplyCommand t PrintSchema = t\napplyCommand t PrintSize = t\napplyCommand t PrintTable = t\napplyCommand t Save = t\napplyCommand _ (Load t') = t'\napplyCommand _ (New ts) = MkTable ts _ []\napplyCommand (MkTable ts n rs) (Prepend r) = MkTable ts _ $ r :: rs\napplyCommand t (Get x) = t\napplyCommand t Quit = t\napplyCommand t (Query ix val) = t\napplyCommand (MkTable ts n rs) (Delete x) = case n of\n S k => MkTable ts k (deleteAt x rs)\n Z => absurd x\n\n\n\n-- *** Parsers ***\n\n\n\nzipWithIndex : Traversable t => t a -> t (Nat, a)\nzipWithIndex = evalState 1 . traverse pairWithIndex\n where pairWithIndex : a -> State Nat (Nat,a)\n pairWithIndex v = (,v) <$> get <* modify S\n\nfromCSV : String -> List String\nfromCSV = forget . split (',' ==)\n\n-- Reads a primitive (non-nullary) type. This is therefore\n-- universally quantified over parameter `b`.\n-- The only interesting part is the parsing of `finXYZ`,\n-- where we `break` the string at the occurrence of\n-- the first digit.\nreadPrim : Nat -> String -> Either Error (ColType0 b)\nreadPrim _ \"i64\" = Right I64\nreadPrim _ \"str\" = Right Str\nreadPrim _ \"boolean\" = Right Boolean\nreadPrim _ \"float\" = Right Float\nreadPrim _ \"natural\" = Right Natural\nreadPrim _ \"bigint\" = Right BigInt\nreadPrim n s =\n let err = Left $ UnknownType n s\n in case break isDigit s of\n (\"fin\",r) => maybe err (Right . Finite) $ parsePositive r\n _ => err\n\n-- This is the parser for (possibly nullary) column types.\n-- A nullary type is encoded as the corresponding non-nullary\n-- type with a question mark appended. We therefore first check\n-- for the presence of said question mark at the end of the string.\nreadColType : Nat -> String -> Either Error ColType\nreadColType n s = case reverse (unpack s) of\n '?' :: t => Optional <$> readPrim n (pack $ reverse t)\n _ => readPrim n s\n\nreadSchema : String -> Either Error Schema\nreadSchema = traverse (uncurry readColType) . zipWithIndex . fromCSV\n\nreadSchemaList : List String -> Either Error Schema\nreadSchemaList [s] = readSchema s\nreadSchemaList _ = Left ExpectedLine\n\n-- For all except nullary types we can just use the `CSVField`\n-- implementation for reading values.\n-- For values of nullary types, we treat the empty string specially.\ndecodeF : (c : ColType0 b) -> String -> Maybe (IdrisType c)\ndecodeF I64 s = read s\ndecodeF Str s = read s\ndecodeF Boolean s = read s\ndecodeF Float s = read s\ndecodeF Natural s = read s\ndecodeF BigInt s = read s\ndecodeF (Finite k) s = read s\ndecodeF (Optional y) \"\" = Just Nothing\ndecodeF (Optional y) s = Just <$> decodeF y s\n\ndecodeField : (row,col : Nat) -> (c : ColType0 b) -> String -> Either Error (IdrisType c)\ndecodeField row k c s = maybeToEither (InvalidCell row k c s) $ decodeF c s\n\ndecodeRow : {ts : _} -> (row : Nat) -> String -> Either Error (Row ts)\ndecodeRow row s = go 1 ts $ fromCSV s\n where go : Nat -> (cs : Schema) -> List String -> Either Error (Row cs)\n go k [] [] = Right []\n go k [] (_ :: _) = Left $ ExpectedEOI k s\n go k (_ :: _) [] = Left $ UnexpectedEOI k s\n go k (c :: cs) (s :: ss) = [| decodeField row k c s :: go (S k) cs ss |]\n\ndecodeRows : {ts : _} -> List String -> Either Error (List $ Row ts)\ndecodeRows = traverse (uncurry decodeRow) . zipWithIndex\n\nreadFin : {n : _} -> String -> Either Error (Fin n)\nreadFin s = do\n S k <- maybeToEither (NoNat s) $ parsePositive {a = Nat} s\n | Z => Left $ OutOfBounds n Z\n maybeToEither (OutOfBounds n $ S k) $ natToFin k n\n\nreadCommand : (t : Table) -> String -> Either Error (Command t)\nreadCommand _ \"schema\" = Right PrintSchema\nreadCommand _ \"size\" = Right PrintSize\nreadCommand _ \"table\" = Right PrintTable\nreadCommand _ \"quit\" = Right Quit\nreadCommand (MkTable ts n _) s = case words s of\n [\"new\", str] => New <$> readSchema str\n \"add\" :: ss => Prepend <$> decodeRow 1 (unwords ss)\n [\"get\", str] => Get <$> readFin str\n [\"delete\", str] => Delete <$> readFin str\n \"query\" :: n :: ss => do\n ix <- readFin n\n val <- decodeField 1 1 (indexList ts ix) (unwords ss)\n pure $ Query ix val\n _ => Left $ UnknownCommand s\n\n\n\n-- *** Printers ***\n\n\n\ntoCSV : List String -> String\ntoCSV = concat . intersperse \",\"\n\n-- We mark optional type by appending a question\n-- mark after the corresponding non-nullary type.\nshowColType : ColType0 b -> String\nshowColType I64 = \"i64\"\nshowColType Str = \"str\"\nshowColType Boolean = \"boolean\"\nshowColType Float = \"float\"\nshowColType Natural = \"natural\"\nshowColType BigInt = \"bigint\"\nshowColType (Finite n) = \"fin\\{show n}\"\nshowColType (Optional t) = showColType t ++ \"?\"\n\n-- Again, only nullary values are treated specially. This\n-- is another case of a dependent pattern match: We use\n-- explicit pattern matches on the value to encode based\n-- on the type calculated from the `ColType0 b` parameter.\n-- There are few languages capable of expressing this as\n-- cleanly as Idris does.\nencodeField : (t : ColType0 b) -> IdrisType t -> String\nencodeField I64 x = show x\nencodeField Str x = x\nencodeField Boolean True = \"t\"\nencodeField Boolean False = \"f\"\nencodeField Float x = show x\nencodeField Natural x = show x\nencodeField BigInt x = show x\nencodeField (Finite k) x = show x\nencodeField (Optional y) (Just v) = encodeField y v\nencodeField (Optional y) Nothing = \"\"\n\nencodeFields : (ts : Schema) -> Row ts -> Vect (length ts) String\nencodeFields [] [] = []\nencodeFields (c :: cs) (v :: vs) = encodeField c v :: encodeFields cs vs\n\nencodeTable : Table -> String\nencodeTable (MkTable ts _ rows) =\n unlines . toList $ map (toCSV . toList . encodeFields ts) rows\n\nencodeSchema : Schema -> String\nencodeSchema = toCSV . map showColType\n\n-- Pretty printing a table plus header. All cells are right-padded\n-- with spaces to adjust their size to the cell with the longest\n-- entry for each colum.\n-- Value `ls` is a `Vect n Nat` holding these lengths.\n-- Here is an example of how the output looks like:\n--\n-- fin100 | boolean | natural | str | bigint?\n-- --------------------------------------------------\n-- 88 | f | 10 | stefan |\n-- 13 | f | 10 | hock | -100\n-- 58 | t | 1000 | hello world | -1234\n--\n-- Ideally, numeric values would be right-aligned, but since this\n-- whole exercise is already quite long and complex, I refrained\n-- from adding this luxury.\nprettyTable : {n : _}\n -> (header : Vect n String)\n -> (table : Vect m (Vect n String))\n -> String\nprettyTable h t =\n let -- vector holding the maximal length of each column\n ls = foldl (zipWith $ \\k => max k . length) (replicate n Z) (h::t)\n\n -- horizontal bar used to separate the header from the rows\n bar = concat . intersperse \"---\" $ map (`replicate` '-') ls\n in unlines . toList $ line ls h :: bar :: map (line ls) t\n\n where pad : Nat -> String -> String\n pad v = padRight v ' '\n\n -- given a vector of lengths, pads each string to the\n -- desired length, separating cells with a vertical bar.\n line : Vect n Nat -> Vect n String -> String\n line lengths = concat . intersperse \" | \" . zipWith pad lengths\n\nprintTable : (cs : List ColType)\n -> (rows : Vect n (Row cs))\n -> String\nprintTable cs rows =\n let header = map showColType $ fromList cs\n table = map (encodeFields cs) rows\n in prettyTable header table\n\nallTypes : String\nallTypes = concat\n . List.intersperse \", \"\n . map (showColType {b = True})\n $ [I64,Str,Boolean,Float]\n\nshowError : Error -> String\nshowError ExpectedLine = \"\"\"\n Error when reading schema.\n Expected a single line of content.\n \"\"\"\n\nshowError (UnknownCommand x) = \"\"\"\n Unknown command: \\{x}.\n Known commands are: clear, schema, size, table, new, add, get, delete, quit.\n \"\"\"\n\nshowError (UnknownType pos x) = \"\"\"\n Unknown type at position \\{show pos}: \\{x}.\n Known types are: \\{allTypes}.\n \"\"\"\n\nshowError (InvalidCell row col tpe x) = \"\"\"\n Invalid value at row \\{show row}, column \\{show col}.\n Expected type: \\{showColType tpe}.\n Value found: \\{x}.\n \"\"\"\n\nshowError (ExpectedEOI k x) = \"\"\"\n Expected end of input.\n Position: \\{show k}\n Input: \\{x}\n \"\"\"\n\nshowError (UnexpectedEOI k x) = \"\"\"\n Unxpected end of input.\n Position: \\{show k}\n Input: \\{x}\n \"\"\"\n\nshowError (OutOfBounds size index) = \"\"\"\n Index out of bounds.\n Size of table: \\{show size}\n Index: \\{show index}\n Note: Indices start at zero.\n \"\"\"\n\nshowError (WriteError path err) = \"\"\"\n Error when writing file \\{path}.\n Message: \\{show err}\n \"\"\"\n\nshowError (ReadError path err) = \"\"\"\n Error when reading file \\{path}.\n Message: \\{show err}\n \"\"\"\n\nshowError (NoNat x) = \"Not a natural number: \\{x}\"\n\nresult : (t : Table) -> Command t -> String\nresult t PrintSchema = \"Current schema: \\{encodeSchema t.schema}\"\nresult t PrintSize = \"Current size: \\{show t.size}\"\nresult t PrintTable = \"Table:\\n\\n\\{printTable t.schema t.rows}\"\nresult _ Save = \"Table written to disk.\"\nresult _ (Load t) = \"Table loaded. Schema: \\{encodeSchema t.schema}\"\nresult _ (New ts) = \"Created table. Schema: \\{encodeSchema ts}\"\nresult t (Prepend r) = \"Row prepended:\\n\\n\\{printTable t.schema [r]}\"\nresult _ (Delete x) = \"Deleted row: \\{show $ FS x}.\"\nresult _ Quit = \"Goodbye.\"\nresult t (Query ix val) =\n let (_ ** rs) = filter (eqAt t.schema ix val) t.rows\n in \"Result:\\n\\n\\{printTable t.schema rs}\"\nresult t (Get x) =\n \"Row \\{show $ FS x}:\\n\\n\\{printTable t.schema [index x t.rows]}\"\n\n\n\n-- *** File IO ***\n\n\n\n-- We use partial function `readFile` for simplicity here.\npartial\nload : (path : String)\n -> (decode : List String -> Either Error a)\n -> IO (Either Error a)\nload path decode = do\n Right ls <- readFile path\n | Left err => pure $ Left (ReadError path err)\n pure $ decode (filter (not . null) $ lines ls)\n\nwrite : (path : String) -> (content : String) -> IO (Either Error ())\nwrite path content = mapFst (WriteError path) <$> writeFile path content\n\nnamespace IOEither\n export\n (>>=) : IO (Either err a) -> (a -> IO (Either err b)) -> IO (Either err b)\n ioa >>= f = Prelude.(>>=) ioa (either (pure . Left) f)\n\n export\n (>>) : IO (Either err ()) -> IO (Either err a) -> IO (Either err a)\n (>>) x y = x >>= const y\n\n export\n pure : a -> IO (Either err a)\n pure = Prelude.pure . Right\n\npartial\nreadCommandIO : (t : Table) -> String -> IO (Either Error (Command t))\nreadCommandIO t s = case words s of\n [\"save\", pth] => IOEither.do\n write (pth ++ \".schema\") (encodeSchema t.schema)\n write (pth ++ \".csv\") (encodeTable t)\n pure Save\n\n [\"load\", pth] => IOEither.do\n schema <- load (pth ++ \".schema\") readSchemaList\n rows <- load (pth ++ \".csv\") (decodeRows {ts = schema})\n pure . Load $ MkTable schema (length rows) (fromList rows)\n\n _ => Prelude.pure $ readCommand t s\n\n\n\n-- *** Main Loop ***\n\n\n\npartial\nrunProg : Table -> IO ()\nrunProg t = do\n putStr \"Enter a command: \"\n str <- getLine\n cmd <- readCommandIO t str\n case cmd of\n Left err => putStrLn (showError err) >> runProg t\n Right Quit => putStrLn (result t Quit)\n Right cmd => putStrLn (result t cmd) >>\n runProg (applyCommand t cmd)\n\npartial\nmain : IO ()\nmain = runProg $ MkTable [] _ []\n", "meta": {"hexsha": "95554926ec53324b3abd854e39c213d89012d2c3", "size": 23084, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Solutions/DPair.idr", "max_stars_repo_name": "ska80/idris2-tutorial", "max_stars_repo_head_hexsha": "ab7c83cfea6761f2fd29841593c92e78c7dfc958", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 60, "max_stars_repo_stars_event_min_datetime": "2022-01-13T16:14:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T16:16:57.000Z", "max_issues_repo_path": "src/Solutions/DPair.idr", "max_issues_repo_name": "ska80/idris2-tutorial", "max_issues_repo_head_hexsha": "ab7c83cfea6761f2fd29841593c92e78c7dfc958", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2022-01-14T15:42:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T09:53:16.000Z", "max_forks_repo_path": "src/Solutions/DPair.idr", "max_forks_repo_name": "ska80/idris2-tutorial", "max_forks_repo_head_hexsha": "ab7c83cfea6761f2fd29841593c92e78c7dfc958", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2022-01-14T15:48:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T06:49:13.000Z", "avg_line_length": 31.5355191257, "max_line_length": 89, "alphanum_fraction": 0.605354358, "num_tokens": 6697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.3030037010423602}} {"text": "module Lens.Util\n\nimport Data.List\nimport Data.Maybe\nimport Lens\nimport Lens.Uninhabited\nimport Map\n\n%default total\n\npublic export\nbeq_prim : (v : PrimitiveValue) -> v == v = True\nbeq_prim (Boolean b) = beq_bool b\nbeq_prim (Number n) = beq_nat n\nbeq_prim (Text t) = beq_str t\n\npublic export\nbeq_prim2 : (v1, v2 : PrimitiveValue) -> (v1 == v2 = True) -> v1 = v2\nbeq_prim2 (Boolean x) (Boolean y) prf = rewrite eq_bool x y prf in Refl\nbeq_prim2 (Boolean _) (Number _) Refl impossible\nbeq_prim2 (Boolean _) (Text _) Refl impossible\nbeq_prim2 (Number _) (Boolean _) Refl impossible\nbeq_prim2 (Number k) (Number j) prf = rewrite eq_nat k j prf in Refl\nbeq_prim2 (Number _) (Text _) Refl impossible\nbeq_prim2 (Text _) (Boolean _) Refl impossible\nbeq_prim2 (Text _) (Number _) Refl impossible\nbeq_prim2 (Text xs) (Text ys) prf = rewrite eq_str xs ys prf in Refl\n\npublic export\nneq_prim : (v1, v2 : PrimitiveValue) -> (v1 == v2 = False) -> Not (v1 = v2)\nneq_prim (Boolean x) (Boolean y) prf =\n neq_bool x y prf . justInjective . cong boolean\nneq_prim (Boolean x) (Number k) prf = uninhabited\nneq_prim (Boolean x) (Text xs) prf = uninhabited\nneq_prim (Number k) (Boolean x) prf = uninhabited\nneq_prim (Number k) (Number j) prf =\n neq_nat k j prf . justInjective . cong number\nneq_prim (Number k) (Text xs) prf = uninhabited\nneq_prim (Text xs) (Boolean x) prf = uninhabited\nneq_prim (Text xs) (Number k) prf = uninhabited\nneq_prim (Text xs) (Text ys) prf =\n neq_str xs ys prf . justInjective . cong text\n\n\nbeq_prim_kind : (k1, k2 : PrimitiveKind) -> (k1 == k2 = True) -> k1 = k2\nbeq_prim_kind KBoolean KBoolean prf = Refl\nbeq_prim_kind KBoolean KNumber Refl impossible\nbeq_prim_kind KBoolean KText Refl impossible\nbeq_prim_kind KNumber KBoolean Refl impossible\nbeq_prim_kind KNumber KNumber prf = Refl\nbeq_prim_kind KNumber KText Refl impossible\nbeq_prim_kind KText KBoolean Refl impossible\nbeq_prim_kind KText KNumber Refl impossible\nbeq_prim_kind KText KText prf = Refl\n\n\npublic export\nvalidate_properties_after_insert : (vm : Map Value) -> (sm : Map Schema) ->\n (k : Key) -> (v : Value) -> (s : Schema) -> validate s v = True ->\n validate_properties vm sm = True -> validate_properties (insert k v vm) (insert k s sm) = True\n\npublic export\nvalidate_properties_after_remove : (vm : Map Value) -> (sm : Map Schema) -> (k : Key) ->\n validate_properties vm sm = True -> validate_properties (remove k vm) (remove k sm) = True\n\npublic export\ninvalid_property : (vm : Map Value) -> (sm : Map Schema) -> (k : Key) ->\n (v : Value) -> (s : Schema) -> get k vm = Just v -> get k sm = Just s -> validate s v = False ->\n validate_properties vm sm = False\n\npublic export\nstill_valid : (vm : Map Value) -> (sm : Map Schema) ->\n (k : Key) -> (kvm : Value) -> (ksm : Schema) ->\n get k vm = Just kvm -> get k sm = Just ksm ->\n validate_properties vm sm = True -> validate ksm kvm = True\n\npublic export\nstill_invalid : (vm : Map Value) -> (sm : Map Schema) ->\n (k : Key) -> get k vm = Just kvm -> get k sm = Just ksm ->\n validate ksm kvm = False -> validate_properties vm sm = False\n\n\npublic export\nflip_map_twice : (m : List (PrimitiveValue, PrimitiveValue)) -> flip_map (flip_map m) = m\nflip_map_twice [] = Refl\nflip_map_twice ((x, y) :: xs) = rewrite flip_map_twice xs in Refl\n\npublic export\nflip_map_preserves_validity : (a, b : PrimitiveKind) -> (m : List (PrimitiveValue, PrimitiveValue)) ->\n validate_map a b m = True -> validate_map b a (flip_map m) = True\nflip_map_preserves_validity a b [] prf = Refl\nflip_map_preserves_validity a b ((x, y) :: xs) prf =\n let sprf = and_split (prim_kind_of x == a) (prim_kind_of y == b && Delay (validate_map a b xs)) prf\n sprf2 = and_split (prim_kind_of y == b) (validate_map a b xs) (snd sprf)\n ind = flip_map_preserves_validity a b xs (snd sprf2)\n in rewrite fst sprf2 in rewrite fst sprf in ind\n\nvalidate_map_kind_a : (m : List (PrimitiveValue, PrimitiveValue)) -> (a, b : PrimitiveKind) -> (va : PrimitiveValue) ->\n (va, vb) :: _ = m -> validate_map a b m = True -> prim_kind_of va = a\nvalidate_map_kind_a [] _ _ _ Refl _ impossible\nvalidate_map_kind_a ((va, vb) :: m) KBoolean b (Number _) prf prf1 =\n let split = and_split (prim_kind_of va == KBoolean) (prim_kind_of vb == b && validate_map KBoolean b m) prf1\n xeq = cong prim_kind_of $ cong fst $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of va) KBoolean (fst split)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_a ((va, vb) :: m) KBoolean b (Text _) prf prf1 =\n let split = and_split (prim_kind_of va == KBoolean) (prim_kind_of vb == b && validate_map KBoolean b m) prf1\n xeq = cong prim_kind_of $ cong fst $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of va) KBoolean (fst split)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_a ((va, vb) :: m) KNumber b (Boolean _) prf prf1 =\n let split = and_split (prim_kind_of va == KNumber) (prim_kind_of vb == b && validate_map KNumber b m) prf1\n xeq = cong prim_kind_of $ cong fst $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of va) KNumber (fst split)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_a ((va, vb) :: m) KNumber b (Text _) prf prf1 =\n let split = and_split (prim_kind_of va == KNumber) (prim_kind_of vb == b && validate_map KNumber b m) prf1\n xeq = cong prim_kind_of $ cong fst $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of va) KNumber (fst split)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_a ((va, vb) :: m) KText b (Boolean _) prf prf1 =\n let split = and_split (prim_kind_of va == KText) (prim_kind_of vb == b && validate_map KText b m) prf1\n xeq = cong prim_kind_of $ cong fst $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of va) KText (fst split)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_a ((va, vb) :: m) KText b (Number _) prf prf1 =\n let split = and_split (prim_kind_of va == KText) (prim_kind_of vb == b && validate_map KText b m) prf1\n xeq = cong prim_kind_of $ cong fst $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of va) KText (fst split)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_a ((_, _) :: _) KBoolean _ (Boolean _) prf prf1 = Refl\nvalidate_map_kind_a ((_, _) :: _) KNumber _ (Number _) prf prf1 = Refl\nvalidate_map_kind_a ((_, _) :: _) KText _ (Text _) prf prf1 = Refl\n\nvalidate_map_kind_b : (m : List (PrimitiveValue, PrimitiveValue)) -> (a, b : PrimitiveKind) -> (vb : PrimitiveValue) ->\n (va, vb) :: _ = m -> validate_map a b m = True -> prim_kind_of vb = b\nvalidate_map_kind_b [] _ _ _ Refl _ impossible\nvalidate_map_kind_b ((va, vb) :: m) a KBoolean (Number _) prf prf1 =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == KBoolean && validate_map a KBoolean m) prf1\n split2 = and_split (prim_kind_of vb == KBoolean) (validate_map a KBoolean m) (snd split)\n xeq = cong prim_kind_of $ cong snd $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of vb) KBoolean (fst split2)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_b ((va, vb) :: m) a KBoolean (Text _) prf prf1 =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == KBoolean && validate_map a KBoolean m) prf1\n split2 = and_split (prim_kind_of vb == KBoolean) (validate_map a KBoolean m) (snd split)\n xeq = cong prim_kind_of $ cong snd $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of vb) KBoolean (fst split2)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_b ((va, vb) :: m) a KNumber (Boolean _) prf prf1 =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == KNumber && validate_map a KNumber m) prf1\n split2 = and_split (prim_kind_of vb == KNumber) (validate_map a KNumber m) (snd split)\n xeq = cong prim_kind_of $ cong snd $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of vb) KNumber (fst split2)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_b ((va, vb) :: m) a KNumber (Text _) prf prf1 =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == KNumber && validate_map a KNumber m) prf1\n split2 = and_split (prim_kind_of vb == KNumber) (validate_map a KNumber m) (snd split)\n xeq = cong prim_kind_of $ cong snd $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of vb) KNumber (fst split2)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_b ((va, vb) :: m) a KText (Boolean _) prf prf1 =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == KText && validate_map a KText m) prf1\n split2 = and_split (prim_kind_of vb == KText) (validate_map a KText m) (snd split)\n xeq = cong prim_kind_of $ cong snd $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of vb) KText (fst split2)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_b ((va, vb) :: m) a KText (Number _) prf prf1 =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == KText && validate_map a KText m) prf1\n split2 = and_split (prim_kind_of vb == KText) (validate_map a KText m) (snd split)\n xeq = cong prim_kind_of $ cong snd $ fst $ consInjective prf\n xeq2 = beq_prim_kind (prim_kind_of vb) KText (fst split2)\n in absurd $ trans xeq xeq2\nvalidate_map_kind_b ((va, vb) :: m) _ KBoolean (Boolean _) prf prf1 = Refl\nvalidate_map_kind_b ((va, vb) :: m) _ KNumber (Number _) prf prf1 = Refl\nvalidate_map_kind_b ((va, vb) :: m) _ KText (Text _) prf prf1 = Refl\n\n\nvalidate_map_kind : (m : List (PrimitiveValue, PrimitiveValue)) -> (a, b : PrimitiveKind) ->\n (va, vb : PrimitiveValue) -> (va, vb) :: _ = m -> validate_map a b m = True ->\n (prim_kind_of va = a, prim_kind_of vb = b)\nvalidate_map_kind m a b va vb prf prf1 =\n let pa = validate_map_kind_a m a b va prf prf1\n pb = validate_map_kind_b m a b vb prf prf1\n in (pa, pb)\n\nmap_still_valid : (m : List (PrimitiveValue, PrimitiveValue)) -> (a, b : PrimitiveKind) ->\n (x :: xs) = m -> validate_map a b m = True -> validate_map a b xs = True\nmap_still_valid [] _ _ Refl _ impossible\nmap_still_valid ((va, vb) :: m) a b prf prf1 with (prim_kind_of va == a, prim_kind_of vb == b) proof prf2\n map_still_valid ((va, vb) :: m) a b prf prf1 | (False, _) =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == b && validate_map a b m) prf1\n in absurd $ trans (sym $ cong fst prf2) (fst split)\n map_still_valid ((va, vb) :: m) a b prf prf1 | (True, False) =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == b && validate_map a b m) prf1\n split2 = and_split (prim_kind_of vb == b) (validate_map a b m) (snd split)\n in absurd $ trans (sym $ cong snd prf2) (fst split2)\n map_still_valid ((va, vb) :: m) a b prf prf1 | (True, True) =\n let split = and_split (prim_kind_of va == a) (prim_kind_of vb == b && validate_map a b m) prf1\n split2 = and_split (prim_kind_of vb == b) (validate_map a b m) (snd split)\n in rewrite snd $ consInjective prf in snd split2\n\npublic export\nconvert_prim_kind : (m : List (PrimitiveValue, PrimitiveValue)) ->\n (a, b : PrimitiveKind) -> (va, vb : PrimitiveValue) ->\n validate_map a b m = True -> prim_kind_of va = a ->\n convert_prim va m = Just vb -> prim_kind_of vb = b\nconvert_prim_kind [] _ _ _ _ _ _ Refl impossible\nconvert_prim_kind ((va', vb') :: m) a b va vb prf prf1 prf2 with (va == va') proof prf3\n convert_prim_kind ((va', vb') :: m) a b va vb prf prf1 prf2 | True =\n rewrite sym $ justInjective prf2 in\n snd $ validate_map_kind ((va', vb') :: m) a b va' vb' Refl prf\n convert_prim_kind ((va', vb') :: m) a b va vb prf prf1 prf2 | False =\n let sv = map_still_valid ((va', vb') :: m) a b Refl prf\n ind = convert_prim_kind m a b va vb sv prf1 prf2\n in ind\n", "meta": {"hexsha": "4b048cbe17c565ca6c13bb7322670c033686c1a2", "size": 11850, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "spec/Lens/Util.idr", "max_stars_repo_name": "Actyx/cambria", "max_stars_repo_head_hexsha": "764b9dc7985fc4a2cca4900ce7e3b964cbbb424e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2021-09-01T16:29:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T15:39:15.000Z", "max_issues_repo_path": "spec/Lens/Util.idr", "max_issues_repo_name": "Actyx/cambria", "max_issues_repo_head_hexsha": "764b9dc7985fc4a2cca4900ce7e3b964cbbb424e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-08-31T16:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-03T09:48:25.000Z", "max_forks_repo_path": "spec/Lens/Util.idr", "max_forks_repo_name": "Actyx/cambria", "max_forks_repo_head_hexsha": "764b9dc7985fc4a2cca4900ce7e3b964cbbb424e", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-12-02T01:43:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-19T21:17:03.000Z", "avg_line_length": 54.6082949309, "max_line_length": 119, "alphanum_fraction": 0.6725738397, "num_tokens": 3775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5888891163376235, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.30134433915952497}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 14, section 3, Hangman part\n\nimport Data.Vect\n\n-- check that all functions are total\n%default total\n\n||| Remove an element in a vector\nremoveElem : (value : a) -> (xs : Vect (S n) a) ->\n {auto prf : Elem value xs} ->\n Vect n a\nremoveElem value (value :: ys) {prf = Here} = ys\nremoveElem {n = Z} value (y :: []) {prf = There later} = absurd later\nremoveElem {n = (S k)} value (y :: ys) {prf = There later}\n = y :: removeElem value ys\n\n||| (Abstract) State of the game\ndata GameState : Type where\n NotRunning : GameState\n Running : (guesses : Nat) -> (letters : Nat) -> GameState\n\n||| Result of a guess\ndata GuessResult = Correct | Incorrect\n\n||| Letters in a word\nletters : String -> List Char\nletters str = nub $ map toUpper $ unpack str\n\n||| Game commands\ndata GameCmd : (ty : Type) -> GameState -> (ty -> GameState) -> Type where\n ||| new game\n NewGame : (word : String) ->\n GameCmd () NotRunning $\n const (Running 6 (length (letters word)))\n ||| won game\n Won : GameCmd () (Running (S guesses) 0) $\n const NotRunning\n ||| lost game\n Lost : GameCmd () (Running 0 (S guesses)) $\n const NotRunning\n ||| guess a letter\n Guess : (c : Char) ->\n GameCmd GuessResult\n (Running (S guesses) (S letters))\n (\\res => case res of\n Correct => Running (S guesses) letters\n Incorrect => Running guesses (S letters))\n ||| display the game state\n ShowState : GameCmd () state $ const state\n ||| display a message\n Message : String -> GameCmd () state $ const state\n ||| read a guess\n ReadGuess : GameCmd Char state $ const state\n ||| pure\n Pure : (res : ty) -> GameCmd ty (state res) state\n ||| sequence\n (>>=) : GameCmd a state1 state2 ->\n ((res : a) -> GameCmd b (state2 res) state3) ->\n GameCmd b state1 state3\n\nnamespace Loop\n ||| Game loop (type)\n data GameLoop : (ty : Type) -> GameState -> (ty -> GameState) -> Type where\n ||| sequence\n (>>=) : GameCmd a state1 state2 ->\n ((res : a) -> Inf (GameLoop b (state2 res) state3)) ->\n GameLoop b state1 state3\n ||| exit game\n Exit : GameLoop () NotRunning $ const NotRunning\n\n||| Game loop (implementation)\ngameLoop : GameLoop () (Running (S guesses) (S letters)) $ const NotRunning\ngameLoop {guesses} {letters}\n = do ShowState\n g <- ReadGuess\n ok <- Guess g\n (case ok of\n Correct => case letters of\n Z => do Won\n ShowState\n Exit\n S k => do Message \"Correct\"\n gameLoop\n Incorrect => case guesses of\n Z => do Lost\n ShowState\n Exit\n S k => do Message \"Incorrect\"\n gameLoop)\n\n||| Game set up\nhangman : GameLoop () NotRunning $ const NotRunning\nhangman = do NewGame \"testing\"\n gameLoop\n\n||| (Concrete) Game state\ndata Game : GameState -> Type where\n GameStart : Game NotRunning\n GameWon : (word : String) -> Game NotRunning\n GameLost : (word : String) -> Game NotRunning\n InProgress : (word : String) -> (guesses : Nat) ->\n (missing : Vect letters Char) ->\n Game (Running guesses letters)\n\n||| Game representation\nShow (Game gs) where\n show GameStart = \"Starting\"\n show (GameWon word) = \"Game won: word was \" ++ word\n show (GameLost word) = \"Game lost: word was \" ++ word\n show (InProgress word guesses missing)\n = \"\\n\" ++ pack (map hideMissing (unpack word))\n ++ \"\\n\" ++ show guesses ++ \" guesses left\"\n where hideMissing : Char -> Char\n hideMissing c = if c `elem` missing then '-' else c\n\n||| Fuel machinery\ndata Fuel = Dry | More (Lazy Fuel)\n\n||| Result of a game\ndata GameResult : (ty : Type) -> (ty -> GameState) -> Type where\n OK : (res : ty) -> Game (outstate res) ->\n GameResult ty outstate\n OutOfFuel : GameResult ty outstate\n\n||| Helper for returns of runs\nok : (res : ty) -> Game (outstate res) -> IO (GameResult ty outstate)\nok res st = pure (OK res st)\n\n||| Running a game command over fuel\nrunCmd : Fuel ->\n Game instate ->\n GameCmd ty instate outstate ->\n IO (GameResult ty outstate)\nrunCmd fuel state (NewGame word)\n = ok () (InProgress (toUpper word) _ (fromList (letters word)))\nrunCmd fuel (InProgress word _ missing) Won = ok () (GameWon word)\nrunCmd fuel (InProgress word _ missing) Lost = ok () (GameLost word)\nrunCmd fuel (InProgress word _ missing) (Guess c)\n = case isElem c missing of\n Yes prf => ok Correct (InProgress word _ (removeElem c missing))\n No contra => ok Incorrect (InProgress word _ missing)\nrunCmd fuel state ShowState = do printLn state\n ok () state\nrunCmd fuel state (Message x) = do putStrLn x\n ok () state\nrunCmd (More fuel) state ReadGuess\n = do putStr \"Guess: \"\n input <- getLine\n case unpack input of\n [x] => if isAlpha x\n then ok (toUpper x) state\n else do putStrLn \"Invalid input\"\n runCmd fuel state ReadGuess\n _ => do putStrLn \"Invalid input\"\n runCmd fuel state ReadGuess\nrunCmd Dry _ _ = pure OutOfFuel\nrunCmd fuel state (Pure res) = ok res state\nrunCmd fuel st (cmd >>= next)\n = do OK cmdRes newSt <- runCmd fuel st cmd\n | OutOfFuel => pure OutOfFuel\n runCmd fuel newSt (next cmdRes)\n\n||| Running a game loop over fuel\nrun : Fuel ->\n Game instate ->\n GameLoop ty instate outstate ->\n IO (GameResult ty outstate)\nrun Dry _ _ = pure OutOfFuel\nrun (More fuel) st (cmd >>= next)\n = do OK cmdRes newSt <- runCmd fuel st cmd\n | OutOfFuel => pure OutOfFuel\n run fuel newSt (next cmdRes)\nrun (More fuel) st Exit = ok () st\n\n-- all remaining functions are partial\n%default partial\n\nforever : Fuel\nforever = More forever\n\nmain : IO ()\nmain = do run forever GameStart hangman\n pure ()\n", "meta": {"hexsha": "38f0449002555933fa39687a0be775c154376de1", "size": 6281, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter14/Hangman.idr", "max_stars_repo_name": "pascalpoizat/idris-book", "max_stars_repo_head_hexsha": "f1ef0ed0a8b8c1690d7ce65258f04322b37ff956", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-08-16T00:58:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T01:07:37.000Z", "max_issues_repo_path": "chapter14/Hangman.idr", "max_issues_repo_name": "pascalpoizat/idris-book", "max_issues_repo_head_hexsha": "f1ef0ed0a8b8c1690d7ce65258f04322b37ff956", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter14/Hangman.idr", "max_forks_repo_name": "pascalpoizat/idris-book", "max_forks_repo_head_hexsha": "f1ef0ed0a8b8c1690d7ce65258f04322b37ff956", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-23T03:15:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-23T03:15:39.000Z", "avg_line_length": 33.9513513514, "max_line_length": 77, "alphanum_fraction": 0.5725202993, "num_tokens": 1609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3005463427108183}} {"text": "module Printf\n\nimport Prelude\nimport Data.String\n\ndata Arg\n = AInt Arg\n | AOther Char Arg\n | AEnd\n\nbuildArg : List Char -> Arg\nbuildArg fmt = case fmt of\n '%' :: 'i' :: fmtTail => AInt (buildArg fmtTail)\n c :: fmtTail => AOther c (buildArg fmtTail)\n Nil => AEnd\n\nargToType : Arg -> Type -> Type\nargToType a result = case a of\n AInt fmtTail => Int -> argToType fmtTail result\n AOther _ fmtTail => argToType fmtTail result\n AEnd => result\n\n-- PrintfType \"foo\" result = result\n-- PrintfType \"%i\\n\" result = Int -> result\n-- etc\nPrintfType : String -> Type -> Type\nPrintfType fmt result = argToType (buildArg (unpack fmt)) result\n\nsprintf : (fmt : String) -> PrintfType fmt String\nsprintf fmt = go \"\" (buildArg (unpack fmt)) where\n go : String -> (arg : Arg) -> argToType arg String\n go strTail arg = case arg of\n AInt fmtTail => \\i : Int => go (strTail ++ show i) fmtTail\n AOther c fmtTail => go (strTail ++ singleton c) fmtTail\n AEnd => strTail\n\ntest : ?result\ntest = sprintf \"%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i\"\n", "meta": {"hexsha": "d365fffdfc17b00dd0e7a016c30ea591c72a9391", "size": 1322, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/perf010/Printf.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/tests/idris2/perf010/Printf.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/tests/idris2/perf010/Printf.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 33.8974358974, "max_line_length": 223, "alphanum_fraction": 0.5771558245, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3000941796301025}}