{"text": "module Physics.Vector2D\n\npublic export\nVector2D : Type\nVector2D = (Double, Double)\n\nexport\nNum Vector2D where\n (a1, b1) + (a2, b2) = (a1+a2, b1+b2)\n (a1, b1) * (a2, b2) = (a1*a2, b1*b2)\n fromInteger a = (cast a, cast a)\n\nexport\nNeg Vector2D where\n negate (x, y) = (-x, -y)\n (x2, y2) - (x1, y1) = (x2-x1, y2-y1)\n\nexport\nAbs Vector2D where\n abs (x, y) = (abs x, abs y)\n\nexport\nnorm : Vector2D -> Double\nnorm (x, y) = sqrt $ x*x + y*y\n\nexport\nscale : Double -> Vector2D -> Vector2D\nscale a (x, y) = (a*x, a*y)\n\ninfix 7 `scale`\n\npublic export\nCast (Integer, Integer) Vector2D where\n cast (x, y) = (the Double (cast x), the Double (cast y))\n\npublic export\nCast Vector2D (Int, Int) where\n cast (x, y) = (cast x, cast y)\n\nexport\nnullVector : Vector2D\nnullVector = (0, 0)\n\nexport\nmagnitude : Vector2D -> Double\nmagnitude (a, b) = sqrt(a*a + b*b)\n\nexport\nnormed : Vector2D -> Vector2D\nnormed x = let magnitude' = 1.0/(magnitude x) in magnitude' `scale` x\n\nexport\nangle : Vector2D -> Double\nangle (x, y) = atan2 y x\n", "meta": {"hexsha": "78b7384887562290ff9e07e17f65faec2d66e858", "size": 1014, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Physics/Vector2D.idr", "max_stars_repo_name": "corazza/idris-box2d", "max_stars_repo_head_hexsha": "5eb58b2de09d72e9f8993852832f6906cdf3e054", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-07-02T20:23:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-01T11:12:52.000Z", "max_issues_repo_path": "src/Physics/Vector2D.idr", "max_issues_repo_name": "corazza/idris-box2d", "max_issues_repo_head_hexsha": "5eb58b2de09d72e9f8993852832f6906cdf3e054", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-15T08:15:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-17T17:43:04.000Z", "max_forks_repo_path": "src/Physics/Vector2D.idr", "max_forks_repo_name": "corazza/idris-box2d", "max_forks_repo_head_hexsha": "5eb58b2de09d72e9f8993852832f6906cdf3e054", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-13T00:33:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T00:33:26.000Z", "avg_line_length": 18.4363636364, "max_line_length": 69, "alphanum_fraction": 0.6360946746, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7496759208583453}} {"text": "data EqNat : Nat -> Nat -> Type where\n Same : (x : Nat) -> EqNat x x\n\ntotal\nsameS : (k : Nat) -> (j : Nat) -> (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS k k (Same k) = Same (S k)\n\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat Z Z = Just (Same Z)\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just eq => Just (sameS _ _ eq)\n\n\n", "meta": {"hexsha": "9b67fe6926a82e2430e3ba517f45815390ba9857", "size": 504, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZPF/Slajdy19/PlikiIdrisa/EqNat.idr", "max_stars_repo_name": "wdomitrz/Coq-Exercises", "max_stars_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/EqNat.idr", "max_issues_repo_name": "wdomitrz/Coq-Exercises", "max_issues_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/EqNat.idr", "max_forks_repo_name": "wdomitrz/Coq-Exercises", "max_forks_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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.0, "max_line_length": 71, "alphanum_fraction": 0.5178571429, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.749544900741594}} {"text": "\ntwoplustwo_not_five : 2 + 2 = 5 -> Void\ntwoplustwo_not_five Refl impossible\n\nvalue_not_suc : (x : Nat) -> x = S x -> Void\nvalue_not_suc _ Refl impossible\n\nzero_not_succ : (0 = S k) -> Void\nzero_not_succ Refl impossible\n\nsucc_not_zero : (S k = 0) -> Void\nsucc_not_zero Refl impossible\n\nno_rec : (contra : (k = j) -> Void) -> (S k = S j) -> Void\nno_rec contra Refl = contra Refl\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Dec (num1 = num2)\ncheckEqNat Z Z = Yes Refl\ncheckEqNat Z (S k) = No zero_not_succ\ncheckEqNat (S k) Z = No succ_not_zero\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n (Yes prf) => Yes (cong prf)\n (No contra) => No (no_rec contra)\n", "meta": {"hexsha": "ad7e9090b8c398187d91e82cec0d9fcada68c68a", "size": 714, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-08/void.idr", "max_stars_repo_name": "tekerson/type-driven-development", "max_stars_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-23T04:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-23T04:46:42.000Z", "max_issues_repo_path": "Chapter-08/void.idr", "max_issues_repo_name": "tekerson/type-driven-development", "max_issues_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": "Chapter-08/void.idr", "max_forks_repo_name": "tekerson/type-driven-development", "max_forks_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": 29.75, "max_line_length": 63, "alphanum_fraction": 0.6120448179, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.941654159388319, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.7492347502500019}} {"text": "module Prelude.Types\n\nimport Builtin\nimport PrimIO\nimport Prelude.Basics\nimport Prelude.EqOrd\nimport Prelude.Interfaces\nimport Prelude.Num\nimport Prelude.Uninhabited\n\n%default total\n\n-----------\n-- NATS ---\n-----------\n\n||| Natural numbers: unbounded, unsigned integers which can be pattern matched.\npublic export\ndata Nat =\n ||| Zero.\n Z\n | ||| Successor.\n S Nat\n\n%name Nat k, j, i\n\n-- This is used in the compiler as an efficient substitute for integerToNat.\nprim__integerToNat : Integer -> Nat\nprim__integerToNat i\n = if intToBool (prim__lte_Integer 0 i)\n then believe_me i\n else Z\n\npublic export\nintegerToNat : Integer -> Nat\nintegerToNat 0 = Z -- Force evaluation and hence caching of x at compile time\nintegerToNat x\n = if intToBool (prim__lte_Integer x 0)\n then Z\n else S (assert_total (integerToNat (prim__sub_Integer x 1)))\n\n-- %builtin IntegerToNatural Prelude.Types.integerToNat\n\n-- Define separately so we can spot the name when optimising Nats\n||| Add two natural numbers.\n||| @ x the number to case-split on\n||| @ y the other numberpublic export\npublic export\nplus : (x : Nat) -> (y : Nat) -> Nat\nplus Z y = y\nplus (S k) y = S (plus k y)\n\n||| Subtract natural numbers. If the second number is larger than the first,\n||| return 0.\npublic export\nminus : (left : Nat) -> Nat -> Nat\nminus Z right = Z\nminus left Z = left\nminus (S left) (S right) = minus left right\n\n||| Multiply natural numbers.\npublic export\nmult : (x : Nat) -> Nat -> Nat\nmult Z y = Z\nmult (S k) y = plus y (mult k y)\n\npublic export\nNum Nat where\n (+) = plus\n (*) = mult\n\n fromInteger x = integerToNat x\n\n-- used for nat hack\npublic export\nequalNat : (m, n : Nat) -> Bool\nequalNat Z Z = True\nequalNat (S j) (S k) = equalNat j k\nequalNat _ _ = False\n\npublic export\nEq Nat where\n (==) = equalNat\n\n-- used for nat hack\npublic export\ncompareNat : (m, n : Nat) -> Ordering\ncompareNat Z Z = EQ\ncompareNat Z (S k) = LT\ncompareNat (S k) Z = GT\ncompareNat (S j) (S k) = compareNat j k\n\npublic export\nOrd Nat where\n compare = compareNat\n\npublic export\nnatToInteger : Nat -> Integer\nnatToInteger Z = 0\nnatToInteger (S k) = 1 + natToInteger k\n -- integer (+) may be non-linear in second\n -- argument\n\n-- %builtin NaturalToInteger Prelude.Types.natToInteger\n\n||| Counts the number of elements that satify a predicate.\npublic export\ncount : (Foldable t) => (predicate : a -> Bool) -> (t a) -> Nat\ncount predicate = foldMap @{%search} @{Additive} (\\x => if predicate x then 1 else 0)\n\n-----------\n-- PAIRS --\n-----------\n\n%inline\npublic export\nBifunctor Pair where\n bimap f g (x, y) = (f x, g y)\n\n%inline\npublic export\nBifoldable Pair where\n bifoldr f g acc (x, y) = f x (g y acc)\n bifoldl f g acc (x, y) = g (f acc x) y\n binull _ = False\n\n%inline\npublic export\nBitraversable Pair where\n bitraverse f g (a,b) = [| (,) (f a) (g b) |]\n\n%inline\npublic export\nFunctor (Pair a) where\n map = mapSnd\n\n%inline\npublic export\nMonoid a => Applicative (Pair a) where\n pure = (neutral,)\n (a1,f) <*> (a2,v) = (a1 <+> a2, f v)\n\n%inline\npublic export\nMonoid a => Monad (Pair a) where\n (a1,a) >>= f = let (a2,b) = f a in (a1 <+> a2, b)\n\n-----------\n-- MAYBE --\n-----------\n\n||| An optional value. This can be used to represent the possibility of\n||| failure, where a function may return a value, or not.\npublic export\ndata Maybe : (ty : Type) -> Type where\n ||| No value stored\n Nothing : Maybe ty\n\n ||| A value of type `ty` is stored\n Just : (x : ty) -> Maybe ty\n\npublic export\nUninhabited (Nothing = Just x) where\n uninhabited Refl impossible\n\npublic export\nUninhabited (Just x = Nothing) where\n uninhabited Refl impossible\n\npublic export\nmaybe : Lazy b -> Lazy (a -> b) -> Maybe a -> b\nmaybe n j Nothing = n\nmaybe n j (Just x) = j x\n\n||| Execute an applicative expression when the Maybe is Just\n%inline public export\nwhenJust : Applicative f => Maybe a -> (a -> f ()) -> f ()\nwhenJust (Just a) k = k a\nwhenJust Nothing k = pure ()\n\npublic export\nEq a => Eq (Maybe a) where\n Nothing == Nothing = True\n Nothing == (Just _) = False\n (Just _) == Nothing = False\n (Just a) == (Just b) = a == b\n\npublic export\nOrd a => Ord (Maybe a) where\n compare Nothing Nothing = EQ\n compare Nothing (Just _) = LT\n compare (Just _) Nothing = GT\n compare (Just a) (Just b) = compare a b\n\npublic export\nSemigroup (Maybe a) where\n Nothing <+> m = m\n (Just x) <+> _ = Just x\n\npublic export\nMonoid (Maybe a) where\n neutral = Nothing\n\npublic export\nFunctor Maybe where\n map f (Just x) = Just (f x)\n map f Nothing = Nothing\n\npublic export\nApplicative Maybe where\n pure = Just\n\n Just f <*> Just a = Just (f a)\n _ <*> _ = Nothing\n\npublic export\nAlternative Maybe where\n empty = Nothing\n\n (Just x) <|> _ = Just x\n Nothing <|> v = v\n\npublic export\nMonad Maybe where\n Nothing >>= k = Nothing\n (Just x) >>= k = k x\n\npublic export\nFoldable Maybe where\n foldr _ z Nothing = z\n foldr f z (Just x) = f x z\n null Nothing = True\n null (Just _) = False\n\npublic export\nTraversable Maybe where\n traverse f Nothing = pure Nothing\n traverse f (Just x) = Just <$> f x\n\n---------\n-- DEC --\n---------\n\n||| Decidability. A decidable property either holds or is a contradiction.\npublic export\ndata Dec : Type -> Type where\n ||| The case where the property holds.\n ||| @ prf the proof\n Yes : (prf : prop) -> Dec prop\n\n ||| The case where the property holding would be a contradiction.\n ||| @ contra a demonstration that prop would be a contradiction\n No : (contra : Not prop) -> Dec prop\n\nexport Uninhabited (Yes p === No q) where uninhabited eq impossible\nexport Uninhabited (No p === Yes q) where uninhabited eq impossible\n\n------------\n-- EITHER --\n------------\n\n||| A sum type.\npublic export\ndata Either : (a : Type) -> (b : Type) -> Type where\n ||| One possibility of the sum, conventionally used to represent errors.\n Left : forall a, b. (x : a) -> Either a b\n\n ||| The other possibility, conventionally used to represent success.\n Right : forall a, b. (x : b) -> Either a b\n\nexport Uninhabited (Left p === Right q) where uninhabited eq impossible\nexport Uninhabited (Right p === Left q) where uninhabited eq impossible\n\nexport\nEither (Uninhabited a) (Uninhabited b) => Uninhabited (a, b) where\n uninhabited (x, _) @{Left _} = uninhabited x\n uninhabited (_, y) @{Right _} = uninhabited y\n\nexport\nUninhabited a => Uninhabited b => Uninhabited (Either a b) where\n uninhabited (Left l) = uninhabited l\n uninhabited (Right r) = uninhabited r\n\n||| Simply-typed eliminator for Either.\n||| @ f the action to take on Left\n||| @ g the action to take on Right\n||| @ e the sum to analyze\npublic export\neither : (f : Lazy (a -> c)) -> (g : Lazy (b -> c)) -> (e : Either a b) -> c\neither l r (Left x) = l x\neither l r (Right x) = r x\n\npublic export\n(Eq a, Eq b) => Eq (Either a b) where\n Left x == Left x' = x == x'\n Right x == Right x' = x == x'\n _ == _ = False\n\npublic export\n(Ord a, Ord b) => Ord (Either a b) where\n compare (Left x) (Left x') = compare x x'\n compare (Left _) (Right _) = LT\n compare (Right _) (Left _) = GT\n compare (Right x) (Right x') = compare x x'\n\n%inline\npublic export\nFunctor (Either e) where\n map f (Left x) = Left x\n map f (Right x) = Right (f x)\n\n%inline\npublic export\nBifunctor Either where\n bimap f _ (Left x) = Left (f x)\n bimap _ g (Right y) = Right (g y)\n\n%inline\npublic export\nBifoldable Either where\n bifoldr f _ acc (Left a) = f a acc\n bifoldr _ g acc (Right b) = g b acc\n\n bifoldl f _ acc (Left a) = f acc a\n bifoldl _ g acc (Right b) = g acc b\n\n binull _ = False\n\n%inline\npublic export\nBitraversable Either where\n bitraverse f _ (Left a) = Left <$> f a\n bitraverse _ g (Right b) = Right <$> g b\n\n%inline\npublic export\nApplicative (Either e) where\n pure = Right\n\n (Left a) <*> _ = Left a\n (Right f) <*> (Right r) = Right (f r)\n (Right _) <*> (Left l) = Left l\n\npublic export\nMonad (Either e) where\n (Left n) >>= _ = Left n\n (Right r) >>= f = f r\n\npublic export\nFoldable (Either e) where\n foldr f acc (Left _) = acc\n foldr f acc (Right x) = f x acc\n null (Left _) = True\n null (Right _) = False\n\npublic export\nTraversable (Either e) where\n traverse f (Left x) = pure (Left x)\n traverse f (Right x) = Right <$> f x\n\n-----------\n-- LISTS --\n-----------\n\npublic export\nEq a => Eq (List a) where\n [] == [] = True\n x :: xs == y :: ys = x == y && xs == ys\n _ == _ = False\n\npublic export\nOrd a => Ord (List a) where\n compare [] [] = EQ\n compare [] (x :: xs) = LT\n compare (x :: xs) [] = GT\n compare (x :: xs) (y ::ys)\n = case compare x y of\n EQ => compare xs ys\n c => c\n\nnamespace List\n public export\n (++) : (xs, ys : List a) -> List a\n [] ++ ys = ys\n (x :: xs) ++ ys = x :: xs ++ ys\n\n public export\n length : List a -> Nat\n length [] = Z\n length (x :: xs) = S (length xs)\n\n public export\n reverseOnto : List a -> List a -> List a\n reverseOnto acc [] = acc\n reverseOnto acc (x::xs) = reverseOnto (x::acc) xs\n\n public export\n reverse : List a -> List a\n reverse = reverseOnto []\n\n ||| Tail-recursive append. Uses of (++) are automatically transformed to\n ||| this. The only reason this is exported is that the proof of equivalence\n ||| lives in a different module.\n public export\n tailRecAppend : (xs, ys : List a) -> List a\n tailRecAppend xs ys = reverseOnto ys (reverse xs)\n\n -- Always use tailRecAppend at runtime. Data.List.tailRecAppendIsAppend\n -- proves these are equivalent.\n %transform \"tailRecAppend\" (++) = tailRecAppend\n\npublic export\nFunctor List where\n map f [] = []\n map f (x :: xs) = f x :: map f xs\n\npublic export\nSemigroup (List a) where\n (<+>) = (++)\n\npublic export\nMonoid (List a) where\n neutral = []\n\npublic export\nFoldable List where\n foldr c n [] = n\n foldr c n (x::xs) = c x (foldr c n xs)\n\n foldl f q [] = q\n foldl f q (x::xs) = foldl f (f q x) xs\n\n null [] = True\n null (_::_) = False\n\n toList = id\n\n foldMap f = foldl (\\acc, elem => acc <+> f elem) neutral\n\npublic export\nApplicative List where\n pure x = [x]\n fs <*> vs = concatMap (\\f => map f vs) fs\n\npublic export\nAlternative List where\n empty = []\n xs <|> ys = xs ++ ys\n\npublic export\nMonad List where\n m >>= f = concatMap f m\n\npublic export\nTraversable List where\n traverse f [] = pure []\n traverse f (x::xs) = [| f x :: traverse f xs |]\n\n-- This works quickly because when string-concat builds the result, it allocates\n-- enough room in advance so there's only one allocation, rather than lots!\n--\n-- Like fastUnpack, this function won't reduce at compile time.\n-- If you need to concatenate strings at compile time, use Prelude.concat.\n%foreign\n \"scheme:string-concat\"\n \"RefC:fastConcat\"\n \"javascript:lambda:(xs)=>''.concat(...__prim_idris2js_array(xs))\"\n \"jvm:concat(io/github/mmhelloworld/idrisjvm/runtime/IdrisList java/lang/String),io/github/mmhelloworld/idrisjvm/runtime/Strings\"\nexport\nfastConcat : List String -> String\n\n%transform \"fastConcat\" concat {t = List} {a = String} = fastConcat\n\n||| Check if something is a member of a list using the default Boolean equality.\npublic export\nelem : Eq a => a -> List a -> Bool\nx `elem` [] = False\nx `elem` (y :: ys) = x == y || elem x ys\n\n||| Lookup a value at a given position\nexport\ngetAt : Nat -> List a -> Maybe a\ngetAt Z (x :: xs) = Just x\ngetAt (S k) (x :: xs) = getAt k xs\ngetAt _ [] = Nothing\n\n-------------\n-- STREAMS --\n-------------\n\nnamespace Stream\n ||| An infinite stream.\n public export\n data Stream : Type -> Type where\n (::) : a -> Inf (Stream a) -> Stream a\n\n%name Stream xs, ys, zs\n\npublic export\nFunctor Stream where\n map f (x :: xs) = f x :: map f xs\n\n||| The first element of an infinite stream.\npublic export\nhead : Stream a -> a\nhead (x :: xs) = x\n\n||| All but the first element.\npublic export\ntail : Stream a -> Stream a\ntail (x :: xs) = xs\n\n||| Take precisely n elements from the stream.\n||| @ n how many elements to take\n||| @ xs the stream\npublic export\ntake : (n : Nat) -> (xs : Stream a) -> List a\ntake Z xs = []\ntake (S k) (x :: xs) = x :: take k xs\n\n-------------\n-- STRINGS --\n-------------\n\nnamespace String\n public export\n (++) : (x : String) -> (y : String) -> String\n x ++ y = prim__strAppend x y\n\n ||| Returns the length of the string.\n |||\n ||| ```idris example\n ||| length \"\"\n ||| ```\n ||| ```idris example\n ||| length \"ABC\"\n ||| ```\n public export\n length : String -> Nat\n length str = fromInteger (prim__cast_IntInteger (prim__strLength str))\n\n||| Reverses the elements within a string.\n|||\n||| ```idris example\n||| reverse \"ABC\"\n||| ```\n||| ```idris example\n||| reverse \"\"\n||| ```\npublic export\nreverse : String -> String\nreverse = prim__strReverse\n\n||| Returns a substring of a given string\n|||\n||| @ index The (zero based) index of the string to extract. If this is beyond\n||| the end of the string, the function returns the empty string.\n||| @ len The desired length of the substring. Truncated if this exceeds the\n||| length of the input\n||| @ subject The string to return a portion of\npublic export\nsubstr : (index : Nat) -> (len : Nat) -> (subject : String) -> String\nsubstr s e subj\n = if natToInteger s < natToInteger (length subj)\n then prim__strSubstr (prim__cast_IntegerInt (natToInteger s))\n (prim__cast_IntegerInt (natToInteger e))\n subj\n else \"\"\n\n||| Adds a character to the front of the specified string.\n|||\n||| ```idris example\n||| strCons 'A' \"B\"\n||| ```\n||| ```idris example\n||| strCons 'A' \"\"\n||| ```\npublic export\nstrCons : Char -> String -> String\nstrCons = prim__strCons\n\npublic export\nstrUncons : String -> Maybe (Char, String)\nstrUncons \"\" = Nothing\nstrUncons str = assert_total $ Just (prim__strHead str, prim__strTail str)\n\n||| Turns a list of characters into a string.\npublic export\npack : List Char -> String\npack [] = \"\"\npack (x :: xs) = strCons x (pack xs)\n\n%foreign\n \"scheme:string-pack\"\n \"RefC:fastPack\"\n \"javascript:lambda:(xs)=>''.concat(...__prim_idris2js_array(xs))\"\n \"jvm:pack(io/github/mmhelloworld/idrisjvm/runtime/IdrisList java/lang/String),io/github/mmhelloworld/idrisjvm/runtime/Strings\"\nexport\nfastPack : List Char -> String\n\n-- always use 'fastPack' at run time\n%transform \"fastPack\" pack = fastPack\n\n||| Turns a string into a list of characters.\n|||\n||| ```idris example\n||| unpack \"ABC\"\n||| ```\npublic export\nunpack : String -> List Char\nunpack str = unpack' (prim__cast_IntegerInt (natToInteger (length str)) - 1) str []\n where\n unpack' : Int -> String -> List Char -> List Char\n unpack' pos str acc\n = if pos < 0\n then acc\n else unpack' (assert_smaller pos (pos - 1)) str $ (assert_total $ prim__strIndex str pos) :: acc\n\n-- This function runs fast when compiled but won't compute at compile time.\n-- If you need to unpack strings at compile time, use Prelude.unpack.\n%foreign\n \"scheme:string-unpack\"\n \"RefC:fastUnpack\"\n \"javascript:lambda:(str)=>__prim_js2idris_array(Array.from(str))\"\n \"jvm:unpack(java/lang/String io/github/mmhelloworld/idrisjvm/runtime/IdrisList),io/github/mmhelloworld/idrisjvm/runtime/Strings\"\nexport\nfastUnpack : String -> List Char\n\n-- always use 'fastPack' at run time\n%transform \"fastUnpack\" unpack = fastUnpack\n\npublic export\nSemigroup String where\n (<+>) = (++)\n\npublic export\nMonoid String where\n neutral = \"\"\n\n----------------\n-- CHARACTERS --\n----------------\n\n||| Returns true if the character is in the range [A-Z].\npublic export\nisUpper : Char -> Bool\nisUpper x = x >= 'A' && x <= 'Z'\n\n||| Returns true if the character is in the range [a-z].\npublic export\nisLower : Char -> Bool\nisLower x = x >= 'a' && x <= 'z'\n\n||| Returns true if the character is in the ranges [A-Z][a-z].\npublic export\nisAlpha : Char -> Bool\nisAlpha x = isUpper x || isLower x\n\n||| Returns true if the character is in the range [0-9].\npublic export\nisDigit : Char -> Bool\nisDigit x = (x >= '0' && x <= '9')\n\n||| Returns true if the character is in the ranges [A-Z][a-z][0-9].\npublic export\nisAlphaNum : Char -> Bool\nisAlphaNum x = isDigit x || isAlpha x\n\n||| Returns true if the character is a whitespace character.\npublic export\nisSpace : Char -> Bool\nisSpace x\n = x == ' ' || x == '\\t' || x == '\\r' ||\n x == '\\n' || x == '\\f' || x == '\\v' ||\n x == '\\xa0'\n\n||| Returns true if the character represents a new line.\npublic export\nisNL : Char -> Bool\nisNL x = x == '\\r' || x == '\\n'\n\n||| Convert a letter to the corresponding upper-case letter, if any.\n||| Non-letters are ignored.\npublic export\ntoUpper : Char -> Char\ntoUpper x\n = if (isLower x)\n then prim__cast_IntChar (prim__cast_CharInt x - 32)\n else x\n\n||| Convert a letter to the corresponding lower-case letter, if any.\n||| Non-letters are ignored.\npublic export\ntoLower : Char -> Char\ntoLower x\n = if (isUpper x)\n then prim__cast_IntChar (prim__cast_CharInt x + 32)\n else x\n\n||| Returns true if the character is a hexadecimal digit i.e. in the range\n||| [0-9][a-f][A-F].\npublic export\nisHexDigit : Char -> Bool\nisHexDigit x = elem (toUpper x) hexChars where\n hexChars : List Char\n hexChars\n = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n 'A', 'B', 'C', 'D', 'E', 'F']\n\n||| Returns true if the character is an octal digit.\npublic export\nisOctDigit : Char -> Bool\nisOctDigit x = (x >= '0' && x <= '7')\n\n||| Returns true if the character is a control character.\npublic export\nisControl : Char -> Bool\nisControl x\n = (x >= '\\x0000' && x <= '\\x001f')\n || (x >= '\\x007f' && x <= '\\x009f')\n\n||| Convert the number to its backend dependent (usually Unicode) Char\n||| equivalent.\npublic export\nchr : Int -> Char\nchr = prim__cast_IntChar\n\n||| Return the backend dependent (usually Unicode) numerical equivalent of the Char.\npublic export\nord : Char -> Int\nord = prim__cast_CharInt\n\n-----------------------\n-- DOUBLE PRIMITIVES --\n-----------------------\n\npublic export\npi : Double\npi = 3.14159265358979323846\n\npublic export\neuler : Double\neuler = 2.7182818284590452354\n\npublic export\nexp : Double -> Double\nexp x = prim__doubleExp x\n\npublic export\nlog : Double -> Double\nlog x = prim__doubleLog x\n\npublic export\npow : Double -> Double -> Double\npow x y = exp (y * log x) -- prim__doublePow x y\n\npublic export\nsin : Double -> Double\nsin x = prim__doubleSin x\n\npublic export\ncos : Double -> Double\ncos x = prim__doubleCos x\n\npublic export\ntan : Double -> Double\ntan x = prim__doubleTan x\n\npublic export\nasin : Double -> Double\nasin x = prim__doubleASin x\n\npublic export\nacos : Double -> Double\nacos x = prim__doubleACos x\n\npublic export\natan : Double -> Double\natan x = prim__doubleATan x\n\npublic export\nsinh : Double -> Double\nsinh x = (exp x - exp (-x)) / 2\n\npublic export\ncosh : Double -> Double\ncosh x = (exp x + exp (-x)) / 2\n\npublic export\ntanh : Double -> Double\ntanh x = sinh x / cosh x\n\npublic export\nsqrt : Double -> Double\nsqrt x = prim__doubleSqrt x\n\npublic export\nfloor : Double -> Double\nfloor x = prim__doubleFloor x\n\npublic export\nceiling : Double -> Double\nceiling x = prim__doubleCeiling x\n\n------------\n-- RANGES --\n------------\n\n-- These functions are here to support the range syntax:\n-- range expressions like `[a..b]` are desugared to `rangeFromXXX` calls.\n\npublic export\ncountFrom : n -> (n -> n) -> Stream n\ncountFrom start diff = start :: countFrom (diff start) diff\n\npublic export\ncovering\ntakeUntil : (n -> Bool) -> Stream n -> List n\ntakeUntil p (x :: xs)\n = if p x\n then [x]\n else x :: takeUntil p xs\n\npublic export\ncovering\ntakeBefore : (n -> Bool) -> Stream n -> List n\ntakeBefore p (x :: xs)\n = if p x\n then []\n else x :: takeBefore p xs\n\npublic export\ninterface Range a where\n constructor MkRange\n rangeFromTo : a -> a -> List a\n rangeFromThenTo : a -> a -> a -> List a\n\n rangeFrom : a -> Stream a\n rangeFromThen : a -> a -> Stream a\n\n-- Idris 1 went to great lengths to prove that these were total. I don't really\n-- think it's worth going to those lengths! Let's keep it simple and assert.\npublic export\nRange Nat where\n rangeFromTo x y = case compare x y of\n LT => assert_total $ takeUntil (>= y) (countFrom x S)\n EQ => pure x\n GT => assert_total $ takeUntil (<= y) (countFrom x (\\n => minus n 1))\n rangeFromThenTo x y z = case compare x y of\n LT => if z >= x\n then assert_total $ takeBefore (> z) (countFrom x (plus (minus y x)))\n else Nil\n EQ => if x == z then pure x else Nil\n GT => assert_total $ takeBefore (< z) (countFrom x (\\n => minus n (minus x y)))\n rangeFrom x = countFrom x S\n rangeFromThen x y\n = if y > x\n then countFrom x (plus (minus y x))\n else countFrom x (\\n => minus n (minus x y))\n\npublic export\n(Integral a, Ord a, Neg a) => Range a where\n rangeFromTo x y = case compare x y of\n LT => assert_total $ takeUntil (>= y) (countFrom x (+1))\n EQ => pure x\n GT => assert_total $ takeUntil (<= y) (countFrom x (\\x => x-1))\n rangeFromThenTo x y z = case compare (z - x) (z - y) of\n -- Go down\n LT => assert_total $ takeBefore (< z) (countFrom x (\\n => n - (x - y)))\n -- Meaningless\n EQ => if x == y && y == z then pure x else Nil\n -- Go up\n GT => assert_total $ takeBefore (> z) (countFrom x (+ (y-x)))\n rangeFrom x = countFrom x (1+)\n rangeFromThen x y\n = if y > x\n then countFrom x (+ (y - x))\n else countFrom x (\\n => n - (x - y))\n", "meta": {"hexsha": "4f02168144b8af000994f2d5cfe4f1fd8372161f", "size": 21456, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/prelude/Prelude/Types.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": "libs/prelude/Prelude/Types.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": "libs/prelude/Prelude/Types.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": 24.409556314, "max_line_length": 130, "alphanum_fraction": 0.6306860552, "num_tokens": 6471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.7491172908836263}} {"text": "import Data.Vect\n\nmy_length : List a -> Nat\nmy_length [] = 0\nmy_length (x :: xs) = 1 + my_length xs\n\nmy_reverse : List a -> List a\nmy_reverse [] = []\nmy_reverse (x :: xs) = reverse xs ++ [x]\n\nmy_map : (a -> b) -> List a -> List b\nmy_map f [] = []\nmy_map f (x :: xs) = f x :: map f xs\n\nmy_vect_map : (a -> b) -> Vect k a -> Vect k b\nmy_vect_map f [] = []\nmy_vect_map f (x :: xs) = f x :: map f xs\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n zipWith (\\x, y => x :: y) x xsTrans\n\naddMatrix : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (\\x, y => x + y) x y :: addMatrix xs ys\n\n\nmultMatrix : Num a => Vect n (Vect m a) ->\n Vect m (Vect p a) ->\n Vect n (Vect p a)\nmultMatrix xs ys = multHelper xs (transposeMat ys)\n where\n dot : Num a => Vect k a -> Vect k a -> a\n dot xs ys = sum $ map (\\ (s1, s2) => s1 * s2) (zip xs ys)\n\n multHelper : Num a => Vect n (Vect m a) ->\n Vect p (Vect m a) ->\n Vect n (Vect p a)\n multHelper [] _ = []\n multHelper (x :: xs) ys = map (dot x) ys :: multHelper xs ys \n", "meta": {"hexsha": "6125128ed4e3f4bae2470a05e48330b0891108f1", "size": 1412, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp3/exercises.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp3/exercises.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp3/exercises.idr", "max_forks_repo_name": "Ryxai/idris_book_notes", "max_forks_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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.3777777778, "max_line_length": 80, "alphanum_fraction": 0.5155807365, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7489244689566309}} {"text": "> module Isomorphism.Properties\n\n> import Control.Isomorphism\n\n> -- import Isomorphism.Operations\n> import Fun.Properties\n> import Basic.Operations\n\n> %default total\n> %access public export\n\n\n> |||\n> isoEq : {A, B : Type} -> A = B -> Iso A B\n> isoEq Refl = isoRefl\n> %freeze isoEq \n\n\n> |||\n> isoCong : {A : Type} -> {x : A} -> {y : A} -> {P : A -> Type} -> x = y -> Iso (P x) (P y)\n> isoCong {x} {P} prf = replace {P = \\ z => Iso (P x) (P z)} prf isoRefl\n> %freeze isoCong\n\n\nInjectivity of to and from\n\n> injectiveFrom : {A, B : Type} -> (iso : Iso A B) -> Injective1 (from iso)\n> injectiveFrom {A} {B} (MkIso to from toFrom fromTo) b1 b2 p = s3 where\n> s1 : from b1 = from b2\n> s1 = p\n> s2 : to (from b1) = to (from b2)\n> s2 = cong s1\n> s3 : b1 = b2\n> s3 = replace2 {a = B} {a1 = to (from b1)} {a2 = b1}\n> {b = B} {b1 = to (from b2)} {b2 = b2}\n> {P = \\ a => \\b => a = b}\n> (toFrom b1) (toFrom b2) s2\n> %freeze injectiveFrom\n\n\n> {-\n\n> ---} \n", "meta": {"hexsha": "afa844b7c580c3988c64d5a6f9d36dd60d6f8342", "size": 1001, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Isomorphism/Properties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Isomorphism/Properties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Isomorphism/Properties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.75, "max_line_length": 91, "alphanum_fraction": 0.5234765235, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.7489220506939185}} {"text": "import Data.Vect\nimport Data.Vect.Elem\nimport Decidable.Equality\n\nremoveElem_v1 : DecEq a => (value : a) -> (xs : Vect (S n) a) -> Vect n a\nremoveElem_v1 value (x :: xs) = case decEq value x of\n Yes prf => xs\n No contra => ?removeElem_v1_rhs -- x :: removeElem_v1 value xs\n\nUninhabited (2 + 2 = 5) where\n uninhabited Refl impossible\n\n{-}\nremoveElem : (value : a) -> (xs : Vect (S n) a) ->\n Elem value xs ->\n Vect n a\nremoveElem value (value :: ys) Here = ys\nremoveElem {n = Z} value (y :: []) (There later) = absurd later\nremoveElem {n = (S k)} value (y :: ys) (There later)\n = y :: removeElem value ys later\n\nremoveElem_auto : (value : a) -> (xs : Vect (S n) a) ->\n {auto prf : Elem value xs} -> Vect n a\nremoveElem_auto value xs {prf} = removeElem value xs prf\n-}\n\nremoveElem : {n : _} ->\n (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\nmy_elem : Eq a => (value : a) -> (xs : Vect n a) -> Bool\nmy_elem value [] = False\nmy_elem value (x :: xs) = case value == x of\n False => my_elem value xs\n True => True\n\nnot_in_nil : Elem value [] -> Void\nnot_in_nil Here impossible\nnot_in_nil (There _) impossible\n\nnot_in_tail : (contra1 : Elem value xs -> Void) -> (contra : (value = x) -> Void) -> Elem value (x :: xs) -> Void\nnot_in_tail contra1 contra Here = contra Refl\nnot_in_tail contra1 contra (There later) = contra1 later\n\nmy_decElem : DecEq a => (value : a) -> (xs : Vect n a) -> Dec (Elem value xs)\nmy_decElem value [] = No not_in_nil\nmy_decElem value (x :: xs)\n = case decEq value x of\n (Yes Refl) => Yes Here\n (No contra) => case my_decElem value xs of\n (Yes prf) => Yes (There prf)\n (No contra1) => No (not_in_tail contra1 contra)\n", "meta": {"hexsha": "9ee84ff6ced95417f1117d4235d5635bee026f1a", "size": 2256, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter09/RemoveElem.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/typedd-book/chapter09/RemoveElem.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/typedd-book/chapter09/RemoveElem.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": 38.8965517241, "max_line_length": 113, "alphanum_fraction": 0.5288120567, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7488840233064085}} {"text": "module Lists\n\n%elim data NatPair = MkPair Nat Nat\n\nnatFst : NatPair -> Nat\nnatFst (MkPair a b) = a\n\nnatSnd : NatPair -> Nat\nnatSnd (MkPair a b) = b\n\npairIsSurjective : (a:Nat) -> (b:Nat) -> (MkPair a b) = (MkPair (natFst (MkPair a b)) (natSnd (MkPair a b)))\npairIsSurjective = ?pairIsSurjectiveCase\n\npairIsSurjective2 : (p:NatPair) -> p = MkPair (natFst p) (natSnd p)\npairIsSurjective2 = ?pairSurCase\n\nLists.pairSurCase = proof\n intro\n induction p\n intros\n compute\n trivial\n\nmkNatPair : NatPair -> (Nat,Nat)\nmkNatPair (MkPair a b) = (a,b)\n\nsurjectivePairingStuck : (a:NatPair) -> a = (MkPair (natFst a) (natSnd a))\nsurjectivePairingStuck = ?surjectivePairingStuckCase\n\nLists.surjectivePairingStuckCase = proof\n intros\n induction a\n compute\n intros\n trivial\n\n%elim data NatList =\n Nil\n | Cons Nat NatList\n\nrepeat : (n:Nat) -> (count:Nat) -> NatList\nrepeat n Z = Nil\nrepeat n (S k) = Cons n (repeat n k)\n\nlength : (n:NatList) -> Nat\nlength Nil = Z\nlength (Cons x xs) = S (length xs)\n\napp : (a:NatList) -> (b:NatList) -> NatList\napp Nil b = b\napp (Cons x xs) b = Cons x (app xs b)\n\nsyntax [x] \"::\" [xs] = Cons x xs\nsyntax \"[ ]\" = Nil\nsyntax \"[\" [x] \"]\" = (Cons x Nil)\nsyntax \"[\" [x] \",\" rem \",\" [y] \"]\" = (Cons x (app rem (Cons y Nil)))\nsyntax [a] \"++\" [b] = app a b\n\nhead : (default:Nat) -> NatList -> Nat\nhead n Nil = n\nhead n (Cons x xs) = x\n\ntail : NatList -> NatList\ntail Nil = Nil\ntail (Cons x xs) = xs\n\nfilterZeros : NatList -> NatList\nfilterZeros Nil = Nil\nfilterZeros (Cons Z xs) = filterZeros xs\nfilterZeros (Cons n xs) = Cons n (filterZeros xs)\n\ntestFilterZeros : filterZeros $ Cons 0 (Cons 1 Nil) = (Cons 1 Nil)\ntestFilterZeros = refl\n\noddMembers : NatList -> NatList\noddMembers Nil = Nil\noddMembers (Cons Z xs) = oddMembers xs\noddMembers (Cons x xs) = if (mod x 2) == 1\n then Cons x (oddMembers xs)\n else oddMembers xs\n\ntestOddMembers : oddMembers $ Cons Z (Cons 1 (Cons 2 Nil)) = (Cons 1 Nil)\ntestOddMembers = refl\n\ncountOddMembers : NatList -> Nat\ncountOddMembers xs = Lists.length $ oddMembers xs\n\ntestCountOddMembers : countOddMembers (Cons Z (Cons 1 (Cons 2 Nil))) = (S Z)\ntestCountOddMembers = refl\n\nappNilEnd : (xs:NatList) -> app xs Lists.Nil = xs\nappNilEnd xs = ?appNilProof\n\nLists.appNilProof = proof\n intro\n induction xs\n trivial\n intros\n compute\n rewrite ihn__1\n trivial\n\nrCons : (xs:NatList) -> (i:Nat) -> NatList\nrCons Nil i = Cons i Lists.Nil\nrCons (Cons x xs) i = Cons x (rCons xs i)\n\n\nrev : NatList -> NatList\nrev Nil = Nil\nrev (Cons x xs) = rCons xs x\n\nlengthRCons : (n:Nat) -> (xs:NatList) -> length (rCons xs n) = S (length xs)\nlengthRCons n xs = ?lengthRConsProof\n\nLists.lengthRConsProof = proof\n intros\n induction xs\n trivial\n intros\n compute\n rewrite ihn__1\n trivial\n\nrevLengthRefl : (xs:NatList) -> length (rev xs) = length xs\nrevLengthRefl = ?revLengthReflProof\n\nLists.revLengthReflProof = proof\n intros\n induction xs\n trivial\n intros\n compute\n rewrite (lengthRCons n__0 n__1)\n trivial\n\nrevRCons : (xs:NatList) -> (n:Nat) -> rev (rCons xs n) = Cons n (rev xs)\nrevRCons Lists.Nil n = ?revRConsBaseProof\nrevRCons xs n = ?revRConsSuccProof\n\nLists.revRConsBaseProof = proof\n intros\n trivial\n\nrevInvolutive : rev $ rev xs = xs\nrevInvolutive = ?revInvolutiveProof\n\n\n", "meta": {"hexsha": "cb879a904dc50e136a2d348b1d05e94bf75d61c1", "size": 3285, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "lists.idr", "max_stars_repo_name": "joshvera/software-foundations-in-idris", "max_stars_repo_head_hexsha": "3424b2a1d713c15765ae9a703646ae3791f500aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-07-08T11:42:30.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-12T23:45:56.000Z", "max_issues_repo_path": "lists.idr", "max_issues_repo_name": "joshvera/software-foundations-in-idris", "max_issues_repo_head_hexsha": "3424b2a1d713c15765ae9a703646ae3791f500aa", "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": "lists.idr", "max_forks_repo_name": "joshvera/software-foundations-in-idris", "max_forks_repo_head_hexsha": "3424b2a1d713c15765ae9a703646ae3791f500aa", "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": 22.1959459459, "max_line_length": 108, "alphanum_fraction": 0.6703196347, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.8438951084436076, "lm_q1q2_score": 0.7487076143097352}} {"text": "module OfficialCrashCourse.DepTypes\n\nimport Data.Vect\n\n-- isSingle : Type\nisSingleton : Bool -> Type\nisSingleton True = Nat\nisSingleton False = List Nat\n\nmkSingle : (x : Bool) -> isSingleton x\nmkSingle True = 0\nmkSingle False = []\n\n\n-- Vect is like a List having length Nat elements\ndata Vector : Nat -> Type -> Type where\n NilVec : Vector Z a\n (::) : a -> Vector k a -> Vector (S k) a\n\n-- Defining a set of Nat many elems like above\ndata FinSet : Nat -> Type where\n FZ : FinSet (S k) -- zeroth element\n FS : FinSet k -> FinSet (S k) -- k + 1 th element from k th element\n\n\n-- using implicit arguments and proofs\nappVec: Ord a => Vector n a -> Vector m a -> Vector (n + m) a\nappVec NilVec vecm = vecm -- 0 + left = left\nappVec {n} vecn NilVec = rewrite plusZeroRightNeutral n in vecn -- left + 0 = left\nappVec {n=(S n)} {m=(S m)} ( x :: xs) (y :: ys) = \n rewrite sym $ plusSuccRightSucc n m in -- using sym to flip args, S (left + right) = left + S right\n x :: y :: (appVec xs ys)\n\n-- what is the i th element in a n sized Vector with i <= n?\nindexer : Fin n -> Vect n a -> a \nindexer FZ (x :: _) = x\nindexer (FS i) (_ :: xs) = indexer i xs\n\n\nisEmpty : {n: Nat} -> Vect n a -> Bool\nisEmpty {n = Z} _ = True\nisEmpty _ = False", "meta": {"hexsha": "51ad4a12e8ccab4531067d55bbd76758243ea923", "size": 1244, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "OfficialCrashCourse/DepTypes.idr", "max_stars_repo_name": "umbrela-academy/idrusti", "max_stars_repo_head_hexsha": "b595db27d2ff7b0816ee248cf4f669402ef55e04", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "OfficialCrashCourse/DepTypes.idr", "max_issues_repo_name": "umbrela-academy/idrusti", "max_issues_repo_head_hexsha": "b595db27d2ff7b0816ee248cf4f669402ef55e04", "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": "OfficialCrashCourse/DepTypes.idr", "max_forks_repo_name": "umbrela-academy/idrusti", "max_forks_repo_head_hexsha": "b595db27d2ff7b0816ee248cf4f669402ef55e04", "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": 29.619047619, "max_line_length": 103, "alphanum_fraction": 0.6294212219, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.7481745755233445}} {"text": "module Universality\n\nimport public Category\nimport public Isomorphism\n\n%default total\n\npublic export\nIsUnique : {cat : Category} -> {a, b : Object cat} ->\n (property : Morphism cat a b -> Type) -> (f : Morphism cat a b) -> Type\nIsUnique {cat} {a} {b} property f =\n (property f, (g : Morphism cat a b) -> property g -> g = f)\n\npublic export\nIsOnlyMorphism : {cat : Category} -> {a, b : Object cat} ->\n Morphism cat a b -> Type\nIsOnlyMorphism f = IsUnique (\\_ => ()) f\n\npublic export\nOnlyMorphismIsUnique : {cat : Category} -> {a, b : Object cat} ->\n {f : Morphism cat a b} -> IsOnlyMorphism {cat} {a} {b} f ->\n (g, h : Morphism cat a b) -> g = h\nOnlyMorphismIsUnique (_, onlyAB) g h = rewrite (onlyAB h ()) in (onlyAB g ())\n\npublic export\nIsTerminal : {cat : Category} -> (a : Object cat) -> Type\nIsTerminal {cat} a = (b : Object cat) -> DPair (Morphism cat b a) IsOnlyMorphism\n\npublic export\nIdOnlyTerminalEndomorphism : {cat : Category} -> {a : Object cat} ->\n (aIsTerminal : IsTerminal {cat} a) -> (f : Morphism cat a a) ->\n f = Identity cat a\nIdOnlyTerminalEndomorphism {cat} {a} aIsTerminal f =\n OnlyMorphismIsUnique (snd (aIsTerminal a)) f (Identity cat a)\n\npublic export\nIsInitial : {cat : Category} -> (a : Object cat) -> Type\nIsInitial {cat} a = (b : Object cat) -> DPair (Morphism cat a b) IsOnlyMorphism\n\npublic export\nIdOnlyInitialEndomorphism : {cat : Category} -> {a : Object cat} ->\n (aIsInitial : IsInitial {cat} a) -> (f : Morphism cat a a) ->\n f = Identity cat a\nIdOnlyInitialEndomorphism {cat} {a} aIsInitial f =\n OnlyMorphismIsUnique (snd (aIsInitial a)) f (Identity cat a)\n\npublic export\nIsUniqueMorphismWithProperty : {cat : Category} -> {a, b : Object cat} ->\n (property : Morphism cat a b -> Type) -> (m : Morphism cat a b) -> Type\nIsUniqueMorphismWithProperty property m =\n (property m, (m' : Morphism cat a b) -> property m' -> m' = m)\n\npublic export\nAreUniquelyIsomorphic : {cat : Category} -> (a, b : Object cat) -> Type\nAreUniquelyIsomorphic {cat} a b =\n (iso : Isomorphic a b **\n IsUniqueMorphismWithProperty IsIsomorphism (fst iso))\n\npublic export\nIsUniqueUpToUniqueIsomorphism : {cat : Category} ->\n (property : Object cat -> Type) -> Object cat -> Type\nIsUniqueUpToUniqueIsomorphism {cat} property a =\n (property a,\n (b : Object cat) -> property b -> AreUniquelyIsomorphic a b)\n", "meta": {"hexsha": "7bcc83637f15fc479cfaa6bb8a60599b98ea034c", "size": 2338, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Universality.idr", "max_stars_repo_name": "rokopt/dao-fp-exercises", "max_stars_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-01-17T17:12:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:52:36.000Z", "max_issues_repo_path": "src/Universality.idr", "max_issues_repo_name": "rokopt/dao-fp-exercises", "max_issues_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "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/Universality.idr", "max_forks_repo_name": "rokopt/dao-fp-exercises", "max_forks_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-17T17:12:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T17:12:19.000Z", "avg_line_length": 35.9692307692, "max_line_length": 80, "alphanum_fraction": 0.6680923867, "num_tokens": 737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7481003253028201}} {"text": "module Solutions.Dependent\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Length-Indexed Lists\n--------------------------------------------------------------------------------\n\ndata Vect : (len : Nat) -> Type -> Type where\n Nil : Vect 0 a\n (::) : a -> Vect n a -> Vect (S n) a\n\n-- 1\nhead : Vect (S n) a -> a\nhead (x :: _) = x\nhead Nil impossible\n\n-- 2\ntail : Vect (S n) a -> Vect n a\ntail (_ :: xs) = xs\ntail Nil impossible\n\n-- 3\nzipWith3 : (a -> b -> c -> d) -> Vect n a -> Vect n b -> Vect n c -> Vect n d\nzipWith3 f [] [] [] = []\nzipWith3 f (x :: xs) (y :: ys) (z :: zs) = f x y z :: zipWith3 f xs ys zs\n\n-- 4\n-- Since we only have a `Semigroup` constraint, we can't conjure\n-- a value of type `a` out of nothing in case of an empty list.\n-- We therefore have to return a `Nothing` in case of an empty list.\nfoldSemi : Semigroup a => List a -> Maybe a\nfoldSemi [] = Nothing\nfoldSemi (x :: xs) = Just . maybe x (x <+>) $ foldSemi xs\n\n-- 5\n-- the `Nil` case is impossible here, so unlike in Exercise 4,\n-- we don't need to wrap the result in a `Maybe`.\n-- However, we need to pattern match on the tail of the Vect to\n-- decide whether to invoke `foldSemiVect` recursively ore not\nfoldSemiVect : Semigroup a => Vect (S n) a -> a\nfoldSemiVect (x :: []) = x\nfoldSemiVect (x :: t@(_ :: _)) = x <+> foldSemiVect t\n\n-- 6\niterate : (n : Nat) -> (a -> a) -> a -> Vect n a\niterate 0 _ _ = Nil\niterate (S k) f v = v :: iterate k f (f v)\n\n-- 7\ngenerate : (n : Nat) -> (s -> (s,a)) -> s -> Vect n a\ngenerate 0 _ _ = Nil\ngenerate (S k) f v =\n let (v', va) = f v\n in va :: generate k f v'\n\n-- 8\nfromList : (as : List a) -> Vect (length as) a\nfromList [] = []\nfromList (x :: xs) = x :: fromList xs\n\n-- 9\n-- Lookup the type and implementation of functions `maybe` `const` and\n-- try figuring out, what's going on here. An alternative implementation\n-- would of course just pattern match on the argument.\nmaybeSize : Maybe a -> Nat\nmaybeSize = maybe 0 (const 1)\n\nfromMaybe : (m : Maybe a) -> Vect (maybeSize m) a\nfromMaybe Nothing = []\nfromMaybe (Just x) = [x]\n\n--------------------------------------------------------------------------------\n-- Fin: Safe Indexing into Vectors\n--------------------------------------------------------------------------------\n\ndata Fin : (n : Nat) -> Type where\n FZ : {0 n : Nat} -> Fin (S n)\n FS : (k : Fin n) -> Fin (S n)\n\n(++) : Vect m a -> Vect n a -> Vect (m + n) a\n(++) [] ys = ys\n(++) (x :: xs) ys = x :: (xs ++ ys)\n\nreplicate : (n : Nat) -> a -> Vect n a\nreplicate 0 _ = []\nreplicate (S k) x = x :: replicate k x\n\nzipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\nzipWith _ [] [] = []\nzipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys\n\n\n\n-- 1\nupdate : (a -> a) -> Fin n -> Vect n a -> Vect n a\nupdate f FZ (x :: xs) = f x :: xs\nupdate f (FS k) (x :: xs) = x :: update f k xs\n\n-- 2\ninsert : a -> Fin (S n) -> Vect n a -> Vect (S n) a\ninsert v FZ xs = v :: xs\ninsert v (FS k) (x :: xs) = x :: insert v k xs\ninsert v (FS k) [] impossible\n\n-- 3\n-- The trick here is to pattern match on the tail of the\n-- vector in the `FS k` case and realize that an empty\n-- tail is impossible. Otherwise we won't be able to\n-- convince the type checker, that the vector's tail is\n-- non-empty in the recursive case.\ndelete : Fin (S n) -> Vect (S n) a -> Vect n a\ndelete FZ (_ :: xs) = xs\ndelete (FS k) (x :: xs@(_ :: _)) = x :: delete k xs\ndelete (FS k) (x :: []) impossible\n\n-- 4\nsafeIndexList : (xs : List a) -> Fin (length xs) -> a\nsafeIndexList (x :: _) FZ = x\nsafeIndexList (x :: xs) (FS k) = safeIndexList xs k\nsafeIndexList Nil _ impossible\n\n-- 5\nfinToNat : Fin n -> Nat\nfinToNat FZ = Z\nfinToNat (FS k) = S $ finToNat k\n\ntake : (k : Fin (S n)) -> Vect n a -> Vect (finToNat k) a\ntake FZ x = []\ntake (FS k) (x :: xs) = x :: take k xs\n\n-- 6\nminus : (n : Nat) -> Fin (S n) -> Nat\nminus n FZ = n\nminus (S j) (FS k) = minus j k\nminus 0 (FS k) impossible\n\n-- 7\ndrop : (k : Fin (S n)) -> Vect n a -> Vect (minus n k) a\ndrop FZ xs = xs\ndrop (FS k) (_ :: xs) = drop k xs\n\n-- 8\nsplitAt : (k : Fin (S n))\n -> Vect n a\n -> (Vect (finToNat k) a, Vect (minus n k) a)\nsplitAt k xs = (take k xs, drop k xs)\n\n--------------------------------------------------------------------------------\n-- Compile-Time Computations\n--------------------------------------------------------------------------------\n\n-- 1\nflattenList : List (List a) -> List a\nflattenList [] = []\nflattenList (xs :: xss) = xs ++ flattenList xss\n\nflattenVect : Vect m (Vect n a) -> Vect (m * n) a\nflattenVect [] = []\nflattenVect (xs :: xss) = xs ++ flattenVect xss\n\n-- 2\ntake' : (m : Nat) -> Vect (m + n) a -> Vect m a\ntake' 0 _ = []\ntake' (S k) (x :: xs) = x :: take' k xs\ntake' (S k) Nil impossible\n\ndrop' : (m : Nat) -> Vect (m + n) a -> Vect n a\ndrop' 0 xs = xs\ndrop' (S k) (x :: xs) = drop' k xs\ndrop' (S k) Nil impossible\n\nsplitAt' : (m : Nat) -> Vect (m + n) a -> (Vect m a, Vect n a)\nsplitAt' m xs = (take' m xs, drop' m xs)\n\n-- 3\n-- Since we must call `replicate` in the `Nil` case, `k`\n-- must be a non-erased argument. I used an implicit argument here,\n-- since this reflects the type of the mathematical function\n-- more closely.\n--\n-- Empty matrices probably don't make too much sense,\n-- so we could also request at the type-level that `k` and `m`\n-- are non-zero, in which case both values could be derived\n-- by pattern matching on the vectors.\ntranspose : {k : _} -> Vect m (Vect k a) -> Vect k (Vect m a)\ntranspose [] = replicate k []\ntranspose (xs :: xss) = zipWith (::) xs (transpose xss)\n", "meta": {"hexsha": "47fcc147d02eff40cf73a20c3dd07b4cff600c44", "size": 5791, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Solutions/Dependent.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/Dependent.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/Dependent.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": 30.6402116402, "max_line_length": 80, "alphanum_fraction": 0.5125194267, "num_tokens": 1833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7480800006522537}} {"text": "module ExVectDecEq \n\nimport Decidable.Equality\n\n%default total\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n{-\n interface DecEq ty where\n decEq : (val1 : ty) -> (val2 : ty) -> Dec (val1 = val2)\n\n data Dec : (prop : Type) -> Type where\n Yes : (prf : prop) -> Dec prop\n No : (contra ; prop -> Void) -> Dec prop\n-}\n\nheadUnequal : DecEq a => { xs: Vect n a } -> { ys : Vect n a } -> \n (contra : (x = y) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\nheadUnequal contra Refl = contra Refl\n\ntailUnequal : DecEq a => { xs : Vect n a } -> { ys : Vect n a } ->\n (contra : (xs = ys) -> Void) -> ((x :: xs) = (y:: ys)) -> Void\ntailUnequal contra Refl = contra Refl\n\nDecEq a => DecEq (Vect n a) where\n decEq [] [] = Yes Refl\n decEq [] _ = No ?nilNotEqualToCons\n decEq _ [] = No ?consNotEqualToNil\n decEq (x :: xs) (y :: ys) = case decEq x y of\n No contra => No (headUnequal contra)\n Yes Refl => case decEq xs ys of\n No contra => No (tailUnequal contra)\n Yes Refl => Yes Refl\n", "meta": {"hexsha": "0d9b733ad25af079384d8d2999d1d222172714d8", "size": 1242, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter8/ExVectDecEq.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter8/ExVectDecEq.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": "chapter8/ExVectDecEq.idr", "max_forks_repo_name": "timmyjose-study/tdd-with-idris", "max_forks_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": 33.5675675676, "max_line_length": 88, "alphanum_fraction": 0.4702093398, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.74807156972477}} {"text": "module Basen\n\nimport Data.Fin\n\n--Defines a data type Base that behaves like a list\ndata Base: (n: Nat) -> Type where\n Ones: (n: Nat) -> (Fin n) -> Base n\n Next: (n: Nat) -> (Fin n) -> (Base n) -> (Base n)\n\n--Auxiliary function that reverses a Base (S n) onto anpther given Base (S n)\nRevonto: (n: Nat) -> (Base (S n)) -> (Base (S n)) -> (Base (S n))\nRevonto n accum (Ones (S n) x) = Next (S n) x accum\nRevonto n accum (Next (S n) x y) = Revonto n (Next (S n) x accum) y\n\n--Reverses a Base (S n)\nRev: (n: Nat) -> (Base (S n)) -> (Base (S n))\nRev n (Ones (S n) x) = Ones (S n) x\nRev n (Next (S n) x y) = Revonto n (Ones (S n) x) y\n\nconcat: (n: Nat) -> (Base (S n)) -> (Base (S n)) -> (Base (S n))\nconcat n (Ones (S n) x) y = Next (S n) x y\nconcat n (Next (S n) x z) y = Next (S n) x (concat n z y)\n\n--Fin to Nat\ntonatFin: (n: Nat) -> Fin(n) -> Nat\ntonatFin (S k) FZ = Z\ntonatFin (S k) (FS x) = S (tonatFin k x)\n\n--List Fin to Nat\ntonat: (n: Nat) -> Base (S n) -> Nat\ntonat n (Ones (S n) FZ) = Z\ntonat Z (Ones (S Z) (FS x)) impossible\ntonat (S k) (Ones (S (S k)) (FS x)) = S(tonat k (Ones (S k) x))\ntonat n (Next (S n) x y) = (tonat n (Ones (S n) x)) + (tonat n y)\n\n\n--Euclid's div\nEucl: (a: Nat) -> (b: Nat) -> (Nat, Nat)\nEucl Z b = (0,0)\nEucl a Z = (0, a)\nEucl (S k) b = case (lte (S (S k)) b) of\n False => (S(fst(Eucl (minus (S k) b) b)), snd(Eucl (minus (S k) b) b))\n True => (0, S k)\n\n--Nat to Fin (modular values)\ntofinNat: (a: Nat) -> (n: Nat) -> Fin n\ntofinNat Z (S j) = FZ\ntofinNat (S k) (S j) = case lte (S k) (S j) of\n True => FS (tofinNat k j)\n False => (tofinNat (snd(Eucl (S k) (S j))) (S j))\n\nstrp: (Base (S n)) -> (Base (S n))\nstrp (Ones (S n) x) = (Ones (S n) x)\nstrp (Next (S n) x y) = case x of\n FZ => strp(y)\n FS z => Next (S n) x y\n\n-- Nat to List Fin n (base n representation)\ntofin: Nat -> (n: Nat) -> Base (S n)\ntofin Z n = Ones (S n) FZ\ntofin (S k) n = strp(concat n (tofin q n) (Ones (S n) rem)) where\n rem: Fin (S n)\n rem = tofinNat (snd(Eucl (S k) (S n))) (S n)\n q: Nat\n q = fst(Eucl (S k) (S n))\n\n--embedding Fin n in Fin S n vertically\nembn: (n: Nat) -> Fin n -> Fin (S n)\nembn (S k) FZ = FZ\nembn (S k) (FS x) = FS (embn k x)\n\n--Generates n in (Fin (S n))\nGenn: (n: Nat) -> (Fin (S n))\nGenn Z = FZ\nGenn (S k) = FS (Genn k)\n\n--Checks if a given element of Fin (S n) is in fact n\nIsn: (n: Nat) -> (p: Fin (S n)) -> Bool\nIsn Z x = True\nIsn (S k) FZ = False\nIsn (S k) (FS x) = Isn k x\n\n--Proves that the definitional equality for Isn holds\nIsnisIsn: (n: Nat) -> (p: Fin (S n)) -> (Isn (S n) (FS p)) = (Isn n p)\nIsnisIsn n p = Refl\n\n--Proves that if a given (FS x) is not n in (Fin (S n)), then x is not n-1 in (Fin n)\nIsNotnPf: (n: Nat) -> (p: Fin (S n)) -> ((Isn (S n) (FS p)) = False) -> ((Isn n p) = False)\nIsNotnPf Z _ Refl impossible\nIsNotnPf (S k) FZ prf = Refl\nIsNotnPf (S k) (FS x) prf = trans (sym (IsnisIsn (S k) (FS x))) prf\n\n--Gives a back embedding whenever the value is not Genn\nPredec: (n: Nat) -> (p: Fin (S n)) -> ((Isn n p) = False) -> (Fin n)\nPredec Z _ Refl impossible\nPredec (S k) FZ Refl = FZ\nPredec (S k) (FS x) prf = FS (Predec k x (IsNotnPf (S k) (FS x) prf))\n\n--Decidable type for Isn\nDecIsn: (n: Nat) -> (p: (Fin (S n))) -> Either (Isn n p = True) (Isn n p = False)\nDecIsn Z p = Left Refl\nDecIsn (S k) FZ = Right Refl\nDecIsn (S k) (FS x) = case (DecIsn k x) of\n Left l => Left (trans (IsnisIsn k x) l)\n Right r => Right (trans (IsnisIsn k x) r)\n\n--adding two Fin n's\naddfin: (n: Nat) -> Fin (S n) -> Fin (S n) -> (Fin (S n), Fin (S n))\naddfin Z x y = (FZ, FZ)\naddfin (S k) FZ y = (FZ, y)\naddfin (S k) (FS x) y = let\n a = Genn (S k)\n b = the (Fin (S (S k))) FZ\n c = the (Fin (S k)) FZ\n w = fst(addfin (S k) (embn (S k) x) y)\n z = snd(addfin (S k) (embn (S k) x) y)\n in\n case (DecIsn (S k) z) of\n Left l => (FS c, b)\n Right r => (w, FS(Predec (S k) z r))\n\n\n--adding two reversed lists as specified\naddfinl: (n: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\naddfinl n (Ones (S n) x) (Ones (S n) y) = case (addfin n x y) of\n (FZ, a) => Ones (S n) a\n (FS c, a) => Next (S n) a (Ones (S n) (FS c))\naddfinl n (Ones (S n) x) (Next (S n) y z) = Next (S n) (snd (addfin n x y)) (addfinl n (Ones (S n) (fst (addfin n x y))) z)\naddfinl n (Next (S n) x z) (Ones (S n) y) = Next (S n) (snd (addfin n x y)) (addfinl n (Ones (S n) (fst (addfin n x y))) z)\naddfinl n (Next (S n) x z) (Next (S n) y w) = Next (S n) (snd (addfin n x y)) (addfinl n (Ones (S n) (fst (addfin n x y))) (addfinl n z w))\n\n--adding two lists\naddfinlist: (n: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\naddfinlist n xs ys = (Rev n (addfinl n (Rev n xs) (Rev n ys)))\n\n--multiply two reversed lists in Fin S n\nmulfinl: (n: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\nmulfinl n (Ones (S n) FZ) y = Ones (S n) FZ\nmulfinl n (Ones (S n) (FS x)) y = addfinl n y (mulfinl n (Ones (S n) (embn n x)) y)\nmulfinl n (Next (S n) FZ z) y = Next (S n) FZ (mulfinl n z y)\nmulfinl n (Next (S n) (FS x) z) y = addfinl n y (mulfinl n (Next (S n) (embn n x) z) y)\n\n\n--multiply two lists\nmulfinList: (n: Nat) -> (Base (S n)) -> (Base (S n)) -> (Base (S n))\nmulfinList n xs ys = Rev n (mulfinl n (Rev n xs) (Rev n ys))\n\n--Custom \"functions are functors\" function\nap: (x: Type) -> (y: Type) -> (f: x->y) -> (n = m) -> (f n = f m)\nap x y f Refl = Refl\n\n", "meta": {"hexsha": "0ab0d64fddd5e95dbf13f4f34070d88e279482bf", "size": 5719, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/BaseN.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": "_local-site/Code/BaseN.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": "_local-site/Code/BaseN.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": 37.625, "max_line_length": 139, "alphanum_fraction": 0.5079559364, "num_tokens": 2331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7479560008082274}} {"text": "-- ------------------------------------------------------------- [ Metrics.idr ]\n-- Module : Metrics.idr\n-- Copyright : (c) Jan de Muijnck-Hughes\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\n||| Readability Metrics\n|||\n||| http://www.editcentral.com/gwt1/EditCentral.html\nmodule Readability.Metrics\n\n%access export\n\npublic export\ndata RMetricTy = FLESCH | ARI | KINCAID | COLEMAN | FOG | SMOG\n\n||| Flesch reading ease score\n|||\n||| ```java\n||| 206.835 - (1.015 * wordCount) / sentenceCount - (84.6 * syllableCount) / wordCount;\n||| ```\n||| @wcount Number of words\n||| @scount Number of sentences.\n||| @sycount Number of syllables.\nflesch : (wcount : Double) -> (scount : Double) -> (sycount : Double) -> Double\nflesch ws ss sys = 206.835 - (1.015 * ws) / ss - (84.6 * sys) / ws\n\n||| Automated readability index\n|||\n||| ```java\n||| (4.71 * letterNumberCount) / wordCount + (0.5 * wordCount) / sentenceCount -21.43;\n||| ```\n||| @ccount Number of Characters\n||| @wcount Number of words.\n||| @scount Number of sentences.\nari : (ccount : Double) -> (wcount : Double) -> (scount : Double) -> Double\nari as ws ss = (4.71 * as) / ws + (0.5 * ws) / ss - 21.43\n\n\n||| Flesch-Kincaid grade level\n|||\n||| ```java\n||| (0.39 * wordCount) / sentenceCount + (11.8 * syllableCount) / wordCount - 15.59;\n||| ```\n||| @wcount The number of words\n||| @scount Number of sentences\n||| @sycount Number of syllables.\nkincaid : (wcount : Double) -> (scount : Double) -> (sycount : Double) -> Double\nkincaid ws ss sys = (0.39 * ws) / ss + (11.8 * sys) / ws - 15.59\n\n\n||| Coleman-Liau index\n|||\n||| ```java\n||| (5.89 * letterNumberCount) / wordCount - (30.0 * sentenceCount) / wordCount - 15.8;\n||| ```\n||| @ccount Number of letters and digits.\n||| @wcount The number of words.\n||| @scount The number of sentences.\ncoleman : (ccount : Double) -> (wcount : Double) -> (scount : Double) -> Double\ncoleman as ws ss = (5.89 * as) / ws - (30.0 * ss) / ws - 15.8\n\n\n||| Gunning fog index\n|||\n||| ```java\n||| 0.4 * ( (double)wordCount / sentenceCount + (100.0 * complexCount) / wordCount );\n||| ```\n||| @wcount Number of Words\n||| @scount Number of sentences\n||| @bwcount Number of words with three plus syllables.\nfog : (wcount : Double) -> (scount : Double) -> (bwcount : Double) -> Double\nfog ws ss bs = 0.4 * ( ws / ss + (100.0 * bs) / ws)\n\n||| SMOG index\n|||\n||| ```java\n||| Math.sqrt( complexCount * 30.0 / sentenceCount ) + 3.0;\n||| ```\n||| @bwcount The number of word with three plus syllables.\n||| @scount The number of sentences.\nsmog : (bwcount : Double) -> (scount : Double) -> Double\nsmog bs ss = 3.0 + sqrt (bs * (30 / ss))\n\n\nShow RMetricTy where\n show FLESCH = \"FLESCH\"\n show ARI = \"ARI\"\n show KINCAID = \"KINCAID\"\n show COLEMAN = \"COLEMAN\"\n show FOG = \"FOG\"\n show SMOG = \"SMOG\"\n\nEq RMetricTy where\n (==) FLESCH FLESCH = True\n (==) ARI ARI = True\n (==) KINCAID KINCAID = True\n (==) COLEMAN COLEMAN = True\n (==) FOG FOG = True\n (==) SMOG SMOG = True\n (==) _ _ = False\n\nreadRMetricTy : String -> Maybe RMetricTy\nreadRMetricTy s =\n case toLower s of\n \"flesch\" => Just FLESCH\n \"ari\" => Just ARI\n \"kincaid\" => Just KINCAID\n \"coleman\" => Just COLEMAN\n \"fog\" => Just FOG\n \"smog\" => Just SMOG\n otherwise => Nothing\n\npublic export\nrecord ReadResult where\n constructor MkReadResult\n flesch : Double\n ari : Double\n kincaid : Double\n coleman : Double\n fog : Double\n smog : Double\n\ntoList : ReadResult -> List (RMetricTy, Double)\ntoList (MkReadResult a b c d e f) =\n [ (FLESCH, a)\n , (ARI, b)\n , (KINCAID, c)\n , (COLEMAN, d)\n , (FOG, e)\n , (SMOG, f)]\n\nShow ReadResult where\n show rslt = show (Metrics.toList rslt)\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "e4c938948fdb34d002ac43b14d23c5c5e1f1fff9", "size": 3872, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Readability/Metrics.idr", "max_stars_repo_name": "jfdm/idris-read", "max_stars_repo_head_hexsha": "22c5f22996f41bb86ffd847ffea2b9e0c6048498", "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": "Readability/Metrics.idr", "max_issues_repo_name": "jfdm/idris-read", "max_issues_repo_head_hexsha": "22c5f22996f41bb86ffd847ffea2b9e0c6048498", "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": "Readability/Metrics.idr", "max_forks_repo_name": "jfdm/idris-read", "max_forks_repo_head_hexsha": "22c5f22996f41bb86ffd847ffea2b9e0c6048498", "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.6814814815, "max_line_length": 87, "alphanum_fraction": 0.5648243802, "num_tokens": 1320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7473905811988083}} {"text": "\nmodule TakeN\n\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n\n-- Ex. 10.1 # 1\ntotal\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z xs = Exact []\ntakeN (S k) [] = Fewer\ntakeN (S k) (x :: xs) = case takeN k xs of\n Fewer => Fewer\n (Exact n_xs) => Exact $ x :: n_xs\n\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\n-- Ex. 10.1 # 2\nhalves : List a -> (List a, List a)\nhalves xs = splitHalf (div (length xs) 2) xs\n where\n splitHalf : Nat -> List a -> (List a, List a)\n splitHalf n xs with (takeN n xs)\n splitHalf n xs | Fewer = ([], xs)\n splitHalf n (n_xs ++ rest) | (Exact n_xs) = (n_xs, rest)\n\n", "meta": {"hexsha": "d9c235513187cb20ddaa640a6156e35630e52262", "size": 866, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter10/TakeN.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter10/TakeN.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter10/TakeN.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 27.935483871, "max_line_length": 68, "alphanum_fraction": 0.5369515012, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152282, "lm_q2_score": 0.7879312006227323, "lm_q1q2_score": 0.7470805409928509}} {"text": "> module So.Properties\n\n> import Data.So\n\n> import Decidable.Predicates\n> import Unique.Predicates\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\n* Introduction and elimination rules\n\n> |||\n> soIntro : (b : Bool) -> b = True -> So b\n> soIntro True Refl = Oh\n> soIntro False contra = void (trueNotFalse (sym contra))\n\n> |||\n> soElim : (b : Bool) -> So b -> b = True\n> soElim True Oh = Refl\n> soElim False Oh impossible\n\n** Or\n\n> |||\n> soOrIntro1 : (b1 : Bool) -> (b2 : Bool) -> So b1 -> So (b1 || b2)\n> soOrIntro1 True _ Oh = Oh\n\n> |||\n> soOrIntro2 : (b1 : Bool) -> (b2 : Bool) -> So b2 -> So (b1 || b2)\n> soOrIntro2 True True Oh = Oh\n> soOrIntro2 False True Oh = Oh\n\n> |||\n> soOrElim : (b1 : Bool) -> (b2 : Bool) -> So (b1 || b2) -> Either (So b1) (So b2)\n> soOrElim True True Oh = Left Oh\n> soOrElim True False Oh = Left Oh\n> soOrElim False True Oh = Right Oh\n> soOrElim False False Oh impossible\n\n> |||\n> soOrElim1 : (b1 : Bool) -> (b2 : Bool) -> So (b1 || b2) -> So (not b1) -> So b2\n> soOrElim1 True True Oh Oh impossible\n> soOrElim1 True False Oh Oh impossible\n> soOrElim1 False True Oh Oh = Oh\n> soOrElim1 False False Oh Oh impossible\n\n> |||\n> soOrElim2 : (b1 : Bool) -> (b2 : Bool) -> So (b1 || b2) -> So (not b2) -> So b1\n> soOrElim2 True True Oh Oh impossible\n> soOrElim2 True False Oh Oh = Oh\n> soOrElim2 False True Oh Oh impossible\n> soOrElim2 False False Oh Oh impossible\n\n** And\n\n> |||\n> soAndElim1 : (b1 : Bool) -> (b2 : Bool) -> So (b1 && b2) -> So b1\n> soAndElim1 True True Oh = Oh\n> soAndElim1 True False Oh impossible\n> soAndElim1 False True Oh impossible\n> soAndElim1 False False Oh impossible\n\n> |||\n> soAndElim2 : (b1 : Bool) -> (b2 : Bool) -> So (b1 && b2) -> So b2\n> soAndElim2 True True Oh = Oh\n> soAndElim2 True False Oh impossible\n> soAndElim2 False True Oh impossible\n> soAndElim2 False False Oh impossible\n\n\n\n* Counter factuals\n\n> |||\n> contra : {b : Bool} -> b = False -> So b -> Void\n> contra {b} p q = trueNotFalse (trans (sym (soElim b q)) p)\n\n\n* Decidability\n\n> ||| Lifted Booleans are decidable\n> decSo : (b : Bool) -> Dec (So b)\n> decSo True = Yes Oh\n> decSo False = No (\\ oh => absurd oh)\n\n> ||| Lifted Boolean functions are decidable\n> dec1So : {A : Type} -> (p : A -> Bool) -> Dec1 (\\ a => So (p a))\n> dec1So p a = decSo (p a)\n\n\n* Uniqueness\n\n> ||| Lifted Booleans are unique\n> uniqueSo : (b : Bool) -> Unique (So b)\n> uniqueSo True Oh Oh = Refl\n> uniqueSo False Oh Oh impossible\n\n\n> ||| Lifted Boolean functions are unique\n> unique1So : {A : Type} -> (p : A -> Bool) -> Unique1 (\\ a => So (p a))\n> unique1So p a = uniqueSo (p a)\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "34757f6f41856761e6cc7f9ca42e797a06d964b5", "size": 2629, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "So/Properties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "So/Properties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "So/Properties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9, "max_line_length": 82, "alphanum_fraction": 0.6124001521, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879432, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7470701701082408}} {"text": "module NatTree\n\nimport Data.Fin\n\n\ndata NatTree : Type where\n Leaf : Nat -> NatTree\n Node : NatTree -> NatTree -> NatTree\n\ntsum : NatTree -> Nat\ntsum (Leaf k) = k\ntsum (Node x y) = (tsum x) + (tsum y)\n\nrecNT : (x: Type) -> (Nat -> x) -> (NatTree -> x -> NatTree -> x -> x)\n -> (NatTree -> x)\nrecNT x f g (Leaf k) = f k\nrecNT x f g (Node y z) = g y yValue z zValue where\n yValue = recNT x f g y\n zValue = recNT x f g z\n\ntsumTheHardWay : NatTree -> Nat\ntsumTheHardWay = recNT Nat leafCase nodeCase where\n leafCase = \\k : Nat => k\n nodeCase = \\t1 => \\n1 => \\t2 => \\n2 => n1 + n2\n\nflattenTree : NatTree -> List Nat\nflattenTree = recNT (List Nat) leafCase nodeCase where\n leafCase = \\k => k :: []\n nodeCase = \\t1 => \\l1 => \\t2 => \\l2 => (l1 ++ l2)\n\ndata FinNatTree : Type where\n FLeaf : Nat -> FinNatTree\n FNode : (n: Nat) -> ((Fin n) -> FinNatTree) -> FinNatTree\n\ndata Evil : Type where\n Diag : (Evil -> Bool) -> Evil\n\nevil : Evil -> Bool\nevil (Diag f) = not (f (Diag f))\n\ncontra : Bool\ncontra = evil (Diag evil)\n", "meta": {"hexsha": "4f23faf0d9c2b47790a73a54da0d22926a7ff2ab", "size": 1021, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/NatTree.idr", "max_stars_repo_name": "AR-MA210/LTS2019", "max_stars_repo_head_hexsha": "28b7bb2bcc9c68915d58b7d03193e1a54fe4b0f6", "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": "Code/NatTree.idr", "max_issues_repo_name": "AR-MA210/LTS2019", "max_issues_repo_head_hexsha": "28b7bb2bcc9c68915d58b7d03193e1a54fe4b0f6", "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": "Code/NatTree.idr", "max_forks_repo_name": "AR-MA210/LTS2019", "max_forks_repo_head_hexsha": "28b7bb2bcc9c68915d58b7d03193e1a54fe4b0f6", "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.7441860465, "max_line_length": 70, "alphanum_fraction": 0.5984329089, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142217223021, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7469401543881447}} {"text": "import Data.Vect\n\n{-\nvApp : Vect n (a -> b) -> Vect n a -> Vect n b\nvApp [] [] = []\nvApp (f :: fs) (a :: as) = f a :: vApp fs as\n-}\n\n\ntotal\nvApp : {a:Type} -> {b:Type} -> {n:Nat} -> Vect n (a -> b) -> Vect n a -> Vect n b\nvApp [] [] = []\nvApp (f :: fs) (e :: es) = f e :: vApp fs es\n\n\n\n--vApp {a} {b} {n=S m} (f :: fs) (e :: es) = f e :: vApp fs es\n\n", "meta": {"hexsha": "1a0213d94c7727567d279f837fee1e89f9bb6df0", "size": 381, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZPF/Slajdy19/PlikiIdrisa/ApplyVec.idr", "max_stars_repo_name": "wdomitrz/Coq-Exercises", "max_stars_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/ApplyVec.idr", "max_issues_repo_name": "wdomitrz/Coq-Exercises", "max_issues_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/ApplyVec.idr", "max_forks_repo_name": "wdomitrz/Coq-Exercises", "max_forks_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": 20.0526315789, "max_line_length": 82, "alphanum_fraction": 0.3989501312, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7468683155780135}} {"text": "module Product_Type_Eq\n\n%access public export\n%default total\n\n||| A proof that equality for product types are generate by the equalities of the componenets\n\nProduct_Eq_property_1 : (ty1, ty2 : Type) -> (a, b : (ty1, ty2)) ->\n ( (fst a) = (fst b) ) -> ( (snd a) = (snd b) ) ->\n ( a = b )\n\nProduct_Eq_property_1 ty1 ty2 (x, y) (x, y) Refl Refl = Refl\n\n\n\n\n\n\n\n", "meta": {"hexsha": "ef2aa24fcc2b9f3762aae40edd379b509a60094b", "size": 402, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Product_Type_Eq.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/Product_Type_Eq.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/Product_Type_Eq.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": 20.1, "max_line_length": 93, "alphanum_fraction": 0.5621890547, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7464259740557109}} {"text": "module Unsigned\n\n%access export\n%default total\n\n||| An unsigned binary number represented with `n` bits\ndata Unsigned : (n : Nat) -> Type where\n ||| Built from an underlying integer\n U : Integer -> Unsigned n\n\n-- We could require a proof for this contructor that our Integer is indeed in\n-- the range 0 -> 2*n-1. We don't bother because only (trusted) functions in\n-- this module can use the constructor.\n\n||| Cast instance for `Unsigned n` to an integer\nCast (Unsigned n) Integer where\n cast (U x) = x\n\n||| Eq instacne for equality of `Unsigned n`\nEq (Unsigned n) where\n (==) (U x) (U y) = x==y\n\n||| Ord instance for ordering of `Unsigned n`\nOrd (Unsigned n) where\n compare (U x) (U y) = compare x y\n\n||| MinBound instance for generating extremes of `Unsigned n`\nMinBound (Unsigned n) where\n minBound = U 0\n\n||| MaxBound instance for generating extremes of `Unsigned n`\nMaxBound (Unsigned n) where\n maxBound = U $ cast (power 2 n)-1\n\n||| Safely create an `Unsigned n` from an Integer using saturation\nsaturate : Integer -> Unsigned n\nsaturate x = let tryU = U {n} x\n in if tryU > maxBound then maxBound else\n if tryU < minBound then minBound else tryU\n\n||| Num instance for saturating arithmetic with `Unsigned n`\nNum (Unsigned n) where\n (+) (U x) (U y) = saturate $ (x+y)\n (*) (U x) (U y) = saturate $ (x*y)\n fromInteger x = saturate $ x\n\n||| Minus operations for two `Unsigned`s. Note that we cannot implement the Neg\n||| typeclass because there are no negative representations.\nminus : Unsigned n -> Unsigned n -> Unsigned n\nminus (U x) (U y) = U (x-y)\n\n||| Helper function to prove that 2^n for all natural n is not 0\nprivate\npowerTwoIsNotZ : (n : Nat) -> Not (power 2 n = 0)\npowerTwoIsNotZ n = believe_me -- TODO prove properly\n\n||| Add operations for two `Unsigned`s with wrapping overflow.\naddWrap : Unsigned n -> Unsigned n -> Unsigned n\naddWrap (U x) (U y) = let max = power 2 n\n res = cast x + cast y\n in U . cast $ modNatNZ res max (powerTwoIsNotZ n)\n\n||| Minus operations for two `Unsigned`s with wrapping overflow.\nminusWrap : Unsigned n -> Unsigned n -> Unsigned n\nminusWrap (U x) (U y) = let max = power 2 n\n res = max + cast x `minus` cast y\n in U . cast $ modNatNZ res max (powerTwoIsNotZ n)\n\n||| Show instance for printing `Unsigned n`\nShow (Unsigned n) where\n show (U x) = \"U\" ++ show n ++ \" \" ++ show x\n\n-- Local Variables:\n-- idris-load-packages: (\"contrib\")\n-- End:\n", "meta": {"hexsha": "f7cf8b16dd6f71030596acc535206b404da0c402", "size": 2525, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Unsigned.idr", "max_stars_repo_name": "croyzor/Idris_dsp_motivation", "max_stars_repo_head_hexsha": "54837b4ee9cf368b9eacaed1d7206ae7996577f6", "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/Unsigned.idr", "max_issues_repo_name": "croyzor/Idris_dsp_motivation", "max_issues_repo_head_hexsha": "54837b4ee9cf368b9eacaed1d7206ae7996577f6", "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/Unsigned.idr", "max_forks_repo_name": "croyzor/Idris_dsp_motivation", "max_forks_repo_head_hexsha": "54837b4ee9cf368b9eacaed1d7206ae7996577f6", "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": 33.2236842105, "max_line_length": 79, "alphanum_fraction": 0.6495049505, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.745877680387786}} {"text": "module Group_property2\n\nimport congruence\nimport Monoid\nimport Group\nimport Group_property \n\n%access public export\n \n||| Property 8 - If f : g -> h is group homomorphism then f(inv(a)) = inv(f(a))\ntotal\nGroup_property_8 : (dom : Type) -> ((*) : dom -> dom -> dom) -> (pfdom : IsGroup dom (*)) ->\n (cod : Type) -> ((+) : cod -> cod -> cod) -> (pfcod : IsGroup cod (+)) ->\n (f : dom -> cod) -> (pfhom : (Hom dom (*) pfdom cod (+) pfcod f)) -> \n (a : dom) -> ( (f (Inv dom (*) pfdom a)) = (Inv cod (+) pfcod (f a)) )\n \nGroup_property_8 dom (*) pfdom cod (+) pfcod f pfhom a = let\n pfid1_dom = (fst (snd pfdom))\n e_dom1 = (fst pfid1_dom) -- identity in the IdentityExists\n e_dom1_pf = (snd pfid1_dom) -- proof that e_dom1 is the identity\n \n pfid2_dom = (fst (snd (snd pfdom)))\n e_dom2 = (fst pfid2_dom) -- identity in the InverseExists\n e_dom2_pf = (snd pfid2_dom) -- prood that it is the identity\n \n pf_eq_dom_id12 = (Group_property_1 dom (*) pfdom e_dom1 e_dom2\n e_dom1_pf e_dom2_pf) -- proof that e_dom1 and e_dom2 are equal\n \n pfid1_cod = (fst (snd pfcod))\n e_cod1 = (fst pfid1_cod) -- identity in the IdentityExists\n e_cod1_pf = (snd pfid1_cod) -- proof that e_cod1 is the identity\n \n pfid2_cod = (fst (snd (snd pfcod)))\n e_cod2 = (fst pfid2_cod) -- identity in the InverseExists\n e_cod2_pf = (snd pfid2_cod) -- prood that it is the identity\n \n pf_eq_cod_id12 = (Group_property_1 cod (+) pfcod e_cod1 e_cod2\n e_cod1_pf e_cod2_pf) -- proof that e_cod1 and e_cod2 are equal\n \n a_inv_with_pf = snd (snd (snd pfdom)) a -- (Inv_with_pf dom (*) pfdom a)\n a_inv = fst a_inv_with_pf\t\n b = (f a_inv)\n c = (Inv cod (+) pfcod (f a))\n \n pf_id_to_id = (fst pfhom)\n pf_res = (snd pfhom)\n \n --aux_pf1 : ( ( Group_id dom (*) pfdom ) = (fst (snd pfdom)) )\n --aux_pf1 = Refl -- proof that fst (Group_id dom (*) pfdom) = fst (fst (snd pfdom))\n \n pf1 = (pf_res a a_inv) -- proof that f(a * a_inv) = f a + f a_inv\n pf2 = (fst (snd a_inv_with_pf)) -- proof that a * a_inv = e_dom2\n pf3 = congruence dom cod (a * a_inv) e_dom2 f pf2 -- proof that a * a_inv = e_dom2\n pf4 = trans (sym pf1) pf3 -- proof that f(a * a_inv) = f e_dom2\n pf5 = (Group_property_1 cod (+) pfcod \n (f e_dom1) e_cod1 pf_id_to_id e_cod1_pf) -- proof that f e_dom1 = e_cod1\n pf6 = congruence dom cod e_dom1 e_dom2 f pf_eq_dom_id12-- proof that f e_dom1 = f e_dom2\n pf7 = trans (trans pf4 (sym pf6)) pf5 -- proof that (f a) + (f a_inv) = e_cod1\n pf8 = Group_property_7 cod (+) pfcod (f a) (f a_inv) pf7 -- proof that inverse of (f a) \n -- is (f a_inv)\n pf9 = snd (Inv_with_pf cod (+) pfcod (f a)) -- proof that c is a inverse of (f a) with \n -- e_cod2 as identity\n pf9.1 = fst pf9 -- proof that (f a) + c = e_cod2\n pf9.2 = snd pf9 -- proof that c + (f a) = e_cod2\n pf10.1 = trans pf9.1 (sym pf_eq_cod_id12) -- proof that (f a) + c = e_cod1\n pf10.2 = trans pf9.2 (sym pf_eq_cod_id12) -- -- proof that c + (f a) = e_cod1\n pf10 = (pf10.1, pf10.2)\n \n in \n (Group_property_2 cod (+) pfcod (f a) b c pf8 pf10)\n \n||| Property 9 - If a*b = c then b = Inv(a) * c\ntotal\nGroup_property_9 : (grp : Type) -> ((*) : grp -> grp -> grp) -> (pfgrp : IsGroup grp (*)) -> \n (a, b, c : grp) -> (a*b = c) -> (b = (Inv grp (*) pfgrp a)*c)\n \nGroup_property_9 grp (*) pfgrp a b c pfEq = ?rhs \n \n \n \n \n \n \n \n \n \n", "meta": {"hexsha": "5bf1896062144bc5c197cf6fa6e76226aee2d5c6", "size": 7139, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Group_property2.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Group_property2.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Group_property2.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 82.0574712644, "max_line_length": 145, "alphanum_fraction": 0.2865947612, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7458569828875226}} {"text": "module Cosets\n\nimport Group\n%access public export\n\n--The type of proofs that a type trav Transverses a given coset only once,\n--if at all\nCosetInj: (h: Type) -> (pfh: Group h) -> (g: Type) -> (pfg: Group g) ->\n (sbgrp: Subgroup h pfh g pfg) ->\n (trav: Type) -> (f: trav -> g) -> Type\nCosetInj h (MkGroup h (+) pfh) g (MkGroup g (*) pfg) sbgrp trav f =\n ((x: trav) -> (y: trav) ->\n (p: h ** (f x) = (incl p)*(f y)) -> (x = y)) where\n incl = (fst sbgrp)\n\n--The type of proofs that a type trav Transverses every coset of a given\n-- group g wrt a subgroup h\nCosetAll: (h: Type) -> (pfh: Group h) -> (g: Type) -> (pfg: Group g) ->\n (sbgrp: Subgroup h pfh g pfg) ->\n (trav: Type) -> (f: trav -> g) -> Type\nCosetAll h (MkGroup h (+) pfh) g (MkGroup g (*) pfg) sbgrp trav f =\n ((a: g) ->\n (p: h ** (t: trav ** ((incl p)*(f t) = a)))) where\n incl = (fst sbgrp)\n\n-- Transversal type - the type of proofs that a given type is a Transversal\n-- of a group g wrt a subgroup h\nIsTransversal: (h: Type) -> (pfh: Group h) -> (g: Type) -> (pfg: Group g) ->\n (sbgrp: Subgroup h pfh g pfg) -> (trav: Type) -> Type\nIsTransversal h pfh g pfg sbgrp trav = DPair (trav -> g) (\\f =>\n (CosetInj h pfh g pfg sbgrp trav f,\n CosetAll h pfh g pfg sbgrp trav f)\n )\n\n--The transversal data type\ndata Transversal: (trav: Type) -> Type where\n MkTransversal: (h: Type) -> (pfh: Group h) -> (g: Type) -> (pfg: Group g) ->\n (sbgrp: Subgroup h pfh g pfg) -> (trav: Type) ->\n (IsTransversal h pfh g pfg sbgrp trav) -> Transversal trav\n\n--Defining the multiplication operation between elements of a traversal\nMulTrans: (trav: Type) -> (Transversal trav) -> trav -> trav -> trav\nMulTrans trav (MkTransversal h (MkGroup h (+) pfh) g (MkGroup g (*) pfg) sbgrp trav pftrav) y z = (fst (snd ((snd (snd pftrav)) ((f y)*(f z))))) where\n f: trav -> g\n f = (fst pftrav)\n", "meta": {"hexsha": "fafc0c1207b124742ace9bb59d2980e51ab931d5", "size": 1917, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Group.Cosets.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Group.Cosets.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Group.Cosets.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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.6739130435, "max_line_length": 150, "alphanum_fraction": 0.5837245696, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7458145841516823}} {"text": "> module BoundedNat.Operations\n\n> import Data.Fin\n> import Data.Vect\n\n> import BoundedNat.BoundedNat\n> import Fin.Properties\n> import Nat.LTProperties\n> import Sigma.Sigma\n> import Pairs.Operations\n\n> %default total\n> %access public export\n\n\n> ||| Mapping bounded |Nat|s to |Fin|s\n> toFin : {b : Nat} -> LTB b -> Fin b\n> toFin {b = Z} (MkSigma _ nLT0 ) = void (succNotLTEzero nLT0)\n> toFin {b = S m} (MkSigma Z _ ) = FZ\n> toFin {b = S m} (MkSigma (S n) (LTESucc prf)) = FS (toFin (MkSigma n prf))\n\n> ||| Mapping |Fin|s to bounded |Nat|s\n> fromFin : {b : Nat} -> Fin b -> LTB b\n> fromFin k = MkSigma (finToNat k) (finToNatLemma k)\n\n> |||\n> toVect : {b : Nat} -> {A : Type} -> (LTB b -> A) -> Vect b A\n> toVect {b = Z} _ = Nil\n> toVect {b = S b'} {A} f = (f (MkSigma Z (ltZS b'))) :: toVect f' where\n> f' : LTB b' -> A\n> f' (MkSigma k q) = f (MkSigma (S k) (LTESucc q))\n", "meta": {"hexsha": "f68fcdbc73edc2ae7f7b94dcc3206198385b9714", "size": 908, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "BoundedNat/Operations.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "BoundedNat/Operations.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "BoundedNat/Operations.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-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.375, "max_line_length": 76, "alphanum_fraction": 0.5748898678, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7456736161404041}} {"text": "import Data.Vect\n\nimport Data.List.Views\nimport Data.Vect.Views\nimport Data.Nat.Views\n\n{- 1 -}\n\ntotal\nequalSuffix : Eq a => List a -> List a -> List a\nequalSuffix input1 input2 with (snocList input1)\n equalSuffix [] input2 | Empty = []\n equalSuffix (xs ++ [x]) input2 | (Snoc xsrec) with (snocList input2)\n equalSuffix (xs ++ [x]) [] | (Snoc xsrec) | Empty = []\n equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec) \n = if x == y \n then equalSuffix xs ys | xsrec | ysrec ++ [y]\n else []\n\n{- 2 -}\n\ntotal\nmergeSort : Ord a => Vect n a -> Vect n a\nmergeSort xs with (splitRec xs)\n mergeSort [] | SplitRecNil = []\n mergeSort [x] | SplitRecOne = [x]\n mergeSort (ys ++ zs) | (SplitRecPair lrec rrec) \n = merge (mergeSort ys | lrec) (mergeSort zs | rrec)\n\n{- 3 -}\n\ntotal\ntoBinary : Nat -> String\ntoBinary k with (halfRec k)\n toBinary Z | HalfRecZ = \"\"\n toBinary (n + n) | (HalfRecEven rec) = toBinary n | rec ++ \"0\"\n toBinary (S (n + n)) | (HalfRecOdd rec) = toBinary n | rec ++ \"1\"\n\n{- 4 -}\n\npalindrome : Eq a => List a -> Bool\npalindrome input with (vList input)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (x :: (xs ++ [y])) | (VCons rec) \n = x == y && palindrome xs\n\n", "meta": {"hexsha": "dd224f1bc219775c98643ceed81fb10107ecfd72", "size": 1265, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter10/Exercises/ex_10_2.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 161, "max_stars_repo_stars_event_min_datetime": "2017-02-27T02:28:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T22:17:47.000Z", "max_issues_repo_path": "Chapter10/Exercises/ex_10_2.idr", "max_issues_repo_name": "gdevanla/TypeDD-Samples", "max_issues_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2017-03-26T23:27:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:32:25.000Z", "max_forks_repo_path": "Chapter10/Exercises/ex_10_2.idr", "max_forks_repo_name": "gdevanla/TypeDD-Samples", "max_forks_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-03-19T11:01:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-10T05:30:22.000Z", "avg_line_length": 26.3541666667, "max_line_length": 70, "alphanum_fraction": 0.5865612648, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7456500598913038}} {"text": "{- Ctrl-Alt-A: Add definition\n Ctrl-Alt-C: Case split\n Ctrl-Alt-D: Documentation\n Ctrl-Alt-L: Lift hole: Lifts a hole to the top level as a new function definition\n Ctrl-Alt-M: Match: Replaces a hole with a case expression that matches on an intermediate result\n Ctrl-Alt-R: Reloads and typechecks the current buffer\n Ctrl-Alt-S: Search\n Ctrl-Alt-T: Type-check: Displays the type under cursor\n Ctrl-Alt-W: Add With View -}\nmodule Main\n\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z xs = Exact []\ntakeN (S k) [] = Fewer\ntakeN (S k) (x :: xs) = case takeN k xs of\n Fewer => Fewer\n Exact ys => Exact (x :: ys)\n\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\nhalves : List a -> (List a, List a)\nhalves xs with (takeN (length xs `div` 2) xs)\n halves xs | Fewer = (xs, [])\n halves (n_xs ++ rest) | (Exact n_xs) = (n_xs, rest)\n\nmain : IO ()\nmain = do\n printLn $ groupByN 3 [1,2,3,4,5,6,7,8,9,10,11]\n printLn $ halves [1..10]\n printLn $ halves [1]\n", "meta": {"hexsha": "969e6307bc11a5d241e8ca9baf25416f5601c8eb", "size": 1217, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/tdd/chapter10/01_Exercises.idr", "max_stars_repo_name": "pdani/idris-grin", "max_stars_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2019-06-06T10:35:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T08:48:30.000Z", "max_issues_repo_path": "test/tdd/chapter10/01_Exercises.idr", "max_issues_repo_name": "pdani/idris-grin", "max_issues_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-11-21T20:45:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T12:29:23.000Z", "max_forks_repo_path": "test/tdd/chapter10/01_Exercises.idr", "max_forks_repo_name": "pdani/idris-grin", "max_forks_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-14T13:14:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-07T06:20:45.000Z", "avg_line_length": 32.0263157895, "max_line_length": 99, "alphanum_fraction": 0.6327033689, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7455472888627616}} {"text": "import Data.Fin\nimport Data.List\nimport Data.Nat\nimport Data.SortedSet as S\nimport Data.String.Parser\nimport Data.Vect\n\nimport System.File\n\n\nNode : Type\nNode = (Nat, Nat)\n\n-- A Non empty grid\nGrid : Nat -> Type\nGrid n = Vect (S n) (Vect (S n) Node)\n\ngupdateAt : (Fin (S n), Fin (S n)) -> (Node -> Node) -> Grid n -> Grid n\ngupdateAt (x, y) f = updateAt y (updateAt x f)\n\ngindex : (Fin (S n), Fin (S n)) -> Grid n -> Node\ngindex (x, y) = index x . index y\n\ninf : Nat\ninf = 1000000\n\nparser : Parser (n ** Grid n)\nparser = do row <- some digit <* char '\\n'\n let n = length row\n Just v <- pure $ toVect n $ (,inf) . finToNat <$> row\n | Nothing => fail \"not length\"\n Yes ItIsSucc <- pure $ isItSucc n\n | No _ => fail \"Row is zero\"\n vs <- ntimes (pred n) (((map ((,inf) . finToNat)) <$> ntimes n digit) <* char '\\n')\n pure $ MkDPair (pred n) (v :: vs)\n\n\ndecFin : Fin n -> Maybe (Fin n)\ndecFin FZ = Nothing\ndecFin (FS x) = Just $ weaken $ x\nincFin : {n : Nat} -> Fin n -> Maybe (Fin n)\nincFin f = strengthen $ shift 1 f\n\nneighbours : {n : Nat} -> (Fin n, Fin n) -> List (Fin n, Fin n)\nneighbours (x, y) = ((, y) <$> catMaybes [decFin x, incFin x]) ++\n ((x, ) <$> catMaybes [decFin y, incFin y])\n\nlowestRisk' : {n : Nat} -> List (Fin (S n), Fin (S n)) -> Grid n -> Grid n\nlowestRisk' [] g = g\nlowestRisk' ((x, y) :: queue) g = let (_, d) = gindex (x, y) g\n n = filter (\\p => let (v, t) = gindex p g in v + d < t) $ neighbours (x, y)\n ng = foldl (\\g' => \\p => gupdateAt p (\\(v, _) => (v, v + d)) g') g $ n\n nq = queue ++ n in\n lowestRisk' nq ng\n\nlowestRisk : {n : Nat} -> Grid n -> Grid n\nlowestRisk g = lowestRisk' ((0, 0) :: []) (gupdateAt (0, 0) (mapSnd (const 0)) g)\n\n\nwrapAdd : Nat -> Nat -> Nat\nwrapAdd 0 n = n\nwrapAdd (S k) n = if n == 9\n then wrapAdd k 1\n else wrapAdd k (S n)\n\nlargerRow : Vect (S n) (Nat, Nat) -> Vect (5 * (S n)) (Nat, Nat)\nlargerRow v = v ++ (concat $ ((\\a => mapFst (wrapAdd a) <$> v) <$> [1,2,3,4]))\n\nlargerColumn : Vect (S n) (Vect (5 * (S n)) (Nat, Nat)) -> Vect (5 * (S n)) (Vect (5 * (S n)) (Nat, Nat))\nlargerColumn v = v ++ (concat $ ((\\a => (mapFst (wrapAdd a) <$>) <$> v) <$> [1,2,3,4]))\n\nlargerGrid : Grid n -> Grid (pred (5 * (S n)))\nlargerGrid g = let rowextended = largerRow <$> g in\n largerColumn rowextended\n\nrun : String -> IO ()\nrun s = do Right (MkDPair n g, _) <- pure $ parse parser s\n | Left err => putStrLn $ show err\n let g = lowestRisk $ largerGrid g\n putStrLn $ show $ snd $ gindex (last, last) g\n\nmain : IO ()\nmain = do Right s <- readFile \"input.txt\"\n | Left err => putStrLn $ show err\n run s\n\n", "meta": {"hexsha": "efec343df863442e587f9dd17fb80b2f638e64aa", "size": 2898, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "15/Main.idr", "max_stars_repo_name": "Olavhaasie/aoc-2021", "max_stars_repo_head_hexsha": "0a0b293bd9c41da785f4a1a0207a72a823944b1c", "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": "15/Main.idr", "max_issues_repo_name": "Olavhaasie/aoc-2021", "max_issues_repo_head_hexsha": "0a0b293bd9c41da785f4a1a0207a72a823944b1c", "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": "15/Main.idr", "max_forks_repo_name": "Olavhaasie/aoc-2021", "max_forks_repo_head_hexsha": "0a0b293bd9c41da785f4a1a0207a72a823944b1c", "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.3103448276, "max_line_length": 113, "alphanum_fraction": 0.5010351967, "num_tokens": 950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7453592009558636}} {"text": "module With\n\nimport Data.Vect\n\nfilter' : (a -> Bool) -> Vect n a -> (p ** Vect p a)\nfilter' f [] = (_ ** [])\nfilter' f (x :: xs) =\n let (_ ** xs') = filter' f xs\n in if f x\n then (_ ** x :: xs')\n else (_ ** xs')\n\nfilter'' : (a -> Bool) -> Vect n a -> (p ** Vect p a)\nfilter'' f [] = (_ ** [])\nfilter'' f (x :: xs) with (filter'' f xs)\n | (_ ** xs') = if f x then (_ ** x :: xs') else (_ ** xs')\n\n\n-- similar to view pattern in haskell?\n-- https://ghc.haskell.org/trac/ghc/wiki/ViewPatterns#Basicviewpatterns\n\n\ndata Parity : Nat -> Type where\n Even : Parity (n + n)\n Odd : Parity (S (n + n))\n\nparity : (n : Nat) -> Parity n\nparity Z = Even {n = Z}\nparity (S Z) = Odd {n = Z}\nparity (S (S k)) = ?incomplete\n-- parity (S (S k)) with (parity k)\n-- parity (S (S (j + j))) | Even = Even { n = S j }\n-- parity (S (S (S (j + j)))) | Odd = Odd { n = S j }\n -- don't know how to go futher, the error message shows it cannot prove:\n -- (S j) + (S j) ~ S (S (j + j))\n\n\n-- `with' syntax can be used to further decompose (pattern matchin) on the\n-- parameter with respect to the result of an expression\n\nnatToBin : Nat -> List Bool\nnatToBin Z = Nil\nnatToBin k with (parity k)\n natToBin (j + j) | Even = False :: natToBin j\n natToBin (S (j + j))| Odd = True :: natToBin j\n", "meta": {"hexsha": "c4f940f50bafe74432cee88633b17eda85174084", "size": 1289, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-tutorial/with.idr", "max_stars_repo_name": "shouya/thinking-dumps", "max_stars_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-14T17:18:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:02:15.000Z", "max_issues_repo_path": "idris-tutorial/with.idr", "max_issues_repo_name": "shouya/thinking-dumps", "max_issues_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-06-14T06:07:33.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-04T22:05:11.000Z", "max_forks_repo_path": "idris-tutorial/with.idr", "max_forks_repo_name": "shouya/thinking-dumps", "max_forks_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-12-02T02:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-03T06:32:26.000Z", "avg_line_length": 28.0217391304, "max_line_length": 74, "alphanum_fraction": 0.5461598138, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.745093441190636}} {"text": "module Math.Algebra.Quantum.Qubit\n\nimport public Data.Fin\nimport public Data.Vect\nimport public Data.Matrix\nimport public Data.Matrix.Algebraic\n--import public Data.Matrix.Numeric\nimport public Data.Complex\n\nimport public Control.Algebra\nimport public Control.Algebra.VectorSpace\n\n%access public export\n%default total\n\nC : Type\nC = Complex Double\n\n-- Euler\ne : Double\ne = exp 1\n\n-- Imaginary unit\ni : C\ni = 0:+1\n\n-- Complex Pi\npii : C \npii = pi:+0\n\n-- Complex exponentiation\nexpi : C -> C\nexpi z = \n let es = exp $ realPart z in \n es * (cos $ imagPart z) :+ es * (sin $ imagPart z) \n\n\n-- WIP\n-- really to enforce conjugate transpose we need to have a 1-col matrix\n-- and a 1-row matrix as a Bra i.e. \n-- Ket = Matrix 2 1 C\n-- Bra = Matrix 1 2 C\n-- them implement all the Semigroup/Monoid/Group/InnerProductSpace etc. instances for these\n-- along with interfaces for (ant general matrix classes, definite, normal, semi-definite etc.?)\n-- Operator = Matrix 2 2 C\n-- Unitary : Operator where ... \n-- Hermitian : Unitary where ... \n\n-- in some sense a vector is a linear transformation anyway especially when\n-- you consider dot product as linear transformation to 1-d field\n-- hermitian = dagger = adjoint\n\n\nmmap : (a -> a) -> Matrix n m a -> Matrix n m a\nmmap = map . map\n\n-- TODO instead of aliases we should define new types and classes\n\nKet : Type\nKet = Matrix 2 1 C\n\nBra: Type\nBra = Matrix 1 2 C\n\nket : C -> C -> Ket\nket a b = [[a], [b]]\n\nbra : C -> C -> Bra\nbra a b = [[a, b]]\n\nqubit : C -> C -> Ket\nqubit = ket\n\none : Ket\none = qubit (0:+0) (1:+0)\n\nzero : Ket\nzero = qubit (1:+0) (0:+0)\n\n\nbra2ket : Bra -> Ket\nbra2ket b = Data.Vect.transpose $ mmap conjugate b\n\nket2bra : Ket -> Bra\nket2bra k = Data.Vect.transpose $ mmap conjugate k\n\n\n--\n\nOperator : Type\nOperator = Matrix 2 2 C\n\n\nId : Operator\nId = [[1:+0, 0:+0], [0:+0, 1:+0]]\n\n\n\n{- \nData.Matrix.Agebraic now takes care of these implementations\n\n[AddComplexSemigroup] Semigroup C where\n (<+>) z w = z + w\n\n[MulComplexSemigroup] Semigroup C where\n (<+>) z w = z * w\n\n[AddComplexMonoid] Monoid C using AddComplexSemigroup where\n neutral = 0:+0\n\n[MulComplexMonoid] Monoid C using MulComplexSemigroup where\n neutral = 1:+0\n \nGroup C using MulComplexMonoid where\n inverse z = 1 / z\n\nAbelianGroup C where { }\n\nRing C where\n (<.>) z w = z * w\n\nRingWithUnity C where\n unity = 1:+0\n \n\n-- Kets upto InnerProductSpace\n\nSemigroup Ket where\n (<+>) u v = zipWith (+) u v \n\nMonoid Ket where\n neutral = [0:+0, 0:+0]\n\n\nGroup Ket where \n inverse u = map (1 /) u\n\n\nAbelianGroup Ket where { }\n\n\nModule C Ket where\n (<#>) c v = map (* c) v\n\n-}\n\n{-\nInnerProductSpace C Ket where \n (<||>) u v = sum $ zipWith (*) u v\n \n\ntest : C\ntest = one <||> one\n-}\n\n\n\n\n\n-- Local Variables:\n-- idris-load-packages: (\"base\" \"contrib\")\n-- End:\n", "meta": {"hexsha": "0e8d5b57d672bf556779042d2208f8d92d504167", "size": 2781, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Math/Algebra/Quantum/QubitV.idr", "max_stars_repo_name": "sebeaumont/hilbert", "max_stars_repo_head_hexsha": "1f9017ae3f805ba120bf02c7104a71a0f0b66c67", "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/Math/Algebra/Quantum/QubitV.idr", "max_issues_repo_name": "sebeaumont/hilbert", "max_issues_repo_head_hexsha": "1f9017ae3f805ba120bf02c7104a71a0f0b66c67", "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/Math/Algebra/Quantum/QubitV.idr", "max_forks_repo_name": "sebeaumont/hilbert", "max_forks_repo_head_hexsha": "1f9017ae3f805ba120bf02c7104a71a0f0b66c67", "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.0613496933, "max_line_length": 96, "alphanum_fraction": 0.656238763, "num_tokens": 885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7450521402139979}} {"text": "-- module Main\n\ndata N = Zero | Suc N\n \naddOne : N -> N\naddOne Zero = Suc Zero\naddOne (Suc n) = Suc (Suc n)\n\nOne : N\nOne = Suc Zero\nTwo : N\nTwo = (Suc (Suc Zero))\nThree : N\nThree = addOne Two\nFour : N\nFour = addOne Three\nFive : N\nFive = addOne Four\n\n\nadd : N -> N -> N\nadd Zero s = s\nadd (Suc a) b = add a (Suc b)\n\ndata Vec : (a : Type) -> N -> Type where\n Nil : Vec a Zero\n Cons : {n : N} -> a -> Vec a n -> Vec a (Suc n)\n\nempt : Vec N Zero\nempt = Nil\n\ntest : Vec N Two\ntest = Cons One (Cons Two Nil)\n\ntest2 : Vec N Three\ntest2 = Cons Three (Cons Four (Cons Five Nil))\n\nconcat : {g : Type} -> {a : N} -> {b : N} -> Vec g a -> Vec g b -> Vec g (add a b)\nconcat Nil rest = rest\nconcat (Cons a rest) b = concat rest (Cons a b)\n\nt3 : Vec N (addOne (addOne (addOne (addOne One))))\nt3 = concat test test2\n", "meta": {"hexsha": "f21e681e3b196813b0e9397ee5dcf79ef80d791c", "size": 803, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "simpleIdris.idr", "max_stars_repo_name": "hjorthjort/IdrisToAgda", "max_stars_repo_head_hexsha": "a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-16T23:22:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-29T20:42:43.000Z", "max_issues_repo_path": "simpleIdris.idr", "max_issues_repo_name": "hjorthjort/IdrisToAgda", "max_issues_repo_head_hexsha": "a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-28T17:52:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-28T17:52:42.000Z", "max_forks_repo_path": "simpleIdris.idr", "max_forks_repo_name": "hjorthjort/IdrisToAgda", "max_forks_repo_head_hexsha": "a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-27T16:25:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-27T16:25:18.000Z", "avg_line_length": 18.25, "max_line_length": 82, "alphanum_fraction": 0.5853051059, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7450521327298827}} {"text": "\nmodule FinCmp\n\n-- Decidable comparison of finite numbers less \n-- than a given bound (i.e. \"ordinals\").\n\n\nimport public Data.Fin\n\n\n%default total\n%access public export\n\n\n-------------------------------------------\n-- Begin: DECIDABLE COMPARISONS OF ORDINALS\n\n-- Data type for evidence that \"i < j\".\ndata FinLT : Fin n -> Fin n -> Type where\n LtZ : FinLT FZ (FS i)\n LtS : FinLT i j -> FinLT (FS i) (FS j)\n\n\n-- Simplified symtax:\ninfixl 6 :<:\n(:<:) : Fin n -> Fin n -> Type\n(:<:) = FinLT\n\n\n-- Data type for evidence of which of the\n-- following holds between ordinals 'i' and 'j':\n--\n-- (a) i < j\n-- (b) i = j\n-- (c) i < j\n--\ndata FinCMP : Fin n -> Fin n -> Type where\n CmpEq : (i = j) -> FinCMP i j\n CmpLt : i :<: j -> FinCMP i j\n CmpGt : j :<: i -> FinCMP i j \n\n\n-- Function 'finNotLtZ' yields a proof of the following:\n--\n-- \"There is no ordinal less than zero.\"\n-- (In other words, given a proof that 'i' is\n-- less than zero, the function 'finNotLtZ' yields\n-- a member of the uninhabited type 'Void'.)\n--\nfinNotLtZ : i :<: FZ -> Void\nfinNotLtZ _ impossible\n\n\n-- Function 'finCmpDec' decides whether\n--\n-- (a) i < j, or \n-- (b) i = j, or\n-- (c) i > j holds,\n--\n-- and yields evidence in the form of a value\n-- of type 'FinCMP i j'.\nfinCmpDec : (i : Fin n) -> (j : Fin n) -> (FinCMP i j)\nfinCmpDec i j = case i of\n FZ => case j of\n FZ => CmpEq Refl\n FS j' => CmpLt LtZ\n FS i' => case j of\n FZ => CmpGt LtZ\n FS j' => case finCmpDec i' j' of\n CmpEq eq => CmpEq (rewrite eq in Refl)\n CmpLt lt => CmpLt (LtS lt)\n CmpGt lt => CmpGt (LtS lt) \n\n\n-- Function 'finLtPred' yields a proof of the following:\n--\n-- \"Given (FS i) < (FS j)m then i < j\".\n--\nfinLtPred : (FS i) :<: (FS j) -> i :<: j\nfinLtPred lt = case lt of LtS lt' => lt'\n\n-- End: DECIDABLE COMPARISONS OF ORDINALS\n-----------------------------------------\n", "meta": {"hexsha": "e5d9f4c296cf829b62647282510a5d05371878c2", "size": 2003, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "typed/src/FinCmp.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "typed/src/FinCmp.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "typed/src/FinCmp.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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.8452380952, "max_line_length": 68, "alphanum_fraction": 0.5227159261, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308054739519, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.7450521201424757}} {"text": "import Decidable.Equality\n\ndata DivisiblebyX : Nat -> Nat -> Type where\n Base: DivisiblebyX x x\n Multiple: DivisiblebyX x y -> DivisiblebyX x (x+y)\n\ndata FizzBuzzProof: Nat -> Type where\n Fizz: DivisiblebyX 3 x -> (DivisiblebyX 5 x -> Void) -> FizzBuzzProof x\n Buzz: DivisiblebyX 5 x -> (DivisiblebyX 3 x -> Void) -> FizzBuzzProof x\n FizzBuzz: DivisiblebyX 3 x -> DivisiblebyX 5 x -> FizzBuzzProof x\n Normal: (x: Nat) -> (DivisiblebyX 3 x -> Void) ->(DivisiblebyX 5 x -> Void) -> FizzBuzzProof x\n\nShow (FizzBuzzProof x) where\n show (Fizz _ _) = \"fizz\"\n show (Buzz _ _) = \"buzz\"\n show (FizzBuzz _ _) = \"fizzbuzz\"\n show (Normal x _ _) = show x\n\nthreeLessNotDivisible3 : (notdiv : DivisiblebyX 3 (S y) -> Void) -> DivisiblebyX 3 (3 + (S y)) -> Void\nthreeLessNotDivisible3 notdiv (Multiple x) = notdiv x\n\nzeroNotDivisible3 : DivisiblebyX 3 0 -> Void\nzeroNotDivisible3 Base impossible\nzeroNotDivisible3 (Multiple _) impossible\n\noneNotDivisible3 : DivisiblebyX 3 1 -> Void\noneNotDivisible3 Base impossible\noneNotDivisible3 (Multiple _) impossible\n\ntwoNotDivisible3 : DivisiblebyX 3 2 -> Void\ntwoNotDivisible3 Base impossible\ntwoNotDivisible3 (Multiple _) impossible\n\ndivisibleby3: (y: Nat) -> Dec (DivisiblebyX 3 y)\ndivisibleby3 Z = No zeroNotDivisible3\ndivisibleby3 (S Z) = No oneNotDivisible3\ndivisibleby3 (S (S Z)) = No twoNotDivisible3\ndivisibleby3 (S (S (S Z))) = Yes Base\ndivisibleby3 (S (S (S (S y)))) = case divisibleby3 (S y) of\n Yes prf => Yes (Multiple prf)\n No notdiv => No (threeLessNotDivisible3 notdiv)\n\nzeroNotDivisible5 : DivisiblebyX 5 0 -> Void\nzeroNotDivisible5 Base impossible\nzeroNotDivisible5 (Multiple _) impossible\n\noneNotDivisible5 : DivisiblebyX 5 1 -> Void\noneNotDivisible5 Base impossible\noneNotDivisible5 (Multiple _) impossible\n\ntwoNotDivisible5 : DivisiblebyX 5 2 -> Void\ntwoNotDivisible5 Base impossible\ntwoNotDivisible5 (Multiple _) impossible\n\nthreeNotDivisible5 : DivisiblebyX 5 3 -> Void\nthreeNotDivisible5 Base impossible\nthreeNotDivisible5 (Multiple _) impossible\n\nfourNotDivisible5 : DivisiblebyX 5 4 -> Void\nfourNotDivisible5 Base impossible\nfourNotDivisible5 (Multiple _) impossible\n\nfiveLessNotDivisible5 : (notdiv : DivisiblebyX (fromInteger 5) (S y) -> Void) -> DivisiblebyX 5 (S (S (S (S (S (S y)))))) -> Void\nfiveLessNotDivisible5 notdiv (Multiple x) = notdiv x\n\ndivisibleby5: (y: Nat) -> Dec (DivisiblebyX 5 y)\ndivisibleby5 Z = No zeroNotDivisible5\ndivisibleby5 (S Z) = No oneNotDivisible5\ndivisibleby5 (S (S Z)) = No twoNotDivisible5\ndivisibleby5 (S (S (S Z))) = No threeNotDivisible5\ndivisibleby5 (S (S (S (S Z)))) = No fourNotDivisible5\ndivisibleby5 (S (S (S (S (S Z))))) = Yes Base\ndivisibleby5 (S (S (S (S (S (S y)))))) = case divisibleby5 (S y) of\n Yes prf => Yes (Multiple prf)\n No notdiv => No (fiveLessNotDivisible5 notdiv)\n\nfizzbuzz: (x: Nat) -> FizzBuzzProof x\nfizzbuzz x = case (divisibleby3 x, divisibleby5 x) of\n (No not_fizz, No not_buzz) => Normal x not_fizz not_buzz\n (Yes fizz_prf, Yes buzz_prf) => FizzBuzz fizz_prf buzz_prf\n (No not_fizz, Yes buzz_prf) => Buzz buzz_prf not_fizz\n (Yes fizz_prf, No not_buzz) => Fizz fizz_prf not_buzz\n\nfizzbuzz_string: (x: Nat) -> String\nfizzbuzz_string x = show $ fizzbuzz x\n\n\nfizzbuzz_loop: (n: Nat) -> (end: Nat) -> IO ()\nfizzbuzz_loop n end with (decEq n end)\n fizzbuzz_loop n end | Yes prf = pure ()\n fizzbuzz_loop n end | No contra = do\n putStrLn $ show $ fizzbuzz n\n fizzbuzz_loop (S n) end\n\nmain: IO ()\nmain = fizzbuzz_loop 1 101\n", "meta": {"hexsha": "81129ec020a427c536a4b3c9ab7e9c14761f3649", "size": 3460, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "full_proof.idr", "max_stars_repo_name": "magpie-engineering/provable_fizz_buzz", "max_stars_repo_head_hexsha": "a8920e9ce196bb69f9ba256fdd0b7ba0e3eaf7e1", "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": "full_proof.idr", "max_issues_repo_name": "magpie-engineering/provable_fizz_buzz", "max_issues_repo_head_hexsha": "a8920e9ce196bb69f9ba256fdd0b7ba0e3eaf7e1", "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": "full_proof.idr", "max_forks_repo_name": "magpie-engineering/provable_fizz_buzz", "max_forks_repo_head_hexsha": "a8920e9ce196bb69f9ba256fdd0b7ba0e3eaf7e1", "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": 35.6701030928, "max_line_length": 129, "alphanum_fraction": 0.7280346821, "num_tokens": 1210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7449876327228455}} {"text": "import Data.Fin\n\ndata Graph : Nat -> Type where\n Empty : Graph Z\n Node : Bool -> Graph (S Z)\n Combine : (Fin (S n) -> Fin (S m) -> Bool) -> Graph (S n) -> Graph (S m) -> Graph (S n + S m)\n\ncombine : {n:Nat} -> {m:Nat} -> (Fin n -> Fin m -> Bool) -> Graph n -> Graph m -> Graph (n+m)\ncombine {n=n} _ a Empty = rewrite plusZeroRightNeutral n in a\ncombine {m=m} _ Empty b = b\ncombine {n=S n} {m=S m} f a b = Combine f a b\n\nf : Bool -> Fin n -> Fin m -> Bool\nf a _ _ = a\n\noverlay : Graph n -> Graph m -> Graph (n+m)\noverlay a b = combine (f False) a b\n\nconnect : Graph n -> Graph m -> Graph (n+m)\nconnect a b = combine (f True) a b\n\nunconnected : (n : Nat) -> Graph n\nunconnected Z = Empty\nunconnected (S n) = overlay (Node False) (unconnected n)\n\nclique : (n : Nat) -> Graph n\nclique Z = Empty\nclique (S n) = connect (Node True) (clique n)\n", "meta": {"hexsha": "985077c1cb527ac2bbb3520984233738f95e9925", "size": 840, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/Graph.idr", "max_stars_repo_name": "Mathnerd314/stroscot", "max_stars_repo_head_hexsha": "4bb8421c8a44facf8ed43749691fa881eeb82c55", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-03-28T06:08:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:07:49.000Z", "max_issues_repo_path": "tests/Graph.idr", "max_issues_repo_name": "Mathnerd314/stroscot", "max_issues_repo_head_hexsha": "4bb8421c8a44facf8ed43749691fa881eeb82c55", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-14T15:45:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-28T16:44:57.000Z", "max_forks_repo_path": "tests/Graph.idr", "max_forks_repo_name": "Mathnerd314/stroscot", "max_forks_repo_head_hexsha": "4bb8421c8a44facf8ed43749691fa881eeb82c55", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-24T03:00:55.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-24T03:00:55.000Z", "avg_line_length": 28.9655172414, "max_line_length": 95, "alphanum_fraction": 0.5928571429, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545289551957, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7445938875961055}} {"text": "import Data.Vect\n\ninputs : Vect 4 Double\ninputs = [1.0, 2.0, 3.0, 2.5]\n\nweights : Vect 3 (Vect 4 Double)\nweights = [[0.2, 0.8, -0.5, 1.0], [0.5, -0.91, 0.26, -0.5], [-0.26, -0.27, 0.17, 0.87]]\n\nbiases : Vect 3 Double\nbiases = [2.0, 3.0, 0.5]\n\n-- NOTE: match numpy interface in the spirit of the Python lesson\ndotProduct : Vect n (Vect m Double) -> \n Vect m Double -> \n Vect n Double\ndotProduct xss ys = map (\\xs => sum $ zipWith (*) xs ys) xss\n\n-- add the biases to the results of the dot product\noutput : Vect 3 Double\noutput = zipWith (+) (dotProduct weights inputs) biases \n\nmain : IO ()\nmain = printLn output\n", "meta": {"hexsha": "f3a99cfe3660d693947280ca1ddd6874fe4216f3", "size": 637, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/p003-Dot-Product.idr", "max_stars_repo_name": "witt3rd/NNfSiX", "max_stars_repo_head_hexsha": "b7dcfd6d74bf3dcc1847edb95ffc02dd2a6169cb", "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": "Idris/p003-Dot-Product.idr", "max_issues_repo_name": "witt3rd/NNfSiX", "max_issues_repo_head_hexsha": "b7dcfd6d74bf3dcc1847edb95ffc02dd2a6169cb", "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": "Idris/p003-Dot-Product.idr", "max_forks_repo_name": "witt3rd/NNfSiX", "max_forks_repo_head_hexsha": "b7dcfd6d74bf3dcc1847edb95ffc02dd2a6169cb", "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.5416666667, "max_line_length": 87, "alphanum_fraction": 0.6138147567, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7445908059240373}} {"text": "module EqNat\n\n%default total\n\ndata EqNat : (num1 : Nat) -> (num2 : Nat) -> Type where\n Same : (num : Nat) -> EqNat num num\n\nsameS : (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS (Same k) = Same (S k)\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat Z Z = Just (Same Z)\ncheckEqNat Z _ = Nothing\ncheckEqNat _ Z = Nothing\ncheckEqNat (S k) (S l) = case checkEqNat k l of\n Nothing => Nothing\n Just eq => Just (sameS eq)\n", "meta": {"hexsha": "84794bf2dea3e79e6d0202689b81152f66fb79c7", "size": 505, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter8/EqNat.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter8/EqNat.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": "chapter8/EqNat.idr", "max_forks_repo_name": "timmyjose-study/tdd-with-idris", "max_forks_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": 28.0555555556, "max_line_length": 68, "alphanum_fraction": 0.5524752475, "num_tokens": 167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7439828890999289}} {"text": "\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a-> Vect k a-> Vect (S k) a\n\n(++) : Vect n a -> Vect m a -> Vect (n+m) a\n(++) Nil ys =ys\n(++) (x::xs) ys = x :: xs ++ ys\n\ndata Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k) \n\nindex : Fin n -> Vect n a -> a\nindex FZ (x::xs) = x\nindex (FS k) (x::xs) = index k xs\n\n\nisEmpty : Vect n a -> Bool\nisEmpty {n=Z} _ = True\nisEmpty {n=S k} _ = False\n\n1::(2::(3::Nil)) : Vect 3 Integer", "meta": {"hexsha": "75e734f9c2cd2045453d83737e6e0a083e68d3b7", "size": 468, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "fin.idr", "max_stars_repo_name": "shij-hsu/idr", "max_stars_repo_head_hexsha": "a51b6eb2c287dec6b051259e4f4da23d649f1d85", "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": "fin.idr", "max_issues_repo_name": "shij-hsu/idr", "max_issues_repo_head_hexsha": "a51b6eb2c287dec6b051259e4f4da23d649f1d85", "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": "fin.idr", "max_forks_repo_name": "shij-hsu/idr", "max_forks_repo_head_hexsha": "a51b6eb2c287dec6b051259e4f4da23d649f1d85", "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": 20.347826087, "max_line_length": 43, "alphanum_fraction": 0.4935897436, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7439464097190233}} {"text": "We start with a trivial language comtaining numbers and booleans.\n\n> import Math\n> import Data.List\n\n> data UntypedTerm : Type where\n> CTrue : UntypedTerm\n> CFalse : UntypedTerm\n> IfThenElse : UntypedTerm -> UntypedTerm -> UntypedTerm -> UntypedTerm\n> CZero : UntypedTerm\n> Succ : UntypedTerm -> UntypedTerm\n> Pred : UntypedTerm -> UntypedTerm\n> IsZero : UntypedTerm -> UntypedTerm\n\nWe can create a generator for such terms:\n\n> data UntypedTermGenerator : Nat -> List UntypedTerm -> Type where\n> GenEmpty : UntypedTermGenerator Z []\n> GenSucc : UntypedTermGenerator k xs -> UntypedTermGenerator (S k) ([CTrue,CFalse,CZero]) -- ++ (map ))\n\nThis generator in fact covers the UntypedTerms. First, we need a notion of the\nsize of a term\n\n> size : UntypedTerm -> Nat\n> size CTrue = 1\n> size CFalse = 1\n> size CZero = 1\n> size (Succ t) = S (size t)\n> size (Pred t) = S (size t)\n> size (IsZero t) = S (size t)\n> size (IfThenElse i t e) = S (plus (plus (size i) (size t)) (size e))\n\nSince the terms form a tree there is a notion of depth:\n\n> depth : UntypedTerm -> Nat\n> depth CTrue = 1\n> depth CFalse = 1\n> depth CZero = 1\n> depth (Succ t) = S (depth t)\n> depth (Pred t) = S (depth t)\n> depth (IsZero t) = S (depth t)\n> depth (IfThenElse i t e) = S (maximum (maximum (depth i) (depth t)) (depth e))--S (maximum (maximum( (depth i) (depth t))) (depth e))\n\nNow we can prove covering. We prove the equivalent result that for any Nat n and any UntypedTerm t with depth LTE n, then there exists an UntypedTermGenerator n xs such that Elem t xs.\n\n> generatorCovers : (t:UntypedTerm) -> (xs : List UntypedTerm ** ((UntypedTermGenerator (depth t) xs), (Elem t xs)))--((n:Nat ** (UntypedTermGenerator n xs)) ** (Elem t xs))\n> generatorCovers CTrue = ([CTrue,CFalse,CZero] ** (GenSucc GenEmpty,Here))\n> generatorCovers CFalse = ([CTrue,CFalse,CZero] ** (GenSucc GenEmpty,There (the (Elem CFalse [CFalse,CZero]) Here)))\n> generatorCovers (IfThenElse x y z) = ?generatorCovers_rhs_1\n> generatorCovers CZero = ([CTrue,CFalse,CZero] ** (GenSucc GenEmpty,There (There (the (Elem CZero [CZero]) Here))))\n> generatorCovers (Succ x) = ?generatorCovers_rhs_5\n> generatorCovers (Pred x) = ?generatorCovers_rhs_6\n> generatorCovers (IsZero x) = ?generatorCovers_rhs_7\n", "meta": {"hexsha": "61f71af73db32892e6668aee4026bbf11c71b6a7", "size": 2257, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "TaPL1/UntypedArithmetic.lidr", "max_stars_repo_name": "nicklecompte/CSLearning", "max_stars_repo_head_hexsha": "34fadc2d36068016cab66a4cc0e57c933f21c300", "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": "TaPL1/UntypedArithmetic.lidr", "max_issues_repo_name": "nicklecompte/CSLearning", "max_issues_repo_head_hexsha": "34fadc2d36068016cab66a4cc0e57c933f21c300", "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": "TaPL1/UntypedArithmetic.lidr", "max_forks_repo_name": "nicklecompte/CSLearning", "max_forks_repo_head_hexsha": "34fadc2d36068016cab66a4cc0e57c933f21c300", "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.7962962963, "max_line_length": 184, "alphanum_fraction": 0.6956136464, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7438476104586933}} {"text": "data Bool = False | True\ndata Nat = Z | S Nat\n\nnot : Bool -> Bool\nnot False = True\nnot True = False\n\nisZero : Nat -> Bool\nisZero Z = True\nisZero (S k) = False\n\nisOdd : Nat -> Bool\nisOdd Z = False\nisOdd (S k) = not (isOdd k)\n\ntestZ : Nat -> String\ntestZ x = if isZero x then \"Zero\" else\n if isOdd x then \"Odd\" else \"Even\"\n", "meta": {"hexsha": "bc30f441a19ca6aeb6031bc2cfda07b1f645a55e", "size": 333, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic008/If.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/basic008/If.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/basic008/If.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": 17.5263157895, "max_line_length": 46, "alphanum_fraction": 0.6126126126, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.7905303211371899, "lm_q1q2_score": 0.7437228239164431}} {"text": "module Minus\n\nimport Data.Nat\n\nplus_mult : (n, m, k : Nat) -> {auto km : k `LTE` m} -> n + (m `minus` k) = (m + n) `minus` k\nplus_mult n m Z = rewrite minusZeroRight m in\n rewrite minusZeroRight $ m + n in\n rewrite plusCommutative m n in\n Refl\nplus_mult n (S m) (S k) {km=LTESucc _} = plus_mult n m k\n\n%hint\npower2_ge_1 : (n : Nat) -> 1 `LTE` (2 `power` n)\npower2_ge_1 Z = LTESucc LTEZero\npower2_ge_1 (S n) = lteTransitive (power2_ge_1 n) $ lteAddRight (2 `power` n)\n", "meta": {"hexsha": "4adedda52a9e5ecaeab03b02d20c54e5bf5fe8ba", "size": 522, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Minus.idr", "max_stars_repo_name": "buzden/idris-playground", "max_stars_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-23T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T02:45:50.000Z", "max_issues_repo_path": "Minus.idr", "max_issues_repo_name": "buzden/idris-playground", "max_issues_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_issues_repo_licenses": ["CC0-1.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": "Minus.idr", "max_forks_repo_name": "buzden/idris-playground", "max_forks_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.625, "max_line_length": 93, "alphanum_fraction": 0.5842911877, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7433704758691454}} {"text": "module IntegerProofs\n\n%access public export\n%default total\n\n||| A decision procedure for `DecEq Integer`\n||| @ m the first number\n||| @ n the second number\nisEq : (m : Integer) -> (n : Integer) -> Dec (m = n)\nisEq m n = decEq m n\n\n||| Proofs that `m` is not equal to `n`\n||| @ m the first number\n||| @ n the second number\nNotEq : (m, n : Integer) -> Type\nNotEq m n = Not (m=n)\n\n||| Not (m = n) implies m /= n\nnotEqImpliesNotEq : (contra : (m = n) -> Void) -> ((m = n) -> Void)\nnotEqImpliesNotEq contra Refl = contra Refl\n\n||| (m = n) implies Not (m /= n)\neqImpliesNotNotEq : (prf : m = n) -> (((m = n) -> Void) -> Void)\neqImpliesNotNotEq Refl f = f Refl\n\n||| A decision procedure for `NotEq`\nisNotEq : (m : Integer) -> (n : Integer) -> Dec (NotEq m n)\nisNotEq m n = case (isEq m n) of\n (Yes prf) => No (eqImpliesNotNotEq prf)\n (No contra) => Yes (notEqImpliesNotEq contra)\n\nsmaller : (m : Integer) -> (n : Integer) -> Integer\nsmaller m n = case m <= n of\n False => n\n True => m\n\nsameIntegerCheckPrf : (prf : m = n) -> (n : Integer) -> Integer\nsameIntegerCheckPrf Refl n = n\n\nsameInteger : (m : Integer) -> (n : Integer) -> (m=n) -> Integer\nsameInteger m n prf = sameIntegerCheckPrf prf n\n\nisTrue : (b : Bool) -> Dec (b = True)\nisTrue b = decEq b True\n\nisFalse : (b : Bool) -> Dec (b = False)\nisFalse b = decEq b False\n", "meta": {"hexsha": "470005ffe14e6d2b017a584f5242094b8111f877", "size": 1390, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "IntegerProofs.idr", "max_stars_repo_name": "zenntenn/Idris-NumericProofs", "max_stars_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": "IntegerProofs.idr", "max_issues_repo_name": "zenntenn/Idris-NumericProofs", "max_issues_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": "IntegerProofs.idr", "max_forks_repo_name": "zenntenn/Idris-NumericProofs", "max_forks_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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.9583333333, "max_line_length": 67, "alphanum_fraction": 0.5827338129, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138559, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7432929763201848}} {"text": "||| Implementing `Decidable.Order.Strict` for `Data.Nat.LT`\nmodule Data.Nat.Order.Strict\n\nimport Data.Nat\nimport Decidable.Order.Strict\nimport Decidable.Equality\nimport Data.Nat.Order\n\n%default total\n\npublic export\nIrreflexive Nat LT where\n irreflexive {x = 0} _ impossible\n irreflexive {x = S _} (LTESucc prf) =\n irreflexive {rel = Nat.LT} prf\n\npublic export\nTransitive Nat LT where\n transitive {x} {y} xy yz =\n transitive {rel = LTE} (lteSuccRight xy) yz\n\npublic export\nStrictPreorder Nat LT where\n\npublic export\ndecLT : (a, b : Nat) -> DecOrdering {lt = LT} a b\ndecLT 0 0 = DecEQ Refl\ndecLT 0 (S b) = DecLT (LTESucc LTEZero)\ndecLT (S a) 0 = DecGT (LTESucc LTEZero)\ndecLT (S a) (S b) = case decLT a b of\n DecLT a_lt_b => DecLT (LTESucc a_lt_b)\n DecEQ Refl => DecEQ Refl\n DecGT b_lt_a => DecGT (LTESucc b_lt_a)\n\npublic export\nStrictOrdered Nat LT where\n order = decLT\n", "meta": {"hexsha": "c6bbfa600c737c861c44af7860cffdda75de1123", "size": 900, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Nat/Order/Strict.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": "libs/contrib/Data/Nat/Order/Strict.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": "libs/contrib/Data/Nat/Order/Strict.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": 23.6842105263, "max_line_length": 59, "alphanum_fraction": 0.7011111111, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7432929716224668}} {"text": "data MyNat = Zero | Succ MyNat\n\ntotal mynat_plus : MyNat -> MyNat -> MyNat\nmynat_plus Zero m = m\nmynat_plus (Succ k) m = Succ (mynat_plus k m)\n\n-- proving that 0 + a = a\ntotal first_proof : (a: MyNat) -> mynat_plus Zero a = a\nfirst_proof a = Refl\n\n-- proving that there exists an x such that Succ x exists\n-- we are basically constructing a dependent pair of (x, Succ x)\n-- that is accomplished with the DPair type\ntotal second_proof : MyNat -> DPair MyNat (\\_ => MyNat)\nsecond_proof x = MkDPair x (Succ x)\n\ndata MyLTE : MyNat -> MyNat -> Type where\n MyLTEZero : MyLTE Zero right\n MyLTESucc : MyLTE left right -> MyLTE (Succ left) (Succ right)\n\n-- proving that a + 0 = a\n-- using induction here\n-- what we do it rewrite the induction hypothesis\ntotal third_proof : (a: MyNat) -> mynat_plus a Zero = a\nthird_proof Zero = Refl\nthird_proof (Succ x) = rewrite (third_proof x) in Refl\n", "meta": {"hexsha": "07103c2288aae76c37ec10fcc44296721ab49c05", "size": 882, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "gitdi-book/nats/nats.idr", "max_stars_repo_name": "Nimor111/idris-exercises", "max_stars_repo_head_hexsha": "1ce01cf9367d6958200847fdcb4c1b3b84c9a657", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gitdi-book/nats/nats.idr", "max_issues_repo_name": "Nimor111/idris-exercises", "max_issues_repo_head_hexsha": "1ce01cf9367d6958200847fdcb4c1b3b84c9a657", "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": "gitdi-book/nats/nats.idr", "max_forks_repo_name": "Nimor111/idris-exercises", "max_forks_repo_head_hexsha": "1ce01cf9367d6958200847fdcb4c1b3b84c9a657", "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": 32.6666666667, "max_line_length": 64, "alphanum_fraction": 0.7063492063, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813501370535, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7430841707471255}} {"text": "data Expr num = Val num\n | Add (Expr num) (Expr num)\n | Sub (Expr num) (Expr num)\n | Mul (Expr num) (Expr num)\n | Div (Expr num) (Expr num)\n | Abs (Expr num)\n\neval : (Neg num, Integral num) => Expr num -> num\neval (Val x) = x\neval (Add x y) = eval x + eval y\neval (Sub x y) = eval x - eval y\neval (Mul x y) = eval x * eval y\neval (Div x y) = eval x `div` eval y\neval (Abs x) = abs (eval x)\n\nNum ty => Num (Expr ty) where\n (+) = Add\n (*) = Mul\n fromInteger = Val . fromInteger\n\nNeg ty => Neg (Expr ty) where\n negate x = 0 - x\n (-) = Sub\n abs = Abs\n\n-- Exercise 1\n\nshowOp : Show a => String -> a -> a -> String\nshowOp op x y = \"(\" ++ show x ++ op ++ show y ++ \")\"\n\nShow ty => Show (Expr ty) where\n show (Val x) = show x\n show (Add x y) = showOp \" + \" x y\n show (Sub x y) = showOp \" - \" x y\n show (Mul x y) = showOp \" * \" x y\n show (Div x y) = showOp \" / \" x y\n show (Abs x) = \"abs \" ++ show x\n\n-- Exercise 2\n\n(Neg a, Integral a, Eq a) => Eq (Expr a) where\n (==) x y = eval x == eval y\n\n-- Exercise 3\n\n(Neg num, Integral num) => Cast (Expr num) num where\n cast orig = eval orig\n", "meta": {"hexsha": "00910bce464c9e35c5eddb823f56190ec6c15dad", "size": 1182, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter07/Exercises/ex_7_2.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter07/Exercises/ex_7_2.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter07/Exercises/ex_7_2.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.625, "max_line_length": 52, "alphanum_fraction": 0.5084602369, "num_tokens": 405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7427299054609816}} {"text": "module Order\n\ndata InclusiveEither : (typeLeft : Type) -> (typRight : Type) -> Type where\n\tOnlyLeft : typLeft -> Not typRight -> InclusiveEither typLeft typRight\n\tOnlyRight : Not typLeft -> typRight -> InclusiveEither typLeft typRight\n\tBoth : typLeft -> typRight -> InclusiveEither typLeft typRight\n\n|||Type of proof that a relation is reflexive\nisReflexive : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisReflexive {typ} r = (a : typ) -> (r a a)\n\n|||Type of proof that a relation is symmetric\nisSymmetric : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisSymmetric {typ} r = (a : typ) -> (b : typ) -> (r a b) -> (r b a)\n\n|||Type of proof that a relation is anti-symmetric\nisAntiSymmetric : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisAntiSymmetric {typ} r = (a : typ) -> (b : typ) -> (r a b) -> (r b a) -> (a = b)\n\n|||Type of proof that a relation is transitive\nisTransitive : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisTransitive {typ} r = (a : typ) -> (b : typ) -> (c : typ) -> (r a b) -> (r b c) -> (r a c)\n\n|||Type of proof that a relation is an equivalence\nisEquivalence : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisEquivalence {typ} r = (isReflexive r, isSymmetric r, isTransitive r)\n\n|||Type of proof that a relation is a partial order\nisPartialOrder : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisPartialOrder {typ} r = (isReflexive r, isAntiSymmetric r, isTransitive r)\n\n|||Type of proof that a relation is a total order\nisTotalOrder : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisTotalOrder {typ} r = (isPartialOrder r, (a : typ) -> (b : typ) -> (InclusiveEither (r a b) (r b a)))\n", "meta": {"hexsha": "438d38ec46ee9e12eae3ea2342c4457896204f47", "size": 1649, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Order.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Order.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Order.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 47.1142857143, "max_line_length": 102, "alphanum_fraction": 0.6203759854, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7425732026644899}} {"text": "module equality\n\nimport Data.Vect\n\n-- 8.1.7 Exercises\nsame_cons : {xs : List a}\n -> {ys : List a}\n -> xs = ys\n -> x :: xs = x :: ys\nsame_cons Refl = Refl\n\n\nsame_lists : {xs : List a}\n -> {ys : List a}\n -> x = y\n -> xs = ys\n -> x :: xs = y :: ys\nsame_lists Refl Refl = Refl\n\n\ndata EqNat : (num1 : Nat) -> (num2 : Nat) -> Type where\n Same : (num : Nat) -> EqNat num num\n\n-- Functions as Proofs: Manipulating Equalities\nsameS : (k : Nat) -> (j : Nat) -> (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS j j (Same j) = Same (S j)\n\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat Z Z = Just (Same Z)\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Just eq => Just $ sameS _ _ eq\n Nothing => Nothing\n\n\ncheckEqNat' : (num1 : Nat) -> (num2 : Nat) -> Maybe (num1 = num2)\ncheckEqNat' Z Z = Just Refl\ncheckEqNat' Z (S k) = Nothing\ncheckEqNat' (S k) Z = Nothing\ncheckEqNat' (S k) (S j) = case checkEqNat' k j of\n Just eq => Just $ cong eq\n Nothing => Nothing\n\n\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case checkEqNat m len of\n Just (Same len) => Just input\n Nothing => Nothing\n\n\nreverseProof : Vect (k + 1) elem -> Vect (S k) elem\nreverseProof {k} ys = rewrite plusCommutative 1 k in ys\n\n\nmy_reverse : Vect n elem -> Vect n elem\nmy_reverse [] = []\nmy_reverse (x :: xs) = reverseProof (my_reverse xs ++ [x])\n", "meta": {"hexsha": "8f792450f6ebed9da50a8e130969ddb09c81dfec", "size": 1707, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "8-equality/equality.idr", "max_stars_repo_name": "prt2121/tdd-playground", "max_stars_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "8-equality/equality.idr", "max_issues_repo_name": "prt2121/tdd-playground", "max_issues_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": "8-equality/equality.idr", "max_forks_repo_name": "prt2121/tdd-playground", "max_forks_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": 28.45, "max_line_length": 71, "alphanum_fraction": 0.5166959578, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7425433550853421}} {"text": "module TypeDrivenDevelopment\n\n||| Map a list of strings to their length\nallLengths : List String -> List Nat\nallLengths xs = map length xs\n\n||| Negate a boolean\ninvert : (t : Bool) -> Bool\ninvert True = False\ninvert False = True\n\n||| Describe whether a list is empty or not\ndescribeList : List Int -> String\ndescribeList [] = \"Empty\"\ndescribeList (x :: xs) = \"Non-empty\"\n\nxor : Bool -> Bool -> Bool\nxor False y = y\nxor True y = not y\n\nmutual\n isEven : Nat -> Bool\n isEven Z = True\n isEven (S k) = isOdd k\n\n isOdd : Nat -> Bool\n isOdd Z = False\n isOdd (S k) = isEven k\n", "meta": {"hexsha": "8413c3f829e2b5a66f47d5bea299da747995e8db", "size": 574, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/3.1-TDD.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/3.1-TDD.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/3.1-TDD.idr", "max_forks_repo_name": "ostera/asdf", "max_forks_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "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": 19.7931034483, "max_line_length": 43, "alphanum_fraction": 0.6637630662, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.742294859717843}} {"text": "module Data.Group\n\nimport Data.Stream\n\n||| This extends 'Monoid' by defining an inverse for every element.\npublic export\ninterface (Monoid t) => Group t where\n inverse : t -> t\n\n||| Stream of elements starting at some given element.\npublic export\ngenerate : (Monoid g) => g -> Stream g\ngenerate g1 = neutral :: map (<+> g1) (generate g1)\n\n||| (Positive) integer exponentiation.\npublic export\nexp : (Monoid g) => (n : Nat) -> g -> g\nexp n g = Prelude.head (drop n (generate g))\n\n||| Whether a group element is idempotent\npublic export\ntotal\nidempotent : (Eq g, Semigroup g) => g -> Bool\nidempotent x = x == (x <+> x)\n\n||| Commutator of two elements.\npublic export\ntotal\ncommutator : (Group g) => g -> g -> g\ncommutator a b = inverse a <+> inverse b <+> a <+> b\n", "meta": {"hexsha": "7d7d5458d3f6421d8fe69d892ce90948f35ed9f9", "size": 761, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Group.idr", "max_stars_repo_name": "vmchale/permutations", "max_stars_repo_head_hexsha": "7a9f028382bf71da524f306125fb1e4c73d475d3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2017-11-13T07:31:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-26T08:02:30.000Z", "max_issues_repo_path": "Data/Group.idr", "max_issues_repo_name": "vmchale/permutation", "max_issues_repo_head_hexsha": "7a9f028382bf71da524f306125fb1e4c73d475d3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-11-29T19:29:03.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-09T23:12:04.000Z", "max_forks_repo_path": "Data/Group.idr", "max_forks_repo_name": "vmchale/permutation", "max_forks_repo_head_hexsha": "7a9f028382bf71da524f306125fb1e4c73d475d3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-28T11:46:17.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-20T07:29:50.000Z", "avg_line_length": 24.5483870968, "max_line_length": 67, "alphanum_fraction": 0.6649145861, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541528387691, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.741958675494421}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 7\n\n-- check that all functions are total\n%default total\n\n--\n-- Shapes and pictures\n--\n\n||| Represents shapes\ndata Shape = ||| A triangle, with its base length and height\n Triangle Double Double\n | ||| A rectangle, with its length and height\n Rectangle Double Double\n | ||| A circle with its radius\n Circle Double\n%name Shape shape, shape1, shape2\n\n||| Area of a shape\narea : Shape -> Double\narea (Triangle x y) = 0.5 * x * y\narea (Rectangle x y) = x * y\narea (Circle x) = pi * x * x\n\nEq Shape where\n (==) (Triangle x z) (Triangle x' z') = x == x' && z == z'\n (==) (Rectangle x z) (Rectangle x' z') = x == x' && z == z'\n (==) (Circle x) (Circle x') = x == x'\n (==) _ _ = False\n\nOrd Shape where\n compare x y = compare (area x) (area y)\n\ntestShapes : List Shape\ntestShapes = [Circle 3, Triangle 3 9, Rectangle 2 6, Circle 4, Rectangle 2 7]\n\n||| Represents pictures\ndata Picture = ||| A primitive shape\n Primitive Shape\n | ||| The combination of two pictures\n Combine Picture Picture\n | ||| The rotation of a picture, given the angle and the picture\n Rotate Double Picture\n | ||| The translation of a picture, given dx, dy, and the picture\n Translate Double Double Picture\n%name Picture pic, pic1, pic2\n\nrectangle : Picture\nrectangle = Primitive $ Rectangle 20 10\n\ncircle : Picture\ncircle = Primitive $ Circle 5\n\ntriangle : Picture\ntriangle = Primitive $ Triangle 10 10\n\ntestPicture : Picture\ntestPicture = Combine (Translate 5 5 rectangle)\n (Combine (Translate 35 5 circle)\n (Translate 15 25 triangle))\n\n||| Area of a picture\npictureArea : Picture -> Double\npictureArea (Primitive shape) = area shape\npictureArea (Combine pic pic1) = pictureArea pic + pictureArea pic1\npictureArea (Rotate x pic) = pictureArea pic\npictureArea (Translate x y pic) = pictureArea pic\n\n||| Computes the largest of two inputs or Nothing if both are Nothing\nmaxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe Nothing Nothing = Nothing\nmaxMaybe (Just x) Nothing = Just x\nmaxMaybe Nothing (Just y) = Just y\nmaxMaybe (Just x) (Just y) = Just (max x y)\n\n||| Biggest triangle\nbiggestTriangle : Picture -> Maybe Double\nbiggestTriangle (Primitive tri@(Triangle x y)) = Just (area tri)\nbiggestTriangle (Primitive (Rectangle x y)) = Nothing\nbiggestTriangle (Primitive (Circle x)) = Nothing\nbiggestTriangle (Combine pic1 pic2)\n = maxMaybe (biggestTriangle pic1) (biggestTriangle pic2)\nbiggestTriangle (Rotate x pic) = biggestTriangle pic\nbiggestTriangle (Translate x y pic) = biggestTriangle pic\n\ntestPic1 : Picture\ntestPic1 = Combine (Primitive (Triangle 2 3)) (Primitive (Triangle 2 4))\n\ntestPic2 : Picture\ntestPic2 = Combine (Primitive (Rectangle 1 3)) (Primitive (Circle 4))\n", "meta": {"hexsha": "efa3638c853acf607aba0d1fb3588e62e357bf0c", "size": 2920, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter7/Shape.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": "chapter7/Shape.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": "chapter7/Shape.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": 31.7391304348, "max_line_length": 78, "alphanum_fraction": 0.6630136986, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7418178025767452}} {"text": "module Data.Sign\n\n%access public export\n\n||| A representation of signs for signed datatypes such as `ZZ`\ndata Sign = Plus | Zero | Minus\n\nopposite : Sign -> Sign\nopposite Plus = Minus\nopposite Zero = Zero\nopposite Minus = Plus\n\nmultiply : Sign -> Sign -> Sign\nmultiply Zero _ = Zero\nmultiply _ Zero = Zero\nmultiply Plus x = x\nmultiply Minus x = opposite x\n\n||| Discover the sign of some type\ninterface Signed t where\n total sign : t -> Sign\n\nSigned Int where\n sign x with (compare x 0)\n | LT = Minus\n | EQ = Zero\n | GT = Plus\n\nSigned Integer where\n sign x with (compare x 0)\n | LT = Minus\n | EQ = Zero\n | GT = Plus\n\nSigned Double where\n sign x with (compare x 0.0)\n | LT = Minus\n | EQ = Zero\n | GT = Plus\n", "meta": {"hexsha": "2d35b509ed159b8e7de2a948779a1a5e817aa84c", "size": 753, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/Sign.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": "_local-site/Code/Sign.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": "_local-site/Code/Sign.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": 18.825, "max_line_length": 63, "alphanum_fraction": 0.636122178, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7416154709075788}} {"text": "module Matrix\n\n-- Based on https://dl.acm.org/doi/10.1145/3406088.3409019\n\nimport Data.Nat.DivMod\n\ndata Shape : Type where\n Zero : Shape\n One : Shape\n Plus : Shape -> Shape -> Shape\n\ndata Matrix : (e : Type) -> (c : Shape) -> (r : Shape) -> Type where\n Elem : e -> Matrix e One One\n Join : Matrix e a r -> Matrix e b r -> Matrix e (Plus a b) r\n Fork : Matrix e c a -> Matrix e c b -> Matrix e c (Plus a b)\n\n\nfromNat' : Nat -> Nat -> Shape\nfromNat' k Z = Zero\nfromNat' k (S Z) = One\nfromNat' Z n = Zero\nfromNat' (S k) n with (divMod n 1)\n fromNat' (S k) (remainder + (quotient * (S (S Z)))) | (MkDivMod quotient remainder remainderSmall) =\n let m = fromNat' k quotient in\n if remainder == Z then Plus m m else Plus One (Plus m m)\n\nfromNat : Nat -> Shape\nfromNat n = fromNat' 64 n\n\nabideJF : Matrix e cols rows -> Matrix e cols rows\nabideJF (Join (Fork a c) (Fork b d)) = Fork (Join (abideJF a) (abideJF b)) (Join (abideJF c) (abideJF d))\nabideJF (Elem e) = Elem e\nabideJF (Join a b) = Join (abideJF a) (abideJF b)\nabideJF (Fork a b) = Fork (abideJF a) (abideJF b)\n\nzipWithM : (e -> f -> g) -> Matrix e cols rows -> Matrix f cols rows -> Matrix g cols rows\nzipWithM f (Elem a) (Elem b) = Elem (f a b)\nzipWithM f (Join a b) (Join c d) = Join (zipWithM f a c) (zipWithM f b d)\nzipWithM f (Fork a b) (Fork c d) = Fork (zipWithM f a c) (zipWithM f b d)\nzipWithM f x@(Fork _ _) y@(Join _ _) = zipWithM f x (abideJF y)\nzipWithM f x@(Join _ _) y@(Fork _ _) = zipWithM f (abideJF x) y\n\ncomp : Num e => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows\ncomp (Elem a) (Elem b) = Elem (a * b)\ncomp (Join a b) (Fork c d) = zipWithM (+) (comp a c) (comp b d)\ncomp (Fork a b) c = Fork (comp a c) (comp b c)\ncomp c (Join a b) = Join (comp c a) (comp c b)\n\niden2x2 : Num e => Matrix e (fromNat 2) (fromNat 2)\niden2x2 = Fork (Join (Elem 1) (Elem 0))\n (Join (Elem 0) (Elem 1))\n", "meta": {"hexsha": "d14359503b4e00442db3f3788dc0ba8519c3569e", "size": 1893, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Matrix.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/Matrix.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/Matrix.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": 36.4038461538, "max_line_length": 105, "alphanum_fraction": 0.6191230851, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7415079175007536}} {"text": "> module SequentialDecisionProblems.examples.LeftAheadRight\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Sigma.Sigma\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n> ||| Left, Ahead or Right\n> data LeftAheadRight = Left | Ahead | Right\n\n> implementation Eq LeftAheadRight where\n> (==) Left Left = True\n> (==) Left _ = False\n> (==) Ahead Ahead = True\n> (==) Ahead _ = False\n> (==) Right Right = True\n> (==) Right _ = False\n\n> implementation Show LeftAheadRight where\n> show Left = \"L\"\n> show Ahead = \"A\"\n> show Right = \"R\"\n\nLeftAheadRight is finite:\n\n> to : LeftAheadRight -> Fin 3\n> to Left = FZ\n> to Ahead = FS FZ\n> to Right = FS (FS FZ)\n\n> from : Fin 3 -> LeftAheadRight\n> from FZ = Left\n> from (FS FZ) = Ahead\n> from (FS (FS FZ)) = Right\n> from (FS (FS (FS k))) = absurd k\n\n> toFrom : (k : Fin 3) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS FZ) = Refl\n> toFrom (FS (FS FZ)) = Refl\n> toFrom (FS (FS (FS k))) = absurd k\n\n> fromTo : (a : LeftAheadRight) -> from (to a) = a\n> fromTo Left = Refl\n> fromTo Ahead = Refl\n> fromTo Right = Refl\n\n> finiteLeftAheadRight : Finite LeftAheadRight\n> finiteLeftAheadRight = MkSigma 3 (MkIso to from toFrom fromTo)\n> %freeze finiteLeftAheadRight\n\n\nLeftAheadRight is non empty:\n\n> cardNotZLeftAheadRight : CardNotZ finiteLeftAheadRight\n> cardNotZLeftAheadRight = cardNotZLemma finiteLeftAheadRight Left\n> %freeze cardNotZLeftAheadRight\n", "meta": {"hexsha": "d5dcfa3c9af0854064c500a9ed559867caf692e4", "size": 1592, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/examples/LeftAheadRight.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/examples/LeftAheadRight.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/examples/LeftAheadRight.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-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.1212121212, "max_line_length": 66, "alphanum_fraction": 0.6438442211, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7408653863382239}} {"text": "module Data.Function\n\n%access public export\n%default total\n\nInverse : (f : a -> b) -> (g : b -> a) -> Type\nInverse f g = (g . f) = Prelude.Basics.id\n\nInvolution : (f : a -> a) -> Type\nInvolution f = (f . f) = Prelude.Basics.id\n\nInjective : (f : a -> b) -> Type\nInjective f {a} {b} = {x : a} -> {y : a} -> (f x = f y) -> (x = y)\n\nSurjective : (g : a -> b) -> Type\nSurjective g = Exists (\\f => Inverse f g)\n\nBijective : (f : a -> b) -> Type\nBijective f = (Injective f, Surjective f)\n\napplyId : (f = Prelude.Basics.id) -> (f x = f y) -> (x = y)\napplyId p = rewrite p in id\n\nhasInverseIsInjective : Inverse f g -> Injective f\nhasInverseIsInjective p1 p2 {g} = applyId p1 (cong p2 {f=g})\n\ninverseIsSurjective : Inverse f g -> Surjective g\ninverseIsSurjective p {f} = Evidence f p\n\ninvolutionIsBijective : Involution f -> Bijective f\ninvolutionIsBijective inv = (hasInverseIsInjective inv, inverseIsSurjective inv)\n\ninverseOfComposition : Inverse f invF -> Inverse g invG -> Inverse (f . g) (invG . invF)\ninverseOfComposition pf pg {g} {invF} {invG} =\n let p = cong (cong pf {f=(. g)}) {f=(invG .)}\n in rewrite sym pg\n in p\n\nuniqueInverse : Surjective f -> Inverse f g -> Inverse f h -> g = h\nuniqueInverse (Evidence inv p) invG invH {f} {g} {h} = trans gInv hInv\n where\n gInv : g = inv\n gInv = trans (sym (cong p {f=(g .)})) (cong invG {f=(. inv)})\n hInv : inv = h\n hInv = trans (sym (cong invH {f=(. inv)})) (cong p {f=(h .)})\n\ninverseSymmetry : Surjective f -> Inverse f g -> Inverse g f\ninverseSymmetry (Evidence val p) invF {f} {g} = solution\n where\n step1 : g . f . val = g\n step1 = cong p {f=(g .)}\n step2 : g . f . val = val\n step2 = cong invF {f=(. val)}\n step3 : g = val\n step3 = trans (sym step1) step2\n solution : Inverse g f\n solution = rewrite step3 in p\n", "meta": {"hexsha": "f34e56a337878ee82a1342ca639ccfe2e643057f", "size": 1822, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Function.idr", "max_stars_repo_name": "mat8913/l2idris", "max_stars_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data/Function.idr", "max_issues_repo_name": "mat8913/l2idris", "max_issues_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "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": "Data/Function.idr", "max_forks_repo_name": "mat8913/l2idris", "max_forks_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "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": 31.4137931034, "max_line_length": 88, "alphanum_fraction": 0.6048298573, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7407348198334103}} {"text": "module Queue\n\nimport Stack as Stack\n\n%access export\n%default total\n\n-- | *Queue\ndata Queue : Type -> Nat -> Nat -> Nat -> Type where\n MkQueue : (front : Stack.Stack n ty)\n -> (back : Stack.Stack m ty)\n -> Queue ty n m (n + m)\n\n%name Queue queue\n-- .end\n\n-- | *empty\nempty : Queue ty Z Z Z\nempty = MkQueue Stack.empty Stack.empty\n-- .end\n\n-- | *rotate\nrotate : Queue ty m n k -> Queue ty n m k\nrotate {m} {n} (MkQueue front back) =\n rewrite (plusCommutative m n) in MkQueue back front\n-- .end\n\n-- | *top\ntop : Queue ty n m (S k) -> ty\ntop {n = S n'} {m = _} (MkQueue front _) =\n Stack.head front\ntop {n = Z} {m = S m'} (MkQueue _ back) =\n Stack.head $ Stack.reverse back\ntop {n = Z} {m = Z} (MkQueue _ _) impossible\n-- .end\n\n-- | *back\nbottom : Queue ty n m (S k) -> ty\nbottom {m = S m'} {n = S n'} (MkQueue _ back) =\n Stack.head back\nbottom {m = S m'} {n = Z} (MkQueue _ back) =\n Stack.head back\nbottom {m = Z} {n = S j} (MkQueue front _) =\n Stack.head $ Stack.reverse front\nbottom {m = Z} {n = Z} (MkQueue _ _) impossible\n-- .end\n\n-- | *inject\ninject : (a : ty) -> Queue ty n m k -> Queue ty n (S m) (S k)\ninject {n} {m} newVal (MkQueue front back) =\n rewrite (plusSuccRightSucc n m) in MkQueue front (Stack.cons newVal back)\n-- .end\n\n-- | *push\npush : (a : ty) -> Queue ty n m k -> Queue ty (S n) m (S k)\npush newVal (MkQueue front back) = MkQueue (Stack.cons newVal front) back\n-- .end\n", "meta": {"hexsha": "1b03d5db047c12561301b9b5aad0438f34452f88", "size": 1453, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Structures/idr/Queue.idr", "max_stars_repo_name": "nomicflux/okasaki-visualization", "max_stars_repo_head_hexsha": "0b403cdbead2ea313dbc32994d08bb096ec7db8d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-08T06:22:30.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-17T02:41:43.000Z", "max_issues_repo_path": "src/Structures/idr/Queue.idr", "max_issues_repo_name": "nomicflux/okasaki-visualization", "max_issues_repo_head_hexsha": "0b403cdbead2ea313dbc32994d08bb096ec7db8d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-10-06T01:58:23.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-23T03:51:54.000Z", "max_forks_repo_path": "src/Structures/idr/Queue.idr", "max_forks_repo_name": "nomicflux/okasaki-visualization", "max_forks_repo_head_hexsha": "0b403cdbead2ea313dbc32994d08bb096ec7db8d", "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": 25.0517241379, "max_line_length": 80, "alphanum_fraction": 0.5801789401, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7406682030241543}} {"text": "import public Data.Vect\n\n-- Write a type for an m×n matrix.\n\nMatrix : Nat -> Nat -> Type -> Type\nMatrix n m a = Vect n (Vect m a)\n\n-- Write a function to mirror a matrix horizontally.\n\nhorizontallyMirrorMatrix: Matrix n m a -> Matrix n m a\nhorizontallyMirrorMatrix [] = []\nhorizontallyMirrorMatrix (row :: rows) = reverse row :: (horizontallyMirrorMatrix rows)\n\n-- Write a function to transpose the matrix so that element m, n in the argument is element n, m in the result.\ntransposeMatrix : Matrix n m a -> Matrix m n a\ntransposeMatrix matrix = transpose matrix\n", "meta": {"hexsha": "eb2d39149b0bae2c8d8e738a1ad071f7db3f898b", "size": 563, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/day2/day2.idr", "max_stars_repo_name": "hemslo/seven-in-seven", "max_stars_repo_head_hexsha": "5c772abf8e0887675e56a9478be663807c79c3a8", "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": "idris/day2/day2.idr", "max_issues_repo_name": "hemslo/seven-in-seven", "max_issues_repo_head_hexsha": "5c772abf8e0887675e56a9478be663807c79c3a8", "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": "idris/day2/day2.idr", "max_forks_repo_name": "hemslo/seven-in-seven", "max_forks_repo_head_hexsha": "5c772abf8e0887675e56a9478be663807c79c3a8", "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.1176470588, "max_line_length": 111, "alphanum_fraction": 0.7317939609, "num_tokens": 137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7406049004458141}} {"text": "data Direction = North\n | East\n | South\n | West\n\nturnClockwise : Direction -> Direction\nturnClockwise North = East\nturnClockwise East = South\nturnClockwise South = West\nturnClockwise West = North\n\n||| Represents shapes\ndata Shape = ||| A triangle, with its base length and height\n Triangle Double Double\n | ||| A rectangle, with its length and height\n Rectangle Double Double\n | ||| A circle, with its radius\n Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\ndata Picture = Primitive Shape\n | Combine Picture Picture\n | Rotate Double Picture\n | Translate Double Double Picture\n\nrectangle : Picture\nrectangle = Primitive (Rectangle 20 10)\n\ncircle : Picture\ncircle = Primitive (Circle 5)\n\ntriangle : Picture\ntriangle = Primitive (Triangle 10 10)\n\ntestPicture : Picture\ntestPicture = Combine (Translate 5 5 rectangle)\n (Combine (Translate 35 5 circle)\n (Translate 15 25 triangle))\n\n%name Shape shape, shape1, shape2\n%name Picture pic, pic1, pic2\n\npictureArea : Picture -> Double\npictureArea (Primitive shape) = area shape\npictureArea (Combine pic pic1) = pictureArea pic + pictureArea pic1\npictureArea (Rotate x pic) = pictureArea pic\npictureArea (Translate x y pic) = pictureArea pic\n\ndata Biggest = NoTriangle | Size Double\n\ncomputeTriangle : (shape : Shape) -> Biggest\ncomputeTriangle (Triangle x y) = Size (0.5 * x * y)\ncomputeTriangle (Rectangle x y) = NoTriangle\ncomputeTriangle (Circle x) = NoTriangle\n\nfindBigger : Biggest -> Biggest -> Biggest\nfindBigger NoTriangle NoTriangle = NoTriangle\nfindBigger NoTriangle (Size x) = (Size x)\nfindBigger (Size x) NoTriangle = (Size x)\nfindBigger (Size x) (Size y) = if x >= y then (Size x)\n else (Size y)\n\nbiggestTriangle : Picture -> Biggest\nbiggestTriangle (Primitive shape) = computeTriangle shape\nbiggestTriangle (Combine pic pic1) = findBigger (biggestTriangle pic) (biggestTriangle pic1)\nbiggestTriangle (Rotate x pic) = biggestTriangle pic\nbiggestTriangle (Translate x y pic) = biggestTriangle pic\n\ntriangle1 : Picture\ntriangle1 = Primitive (Triangle 50 50)\n\ntriangle2 : Picture\ntriangle2 = Primitive (Triangle 10 10)\n\ntriangle3 : Picture\ntriangle3 = Primitive (Triangle 1 1)\n\ntestPicture2 : Picture\ntestPicture2 = Combine (Translate 5 5 triangle1)\n (Combine (Translate 35 5 triangle2)\n (Translate 15 25 triangle3))\n", "meta": {"hexsha": "b65f1ccf2000b52f6a1edd568b35c8f71a859361", "size": 2627, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Direction.idr", "max_stars_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_stars_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "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": "Direction.idr", "max_issues_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_issues_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "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": "Direction.idr", "max_forks_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_forks_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "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.5465116279, "max_line_length": 92, "alphanum_fraction": 0.6893795204, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7404634586986243}} {"text": "plusId : (n, m, o : Nat) -> (n = m) -> (m = o) -> n + m = m + o\nplusId n m o prf prf1 = rewrite prf in rewrite prf1 in Refl\n\nmult0Plus : (n, m : Nat) -> (0 + n) * m = n * (0 + m)\nmult0Plus n m = Refl\n\nmult_S_1 : (n, m : Nat) -> (m = S n) -> m * (1 + n) = m * m\nmult_S_1 n m prf = rewrite prf in Refl\n\nandb_true_elim_2 : (b, c : Bool) -> b && c = True -> c = True\nandb_true_elim_2 False False Refl impossible\nandb_true_elim_2 True False Refl impossible\nandb_true_elim_2 False True prf = Refl\nandb_true_elim_2 True True prf = Refl\n\nzero_nbeq_plus_1 : (n : Nat) -> 0 == (n + 1) = False\nzero_nbeq_plus_1 Z = Refl\nzero_nbeq_plus_1 (S k) = Refl\n", "meta": {"hexsha": "843a9ee05dd8da6476e8b638103884cce49dccfc", "size": 639, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/SF8.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/SF8.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/SF8.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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.6315789474, "max_line_length": 63, "alphanum_fraction": 0.6197183099, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.740463454803898}} {"text": "module Tensor\n\n-- Based on https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/aplicative.pdf\n\nimport Data.Vect\nimport Data.Matrix.Numeric\n\n%access public export\n\ndata Tensor : Vect n Nat -> Type -> Type where\n Scalar : a -> Tensor [] a\n Prism : Tensor ns (Vect n a) -> Tensor (n :: ns) a\n\ntoVectT : Vect n Nat -> Type -> Type\ntoVectT [] a = a\ntoVectT (x :: xs) a = toVectT xs (Vect x a)\n\ntoTensor : toVectT xs a -> Tensor xs a\ntoTensor {xs = []} v = Scalar v\ntoTensor {xs = (x :: xs)} v = Prism (toTensor v)\n\ntoVect : Tensor xs a -> toVectT xs a\ntoVect {xs = []} (Scalar v) = v\ntoVect {xs = (x :: xs)} (Prism v) = toVect v\n\ntabulate : (Fin n -> a) -> Vect n a\ntabulate {n = Z} _ = []\ntabulate {n = S k} f = f FZ :: tabulate (f . FS)\n\nFunctor (Tensor ns) where\n map f (Scalar x) = Scalar (f x)\n map f (Prism x) = Prism (map (map f) x)\n\nFoldable (Tensor ns) where\n foldr {ns = []} f acc (Scalar x) = f x acc\n foldr {ns = (n :: ns)} f acc (Prism x) = foldr (\\x, acc => foldr f acc x) acc x\n\nApplicative (Tensor ns) where\n pure {ns = []} x = Scalar x\n pure {ns = (n :: ns)} x = Prism (pure (pure x))\n\n (<*>) {ns = []} (Scalar f) (Scalar x) = Scalar (f x)\n (<*>) {ns = (n :: ns)} (Prism f) (Prism x) = Prism ((<*>) <$> f <*> x)\n\nTraversable (Tensor ns) where\n traverse {ns = []} f (Scalar x) = map Scalar (f x)\n traverse {ns = (n :: ns)} f (Prism x) = map Prism (traverse (traverse f) x)\n\nShow a => Show (Tensor ns a) where\n show (Scalar x) = show x\n show (Prism x) = show x\n\nNum a => Num (Tensor ns a) where\n (+) {ns = []} (Scalar x) (Scalar y) = Scalar (x + y)\n (+) {ns = (n :: ns)} (Prism x) (Prism y) = Prism (x + y)\n (*) {ns = []} (Scalar x) (Scalar y) = Scalar (x * y)\n (*) {ns = (n :: ns)} (Prism x) (Prism y) = Prism (x * y)\n fromInteger {ns = []} i = Scalar (fromInteger i)\n fromInteger {ns = (n :: ns)} i = Prism (fromInteger i)\n\n\nexample : Tensor [2, 2] Int\nexample = Prism (Prism (Scalar [[1, 2], [3, 4]]))\n\ntest : Tensor [2, 2] Int\ntest = map (\\x => x * 2) example\n", "meta": {"hexsha": "a00e6448bb9b7a8876b57117a4ab6427d1527c08", "size": 2001, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Tensor.idr", "max_stars_repo_name": "vikfret/idris-snippets", "max_stars_repo_head_hexsha": "ae006f79275bf5df2d9152f0f12f8e961492972c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-20T00:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:29:09.000Z", "max_issues_repo_path": "src/Tensor.idr", "max_issues_repo_name": "vikfret/idris-snippets", "max_issues_repo_head_hexsha": "ae006f79275bf5df2d9152f0f12f8e961492972c", "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/Tensor.idr", "max_forks_repo_name": "vikfret/idris-snippets", "max_forks_repo_head_hexsha": "ae006f79275bf5df2d9152f0f12f8e961492972c", "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": 29.8656716418, "max_line_length": 85, "alphanum_fraction": 0.5657171414, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.740278146463682}} {"text": "import Data.Fin\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a\n\n%name Vect xs, ys, zs\n\nappend : Vect n e -> Vect m e -> Vect (n + m) e\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n\nzip : Vect n a -> Vect n b -> Vect n (a, b)\nzip [] ys = []\nzip (x :: xs) (y :: ys) = (x, y) :: zip xs ys\n\nindex : Fin len -> Vect len e -> e\nindex FZ (x::_) = x\nindex (FS k) (_::xs) = index k xs\n\ntryIndex : {n : _} -> Integer -> Vect n a -> Maybe a\ntryIndex i xs = case integerToFin i n of\n Nothing => Nothing\n (Just x) => Just (index x xs)\n", "meta": {"hexsha": "e757da8edef574c0b0d87d8060adc7a7ed03e43a", "size": 637, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Vect.idr", "max_stars_repo_name": "brunoflores/type-driven-with-idris", "max_stars_repo_head_hexsha": "52bb008df2c34bdecab4a37aea626be33042e611", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Vect.idr", "max_issues_repo_name": "brunoflores/type-driven-with-idris", "max_issues_repo_head_hexsha": "52bb008df2c34bdecab4a37aea626be33042e611", "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": "Vect.idr", "max_forks_repo_name": "brunoflores/type-driven-with-idris", "max_forks_repo_head_hexsha": "52bb008df2c34bdecab4a37aea626be33042e611", "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": 25.48, "max_line_length": 52, "alphanum_fraction": 0.5007849294, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.945801271704518, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7402431631144232}} {"text": "import Data.Vect\nimport Data.List.Views\nimport Data.Vect.Views\nimport Data.Nat.Views\n\n-- Page 270\n-- Exercise 1\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z _ = Exact []\ntakeN (S k) [] = Fewer\ntakeN (S k) (x :: xs) = case takeN k xs of\n Fewer => Fewer\n Exact n_xs => Exact (x :: n_xs)\n\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\n-- Exercise 2\nhalves : List a -> (List a, List a)\nhalves xs with (takeN ((length xs) `div` 2) xs)\n halves xs | Fewer = ([], xs)\n halves (n_xs ++ rest) | Exact (n_xs) = (n_xs, rest)\n\n\n-- Page 279\n-- Exercise 1\nequalSuffix : Eq a => List a -> List a -> List a\nequalSuffix x y with (snocList x)\n equalSuffix [] y | Empty = []\n equalSuffix (xs ++ [x_item]) y | (Snoc recX) with (snocList y)\n equalSuffix (xs ++ [x_item]) [] | (Snoc recX) | Empty = []\n equalSuffix (xs ++ [x_item]) (ys ++ [y_item]) | (Snoc recX) | (Snoc recY) =\n if x_item == y_item then equalSuffix xs ys | recX | rexY ++ [x_item] else []\n\n-- Exercise 4\ntotal\npalindrome : Eq a => List a -> Bool\npalindrome xs with (vList xs)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (first :: (ys ++ [last])) | (VCons rec) =\n (first == last) && palindrome ys | rec\n\n\n-- Page 287\n-- Exercise 2\nexport\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n{-\narea : Shape -> Double\narea s with (shapeView s)\n area (triangle base height) | STriangle = ?area_rhs_1\n area (rectangle width height) | SRectangle = ?area_rhs_2\n area (circle radius) | SCircle = ?area_rhs_3\n-}\n\n-- Page 304\n-- Exercise 1\ntotal\nevery_other : Stream a -> Stream a\nevery_other (x :: _ :: xs) = x :: every_other xs\n\n-- Exercise 2\ndata InfList : Type -> Type where\n (::) : (value : elem) -> Inf (InfList elem) -> InfList elem\n\n%name InfList xs, ys, zs\n\nFunctor InfList where\n map f (value :: xs) = f value :: map f xs\n\n-- Exercise 4\ntotal\nsquare_root_approx : (number : Double) -> (approx : Double) -> Stream Double\nsquare_root_approx number approx =\n let next = (approx + (number / approx)) / 2 in -- Newton's method\n approx :: square_root_approx number next\n\ntotal\nsquare_root_bound : (max : Nat) -> (number : Double) -> (bound : Double) -> (approxs : Stream Double) -> Double\nsquare_root_bound Z number bound (val :: xs) = val\nsquare_root_bound (S k) number bound (val :: xs) =\n if abs(val*val - number) < bound\n then val\n else square_root_bound k number bound xs\n\ntotal\nsquare_root : (number : Double) -> Double\nsquare_root number =\n let recursiveCall = square_root_approx number number in\n square_root_bound 100 number 0.00000000001 recursiveCall\n\n\n-- Page 314\n-- Exercise 1\ndata InfIO : Type where\n Do : IO a\n -> (a -> Inf InfIO)\n -> InfIO\n\ntotal\ntotalREPL : (prompt : String) -> (action : String -> String) -> InfIO\ntotalREPL prompt action = Do (putStrLn prompt) (\\_ => totalREPL prompt action)\n\n-- Page 322\n-- Exercise 1\n-- (Done in class)\n", "meta": {"hexsha": "b2dc1cd26136c53509f856a24b7e9be469f60bc1", "size": 3234, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "B_type_driven_development/Week_8/week8.idr", "max_stars_repo_name": "JnxF/advanced-software-analysis", "max_stars_repo_head_hexsha": "3ad336918f4aa6272d6d2feebf4e02ee264e8e0b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-26T11:16:02.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T11:20:06.000Z", "max_issues_repo_path": "B_type_driven_development/Week_8/week8.idr", "max_issues_repo_name": "JnxF/advanced-software-analysis", "max_issues_repo_head_hexsha": "3ad336918f4aa6272d6d2feebf4e02ee264e8e0b", "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": "B_type_driven_development/Week_8/week8.idr", "max_forks_repo_name": "JnxF/advanced-software-analysis", "max_forks_repo_head_hexsha": "3ad336918f4aa6272d6d2feebf4e02ee264e8e0b", "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": 27.8793103448, "max_line_length": 111, "alphanum_fraction": 0.6280148423, "num_tokens": 1009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7399305058299315}} {"text": "data EqNat : (num1 : Nat) -> (num2 : Nat) -> Type where\n Same : (num : Nat) -> EqNat num num\n\nsameS : (k : Nat) -> (j : Nat) -> (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS k k (Same k) = Same (S k)\n\nsameS' : (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS' (Same k) = Same (S k)\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat Z Z = Just $ Same 0\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just eq => Just (sameS _ _ eq)\n\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case checkEqNat m len of\n Nothing => Nothing\n Just (Same len) => Just input\n", "meta": {"hexsha": "be869f65356ab64f3ea9bed8fe36201df4e6fca6", "size": 931, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter08/EqNat.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter08/EqNat.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter08/EqNat.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.4814814815, "max_line_length": 71, "alphanum_fraction": 0.5059076262, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.739886944445849}} {"text": "module NatDivisors\n\nimport NatUtils\nimport NatOrder\n\n%default total\n%access public export\n\n---------------------------------------------------------------------------------------------\n\n--Definitions involving divisibility\n\n|||Type of proof that d divides n\nisDivisible : (n : Nat) -> (d : Nat) -> Type\nisDivisible n d = (k : Nat ** (n = k * d, Not (d = Z)))\n\n|||Type of proof that d is a common divisor of a and b\nisCommonDivisor : (a : Nat) -> (b : Nat) -> (d : Nat) -> Type\nisCommonDivisor a b d = (isDivisible a d, isDivisible b d)\n\n|||Type of proof that a given number is \"larger\" than all common divisors of a and b\nisMaxDivisor : (a : Nat) -> (b : Nat) -> (d : Nat) -> Type\nisMaxDivisor a b d = (n : Nat) -> (isCommonDivisor a b n) -> (isDivisible d n)\n\n---------------------------------------------------------------------------------------------\n\n-- Division algorithms to get the quotient and reminder\n\n||| Given a, b, and a proof that b != 0, returns q, r and proofs that a = r + (b * q) and r < b (r < b as LT r b)\n--removed possible problems with Rohit's\neuclidDivideOld : (a : Nat) -> (b : Nat) -> (Not (b = Z)) ->\n\t\t\t (q : Nat ** (r : Nat ** ((a = r + (q * b)), LT r b)))\neuclidDivideOld _ Z proofEq = void (proofEq Refl)\neuclidDivideOld Z (S k) SIsNotZ = (Z ** (Z ** (Refl, LTESucc LTEZero)))\neuclidDivideOld (S n) (S k) SIsNotZ =\n\tcase (euclidDivideOld n (S k) SIsNotZ) of\n\t(q ** (r ** (proofEq, ltproof))) =>\n\t\tcase (ltImpliesEqOrLT r (S k) ltproof) of\n\t\t(Right proofSrLTSk) => (q ** ((S r) ** ((cong proofEq), proofSrLTSk)))\n\t\t(Left proofSrEqSk) => ((S q) ** (Z ** ((trans (cong proofEq) (plusConstantRight (S r) (S k) (q * (S k)) proofSrEqSk)), LTESucc LTEZero)))\n\n||| Given a, b, and a proof that b != 0, returns (q, r) and proofs that a = r + q * b and r < b (r < b as LNEQ r b)\neuclidDivide : (a : Nat) -> (b : Nat) -> (Not (b = Z)) ->\n\t\t\t(q : Nat ** (r : Nat ** (a = r + (q * b), LNEQ r b)))\neuclidDivide _ Z proofeq = void (proofeq Refl)\neuclidDivide Z (S k) SIsNotZ = (Z ** (Z ** (Refl, (LEQZero, ZIsNotS))))\neuclidDivide (S n) (S k) SIsNotZ =\n\tcase (euclidDivide n (S k) SIsNotZ) of\n\t\t(q ** (r ** (proofEq, proofLNEQ))) =>\n\t\t\tcase (lneqImpliesEqOrLNEQ r (S k) proofLNEQ) of\n\t\t\t\t(Right proofSrLNEQSk) => (q ** ((S r) ** ((cong proofEq), proofSrLNEQSk)))\n\t\t\t\t(Left proofSrEqSk) => ((S q) ** (Z ** ((trans (cong proofEq) (plusConstantRight (S r) (S k) (q * (S k)) proofSrEqSk)), (LEQZero, ZIsNotS))))\n\n---------------------------------------------------------------------------------------------\n\n-- General recursive functions for proofs using Euclid's division algorithms\n\n|||A general algorithm that runs recursively using Euclid's division, with proof (helper function with bound, use euclidRecursion instead)\neuclidRecursionBound : (bound : Nat) -> (a : Nat) -> (b : Nat) -> (LTE a bound) -> (LTE (S b) bound) -> (Either (Not (a = Z)) (Not (b = Z))) ->\n(proofType : (Nat -> Nat -> Type)) ->\n(baseLeft : (k : Nat) -> (Not (k = Z)) -> (proofType k Z)) ->\n(baseRight : (k : Nat) -> (Not (k = Z)) -> (proofType Z k)) ->\n(proofExtend : {a1 : Nat} -> {b1 : Nat} -> {r1 : Nat} -> {q1 : Nat} -> (proofType b1 r1) -> (a1 = r1 + (q1 * b1)) -> (proofType a1 b1)) ->\n(proofType a b)\n\neuclidRecursionBound _ Z Z _ _ notBothZ _ _ _ _ =\n\tcase notBothZ of\n\t\tLeft notZ => void (notZ Refl)\n\t\tRight notZ => void (notZ Refl)\n\neuclidRecursionBound bound (S a) Z _ _ _ _ baseLeft _ _ = baseLeft (S a) SIsNotZ\neuclidRecursionBound bound Z (S b) _ _ _ _ _ baseRight _ = baseRight (S b) SIsNotZ\n\neuclidRecursionBound Z (S a) (S b) lteLeft lteRight _ _ _ _ _ = void (succNotLTEzero lteLeft)\n\neuclidRecursionBound (S bound) (S a) (S b) (LTESucc lteLeft) (LTESucc lteRight) _\nproofType baseLeft baseRight proofExtend =\n\tcase (euclidDivide (S a) (S b) SIsNotZ) of\n\t\t(q ** (r ** (proofEq, proofLNEQ))) =>\n\t\t\tcase (euclidRecursionBound bound (S b) r lteRight (lteTransitive (lneqToLT proofLNEQ) lteRight) (Left SIsNotZ) proofType baseLeft baseRight proofExtend) of\n\t\t\t\tproofRemainder => proofExtend proofRemainder proofEq\n\n\n\n|||A general algorithm that runs recursively using Euclid's division, with proof\neuclidRecursion : (a : Nat) -> (b : Nat) -> (Either (Not (a = Z)) (Not (b = Z))) ->\n(proofType : (Nat -> Nat -> Type)) ->\n(baseLeft : (k : Nat) -> (Not (k = Z)) -> (proofType k Z)) ->\n(baseRight : (k : Nat) -> (Not (k = Z)) -> (proofType Z k)) ->\n(proofExtend : {a1 : Nat} -> {b1 : Nat} -> {r1 : Nat} -> {q1 : Nat} -> (proofType b1 r1) -> (a1 = r1 + (q1 * b1)) -> (proofType a1 b1)) ->\n(proofType a b)\n\neuclidRecursion a b notBothZ proofType baseLeft baseRight proofExtend =\n\tcase (isLTE a b) of\n\t\t(Yes proofLTE) => euclidRecursionBound (S b) a b (lteTransitive proofLTE (lteSuccRight lteRefl)) lteRefl notBothZ proofType baseLeft baseRight proofExtend\n\t\t(No proofNotLTE) => euclidRecursionBound (S a) a b (lteSuccRight lteRefl) (LTESucc (notLTEImpliesGTE proofNotLTE)) notBothZ proofType baseLeft baseRight proofExtend\n\n----------------------------------------------------------------------------------------------\n\n--Basic utility functions involving divisibility\n\n|||Proof d1 divides a1 and a1 = a2, d1 = d2 implies d2 divides a2\neqConservesDivisible : {a1 : Nat} -> {a2 : Nat} -> {d1 : Nat} -> {d2 : Nat} ->\n\t\t\t\t (isDivisible a1 d1) -> (a1 = a2) -> (d1 = d2) -> (isDivisible a2 d2)\neqConservesDivisible {a1} {d1} proofDivides Refl Refl = proofDivides\n\n|||Proof that all natural numbers divide zero\nzeroDivisible : {n : Nat} -> (Not (n = Z)) -> (isDivisible Z n)\nzeroDivisible {n} notZ = (Z ** (sym (multZeroLeftZero n), notZ))\n\n|||Proof that 1 divides all natural numbers\noneDivides : {n : Nat} -> (isDivisible n (S Z))\noneDivides {n} = (n ** ((rewrite (multOneRightNeutral n) in Refl), SIsNotZ))\n\n|||Proof that all natural numbers divide themselves\ndivisionReflexive : {n : Nat} -> (Not (n = Z)) -> (isDivisible n n)\ndivisionReflexive {n} notZ = (1 ** (rewrite (multOneLeftNeutral n) in Refl, notZ))\n\n|||Proof that 1 is a common divisor of all pairs of natural numbers\noneCommonDivisor : {a : Nat} -> {b : Nat} -> (isCommonDivisor a b (S Z))\noneCommonDivisor {a} {b} = (oneDivides, oneDivides)\n\n|||Proof that n is a common divisor of n and 0\nzeroCommonDivisorRight : {n : Nat} -> (Not (n = Z)) -> (isCommonDivisor n Z n)\nzeroCommonDivisorRight {n} notZ = (divisionReflexive notZ, zeroDivisible notZ)\n\n|||Proof that n is a common divisor of 0 and n\nzeroCommonDivisorLeft : {n : Nat} -> (Not (n = Z)) -> (isCommonDivisor Z n n)\nzeroCommonDivisorLeft {n} notZ = (zeroDivisible notZ, divisionReflexive notZ)\n\n|||Proof that a common divisor of (a, b) is a common divisor of (b, a)\ncommonDivisorSymmetric : {a : Nat} -> {b : Nat} -> {d : Nat} ->\n\t\t\t\t\t(isCommonDivisor a b d) -> (isCommonDivisor b a d)\ncommonDivisorSymmetric {a} {b} {d} (proofDividesa, proofDividesb) =\n\t(proofDividesb, proofDividesa)\n\n|||Proof that a divides b and b divides a implies a = b\ndividesAntiSymmetric : {a : Nat} -> {b : Nat} ->\n\t\t\t\t (isDivisible a b) -> (isDivisible b a) -> (a = b)\ndividesAntiSymmetric {a} {b} (k ** (leftEq, leftNotZ)) (l ** (rightEq, rightNotZ)) =\n\tmultAntiSymmetric leftEq rightEq\n\n----------------------------------------------------------------------------------------------\n\n--Utility functions for linear combinations\n\n|||Proof that d divides a implies d divides n * a\ndividesMultiple : {a : Nat} -> {d : Nat} ->\n\t\t\t (isDivisible a d) -> (n : Nat) -> (isDivisible (n * a) d)\ndividesMultiple {a} {d} (k ** (proofDiv, notZ)) n = ((n * k) ** (proofEq, notZ)) where\n\tproofEq = rewrite (sym (multAssociative n k d)) in\n\t\t\tcong {f = (\\l => n * l)} proofDiv\n\n|||Proof that a divides n and b divides (n/a) implies b * a divides n\nmultipleDivides : {n : Nat} -> {a : Nat} -> {b : Nat} -> (proofDiv : isDivisible n a) ->\n\t\t\t (isDivisible (fst proofDiv) b) -> (isDivisible n (b * a))\nmultipleDivides {n} {a} {b} (k ** (proofDiv1, aNotZ)) (l ** (proofDiv2, bNotZ)) =\n\t(l ** (proofEq, nonZeroMultNotZero bNotZ aNotZ)) where\n\t\tproofEq = rewrite (multAssociative l b a) in\n\t\t\t\trewrite (sym proofDiv2) in proofDiv1\n\n|||Proof that d divides a and n != 0 implies (n * d) divides (n * a)\nmultipleDividesMultiple : {a : Nat} -> {d : Nat} -> (isDivisible a d) ->\n\t\t\t\t\t (n : Nat) -> (Not (n = Z)) -> (isDivisible (n * a) (n * d))\nmultipleDividesMultiple {a} {d} (k ** (proofDiv, dNotZ)) n nNotZ =\n\t(k ** (proofEqExtend, (nonZeroMultNotZero nNotZ dNotZ))) where\n\t\tproofEqExtend = rewrite (multAssociative k n d) in\n\t\t\t\t\t rewrite (multCommutative k n) in\n\t\t\t\t\t rewrite (sym (multAssociative n k d)) in\n\t\t\t\t\t cong {f = (\\l => (n * l))} proofDiv\n\n|||Proof that d is a common divisor of a and b implies d divides a + b\ndividesSum : {a : Nat} -> {b : Nat} -> {d : Nat} ->\n\t\t (isCommonDivisor a b d)-> (isDivisible (a + b) d)\ndividesSum {a} {b} {d} ((m ** (proofDividesa, dNotZ1)), (n ** (proofDividesb, dNotZ2))) =\n\t((m + n) ** ((distributeProof a b d m n proofDividesa proofDividesb), dNotZ1))\n\n|||Proof that d is a common divisor of a and b implies d divides x * a + y * b\ndividesLinearCombination : {a : Nat} -> {b : Nat} -> {d : Nat} ->\n\t\t\t\t\t (isCommonDivisor a b d) -> (x : Nat) -> (y : Nat) ->\n\t\t\t\t\t (isDivisible ((x * a) + (y * b)) d)\ndividesLinearCombination commonDivisorProof x y =\n\tdividesSum ((dividesMultiple (fst commonDivisorProof) x), (dividesMultiple (snd commonDivisorProof) y))\n\n|||Proof that d divides (a + b) and d divides b implies d divides a\ndividesDifference : {a : Nat} -> {b : Nat} -> {d : Nat} ->\n\t\t\t\t(isDivisible (a + b) d) -> (isDivisible b d) -> (isDivisible a d)\ndividesDifference {a} {b} {d} (n ** (proofDivSum, dNotZ1)) (m ** (proofDivb, dNotZ2)) =\n\tcase (leqDivConstantRight dNotZ1 (eqPreservesLEQ (a ** (plusCommutative b a)) proofDivb proofDivSum)) of\n\t(l ** proofEq) =>\n\t\t(l ** (sym (plusLeftCancel b (l * d) a (rewrite (plusCommutative b a) in (rewrite proofDivSum in (rewrite proofDivb in (trans (sym (multDistributesOverPlusLeft m l d)) (cong {f = (\\n => n * d)} proofEq)))))), dNotZ1))\n\n|||Proof that d divides b, d divides r and a = r + q * b implies d divides a\ndividesSumExtend : {a : Nat} -> {b : Nat} -> {q : Nat} -> {r : Nat} ->\n\t\t\t (isDivisible b d) -> (isDivisible r d) -> (a = r + (q * b)) ->\n\t\t\t (isDivisible a d)\ndividesSumExtend {a} {b} {q} {r} divB divR proofEq =\n\t(eqConservesDivisible (dividesSum (divR, dividesMultiple divB q)) (sym proofEq) Refl)\n\n|||Proof that d divides a, d divides b and a = r + q * b implies d divides r\ndividesDiffExtend : {a : Nat} -> {b : Nat} -> {q : Nat} -> {r : Nat} ->\n\t\t\t\t(isDivisible a d) -> (isDivisible b d) -> (a = r + (q * b)) -> (isDivisible r d)\ndividesDiffExtend {a} {b} {q} {r} divA divB proofEq =\n\tdividesDifference (eqConservesDivisible divA proofEq Refl) (dividesMultiple divB q)\n\n----------------------------------------------------------------------------------------------\n\n-- Proofs involving divisibility with remainders\n\n|||Proof that given a = r + q * b, and d divides b and r, d divides a and b\nremExtendsCommDiv : {a : Nat} -> {b : Nat} -> {q : Nat} -> {r : Nat} -> {d : Nat} ->\n\t\t\t\t(isCommonDivisor b r d) -> (a = r + (q * b)) -> (isCommonDivisor a b d)\nremExtendsCommDiv {a} {b} {q} {r} (divB, divR) proofEq = (divA, divB) where\n\tdivA = dividesSumExtend divB divR proofEq\n\n|||Proof that given a = r + q * b, and d divides a and b, d divides b and r\nremConservesCommDiv : {a : Nat} -> {b : Nat} -> {q : Nat} -> {r : Nat} -> {d : Nat} ->\n\t\t\t\t (isCommonDivisor a b d) -> (a = r + (q * b)) -> (isCommonDivisor b r d)\nremConservesCommDiv {a} {b} {q} {r} (divA, divB) proofEq = (divB, divR) where\n\tdivR = dividesDiffExtend divA divB proofEq\n\n|||Proof that given a = r + q * b, and d divides a and b, d divides b and r\nremExtendsMaxDiv : {a : Nat} -> {b : Nat} -> {q : Nat} -> {r : Nat} -> {d : Nat} ->\n\t\t\t (isMaxDivisor b r d) -> (a = r + (q * b)) -> (isMaxDivisor a b d)\nremExtendsMaxDiv maxDiv proofEq =\n\t(\\n => (\\commDiv => maxDiv n (remConservesCommDiv commDiv proofEq)))\n\n|||Proof that given a = r + q * b, and d divides b and r, d divides a and b\nremConservesMaxDiv : {a : Nat} -> {b : Nat} -> {q : Nat} -> {r : Nat} -> {d : Nat} ->\n\t\t\t\t (isMaxDivisor a b d) -> (a = r + (q * b)) -> (isMaxDivisor b r d)\nremConservesMaxDiv maxDiv proofEq =\n\t(\\n => (\\commDiv => maxDiv n (remExtendsCommDiv commDiv proofEq)))\n\n----------------------------------------------------------------------------------------------\n\n--Decidability of divisibility\n\n|||Proof that d divides n and n != 0 implies n >= d\ndividesImpliesGEQ : {n : Nat} -> {d : Nat} -> (isDivisible n d) -> (Not (n = Z)) -> (LEQ d n)\ndividesImpliesGEQ {n} {d} (k ** (proofEq, dNotZ)) nNotZ =\n\tcase k of\n\t\tZ => void (nNotZ proofEq)\n\t\t(S l) => ((l * d) ** (sym proofEq))\n\n|||Proof that if n = r + q * d, where r ! = 0 and r < d, then n is not divisible by d\nnotDivisible : {n : Nat} -> {r : Nat} -> {q : Nat} -> {d : Nat} ->\n\t\t\t(Not (r = Z)) -> (LNEQ r d) -> (n = r + (q * d)) -> (Not (isDivisible n d))\nnotDivisible {n} {r} {q} {d} rNotZ proofLNEQ proofEq (k ** (proofDiv, dNotZ)) =\n\t(leqImpliesNotLNEQ dLEQr proofLNEQ) where\n\t\tdLEQr = (dividesImpliesGEQ dDividesr rNotZ) where\n\t\t\tdDividesr = dividesDifference (k ** ((trans (sym proofEq) proofDiv), dNotZ)) (q ** (Refl, dNotZ))\n\n|||Decision procedure to check if n is divisible by d\ndecDivisible : (n : Nat) -> (d : Nat) -> Dec (isDivisible n d)\ndecDivisible n Z = No (\\proofDivides => (snd (snd proofDivides)) Refl)\ndecDivisible n (S d) =\n\tcase (euclidDivide n (S d) SIsNotZ) of\n\t\t(q ** (r ** ((proofEq, proofLNEQ)))) =>\n\t\t\tcase r of\n\t\t\t\tZ => Yes (q ** (proofEq, SIsNotZ))\n\t\t\t\t(S k) => No (notDivisible SIsNotZ proofLNEQ proofEq)\n\n----------------------------------------------------------------------------------------------\n", "meta": {"hexsha": "9705c7c6be419fbaa99c647aa21f977b21ab6279", "size": 13644, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/NatDivisors.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/NatDivisors.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/NatDivisors.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": 51.6818181818, "max_line_length": 219, "alphanum_fraction": 0.5920551158, "num_tokens": 4736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7395102680687872}} {"text": "\nmodule Step\n\n-- Relation 'Step' for reducing terms\n-- in the simply-typed lambda calculus.\n \n\nimport Term\nimport Subst\n\n\n%default total\n%access public export\n\n\n-------------------------------------------------------------------------\n-- Begin: SMALL-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n\n-- The relation 'Step' defines evaluation of terms in the lambda\n-- calculus following small-step semantics. 'Step' relates two \n-- terms 'x' and 'y' precisely when 'x' can be rewritten into 'y'\n-- in a single step of evaluation.\n--\n-- (Note that the arguments 'x' and 'y' to the type constructor 'Step'\n-- are named only for the purpose of easing documentation.) \n--\n-- Note that the 'Step' relation automatically enforces preservation\n-- since the arguments 'x' and 'y' are required to have the same type 't'.\ndata Step : (x : Term [] t) -> (y : Term [] t) -> Type where\n StApp1 : Step t1 t1' ->\n Step (TApp t1 t2) (TApp t1' t2)\n --\n StApp2 : Value v -> Step t2 t2' ->\n Step (TApp v t2) (TApp v t2')\n --\n StBeta : Value v -> \n Step (TApp (TAbs t) v) (subst v First t)\n -- \n StFix : Step t t' ->\n Step (TFix t) (TFix t')\n --\n StFixBeta : Step (TFix (TAbs t)) (subst (TFix (TAbs t)) First t)\n --\n StSucc : Step t t' -> \n Step (TSucc t) (TSucc t')\n --\n StPred : Step t t' -> \n Step (TPred t) (TPred t')\n -- \n StPredZero : Step (TPred TZero) TZero\n --\n StPredSucc : Value v ->\n Step (TPred (TSucc v)) v\n --\n StIfz : Step t1 t1' ->\n Step (TIfz t1 t2 t3) (TIfz t1' t2 t3)\n --\n StIfzZero : Step (TIfz TZero t1 t2) t1\n --\n StIfzSucc : Value v ->\n Step (TIfz (TSucc v) t1 t2) t2\n \n-- End: SMALL-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n-----------------------------------------------------------------------\n\n\n\n----------------------------\n-- Begin: TRANSITIVE CLOSURE\n\n-- Data type for representing the transistive closure\n-- of an arbitrary relation 'rel : a -> a -> Type'.\nusing (a : Type, rel : a -> a -> Type)\n data TransCl : {a : Type} -> (a -> a -> Type) -> (a -> a -> Type) where\n TClRefl : (x : a) -> TransCl rel x x \n TClSingle : rel x y -> TransCl rel x y\n TClTrans : TransCl rel x y -> TransCl rel y z -> TransCl rel x z\n\n \n-- Data type specifically for representing the\n-- transitive closure of the 'Step' relation.\ndata TransStep : Term [] t -> Term [] t -> Type where\n TStRefl : (e : Term [] t) -> TransStep e e\n TStTrans : {e : Term [] t} -> {e' : Term [] t} -> {e'' : Term [] t} ->\n Step e e' -> TransStep e' e'' -> TransStep e e''\n\n\n-- 'TransStep' is indeed transitive.\ntransStepTransitive : TransStep e1 e2 -> TransStep e2 e3 -> TransStep e1 e3\ntransStepTransitive (TStRefl _) y = y\ntransStepTransitive (TStTrans x y) z = TStTrans x (transStepTransitive y z)\n\n\n-- Correctness proof for 'TransStep', i.e.: TransStep => (TransCl Step).\ntransStepCorrect : TransStep e e' -> TransCl Step e e'\ntransStepCorrect (TStRefl e) = TClRefl e\ntransStepCorrect (TStTrans x y) = TClTrans (TClSingle x) (transStepCorrect y)\n\n\n-- Completeness proof for 'TransStep', i.e.: (TransCl Step) => TransStep.\ntransStepComplete : TransCl Step e e' -> TransStep e e'\ntransStepComplete (TClRefl e) = TStRefl e\ntransStepComplete (TClSingle x) = TStTrans x (TStRefl _)\ntransStepComplete (TClTrans x z) = transStepTransitive (transStepComplete x)\n (transStepComplete z)\n\n-- Operators for compact notation:\ninfixl 10 .++.\n(.++.) : TransStep e1 e2 -> TransStep e2 e3 -> TransStep e1 e3\n(.++.) = transStepTransitive \n\ninfixl 10 .+.\n(.+.) : TransStep e1 e2 -> Step e2 e3 -> TransStep e1 e3\n(.+.) x y = x .++. (TStTrans y (TStRefl _))\n\n-- End: TRANSITIVE CLOSURE\n--------------------------\n", "meta": {"hexsha": "75a458a68c749f5840ba58d490f88be0d7bb6c31", "size": 3907, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "conventional/src/Step.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "conventional/src/Step.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "conventional/src/Step.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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.1101694915, "max_line_length": 77, "alphanum_fraction": 0.5710263629, "num_tokens": 1188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.7393014691278966}} {"text": "-- | Exercises on Lists\nmodule Koans.Lists\n\n-- | What is the type of this list.\nnats : List Int\nnats = [0,1,2,3,4,5,6,7,9]\n\n-- | Reproduce the list [0,1,3,5,7,9,2,4,6,8] using the following functions.\nodds : List Int\nodds = [1,3,5,7,9]\n\nevens : List Int\nevens = [2,4,6,8]\n\nzero : Int\nzero = 0\n\nzeroOddsEvens : Bool\nzeroOddsEvens = (zero ++ odds ++ evens) == [0,1,3,5,7,9,2,4,6,8]\n\n-- | Complete the result of following functions.\n\nheadOList : Bool\nheadOList = 5 == Vect.head [5,4,3,2,1]\n\ntailOList : Bool\ntailOList = [1,2,3,4,5] == Vect.tail [0,1,2,3,4,5]\n\nlastOList : Bool\nlastOList = 1 == Vect.last [5,4,3,2,1]\n\ninitOList : Bool\ninitOList = [1,2,3,4,5] == Vect.init [1,2,3,4,5,6]\n\nlengthOList : Bool\nlengthOList = 5 == List.length [1,2,3,4,5]\n\nreverseTheList : Bool\nreverseTheList = [5,4,3,2,1] == List.reverse [1,2,3,4,5]\n\nfirst3 : Bool\nfirst3 = [1,2,3] == take 3 [1..10]\n\ndrop3 : Bool\ndrop3 = [4,5,6,7,8,9,10] == drop 3 [1..10]\n\ncountAllTheNumbers : Bool\ncountAllTheNumbers = 55 == sum [1..10]\n\ntimesAllTheNnumbers : Bool\ntimesAllTheNnumbers = 3628800 == product [1..10]\n\nelementOrNot : Bool\nelementOrNot = List.elem 4 [4] == True\n\n-- | Make this function true\nstopPete : Bool\nstopPete = take 4 (repeat 3) == [3,3,3,3]\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "c9d0bb6f204b0755d51ec9ef9e1cc993f7600877", "size": 1306, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "list-expansion/Idris/idris-koans-master/Koans/05-Lists.idr", "max_stars_repo_name": "harrisi/on-being-better", "max_stars_repo_head_hexsha": "81dc6d02de582e1d0dcf48d8d9f603bee9f2ef39", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "list-expansion/Idris/idris-koans-master/Koans/05-Lists.idr", "max_issues_repo_name": "harrisi/on-being-better", "max_issues_repo_head_hexsha": "81dc6d02de582e1d0dcf48d8d9f603bee9f2ef39", "max_issues_repo_licenses": ["CC0-1.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": "list-expansion/Idris/idris-koans-master/Koans/05-Lists.idr", "max_forks_repo_name": "harrisi/on-being-better", "max_forks_repo_head_hexsha": "81dc6d02de582e1d0dcf48d8d9f603bee9f2ef39", "max_forks_repo_licenses": ["CC0-1.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.4098360656, "max_line_length": 80, "alphanum_fraction": 0.6033690658, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7392478283838174}} {"text": "||| Properties of Data.Vect.index\nmodule Data.Vect.Properties.Index\n\nimport Data.Vect.Properties.Tabulate\n\nimport Data.Vect\nimport Data.Vect.Elem\nimport Data.Fin\n\nimport Syntax.PreorderReasoning\n\n||| Recall an element by its position, as we may not have the element\n||| at runtime\npublic export\nrecallElem : {xs : Vect n a} -> x `Elem` xs -> a\nrecallElem {xs = x :: _ } Here = x\nrecallElem {xs = _ :: xs} (There later) = recallElem later\n\n||| Recalling by a position of `x` does yield `x`\nexport\nrecallElemSpec : (pos : x `Elem` xs) -> recallElem pos = x\nrecallElemSpec Here = Refl\nrecallElemSpec (There later) = recallElemSpec later\n\n||| `index i : Vect n a -> a` is a natural transformation\nexport\nindexNaturality : (i : Fin n) -> (f : a -> b) -> (xs : Vect n a)\n -> index i (map f xs) = f (index i xs)\nindexNaturality FZ f (x :: xs) = Refl\nindexNaturality (FS x) f (_ :: xs) = indexNaturality x f xs\n\n||| Replication tabulates the constant function\nexport\nindexReplicate : (i : Fin n) -> (x : a)\n -> index i (replicate n x) = x\nindexReplicate FZ x = Refl\nindexReplicate (FS i) x = indexReplicate i x\n\n||| `range` tabulates the identity function (by definition)\nexport\nindexRange : (i : Fin n) -> index i (range {len = n}) === i\nindexRange i = irrelevantEq $ indexTabulate id i\n\n||| Inductive step auxiliary lemma for indexTranspose\nindexZipWith_Cons : (i : Fin n) -> (xs : Vect n a) -> (xss : Vect n (Vect m a))\n -> index i (zipWith (::) xs xss)\n = (index i xs) :: (index i xss)\nindexZipWith_Cons FZ (x :: _ ) (xs:: _ ) = Refl\nindexZipWith_Cons (FS i) (_ :: xs) (_ :: xss) = indexZipWith_Cons i xs xss\n\n||| The `i`-th vector in a transposed matrix is the vector of `i`-th components\nexport\nindexTranspose : (xss : Vect m (Vect n a)) -> (i : Fin n)\n -> index i (transpose xss) = map (index i) xss\nindexTranspose [] i = indexReplicate i []\nindexTranspose (xs :: xss) i = Calc $\n |~ index i (transpose (xs :: xss))\n ~~ index i (zipWith (::) xs (transpose xss)) ...(Refl)\n ~~ index i xs :: index i (transpose xss) ...(indexZipWith_Cons i xs (transpose xss))\n ~~ index i xs :: map (index i) xss ...(cong (index i xs ::)\n $ indexTranspose xss i)\n", "meta": {"hexsha": "d4de951615612aa764dd48992b75de9e74f75621", "size": 2272, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Vect/Properties/Index.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": "libs/contrib/Data/Vect/Properties/Index.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": "libs/contrib/Data/Vect/Properties/Index.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": 36.6451612903, "max_line_length": 91, "alphanum_fraction": 0.6254401408, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7390000047793542}} {"text": "module Group\n\nimport Monoid\n%access public export\n\n||| The proof that b is inverse of a\ntotal\nIsInverse : (typ : Type) -> ((*) : typ -> typ -> typ) -> (IdentityExists typ (*)) -> (a : typ) -> (b : typ) -> Type\nIsInverse typ (*) pfid a b = ((a*b = fst(pfid)),(b*a = fst(pfid)))\n\n||| Given a type and a binary operation the type of proofs that each element has its inverse\ntotal\nInverseExists : (typ : Type) -> ((*) : typ -> typ -> typ) -> Type\nInverseExists typ (*) = (pfid : (IdentityExists typ (*)) ** ((a : typ) -> (a_inv ** (IsInverse typ (*) pfid a a_inv))))\n--(pfid : (IdentityExists typ (*)) ** ((a : typ) -> (a_inv : typ ** ((a*a_inv = fst(pfid)),(a_inv*a = fst(pfid))))))\n\n||| Given a type and a binary operation the type of proofs that the type along with the\n||| operation is a group\ntotal\nIsGroup : (grp : Type) -> ((*) : grp -> grp -> grp) -> Type\nIsGroup grp (*) = (Associative grp (*), (IdentityExists grp (*), InverseExists grp (*)))\n\n||| Given a group gives it's identity with proof\ntotal\nGroup_id : (grp : Type) -> ((*) : grp -> grp -> grp) -> (IsGroup grp (*)) -> (IdentityExists grp (*))\nGroup_id grp (*) pfgrp = (fst (snd pfgrp))\n\n||| Generates inverses with proofs\ntotal\nInv_with_pf : (grp : Type) -> ((*) : grp -> grp -> grp) -> (pfgrp : IsGroup grp (*)) -> (x : grp)\n -> (y : grp ** (IsInverse grp (*) (fst (snd (snd pfgrp))) x y))\nInv_with_pf grp (*) pfgrp x = (snd (snd (snd pfgrp))) x\n\n||| Generates inverses\ntotal\nInv: (grp : Type) -> ((*) : grp -> grp -> grp) -> IsGroup grp (*) -> (x: grp) -> grp\nInv grp (*) pf x = fst (Inv_with_pf grp (*) pf x)\n-- fst(snd(snd(snd(pf))) x)\n\n||| Given a group, the type of proofs that it is abelian\ntotal\nIsAbelianGrp: (grp : Type) -> ((*) : grp -> grp -> grp) -> Type\nIsAbelianGrp grp (*) = (IsGroup grp (*), Commutative grp (*))\n--- (a:grp) -> (b:grp) -> (a*b = b*a)\n\n||| The type of proofs that a given function f between x and y is injective\ntotal\nInj: (x: Type) -> (y: Type) -> (f: x-> y) -> Type\nInj x y f = (a : x) -> (b : x) -> (f a = f b) -> (a = b)\n\n|||The Group data type, with a single constructor\ndata Group: (g: Type) -> Type where\n MkGroup: (grp : Type) -> ((*) : grp -> grp -> grp) -> (IsGroup grp (*)) -> Group grp\n\n||| The type of proofs that a function between groups is a group homomorphism\ntotal\nHom: (grp : Type) -> Group grp -> (g: Type) -> Group g -> (f : grp -> g) -> Type\nHom grp (MkGroup grp (*) pf1) g (MkGroup g (+) pf2) f = ((IsIdentity g (+) e) , (\n (a : grp) -> (b : grp) -> ((f (a*b)) = ((f a) + (f b))))) where\n e = f(fst (Group_id grp (*) pf1))\n\n||| The type of proofs that a given group is a subgroup of another, via injective homorphisms\ntotal\nSubgroup: (h: Type) -> Group h -> (g: Type) -> Group g -> Type\nSubgroup h pfh g pfg = DPair (h -> g) (\\f => (Hom h pfh g pfg f , Inj h g f))\n--- DPair (h->g) (\\f => ((Hom h (+) pfh g (*) pfg f), (Inj h g f)))\n\n||| The type of proofs that a given subgroup is normal/self-conjugate\ntotal\nNSub: (h: Type) -> (pfh: Group h) -> (g: Type) -> (pfg: Group g) ->\n (Subgroup h pfh g pfg) -> Type\nNSub h (MkGroup h (+) pfh) g (MkGroup g (*) pfg) (f ** pff) = (a : h) -> (b : g) -> (x : h ** (b*(f a)*(inv b) = (f x))) where\n inv = Inv g (*) pfg\n", "meta": {"hexsha": "e61112f4d3fc9ba59480df0086afa5f16cd2e00e", "size": 3266, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/Group.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": "_local-site/Code/Group.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": "_local-site/Code/Group.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": 44.1351351351, "max_line_length": 127, "alphanum_fraction": 0.5529699939, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.738971798470786}} {"text": "data Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\nnatToFin : Nat -> (n : Nat) -> Maybe (Fin n)\nnatToFin Z (S j) = Just FZ\nnatToFin (S k) (S j)\n = case natToFin k j of\n Just k' => Just (FS k')\n Nothing => Nothing\nnatToFin _ _ = Nothing\n\nintegerToFin : Integer -> (n : Nat) -> Maybe (Fin n)\nintegerToFin x Z = Nothing\nintegerToFin x n = if x >= 0 then natToFin (fromInteger x) n else Nothing\n\ndata IsJust : Maybe a -> Type where\n ItIsJust : IsJust (Just x)\n\n-- Testing that %allow_overloads lets this one through!\npartial\nfromInteger : {k : Nat} ->\n (n : Integer) ->\n {auto prf : IsJust (integerToFin n k)} ->\n Fin k\nfromInteger {k} n {prf}\n = case integerToFin n k of\n Just val => val\n\nfoo : Fin 5\nfoo = 3\n\nbar : Fin 5\nbar = 8\n\n", "meta": {"hexsha": "fddd79dde9badca3f676da0a504192ac66f9b2e8", "size": 836, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic018/Fin.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/tests/idris2/basic018/Fin.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/tests/idris2/basic018/Fin.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": 23.2222222222, "max_line_length": 73, "alphanum_fraction": 0.5657894737, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7386677044412494}} {"text": "import Data.Primitives.Views\n\n-- Exercise 1\n\nevery_other : Stream a -> Stream a\nevery_other (x :: y :: xs) = y :: every_other xs\n\n-- Exercise 2\n\ndata InfList : Type -> Type where\n (::) : (value : elem) -> Inf (InfList elem) -> InfList elem\n\n%name InfList xs, ys, zs\n\ncountFrom : Integer -> InfList Integer\ncountFrom x = x :: Delay (countFrom (x + 1))\n\ngetPrefix : (count : Nat) -> InfList a -> List a\ngetPrefix Z xs = []\ngetPrefix (S k) (value :: xs) = value :: getPrefix k xs\n\nFunctor InfList where\n map func (value :: xs) = func value :: map func xs\n\nExercise 3\n\nrandoms : Int -> Stream Int\nrandoms seed = let seed' = 1664525 * seed + 1013904223 in\n (seed' `shiftR` 2) :: randoms seed'\n\ndata Face = Heads | Tails\n\ntotal\ngetFace : Int -> Face\ngetFace x with (divides x 2)\n getFace ((2 * div) + rem) | (DivBy prf)\n = case rem of\n 0 => Heads\n _ => Tails\n\ncoinFlips : Nat -> Stream Int -> List Face\ncoinFlips k rnds = map getFace (take k rnds)\n\n-- Exercise 4\n\nsquare_root_approx : (number : Double) -> (approx : Double) -> Stream Double\nsquare_root_approx number approx\n = let next = (approx + (number / approx)) / 2 in\n approx :: square_root_approx number next\n\n-- Exercise 5\n\nsquare_root_bound : (max : Nat) -> (number : Double) -> (bound : Double) ->\n (approxs : Stream Double) -> Double\nsquare_root_bound Z number bound (x :: xs) = x\nsquare_root_bound (S k) number bound (x :: xs) =\n if (abs (x * x - number) < bound)\n then x\n else square_root_bound k number bound xs\n\nsquare_root : (number : Double) -> Double\nsquare_root number = square_root_bound 100 number 0.00000000001\n (square_root_approx number number)\n", "meta": {"hexsha": "f3b75410528c1124c6a76a2e8a3a2706ab0ce6cf", "size": 1764, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter11/Exercises/ex_11_1.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter11/Exercises/ex_11_1.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter11/Exercises/ex_11_1.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5625, "max_line_length": 76, "alphanum_fraction": 0.6145124717, "num_tokens": 500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7386002660515576}} {"text": "module xquant.Math.Hilbert\n\nimport xquant.Core.Types\nimport Data.Matrix\nimport Data.Complex\n\n-- Normalize\nnormalize : StateSpace n Float -> StateSpace n Float\nnormalize q = map (\\(r :+ i) => (r / (sqrt sqn)) :+ (i / (sqrt sqn))) q where\n sqn : Double\n sqn = sum $ map ((\\x => x*x) . magnitude) q\n\nconjugate : (Num a , Neg a) => Complex a -> Complex a\nconjugate (r :+ i) = r :+ -i\n\n-- Infix Hilbert inner product\n-- should be more general, but no official declaration for Num a => Num (Complex a)\n||| Hilbert Inner product\n(<|>) : StateSpace n Float -> StateSpace n Float -> Complex Float\n(<|>) q w = sum $ zipWith (*) (map Complex.conjugate q) w\n\n\n-- Hermitian conjugate (adjoint) on complex matrices\ndagger : (Num a , Neg a) => Matrix n m (Complex a) -> Matrix m n (Complex a)\ndagger h = map (map Hilbert.conjugate) $ transpose h\n\n-- Complex number divide\n(/) : Complex Float -> Complex Float -> Complex Float\n(/) (a:+b) (c:+d) = let real = (a*c+b*d)/(c*c+d*d)\n imag = (b*c-a*d)/(c*c+d*d)\n in (real :+ imag)\n", "meta": {"hexsha": "3af42749ff3591b08682c647aa7218e333a98284", "size": 1058, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/xquant/Math/Hilbert.idr", "max_stars_repo_name": "BlackBrane/xquant", "max_stars_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-10-31T21:21:40.000Z", "max_stars_repo_stars_event_max_datetime": "2017-01-23T17:42:39.000Z", "max_issues_repo_path": "src/xquant/Math/Hilbert.idr", "max_issues_repo_name": "fieldstrength/xquant", "max_issues_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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/xquant/Math/Hilbert.idr", "max_forks_repo_name": "fieldstrength/xquant", "max_forks_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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.0625, "max_line_length": 85, "alphanum_fraction": 0.6096408318, "num_tokens": 327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801094, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.7381340443187493}} {"text": "module MyLibrary.ZZ2\n--mainly code from:https://github.com/idris-lang/Idris-dev/blob/master/libs/contrib/Data/ZZ.idr and adjusted for Idris2\n--includes Sign functionality adjusted for Idris2 from:https://github.com/idris-lang/Idris-dev/blob/master/libs/contrib/Data/Sign.idr\n\nimport Data.Nat\nimport Decidable.Equality\n--import MyLibrary.Sign\n\n%default total\n\n||| A representation of signs for signed datatypes such as `ZZ`\npublic export\ndata Sign = Plus | Zero | Minus\n\npublic export\nopposite : Sign -> Sign\nopposite Plus = Minus\nopposite Zero = Zero\nopposite Minus = Plus\n\npublic export\nmultiply : Sign -> Sign -> Sign\nmultiply Zero _ = Zero\nmultiply _ Zero = Zero\nmultiply Plus x = x\nmultiply Minus x = opposite x\n\n||| Discover the sign of some type\npublic export\ninterface Signed t where\n total sign : t -> Sign\n\npublic export\nSigned Int where\n sign x = if (compare x 0) == LT then Minus else\n if (compare x 0) == EQ then Zero else Plus\n --| LT = Minus\n --| EQ = Zero\n --| GT = Plus...could use case statements => etc\n\npublic export\nSigned Integer where\n sign x = if (compare x 0) == LT then Minus else\n if (compare x 0) == EQ then Zero else Plus\n\npublic export\nSigned Double where\n sign x = if (compare x 0) == LT then Minus else\n if (compare x 0) == EQ then Zero else Plus\n\n||| An integer is either a positive `Nat` or the negated successor of a `Nat`.\n|||\n||| For example, 3 is `Pos 3` and -2 is `NegS 1`. Zero is arbitrarily chosen\n||| to be positive.\n|||\npublic export\ndata ZZ = Pos Nat | NegS Nat\n\npublic export\nimplementation Signed ZZ where\n sign (Pos Z) = Zero\n sign (Pos _) = Plus\n sign (NegS _) = Minus\n\n||| Take the absolute value of a `ZZ`\npublic export\nabsZ : ZZ -> Nat\nabsZ (Pos n) = n\nabsZ (NegS n) = S n\n\npublic export\nimplementation Show ZZ where\n showPrec d (Pos n) = showPrec d n\n showPrec d (NegS n) = showParens (d >= PrefixMinus) $ \"-\" ++ showPrec PrefixMinus (S n)\n\npublic export\nnegNat : Nat -> ZZ\nnegNat Z = Pos Z\nnegNat (S n) = NegS n\n\n||| Construct a `ZZ` as the difference of two `Nat`s\npublic export\nminusNatZ : Nat -> Nat -> ZZ\nminusNatZ n Z = Pos n\nminusNatZ Z (S m) = NegS m\nminusNatZ (S n) (S m) = minusNatZ n m\n\n||| Add two `ZZ`s. Consider using `(+) {a=ZZ}`.\npublic export\nplusZ : ZZ -> ZZ -> ZZ\nplusZ (Pos n) (Pos m) = Pos (n + m)\nplusZ (NegS n) (NegS m) = NegS (S (n + m))\nplusZ (Pos n) (NegS m) = minusNatZ n (S m)\nplusZ (NegS n) (Pos m) = minusNatZ m (S n)\n\npublic export\nimplementation Eq ZZ where\n (Pos n) == (Pos m) = n == m\n (NegS n) == (NegS m) = n == m\n _ == _ = False\n\npublic export\nimplementation Ord ZZ where\n compare (Pos n) (Pos m) = compare n m\n compare (NegS n) (NegS m) = compare m n\n compare (Pos _) (NegS _) = GT\n compare (NegS _) (Pos _) = LT\n\n||| Multiply two `ZZ`s. Consider using `(*) {a=ZZ}`.\npublic export\nmultZ : ZZ -> ZZ -> ZZ\nmultZ (Pos n) (Pos m) = Pos $ n * m\nmultZ (NegS n) (NegS m) = Pos $ (S n) * (S m)\nmultZ (NegS n) (Pos m) = negNat $ (S n) * m\nmultZ (Pos n) (NegS m) = negNat $ n * (S m)\n\n||| Convert an `Integer` to an inductive representation.\npublic export\nfromInt : Integer -> ZZ\nfromInt n = if n < 0\n then NegS $ fromInteger ((-n) - 1)\n else Pos $ fromInteger n\n\npublic export\nimplementation Cast Nat ZZ where\n cast n = Pos n\n\npublic export\nimplementation Num ZZ where\n (+) = plusZ\n (*) = multZ\n fromInteger = fromInt\n\npublic export\nimplementation Abs ZZ where\n abs = cast . absZ\n\npublic export\nimplementation Neg ZZ where\n negate (Pos Z) = Pos Z\n negate (Pos (S n)) = NegS n\n negate (NegS n) = Pos (S n)\n (-) n m = plusZ n (negate m)\n\n||| Subtract two `ZZ`s. Consider using `(-) {a=ZZ}`.\npublic export\nsubZ : ZZ -> ZZ -> ZZ\nsubZ n m = (-) n m\n\npublic export\nimplementation Cast ZZ Integer where\n cast (Pos n) = cast n\n cast (NegS n) = (-1) * (cast n + 1)\n\npublic export\nimplementation Cast Integer ZZ where\n cast = fromInteger\n\n--------------------------------------------------------------------------------\n-- Properties\n--------------------------------------------------------------------------------\n\npublic export\nnatPlusZPlus : (n : Nat) -> (m : Nat) -> (x : Nat)\n -> n + m = x -> (Pos n) + (Pos m) = Pos x\nnatPlusZPlus n m x h = (cong Pos) h\n\npublic export\nnatMultZMult : (n : Nat) -> (m : Nat) -> (x : Nat)\n -> n * m = x -> (Pos n) * (Pos m) = Pos x\nnatMultZMult n m x h = (cong Pos) h\n\npublic export\ndoubleNegElim : (z : ZZ) -> negate (negate z) = z\ndoubleNegElim (Pos Z) = Refl\ndoubleNegElim (Pos (S n)) = Refl\ndoubleNegElim (NegS Z) = Refl\ndoubleNegElim (NegS (S n)) = Refl\n\n-- Injectivity\npublic export\nposInjective : Pos n = Pos m -> n = m\nposInjective Refl = Refl\n\npublic export\nnegSInjective : NegS n = NegS m -> n = m\nnegSInjective Refl = Refl\n\npublic export\nposNotNeg : Pos n = NegS m -> Void\nposNotNeg Refl impossible\n\n-- Decidable equality\npublic export\nimplementation DecEq ZZ where\n decEq (Pos n) (NegS m) = No posNotNeg\n decEq (NegS n) (Pos m) = No $ negEqSym posNotNeg\n decEq (Pos n) (Pos m) = case (decEq n m) of\n Yes p => Yes $ (cong Pos) p\n No p => No $ \\h => p $ posInjective h\n decEq (NegS n) (NegS m) = case (decEq n m) of\n Yes p => Yes $ (cong NegS) p\n No p => No $ \\h => p $ negSInjective h\n\n-- Plus\npublic export\nplusZeroLeftNeutralZ : (right : ZZ) -> 0 + right = right\nplusZeroLeftNeutralZ (Pos n) = Refl\nplusZeroLeftNeutralZ (NegS n) = Refl\n\npublic export\nplusZeroRightNeutralZ : (left : ZZ) -> left + 0 = left\nplusZeroRightNeutralZ (Pos n) = (cong Pos) $ plusZeroRightNeutral n\nplusZeroRightNeutralZ (NegS n) = Refl\n\npublic export\nplusCommutativeZ : (left : ZZ) -> (right : ZZ) -> (left + right = right + left)\nplusCommutativeZ (Pos n) (Pos m) = (cong Pos) $ plusCommutative n m\nplusCommutativeZ (Pos n) (NegS m) = Refl\nplusCommutativeZ (NegS n) (Pos m) = Refl\nplusCommutativeZ (NegS n) (NegS m) = (cong NegS)\n $ (cong S) $ plusCommutative n m\n\npublic export\nminusNatZAntiCommutative : (j, k : Nat) -> negate (minusNatZ j k) = minusNatZ k j\nminusNatZAntiCommutative Z Z = Refl\nminusNatZAntiCommutative Z (S k) = Refl\nminusNatZAntiCommutative (S j) Z = Refl\nminusNatZAntiCommutative (S j) (S k) = minusNatZAntiCommutative j k\n\npublic export\nnegateDistributesPlus : (a, b : ZZ) -> negate (a + b) = (negate a) + (negate b)\nnegateDistributesPlus (Pos Z) b = rewrite plusZeroLeftNeutralZ b in\n rewrite plusZeroLeftNeutralZ (negate b) in Refl\nnegateDistributesPlus (Pos (S k)) (Pos Z) = rewrite plusZeroRightNeutral k in Refl\nnegateDistributesPlus (Pos (S k)) (Pos (S j)) = rewrite plusCommutative k (S j) in\n rewrite plusCommutative j k in Refl\nnegateDistributesPlus (Pos (S k)) (NegS j) = minusNatZAntiCommutative k j\nnegateDistributesPlus (NegS k) (Pos Z) = rewrite plusZeroRightNeutral k in Refl\nnegateDistributesPlus (NegS k) (Pos (S j)) = minusNatZAntiCommutative j k\nnegateDistributesPlus (NegS k) (NegS j) = rewrite plusCommutative k (S j) in\n rewrite plusCommutative k j in Refl\n\npublic export\nlemmaMinusSucc : (k, j, i : Nat) -> plusZ (minusNatZ k (S j)) (Pos i) = plusZ (minusNatZ k (S (S j))) (Pos (S i))\nlemmaMinusSucc Z j i = Refl\nlemmaMinusSucc (S Z) Z i = Refl\nlemmaMinusSucc (S (S k)) Z i = rewrite plusCommutative k (S i) in\n rewrite plusCommutative i k in Refl\nlemmaMinusSucc (S k) (S j) i = lemmaMinusSucc k j i\n\npublic export\nlemmaAssocNegation : (k : Nat) -> (c, r : ZZ) -> (Pos (S k)) + (c + r) = ((Pos (S k)) + c) + r -> (NegS k) + ((negate c) + (negate r)) = ((NegS k) + (negate c)) + (negate r)\nlemmaAssocNegation k c r prf = rewrite sym $ negateDistributesPlus c r in\n rewrite sym $ negateDistributesPlus (Pos (S k)) (plusZ c r) in\n rewrite sym $ negateDistributesPlus (Pos (S k)) c in\n rewrite sym $ negateDistributesPlus (plusZ (Pos (S k)) c) r in\n (cong negate) $ prf\n\npublic export\nlemmaAssocPos : (k : Nat) -> (c, r : ZZ) -> (Pos k) + (c + r) = ((Pos k) + c) + r\nlemmaAssocPos k (Pos j) (Pos i) = (cong Pos) $ plusAssociative k j i\nlemmaAssocPos k (Pos Z) (NegS i) = rewrite plusZeroRightNeutral k in Refl\nlemmaAssocPos k (Pos (S j)) (NegS Z) = rewrite plusCommutative k (S j) in\n rewrite plusCommutative j k in Refl\nlemmaAssocPos k (Pos (S j)) (NegS (S i)) = let ind = lemmaAssocPos k (assert_smaller (Pos (S j)) (Pos j)) (assert_smaller (NegS (S i)) (NegS i)) in\n rewrite ind in\n rewrite plusCommutative k (S j) in\n rewrite plusCommutative j k in Refl\nlemmaAssocPos k (NegS j) (Pos Z) = rewrite plusZeroRightNeutralZ (minusNatZ k (S j)) in Refl\nlemmaAssocPos k (NegS (S j)) (Pos (S i)) = let ind = lemmaAssocPos k (assert_smaller (NegS (S j)) (NegS j)) (assert_smaller (Pos (S i)) (Pos i)) in\n rewrite ind in\n rewrite lemmaMinusSucc k j i in Refl\nlemmaAssocPos Z (NegS Z) (Pos (S i)) = Refl\nlemmaAssocPos (S k) (NegS Z) (Pos (S i)) = rewrite plusCommutative k (S i) in\n rewrite plusCommutative k i in Refl\nlemmaAssocPos Z (NegS j) (NegS i) = Refl\nlemmaAssocPos (S k) (NegS Z) (NegS i) = Refl\nlemmaAssocPos (S k) (NegS (S j)) (NegS i) = let ind = lemmaAssocPos (assert_smaller (S k) k) (assert_smaller (NegS (S j)) (NegS j)) (NegS i) in\n rewrite ind in Refl\n\npublic export\nplusAssociativeZ : (l, c, r : ZZ) -> l + (c + r) = (l + c) + r\nplusAssociativeZ (Pos k) c r = lemmaAssocPos k c r\nplusAssociativeZ (NegS k) c r = rewrite sym $ doubleNegElim c in\n rewrite sym $ doubleNegElim r in\n lemmaAssocNegation k (negate c) (negate r) (lemmaAssocPos (S k) (negate c) (negate r))\n\npublic export\nlemmaMinusSymmZero : (k : Nat) -> minusNatZ k k = Pos 0\nlemmaMinusSymmZero Z = Refl\nlemmaMinusSymmZero (S k) = let ind = lemmaMinusSymmZero k in\n rewrite ind in Refl\n\npublic export --should be RZ? - changed from LZ in original file\nplusNegateInverseRZ2 : (a : ZZ) -> a + negate a = Pos Z\nplusNegateInverseRZ2 (Pos Z) = Refl\nplusNegateInverseRZ2 (Pos (S k)) = rewrite lemmaMinusSymmZero k in Refl\nplusNegateInverseRZ2 (NegS k) = rewrite lemmaMinusSymmZero k in Refl\n\npublic export --should be LZ? changed from RZ in original file\nplusNegateInverseLZ2 : (a : ZZ) -> negate a + a = Pos Z\nplusNegateInverseLZ2 (Pos Z) = Refl\nplusNegateInverseLZ2 (Pos (S k)) = rewrite lemmaMinusSymmZero k in Refl\nplusNegateInverseLZ2 (NegS k) = rewrite lemmaMinusSymmZero k in Refl\n\n-- Mult\npublic export\nmultZeroLeftZeroZ : (right : ZZ) -> (Pos Z) * right = (Pos Z)\nmultZeroLeftZeroZ (Pos k) = Refl\nmultZeroLeftZeroZ (NegS k) = Refl\n\npublic export\nmultZeroRightZeroZ : (left : ZZ) -> left * (Pos Z) = (Pos Z)\nmultZeroRightZeroZ (Pos k) = rewrite multZeroRightZero k in Refl\nmultZeroRightZeroZ (NegS k) = rewrite multZeroRightZero k in Refl\n\npublic export\nmultOneLeftNeutralZ : (right : ZZ) -> 1 * right = right\nmultOneLeftNeutralZ (Pos k) = rewrite plusZeroRightNeutral k in Refl\nmultOneLeftNeutralZ (NegS k) = rewrite plusZeroRightNeutral k in Refl\n\npublic export\nmultOneRightNeutralZ : (left : ZZ) -> left * 1 = left\nmultOneRightNeutralZ (Pos Z) = Refl\nmultOneRightNeutralZ (Pos (S k)) = (cong Pos) $ multOneRightNeutral (S k)\nmultOneRightNeutralZ (NegS k) = (cong NegS) $ multOneRightNeutral k\n\npublic export\nmultCommutativeZ : (left : ZZ) -> (right : ZZ) -> (left * right = right * left)\nmultCommutativeZ (Pos k) (Pos j) = (cong Pos) $ multCommutative k j\nmultCommutativeZ (Pos k) (NegS j) = rewrite multCommutative j k in\n (cong negNat) $ multRightSuccPlus k j\nmultCommutativeZ (NegS k) (Pos j) = rewrite multCommutative j (S k) in Refl\nmultCommutativeZ (NegS k) (NegS j) = (cong Pos) $ multCommutative (S k) (S j)\n\npublic export\nlemmaPosMultNegNat : (k, j : Nat) -> multZ (Pos k) (negNat j) = negNat (mult k j)\nlemmaPosMultNegNat k Z = rewrite multZeroRightZero k in Refl\nlemmaPosMultNegNat k (S j) = Refl\n\npublic export\nlemmaNegMultNegNat : (k, j : Nat) -> multZ (NegS k) (negNat j) = multZ (Pos (S k)) (Pos j)\nlemmaNegMultNegNat k Z = rewrite multZeroRightZero k in Refl\nlemmaNegMultNegNat k (S j) = Refl\n\npublic export\nlemmaNegatePosNegNat : (k : Nat) -> negate (Pos k) = negNat k\nlemmaNegatePosNegNat Z = Refl\nlemmaNegatePosNegNat (S k) = Refl\n\npublic export\nmultNegLeftZ : (k : Nat) -> (j : ZZ) -> (NegS k) * j = negate (Pos (S k) * j)\nmultNegLeftZ k (Pos j) = rewrite lemmaNegatePosNegNat ((S k) * j) in Refl\nmultNegLeftZ k (NegS j) = Refl\n\npublic export\nmultNegateLeftZ : (k, j : ZZ) -> (negate k) * j = negate (k * j)\nmultNegateLeftZ (Pos Z) j = rewrite multZeroLeftZeroZ j in Refl\nmultNegateLeftZ (Pos (S k)) (Pos j) = rewrite lemmaNegatePosNegNat ((S k) * j) in Refl\nmultNegateLeftZ (Pos (S k)) (NegS j) = Refl\nmultNegateLeftZ (NegS k) j = rewrite sym $ doubleNegElim (multZ (Pos (S k)) j) in\n rewrite multNegLeftZ k j in Refl\n\npublic export\nmultAssociativeZPos : (k : Nat) -> (c, r : ZZ) -> (Pos k) * (c * r) = ((Pos k) * c) * r\nmultAssociativeZPos k (Pos j) (Pos i) = (cong Pos) $ multAssociative k j i\nmultAssociativeZPos k (Pos j) (NegS i) = rewrite sym $ multAssociative k j (S i) in lemmaPosMultNegNat k (mult j (S i))\nmultAssociativeZPos k (NegS j) (Pos i) = rewrite multCommutative j i in\n rewrite sym $ multRightSuccPlus i j in\n rewrite lemmaPosMultNegNat k (mult i (S j)) in\n rewrite multCommutativeZ (negNat (mult k (S j))) (Pos i) in\n rewrite lemmaPosMultNegNat i (mult k (S j)) in\n rewrite multAssociative k i (S j) in\n rewrite multAssociative i k (S j) in\n rewrite multCommutative i k in Refl\nmultAssociativeZPos k (NegS j) (NegS i) = rewrite multCommutativeZ (negNat (mult k (S j))) (NegS i) in\n rewrite lemmaNegMultNegNat i (mult k (S j)) in\n rewrite multAssociative k (S j) (S i) in\n rewrite multCommutative (mult k (S j)) (S i) in Refl\n\npublic export\nmultAssociativeZ : (l, c, r : ZZ) -> l * (c * r) = (l * c) * r\nmultAssociativeZ (Pos k) c r = multAssociativeZPos k c r\nmultAssociativeZ (NegS k) c r = rewrite multNegLeftZ k (c * r) in\n rewrite multNegLeftZ k c in\n rewrite multNegateLeftZ (multZ (Pos (S k)) c) r in\n (cong negate) $ multAssociativeZPos (S k) c r\n\npublic export\nlemmaPlusPosNegCancel : (k, j, i : Nat) -> plusZ (Pos (plus k j)) (negNat (plus k i)) = plusZ (Pos j) (negNat i)\nlemmaPlusPosNegCancel Z j i = Refl\nlemmaPlusPosNegCancel (S Z) j Z = rewrite plusZeroRightNeutral j in Refl\nlemmaPlusPosNegCancel (S Z) j (S i) = Refl\nlemmaPlusPosNegCancel (S (S k)) j i = lemmaPlusPosNegCancel (S k) j i\n\npublic export\nlemmaPlusPosNegZero : (k : Nat) -> plusZ (Pos k) (negNat k) = Pos Z\nlemmaPlusPosNegZero Z = Refl\nlemmaPlusPosNegZero (S k) = rewrite lemmaMinusSymmZero k in Refl\n\npublic export\nnegNatDistributesPlus : (j, k : Nat) -> plusZ (negNat j) (negNat k) = negNat (plus j k)\nnegNatDistributesPlus Z k = rewrite plusZeroLeftNeutralZ (negNat k) in Refl\nnegNatDistributesPlus (S j) Z = rewrite plusZeroRightNeutral j in Refl\nnegNatDistributesPlus (S j) (S k) = rewrite plusSuccRightSucc j k in Refl\n\n-- Distributivity\npublic export\nmultDistributesOverPlusRightPosPosZ : (l, c : Nat) -> (r : ZZ) -> (Pos l) * ((Pos c) + r) = ((Pos l) * (Pos c)) + ((Pos l) * r)\nmultDistributesOverPlusRightPosPosZ l c (Pos i) = rewrite multDistributesOverPlusRight l c i in Refl\nmultDistributesOverPlusRightPosPosZ l Z (NegS i) = rewrite multZeroRightZero l in\n rewrite plusZeroLeftNeutralZ (negNat (mult l (S i))) in Refl\nmultDistributesOverPlusRightPosPosZ l (S c) (NegS Z) = rewrite multOneRightNeutral l in\n rewrite multRightSuccPlus l c in\n rewrite sym $ plusAssociativeZ (Pos l) (Pos (mult l c)) (negNat l) in\n rewrite plusCommutativeZ (Pos (mult l c)) (negNat l) in\n rewrite plusAssociativeZ (Pos l) (negNat l) (Pos (mult l c)) in\n rewrite lemmaPlusPosNegZero l in Refl\nmultDistributesOverPlusRightPosPosZ l (S c) (NegS (S i)) = let ind = multDistributesOverPlusRightPosPosZ l (assert_smaller (S c) c) (assert_smaller (NegS (S i)) (NegS i)) in\n rewrite ind in\n rewrite multRightSuccPlus l (S i) in\n rewrite multRightSuccPlus l c in\n rewrite lemmaPlusPosNegCancel l (mult l c) (mult l (S i)) in Refl\n\npublic export\nmultDistributesOverPlusRightPosZ : (k : Nat) -> (c, r : ZZ) -> (Pos k) * (c + r) = ((Pos k) * c) + ((Pos k) * r)\nmultDistributesOverPlusRightPosZ k (Pos j) r = multDistributesOverPlusRightPosPosZ k j r\nmultDistributesOverPlusRightPosZ k (NegS j) (Pos i) = rewrite plusCommutativeZ ((Pos k) * (NegS j)) ((Pos k) * (Pos i)) in\n rewrite multDistributesOverPlusRightPosPosZ k i (NegS j) in Refl\nmultDistributesOverPlusRightPosZ k (NegS j) (NegS i) = rewrite negNatDistributesPlus (mult k (S j)) (mult k (S i)) in\n rewrite sym $ multDistributesOverPlusRight k (S j) (S i) in\n rewrite plusSuccRightSucc j i in Refl\n\npublic export\nmultDistributesOverPlusRightZ : (l, c, r : ZZ) -> l * (c + r) = (l * c) + (l * r)\nmultDistributesOverPlusRightZ (Pos k) c r = multDistributesOverPlusRightPosZ k c r\nmultDistributesOverPlusRightZ (NegS k) c r = rewrite multNegLeftZ k (plusZ c r) in\n rewrite multNegLeftZ k c in\n rewrite multNegLeftZ k r in\n rewrite sym $ negateDistributesPlus (multZ (Pos (S k)) c) (multZ (Pos (S k)) r) in\n rewrite multDistributesOverPlusRightPosZ (S k) c r in Refl\n\npublic export\nmultDistributesOverPlusLeftZ : (l, c, r : ZZ) -> (l + c) * r = (l * r) + (c * r)\nmultDistributesOverPlusLeftZ l c r = rewrite multCommutativeZ (l + c) r in\n rewrite multDistributesOverPlusRightZ r l c in\n rewrite multCommutativeZ r l in\n rewrite multCommutativeZ r c in Refl\n", "meta": {"hexsha": "3ce53dee45679fcdb43927394851e8c1adf26988", "size": 19335, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZZ.idr", "max_stars_repo_name": "reswatson/ZZ", "max_stars_repo_head_hexsha": "a874526a7865b545eea64756d3c4e95c8cc182a0", "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": "ZZ.idr", "max_issues_repo_name": "reswatson/ZZ", "max_issues_repo_head_hexsha": "a874526a7865b545eea64756d3c4e95c8cc182a0", "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": "ZZ.idr", "max_forks_repo_name": "reswatson/ZZ", "max_forks_repo_head_hexsha": "a874526a7865b545eea64756d3c4e95c8cc182a0", "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": 42.9666666667, "max_line_length": 173, "alphanum_fraction": 0.6042927334, "num_tokens": 6042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7379556541985769}} {"text": "-- Borrowed from Botta at https://gitlab.pik-potsdam.de/botta/IdrisLibs/blob/master/Nat/LTEProperties.lidr\n\nmodule Positive\n\n\n%default total\n%access public export\n%auto_implicits on\n\n\n|||\ndata Positive : Nat -> Type where\n MkPositive : {n : Nat} -> Positive (S n)\n\n|||\nfromSucc : (m : Nat) -> (n : Nat) -> S m = n -> Positive n\nfromSucc m n prf = s2 where\n s1 : Positive (S m)\n s1 = MkPositive\n s2 : Positive n\n s2 = replace prf s1\n\n|||\nimplementation Uninhabited (Positive Z) where\n uninhabited (MkPositive {n}) impossible\n\n|||\npositiveNotZ : {n : Nat} -> Positive n -> Not (n = Z)\npositiveNotZ {n = Z} p = absurd p\npositiveNotZ {n = S m} _ = SIsNotZ\n\n|||\nplusPreservesPositivity : Positive m -> Positive n -> Positive (m + n)\nplusPreservesPositivity {m = Z } {n } MkPositive _ impossible\nplusPreservesPositivity {m } {n = Z } _ MkPositive impossible\nplusPreservesPositivity {m = S m} {n = S n} _ _ = MkPositive\n\n|||\nmultPreservesPositivity : Positive m -> Positive n -> Positive (m * n)\nmultPreservesPositivity {m = Z } {n } MkPositive _ impossible\nmultPreservesPositivity {m } {n = Z } _ MkPositive impossible\nmultPreservesPositivity {m = S m} {n = S n} _ _ = MkPositive\n", "meta": {"hexsha": "ae72b04145b3e17c06e0de7dfb239006bba16732", "size": 1287, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "NonZeroNat.idr", "max_stars_repo_name": "zenntenn/Idris-NumericProofs", "max_stars_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": "NonZeroNat.idr", "max_issues_repo_name": "zenntenn/Idris-NumericProofs", "max_issues_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": "NonZeroNat.idr", "max_forks_repo_name": "zenntenn/Idris-NumericProofs", "max_forks_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": 29.9302325581, "max_line_length": 106, "alphanum_fraction": 0.6285936286, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7374242541916306}} {"text": "-- Idris 0.9.20\nmodule Main\n\nimport data.Vect\nimport Data.List\n\n%default total\n\n-- Aliases\n\nQueen : Type\nQueen = (Nat, Nat)\n\nIsValid : Type\nIsValid = Bool\n\nValid : IsValid\nValid = True\n\nInvalid : IsValid\nInvalid = False\n\nBoardsize : Type\nBoardsize = Nat\n\nQueens : Nat -> Type\nQueens n = Vect n Queen\n\n-- Helper methods\n\nforAllPairsWithList : List a -> a -> (a -> a -> Bool) -> Bool\nforAllPairsWithList [] element p = True\nforAllPairsWithList (x :: xs) element p = if p element x then forAllPairsWithList xs element p else False\n\nforAllPairsInList : List a -> (a -> a -> Bool) -> Bool\nforAllPairsInList [] p = True\nforAllPairsInList (x :: xs) p = (forAllPairsWithList xs x p) && forAllPairsInList xs p\n\n-- NQueens\n\nisValidNQueens : {n : Boardsize} -> Queens n -> IsValid\nisValidNQueens {n=boardsize} queens =\n let\n queenList = toList queens\n isAllOnBoard = all (isOnBoard boardsize) queenList\n isAllDifferentRows = forAllPairsInList queenList isDifferentRows\n isAllDifferentCols = forAllPairsInList queenList isDifferentCols\n isAllDifferentDiags = forAllPairsInList queenList isDifferentDiags\n in\n isAllOnBoard && isAllDifferentRows && isAllDifferentCols && isAllDifferentDiags\n where\n isOnBoard : Boardsize -> Queen -> Bool\n isOnBoard boardsize (a, b) = a < boardsize && b < boardsize\n\n isDifferentRows : Queen -> Queen -> Bool\n isDifferentRows (a1, a2) (b1, b2) = a1 /= b1\n\n isDifferentCols : Queen -> Queen -> Bool\n isDifferentCols (a1, a2) (b1, b2) = a2 /= b2\n\n -- False if they're on the same diagonale looking from 0/0 to n/n; True otherwise\n isDifferentDiags1 : Queen -> Queen -> Bool\n isDifferentDiags1 ((S a1), (S a2)) b = assert_total (isDifferentDiags1 (a1, a2) b) -- meh\n isDifferentDiags1 a ((S b1), (S b2)) = assert_total (isDifferentDiags1 a (b1, b2)) -- meh\n isDifferentDiags1 (a1, a2) (b1, b2) = if (a1 == b1 && a2 == b2) then False else True\n\n -- False if they're on the same diagonale looking from 0/n to n/0; True otherwise\n isDifferentDiags2 : Queen -> Queen -> Bool\n isDifferentDiags2 ((S a1), a2) (b1, (S b2)) = assert_total (isDifferentDiags2 (a1, a2) (b1, b2)) -- meh\n isDifferentDiags2 (a1, (S a2)) ((S b1), b2) = assert_total (isDifferentDiags2 (a1, a2) (b1, b2)) -- meh\n isDifferentDiags2 (a1, a2) (b1, b2) = if (a1 == b1 && a2 == b2) then False else True\n\n isDifferentDiags : Queen -> Queen -> Bool\n isDifferentDiags a b = (isDifferentDiags1 a b) && (isDifferentDiags2 a b)\n\ndata NQueens : Boardsize -> IsValid -> Type where\n MkNQueens : (queens : Queens n) -> NQueens n (isValidNQueens queens)\n MkInvalidNQueens : (n : Nat) -> NQueens n Invalid\n\ninstance Show (NQueens n isValid) where\n show (MkNQueens queens) =\n if (isValidNQueens queens) then -- meh\n (show (length queens)) ++ \"-Queens \" ++ (show queens)\n else\n \"Invalid \" ++ (show (length queens)) ++ \"-Queens\"\n show (MkInvalidNQueens n) = \"Invalid \" ++ (show n) ++ \"-Queens\"\n\n-- (Compile) Tests\n\nqueen1 : Queen\nqueen1 = (3, 2)\n\nqueen2 : Queen\nqueen2 = (2, 0)\n\nqueen3 : Queen\nqueen3 = (1, 3)\n\nqueen4 : Queen\nqueen4 = (0, 1)\n\nnQueens1 : NQueens 1 Valid\nnQueens1 = MkNQueens [(0, 0)]\n\ninvalidNQueens1 : NQueens 1 Invalid\ninvalidNQueens1 = MkInvalidNQueens _\n\nnQueens4 : NQueens 4 Valid\nnQueens4 = MkNQueens [queen1, queen2, queen3, queen4]\n\ninvalidNQueens4 : NQueens 4 Invalid\ninvalidNQueens4 = MkNQueens [queen1, (3, 3), queen3, queen4]\n\ninvalidNQueens4b : NQueens 4 Invalid\ninvalidNQueens4b = MkNQueens [(2, 2), (3, 0), queen3, queen4]\n\n---- Does not compile! :-)\n--invalidNQueens1Error : NQueens 1 Invalid\n--invalidNQueens1Error = MkNQueens [(0, 0)]\n\n--invalidNQueens2Error : NQueens 2 Valid -- Does not even compile as Invalid!\n--invalidNQueens2Error = MkNQueens [(0, 0)]\n\n--invalidNQueens4Error : NQueens 4 Valid\n--invalidNQueens4Error = MkNQueens [queen1, (3, 3), queen3, queen4]\n\n", "meta": {"hexsha": "a3f27a85a15a701eb35c72381fc6be756d90ba17", "size": 3863, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "nqueens.idr", "max_stars_repo_name": "ExNexu/nqueens-idris", "max_stars_repo_head_hexsha": "b281d15142bea81e1715691346fa5775877db9ba", "max_stars_repo_licenses": ["BSD-2-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": "nqueens.idr", "max_issues_repo_name": "ExNexu/nqueens-idris", "max_issues_repo_head_hexsha": "b281d15142bea81e1715691346fa5775877db9ba", "max_issues_repo_licenses": ["BSD-2-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": "nqueens.idr", "max_forks_repo_name": "ExNexu/nqueens-idris", "max_forks_repo_head_hexsha": "b281d15142bea81e1715691346fa5775877db9ba", "max_forks_repo_licenses": ["BSD-2-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.4173228346, "max_line_length": 107, "alphanum_fraction": 0.6857364742, "num_tokens": 1342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7373097415239406}} {"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 definitions for and implementations of kernel functions, intended\n||| particularly for use in Gaussian processes.\nmodule Model.Kernel\n\nimport Tensor\nimport Data.Nat\n\n||| A `Kernel` function maps pairs of points in a feature space to the covariance between those two\n||| points in some target space.\n|||\n||| @features The shape of the feature domain.\npublic export 0\nKernel : (0 features : Shape) -> Type\nKernel features = {sk, sk' : _} ->\n Tensor (sk :: features) Double ->\n Tensor (sk' :: features) Double ->\n Tensor [sk, sk'] Double\n\nscaled_l2_norm : Tensor [] Double -> {d, n, n' : _}\n -> Tensor [n, S d] Double\n -> Tensor [n', S d] Double\n -> Tensor [n, n'] Double\nscaled_l2_norm len x x' = let xs = broadcast {to=[n, n', S d]} $ expand 1 x\n in reduce_sum 2 $ ((xs - broadcast (expand 0 x')) / len) ^ fill 2.0\n\n||| The radial basis function, or squared exponential kernel. This is a stationary kernel with form\n|||\n||| (\\mathbf x_i, \\mathbf x_j) \\mapsto \\exp \\left(- \\frac{r^2}{2l^2} \\right)\n|||\n||| where `r^2 = (\\mathbf x_i - \\mathbf x_j)^ \\intercal (\\mathbf x_i - \\mathbf x_j)` and the\n||| length scale `l > 0`.\n|||\n||| Two points that are close in feature space will be more tightly correlated than points that\n||| are further apart. The distance over which the correlation reduces is given by the length\n||| scale `l`. Smaller length scales result in faster-varying target values.\n|||\n||| @length_scale The length scale `l`.\nexport\nrbf : (length_scale : Tensor [] Double) -> {d : _} -> Kernel [S d]\nrbf length_scale x x' = exp (- scaled_l2_norm length_scale x x' / const 2.0)\n\n||| The Matern kernel for parameter 5/2. This is a stationary kernel with form\n|||\n||| (\\mathbf x_i, \\mathbf x_j) \\mapsto \\sigma^2 \\left(\n||| 1 + \\frac{\\sqrt{5}r}{l} + \\frac{5 r^2}{3 l^2}\n||| \\right) \\exp \\left( -\\frac{\\sqrt{5}r}{l} \\right)\n|||\n||| where `r^2 = (\\mathbf x_i - \\mathbf x_j)^ \\intercal (\\mathbf x_i - \\mathbf x_j)` and the\n||| length scale `l > 0`.\n|||\n||| @amplitude The amplitude `\\sigma`.\n||| @length_scale The length scale `l`.\nexport\nmatern52 : (amplitude : Tensor [] Double) -> (length_scale : Tensor [] Double)\n -> {d : _} -> Kernel [S d]\nmatern52 amp len x x' = let d2 = const 5.0 * scaled_l2_norm len x x'\n d = d2 ^ fill 0.5\n in (amp ^ const 2.0) * (d2 / fill 3.0 + d + fill 1.0) *# exp (- d)\n", "meta": {"hexsha": "f753f845a4eb8282bbd81ba94621eaa79b28401e", "size": 2982, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Model/Kernel.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/Model/Kernel.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/Model/Kernel.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": 40.2972972973, "max_line_length": 99, "alphanum_fraction": 0.6562709591, "num_tokens": 878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7371326089471042}} {"text": "module Main\n\nimport BSTree\n\nlistToTree : Ord a => List a -> BSTree a\nlistToTree [] = Empty\nlistToTree (x :: xs) = insert x (listToTree xs)\n\ntreeToList : BSTree a -> List a\ntreeToList Empty = []\ntreeToList (Node left val right) = (treeToList left) ++ val :: (treeToList right)\n\ndata Expr = Val Int\n | Add Expr Expr\n | Sub Expr Expr\n | Mult Expr Expr\n\nevaluate : Expr -> Int\nevaluate (Val x) = x\nevaluate (Add x y) = (evaluate x) + (evaluate y)\nevaluate (Sub x y) = (evaluate x) - (evaluate y)\nevaluate (Mult x y) = (evaluate x) * (evaluate y)\n\nmaxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe Nothing Nothing = Nothing\nmaxMaybe Nothing (Just x) = Just x\nmaxMaybe (Just x) Nothing = Just x\nmaxMaybe (Just x) (Just y) = case compare x y of\n LT => Just y\n EQ => Just x\n GT => Just x\n", "meta": {"hexsha": "f2e2103f77f20c7b6ce6b378e87f92904bd5b463", "size": 900, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Excercise_4_1.idr", "max_stars_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_stars_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "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": "Excercise_4_1.idr", "max_issues_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_issues_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "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": "Excercise_4_1.idr", "max_forks_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_forks_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "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.125, "max_line_length": 81, "alphanum_fraction": 0.5811111111, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100817, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7370891514098058}} {"text": "module BoehmBerarducci\n\n%default total\n\n-- NOTE: Issues with scoped implicits:\n-- https://github.com/idris-lang/Idris-dev/issues/2346\n\n\nNatQ : Type\nNatQ = {A : Type} -> (A -> A) -> A -> A\n\nunNatQ : {A : Type} -> (A -> A) -> A -> NatQ -> A\nunNatQ f a q = q f a\n\nsuccQ : NatQ -> NatQ\nsuccQ q = \\f, a => f (q f a)\n\nzeroQ : NatQ\nzeroQ = \\f, a => a\n\nfromNatQ : NatQ -> Nat\nfromNatQ q = unNatQ S Z q\n\n-- NOTE: Issue #2346 / 1\ntoNatQ : Nat -> NatQ\ntoNatQ (S n) = succQ (toNatQ n)\ntoNatQ Z = zeroQ\n\niterated : Nat -> (a -> a) -> a -> a\niterated (S n) f a = f (iterated n f a)\niterated Z f a = a\n\ntest_iterated : (n : Nat) -> iterated n S Z = n\ntest_iterated (S n) = rewrite test_iterated n in Refl\ntest_iterated Z = Refl\n\n-- NOTE: Issue #2346 / 1\n-- test_fromNatQ : (n : Nat) -> fromNatQ (iterated n succQ zeroQ) = n\n-- test_fromNatQ (S n) = rewrite test_fromNatQ n in Refl\n-- test_fromNatQ Z = Refl\n\n-- TODO: Unknown issue\n-- test_toNatQ : (n : Nat) -> toNatQ n = iterated n succQ zeroQ\n-- test_toNatQ (S n) = rewrite test_toNatQ n in Refl\n-- test_toNatQ Z = Refl\n\n\nListQ : Type -> Type\nListQ A = {B : Type} -> (A -> B -> B) -> B -> B\n\nunListQ : {A, B : Type} -> (A -> B -> B) -> B -> ListQ A -> B\nunListQ f b q = q f b\n\nconsQ : {A : Type} -> A -> ListQ A -> ListQ A\nconsQ a q = \\f, b => f a (q f b)\n\nnilQ : {A : Type} -> ListQ A\nnilQ = \\f, b => b\n\nfromListQ : {A : Type} -> ListQ A -> List A\nfromListQ q = unListQ (::) [] q\n\n-- NOTE: Issue #2346 / 1\ntoListQ : {A : Type} -> List A -> ListQ A\ntoListQ (a :: aa) = consQ a (toListQ aa)\ntoListQ [] = nilQ\n", "meta": {"hexsha": "525934c6e1b409db3d97137a206165ae721d548c", "size": 1568, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-implicit/BoehmBerarducci.idr", "max_stars_repo_name": "mietek/scott-encoding", "max_stars_repo_head_hexsha": "14e819383dd8730e1c3cbd9c2ce53335bd95188b", "max_stars_repo_licenses": ["X11", "MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-05-27T19:33:52.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-08T16:31:59.000Z", "max_issues_repo_path": "idris-implicit/BoehmBerarducci.idr", "max_issues_repo_name": "mietek/scott-encoding", "max_issues_repo_head_hexsha": "14e819383dd8730e1c3cbd9c2ce53335bd95188b", "max_issues_repo_licenses": ["X11", "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": "idris-implicit/BoehmBerarducci.idr", "max_forks_repo_name": "mietek/scott-encoding", "max_forks_repo_head_hexsha": "14e819383dd8730e1c3cbd9c2ce53335bd95188b", "max_forks_repo_licenses": ["X11", "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.4029850746, "max_line_length": 69, "alphanum_fraction": 0.5739795918, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7368881398102276}} {"text": "-- -*- idris-interpreter-flags: (\"-p\" \"contrib\") -*-\n\nimport Data.ZZ\nimport Data.Vect\n\ndata CountChange : ZZ -> Vect n ZZ -> Type where\n C1 : CountChange 0 k -- 1 way\n C0a : CountChange (NegS a) k -- 0 ways\n C0b : CountChange a [] -- 0 ways\n CC : CountChange (a - (head k)) k -> CountChange a (tail k) -> CountChange a k -- x + y ways\n\ncount : CountChange x y -> Nat\ncount C1 = 1\ncount C0a = 0\ncount C0b = 0\ncount (CC x y) = count x + count y\n\ncc_2_by_1 : CountChange 2 [1]\ncc_2_by_1 = CC (CC C1 C0b) C0b\n\ncc_2_by_2_1 : CountChange 2 [2,1]\ncc_2_by_2_1 = CC C1 (CC (CC C1 C0b) C0b)\n\ncc_11_by_50_25_10_5_1 : CountChange 11 [50,25,10,5,1] \ncc_11_by_50_25_10_5_1 = ?try_it\n{- ex 1.14 'tree', generated by 'C-c-a'\ncc_11_by_50_25_10_5_1 = CC\n C0a\n (CC\n C0a\n (CC\n (CC\n C0a\n (CC\n C0a\n (CC\n C1\n C0b\n )\n )\n )\n (CC\n (CC\n (CC\n C0a\n (CC\n C1\n C0b\n )\n )\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n C1\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n )\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n (CC\n C1\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n C0b\n )\n )\n )\n )\n-}\n", "meta": {"hexsha": "c2e6037bed5d188e0ac7ea17f9112598260ab403", "size": 4140, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "exchange.idr", "max_stars_repo_name": "oddsome/sicp_1.14_idris", "max_stars_repo_head_hexsha": "68bc8aa67d9637300988408637368fc5d909e13c", "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": "exchange.idr", "max_issues_repo_name": "oddsome/sicp_1.14_idris", "max_issues_repo_head_hexsha": "68bc8aa67d9637300988408637368fc5d909e13c", "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": "exchange.idr", "max_forks_repo_name": "oddsome/sicp_1.14_idris", "max_forks_repo_head_hexsha": "68bc8aa67d9637300988408637368fc5d909e13c", "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.9816513761, "max_line_length": 98, "alphanum_fraction": 0.1492753623, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.7367168356310105}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 4\n\nimport Data.Vect\n\n-- check that all functions are total\n%default total\n\n--\n-- section 4.1\n-- see BSTree.idr\n-- see Expr.idr\n-- see Shape.idr\n--\n\n--\n-- section 4.2\n-- see Vehicle.idr\n--\n\n-- first version, does not output the same error than in the book\n-- > vectTake1 3 [1,2,3,4,5,6,7]\n-- [1, 2, 3] : Vect 3 Integer\n-- > vectTake1 8 [1,2,3,4,5,6,7]\n-- (input):1:11:When checking argument prf to function Data.Fin.fromInteger:\n-- When using 8 as a literal for a Fin 8\n-- 8 is not strictly less than 8\nvectTake1 : (q : Fin (S n)) -> Vect n t -> Vect (finToNat q) t\nvectTake1 FZ _ = []\nvectTake1 (FS x) [] impossible\nvectTake1 (FS x) (y :: ys) = y :: vectTake1 x ys\n\n-- second version\n-- > vectTake2 3 [1,2,3,4,5,6,7]\n-- [1, 2, 3] : Vect 3 Integer\n-- > vectTake2 8 [1,2,3,4,5,6,7]\n-- (input):1:14:When checking argument xs to constructor Data.Vect.:::\n-- Type mismatch between\n-- Vect 0 elem (Type of [])\n-- and\n-- Vect (S k) t (Expected type)\n--\n-- Specifically:\n-- Type mismatch between\n-- 0\n-- and\n-- S k\nvectTake2 : (q : Nat) -> Vect (q+k) t -> Vect q t\nvectTake2 Z _ = []\nvectTake2 (S k) (x :: xs) = x :: vectTake2 k xs\n\nsumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos xs ys = case integerToFin pos n of\n Nothing => Nothing\n (Just x) => Just (index x xs + index x ys)\n\n--\n-- section 4.3\n-- see DataStore.idr\n--\n", "meta": {"hexsha": "4441c644f65ef3d93501f7b1996b8cd600687fe3", "size": 1645, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter4/exercises.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": "chapter4/exercises.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": "chapter4/exercises.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": 26.9672131148, "max_line_length": 76, "alphanum_fraction": 0.5404255319, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.7364751602059596}} {"text": "module Circuits.Common\n\nimport Decidable.Equality\n\nimport Data.Nat\nimport Toolkit.Data.Whole\n\n%default total\n\npublic export\ndata DType = LOGIC | BVECT Whole DType\n\npublic export\nsize : DType -> Nat\nsize LOGIC = (S Z)\nsize (BVECT (W (S n) ItIsSucc) type)\n = mult (S n) (size type)\n\n\nUninhabited (LOGIC = BVECT n k) where\n uninhabited Refl impossible\n\nexport\nShow DType where\n show LOGIC = \"logic\"\n show (BVECT n type) = show type <+> concat [\"[\", show n, \"]\"]\n\nexport\nDecEq DType where\n decEq LOGIC LOGIC = Yes Refl\n decEq LOGIC (BVECT k x) = No absurd\n\n decEq (BVECT k x) LOGIC = No (negEqSym absurd)\n decEq (BVECT k x) (BVECT j y) with (decEq k j)\n decEq (BVECT k x) (BVECT k y) | (Yes Refl) with (decEq x y)\n decEq (BVECT k x) (BVECT k x) | (Yes Refl) | (Yes Refl)\n = Yes Refl\n decEq (BVECT k x) (BVECT k y) | (Yes Refl) | (No contra)\n = No (\\Refl => contra Refl)\n\n decEq (BVECT k x) (BVECT j y) | (No contra)\n = No (\\Refl => contra Refl)\n\n\npublic export\ndata Usage = USED | FREE\n\nUninhabited (USED = FREE) where\n uninhabited Refl impossible\n\nexport\nShow Usage where\n show USED = \"Used\"\n show FREE = \"Free\"\n\nexport\nDecEq Usage where\n decEq USED USED = Yes Refl\n decEq USED FREE = No absurd\n decEq FREE USED = No (negEqSym absurd)\n decEq FREE FREE = Yes Refl\n\n-- [ EOF ]\n", "meta": {"hexsha": "a9a202817336e2ee99d02d7cd3264a6e49a5d304", "size": 1322, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Circuits/Common.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/Common.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/Common.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": 20.65625, "max_line_length": 63, "alphanum_fraction": 0.6512859304, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7364495173368071}} {"text": "module Divisors\n\nimport ZZ\n%access public export\n%default total\n|||IsDivisibleZ a b can be constucted if b divides a\nIsDivisibleZ : ZZ -> ZZ -> Type\nIsDivisibleZ a b = (n : ZZ ** a = b * n)\n\n\n|||1 divides everything\noneDiv : (a : ZZ) -> IsDivisibleZ a 1\noneDiv a = (a ** rewrite sym (multOneLeftNeutralZ a) in Refl)\n\n|||Genetes a proof of (a+b) = d*(n+m) from (a=d*n)and (b=d*m)\ndistributeProof: (a:ZZ)->(b:ZZ)->(d:ZZ)->\n (n:ZZ)->(m:ZZ)->(a=d*n)->(b=d*m)->((a+b) = d*(n+m))\ndistributeProof a b d n m pf1 pf2 =\n rewrite (multDistributesOverPlusRightZ d n m) in\n (trans (the (a+b=(d*n)+b) (v1)) v2) where\n v1 =plusConstantRightZ a (d*n) b pf1\n v2 =plusConstantLeftZ b (d*m) (d*n) pf2\n\n|||The theorem d|a =>d|ac\nmultDiv:(IsDivisibleZ a d) ->(c:ZZ)->(IsDivisibleZ (a*c) d)\nmultDiv {d} (n**Refl) c =\n ((n*c)** (rewrite sym (multAssociativeZ d n c) in (Refl)))\n|||The theorem d|a =>d|ca\nmultDivLeft:(IsDivisibleZ a d) ->(c:ZZ)->(IsDivisibleZ (c*a) d)\nmultDivLeft{a} x c = rewrite (multCommutativeZ c a) in (multDiv x c)\n\n|||The theorem d|a and d|b =>d|(a+b)\nplusDiv : (IsDivisibleZ a d)->(IsDivisibleZ b d)->(IsDivisibleZ (a+b) d)\nplusDiv {d}{a}{b} (n**prf1) (m**prf2) =\n ((n+m)**(distributeProof a b d n m prf1 prf2))\n|||The theorem b|a and c|b =>c|a\ntransDivide : (IsDivisibleZ a b)->(IsDivisibleZ b c)->(IsDivisibleZ a c)\ntransDivide {c} (x ** pf1) (y ** pf2) =\n (y*x ** (rewrite multAssociativeZ c y x in\n (rewrite pf1 in (rewrite pf2 in Refl))))\n\n\n|||If d divides a and b it divides a linear combination of a and b\nlinCombDiv:(m:ZZ)->(n:ZZ)->(IsDivisibleZ a d)->(IsDivisibleZ b d)->\n (IsDivisibleZ ((a*m)+(b*n)) d)\nlinCombDiv m n dDiva dDivb =\n plusDiv (multDiv dDiva m) (multDiv dDivb n)\n\n|||The theorem that d|a and d|b implies d |(a+b*(-m)\neuclidConservesDivisor:(m:ZZ)->(IsDivisibleZ a d)->(IsDivisibleZ b d)->\n (IsDivisibleZ (a+(b*(-m))) d)\neuclidConservesDivisor m dDiva dDivb = plusDiv dDiva (multDiv dDivb (-m) )\n\n|||Any integer divides zero\nzzDividesZero:(a:ZZ)->(IsDivisibleZ 0 a )\nzzDividesZero a = (0**(sym (multZeroRightZeroZ a)))\n|||A type that is occupied iff c is a common factor of a and b\nIsCommonFactorZ : (a:ZZ) -> (b:ZZ) -> (c:ZZ) -> Type\nIsCommonFactorZ a b c = ((IsDivisibleZ a c),(IsDivisibleZ b c))\n|||The theorem that d is a common factor of a and b implies\n|||d is a common factor of b and a\ncommonfactSym: IsCommonFactorZ a b d ->IsCommonFactorZ b a d\ncommonfactSym (dDiva, dDivb) = (dDivb,dDiva)\n\n\n|||The GCD type that is occupied iff d = gcd (a,b).\n||| Here GCD is defined as that positive integer such that any common factor\n||| of a and b divides it\nGCDZ : (a:ZZ) -> (b:ZZ) -> (d:ZZ) -> Type\nGCDZ a b d = ((IsPositive d),(IsCommonFactorZ a b d),\n ({c:ZZ}->(IsCommonFactorZ a b c)->(IsDivisibleZ d c)))\n|||Anything divides itself\nselfDivide:(a:ZZ)->(IsDivisibleZ a a)\nselfDivide a = (1**sym (multOneRightNeutralZ a))\n\n|||Generates the proof that if c is a common factor of a and 0 then c divides a\ngcdCondition : (a:ZZ) -> ({c:ZZ}->(IsCommonFactorZ a 0 c)->(IsDivisibleZ a c))\ngcdCondition a {c} (cDiva,cDiv0) = cDiva\n|||Proves that the GCD of a and 0 is a\ngcdOfZeroAndInteger:(a:ZZ)->IsPositive a ->GCDZ a 0 a\ngcdOfZeroAndInteger a pf =\n (pf,((selfDivide a),(zzDividesZero a)),((gcdCondition a)))\n|||The theorem, d|a =>d|(-a)\ndDividesNegative:(IsDivisibleZ a d)->(IsDivisibleZ (-a) d)\ndDividesNegative{a}{d} (x ** pf) =\n ((-x)**(multNegateRightIsNegateZ a d x pf))\n|||The theorem that d|(-a) implies d|a\ndDividesNegative2: (IsDivisibleZ (-a) d)->(IsDivisibleZ a d)\ndDividesNegative2 {a}x = rewrite (sym (doubleNegElim a)) in (dDividesNegative x)\n\n|||The theorem c|b and c|(a+bp) then c|a\ncDiva :{p:ZZ} ->(cDIvb :(IsDivisibleZ b c))->\n (cDIvExp:IsDivisibleZ (a+(b*p)) c)->(IsDivisibleZ a c)\ncDiva {p}{b}{a}{c} cDivb cDivExp =\n rewrite (sym (addAndSubNeutralZ a (b*p))) in (\n plusDiv cDivExp (dDividesNegative(multDiv cDivb (p))))\n|||A helper function for euclidConservesGcd function\ngenFunctionForGcd :(f:({c:ZZ}->(IsCommonFactorZ a b c)->(IsDivisibleZ d c)))->\n (({c:ZZ}->(IsCommonFactorZ b (a+(b*(-m))) c)->(IsDivisibleZ d c)))\ngenFunctionForGcd f (cDivb,cDivExp) =\n f((cDiva cDivb cDivExp,cDivb))\n\n|||The theorem, gcd(a,b)=d => gcd (b, a+ b(-m))=d\neuclidConservesGcd :(m:ZZ)->(GCDZ a b d)->(GCDZ b (a+(b*(-m))) d)\neuclidConservesGcd m (posProof, (dDiva,dDivb), f) =\n (posProof,(dDivb,(euclidConservesDivisor m dDiva dDivb)),genFunctionForGcd f)\n|||The theorem that if c and d are positive d|c => (d is less than or equal to c)\nposDivPosImpliesLte:(IsDivisibleZ c d)->(IsPositive c)->\n (IsPositive d)->LTEZ d c\nposDivPosImpliesLte {d}{c}(x ** pf) cPos dPos =\n posLteMultPosPosEqZ {q=x} d c dPos cPos pf\n\n|||The Theorem that if c and d are positive, d|c and c|d =>(c=d)\nposDivAndDivByImpliesEqual: (IsDivisibleZ c d)->(IsDivisibleZ d c)->(IsPositive c)\n ->(IsPositive d) -> (c=d)\nposDivAndDivByImpliesEqual x y z x1 =lteAndGteImpliesEqualZ dLtec cLted where\n dLtec =posDivPosImpliesLte x z x1\n cLted =posDivPosImpliesLte y x1 z\n|||Gcd of a and b is unique\ngcdIsUnique: (GCDZ a b d)-> (GCDZ a b c)->(c=d)\ngcdIsUnique {a}{b}{c}{d}(dPos, dCommonFactor,fd) (cPos, cCommonFactor,fc) =\n posDivAndDivByImpliesEqual (fc dCommonFactor) (fd cCommonFactor) cPos dPos\n|||A helper function for GcdSym\ngenFunctionForGcdSym:({c:ZZ}->(IsCommonFactorZ a b c)->(IsDivisibleZ d c))->\n ({c:ZZ}->(IsCommonFactorZ b a c)->(IsDivisibleZ d c))\ngenFunctionForGcdSym f x = f (commonfactSym x)\n\n|||A helper function for negatingPreservesGcdLeft\ngenFunctionForGcdNeg:({c:ZZ}->(IsCommonFactorZ (-a) b c)->(IsDivisibleZ d c))->\n ({c:ZZ}->(IsCommonFactorZ a b c)->(IsDivisibleZ d c))\ngenFunctionForGcdNeg f (cDiva,cDivb) = f (cDivNega,cDivb) where\n cDivNega = (dDividesNegative cDiva)\n|||Proof that gcd (a,b)=gcd(b,a)\ngcdSymZ: (GCDZ a b d)->(GCDZ b a d)\ngcdSymZ (dPos,(dDiva,dDivb),fd) = (dPos, (dDivb, dDiva), (genFunctionForGcdSym fd))\n\n|||Theorem that gcd(-a,b)=gcd(a,b)\nnegatingPreservesGcdLeft: (GCDZ (-a) b d)->(GCDZ a b d)\nnegatingPreservesGcdLeft (dPos,(dDivNega,dDivb),fd) =\n (dPos,(dDiva,dDivb),(genFunctionForGcdNeg fd)) where\n dDiva = dDividesNegative2 dDivNega\n|||Theorem that gcd (p, -q) = gcd (p,q)\nnegatingPreservesGcdRight: (GCDZ p (-q) r)->(GCDZ p q r)\nnegatingPreservesGcdRight {p}{q} x =\n gcdSymZ{a=q}{b=p} (negatingPreservesGcdLeft (gcdSymZ {a=p}{b=(-q)} x))\n\n|||Theorem that if d|rem , d|b and a = rem+(quot*b) then d|a\neuclidConservesDivisorWithProof :{a:ZZ}->{b:ZZ}->{quot:ZZ}->{rem:ZZ}->\n (a=rem+(quot*b))->(IsDivisibleZ rem d)->(IsDivisibleZ b d)->(IsDivisibleZ a d)\neuclidConservesDivisorWithProof {a}{b}{quot}{rem}equality dDivrem dDivb =\n rewrite equality in (plusDiv dDivrem (multDivLeft dDivb quot))\n\n|||Theorem that a = rem +quot*b implies rem = a + (-quot)*b\nauxEqProof:{a:ZZ}->{b:ZZ}->{quot:ZZ}->{rem:ZZ}->(a=rem+(quot *b))->\n (rem = (a + (-quot)*b))\nauxEqProof {a}{b}{quot}{rem}prf =\n (rewrite (multNegateLeftZ quot b) in (sym (subOnBothSides a rem (quot*b) prf)))\n\n|||A helper function for euclidConservesGcdWithProof\ngenfunction:(a=rem+(quot*b))-> ({c:ZZ}->(IsCommonFactorZ b rem c)->(IsDivisibleZ d c))->\n ({c:ZZ}->(IsCommonFactorZ a b c)->(IsDivisibleZ d c))\ngenfunction prf f (dDiva,dDivb) = f(dDivb,dDivrem) where\n dDivrem = euclidConservesDivisorWithProof (auxEqProof prf) dDiva dDivb\n\n|||Proof that if a=rem +quot*b and gcd (b,rem)=d, then gcd(a,b)=d\neuclidConservesGcdWithProof: {a:ZZ}->{b:ZZ}->{quot:ZZ}->{rem:ZZ}->\n (a=rem+(quot*b))->(GCDZ b rem d)->(GCDZ a b d)\neuclidConservesGcdWithProof {a}{b}{quot}{rem}equality (dPos,(dDivb,dDivrem),fd) =\n (dPos,(dDiva,dDivb),(genfunction equality fd)) where\n dDiva = euclidConservesDivisorWithProof equality dDivrem dDivb\n", "meta": {"hexsha": "876f4971fa6a8ef671fdec8b97f54dd77bcb5ad1", "size": 7696, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Divisors.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Divisors.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Divisors.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 45.0058479532, "max_line_length": 89, "alphanum_fraction": 0.6748960499, "num_tokens": 3035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587142, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7363208420976077}} {"text": "-- Code based on the question in the Idris mailing list\n\nimport Data.Vect\n\n%default total\n\npublic export\ngroup : (n : Nat) -> (m : Nat) -> Vect (n * m) a -> Vect n (Vect m a)\ngroup Z _ _ = []\ngroup (S n) m xs = let (l, r) = splitAt m xs in l :: group n m r\n\npublic export\ngroup' : (n : Nat) -> (m : Nat) -> Vect (n * m) a -> Vect m (Vect n a)\ngroup' n m xs = group m n $ rewrite multCommutative m n in xs\n\nexport\nsplitAtConcatRev : (n : Nat) -> (xs : Vect (n + m) a) -> {0 l : Vect n a} -> {0 r : Vect m a} -> (0 _ : splitAt n xs = (l, r)) -> l ++ r = xs\nsplitAtConcatRev Z _ Refl = Refl\nsplitAtConcatRev (S n) (x::xs) {l} prf with (splitAt n xs) proof sprf\n splitAtConcatRev (S n) (x::xs) {l=x::l} Refl | (l, r) = cong (x::) $ splitAtConcatRev n xs sprf\n\npublic export\nconcat_group_id : (n : Nat) -> (m : Nat) -> (v : Vect (n * m) a) -> concat (group n m v) = v\nconcat_group_id Z _ [] = Refl\nconcat_group_id (S n) m xs with (splitAt m xs) proof prf\n _ | (l, r) = rewrite concat_group_id n m r in splitAtConcatRev m xs prf\n", "meta": {"hexsha": "f18fcda57557fd83c71b043ffdac6a398bb64abd", "size": 1034, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "WindR.idr", "max_stars_repo_name": "buzden/idris-playground", "max_stars_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-23T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T02:45:50.000Z", "max_issues_repo_path": "WindR.idr", "max_issues_repo_name": "buzden/idris-playground", "max_issues_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_issues_repo_licenses": ["CC0-1.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": "WindR.idr", "max_forks_repo_name": "buzden/idris-playground", "max_forks_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2962962963, "max_line_length": 141, "alphanum_fraction": 0.5967117988, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7362944551620938}} {"text": "module DataVect\n\nimport public Data.Fin\nimport Language.Reflection\n\n%access public export\n%default total\n\ninfixr 7 :>\n\ndata Vec : Nat -> Type -> Type where\n V0 : Vec Z a\n (:>) : a -> Vec n a -> Vec (S n) a\n\nimplementation Eq a => Eq (Vec n a) where\n (==) V0 V0 = True\n (==) (l :> ls) (r :> rs) = l == r && ls == rs\n\nimplementation Show a => Show (Vec n a) where\n show V0 = \"V0\"\n show (x :> xs) = show x ++ \" :> \" ++ show xs\n\nvappend : Vec m a -> Vec n a -> Vec (m + n) a\nvappend V0 ys = ys\nvappend (x :> xs) ys = x :> vappend xs ys\n\nvtake : (m : Nat) -> Vec (m + n) a -> Vec m a\nvtake Z xs = V0\nvtake (S k) (x :> xs) = x :> vtake k xs\n\nvdrop : (n : Nat) -> Vec (n + m) a -> Vec m a\nvdrop Z xs = xs\nvdrop (S k) (x :> xs) = vdrop k xs\n\nvlength : Vec n _ -> Nat\nvlength {n} _ = n\n\nvchop : (m : Nat) -> Vec (m + n) a -> (Vec m a, Vec n a)\nvchop m xs = (vtake m xs, vdrop m xs)\n{-\nvchop' : (m : Nat) -> Vec (m + n) a -> (Vec m a, Vec n a)\nvchop' Z xs = (V0, xs)\nvchop' (S k) (x :> xs) = (x :> Prelude.Basics.fst yszs, Prelude.Basics.snd yszs)\n where yszs = vchop' k xs\n-}\n\n-- TODO\n\narity : (n : Nat) -> (a : Type) -> Type\narity Z x = x\narity (S n) x = x -> arity n x\n\n-- varity :: Arity n x -> Vec n x -> x\n-- varity x V0 = x\n-- varity f (x :> xs) = varity (f x) xs\n\n", "meta": {"hexsha": "f80ca4c1b060fb3b7ab395b32e7744b288f2e613", "size": 1380, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "haskell/topic/type-level/2013-09-lindley-mcbride-hasochism/src/DataVect.idr", "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_issues_repo_path": "haskell/topic/type-level/2013-09-lindley-mcbride-hasochism/src/DataVect.idr", "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "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": "haskell/topic/type-level/2013-09-lindley-mcbride-hasochism/src/DataVect.idr", "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "avg_line_length": 24.2105263158, "max_line_length": 80, "alphanum_fraction": 0.4891304348, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.736294453683512}} {"text": "module Monoids\n\n%default total\n\n{-\n interface Semigroup ty where\n (<+>) : ty -> ty -> ty\n\n interface Semigroup ty => Monoid ty where\n neutral : ty\n-}\n\n-- lets' define IntS as Monoids under both addition and multiplication\n\n[PlusIntSemi] Semigroup Int where\n (<+>) x y = x + y\n\n[PlusIntMonoid] Monoid Int using PlusIntSemi where\n neutral = 0\n\n[MultIntSemi] Semigroup Int where\n (<+>) x y = x * y\n\n[MultIntMonoid] Monoid Int using MultIntSemi where\n neutral = 1\n", "meta": {"hexsha": "986a42f7536f164a930f11b6daee2eadb3dec9b9", "size": 472, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "interfaces/Monoids.idr", "max_stars_repo_name": "timmyjose-study/idris-from-the-docs", "max_stars_repo_head_hexsha": "ea1b7af57245ddb29b5d9d24ae623e37ecc01d12", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "interfaces/Monoids.idr", "max_issues_repo_name": "timmyjose-study/idris-from-the-docs", "max_issues_repo_head_hexsha": "ea1b7af57245ddb29b5d9d24ae623e37ecc01d12", "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": "interfaces/Monoids.idr", "max_forks_repo_name": "timmyjose-study/idris-from-the-docs", "max_forks_repo_head_hexsha": "ea1b7af57245ddb29b5d9d24ae623e37ecc01d12", "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": 18.1538461538, "max_line_length": 70, "alphanum_fraction": 0.6800847458, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7362944512640762}} {"text": "module pigeonhole\n\n-- a try to prove pegionhole principle\n\nimport Data.Fin\nimport Data.Vect\n\n%access public export\n%default total\n\nsame_hole : (n : Nat) -> (m : Nat) -> (Vect n (Fin m)) -> Type\nsame_hole n m v = (p : (Fin n) ** (q : (Fin n) ** \n ( prf : ((p = q) -> Void) ** ( (index p v) = (index q v)))))\n\n---------------------------------------------------------------------------------------------------------------\n \n||| proof that Fin Z is empty \naux_prf_1 : (Fin Z) -> Void \naux_prf_1 q impossible\n\n---------------------------------------------------------------------------------------------------------------\n\n||| the type of proofs that a particular element is in the vector or not\ndata There_is : (n : Nat) -> (m : Nat) -> (v : Vect n (Fin m)) -> (a : Fin m) -> Type where\n Yes : (k : (Fin n) ** ( (index k v) = a)) -> (There_is n m v a)\n No : ( (k : (Fin n) ** ( (index k v) = a)) -> Void ) -> (There_is n m v a)\n\n---------------------------------------------------------------------------------------------------------------\n\n||| finds the first index with the given entry, or returns that there is no such index \n \nis_there : (n : Nat) -> (m : Nat) -> (a : Fin m) -> (v : Vect n (Fin m)) -> \n (There_is n m v a)\n\n-- for vectors of length zero this is false clearly. \nis_there Z m a v = No contra where \n contra : ( (k : (Fin Z) ** ( (index k v) = a)) -> Void )\n contra = aux_prf_1 . fst\n\n-- for vectors of non zero length it checks if the first element is a. \nis_there (S n) m a (x :: v) = case (decEq x a) of\n\n -- If yes gives it as the proof\n Yes prf => Yes (FZ ** prf) \n \n -- if not then recursively checks the remaining part.\n No contra => (case (is_there n m a v) of \n \n -- If the element is in the remaining part then gives the proof \n Yes prf1 => (let \n k = fst prf1 \n prf2 = snd prf1\n in\n ( Yes ( (FS k) ** prf2) ) )\n \n -- if the element is not in the remaining part recursively \n -- constructs the contradiction \n \n No not_in_v => (No (\\k => case k of \n (FZ ** prf3) => (contra prf3) -- \n ((FS l) ** prf4) => (not_in_v (l ** prf4 ) )))) \n \n----------------------------------------------------------------------------------------------------------------\n\nswapHelper : (m : Nat) -> (a , b, x : (Fin m)) -> (Dec (x = a)) -> (Dec (x = b)) -> (Fin m)\nswapHelper m a b x (Yes pf) _ = b\nswapHelper m a b x (No con) (Yes pf) = a\nswapHelper m a b x (No con1) (No con2) = x\n\n----------------------------------------------------------------------------------------------------------------\n||| swaps two element in a vector\nswap : (n : Nat) -> (m : Nat) -> (a, b : Fin m) -> (v : Vect n (Fin m)) -> (Vect n (Fin m))\nswap Z _ _ _ _ = []\nswap (S n) m a b (x :: v) = (swapHelper m a b x (decEq x a) (decEq x b)) :: (swap n m a b v)\n{-\n case (decEq x a) of\n Yes prf => b :: (swap n m a b v)\n No prf => case (decEq x b) of\n Yes prf => a :: (swap n m a b v)\n No prf => x :: (swap n m a b v) \n-} \n \n \n \n----------------------------------------------------------------------------------------------------------------\n \nsimple_case : (n : Nat) -> (v : Vect (S n) (Fin n) ) -> (same_hole (S n) n v)\nsimple_case Z v = void (aux_prf_1 (Vect.index FZ v ))\nsimple_case (S n) v = ?rhs\n\n\n", "meta": {"hexsha": "32053a658b7b9893e55c9172fd17a3cf61b1fca6", "size": 3877, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/pigeonhole.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/pigeonhole.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/pigeonhole.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": 42.1413043478, "max_line_length": 112, "alphanum_fraction": 0.3631673975, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7362501703646822}} {"text": "module RingExamples\n\nimport Ring\nimport RingProperties\nimport Group\nimport Group_property\nimport ZZ\nimport ZZUtils\nimport Monoid\n\n%access public export\n\nZZAbGrp: IsAbelianGrp ZZ (+)\nZZAbGrp = ((Assoc, (((Pos Z)**PrfZ), (((Pos Z)**PrfZ)**PfInv))), CommutativeZ) where\n Assoc: (l,c,r:ZZ) -> (l+c)+r = l +(c+r)\n Assoc l c r = sym (plusAssociativeZ l c r)\n PrfZ: (a: ZZ) -> (a+(Pos Z) = a, (Pos Z) + a = a)\n PrfZ a = (plusZeroRightNeutralZ a, plusZeroLeftNeutralZ a)\n PfInv: (a: ZZ) -> DPair ZZ (\\a_inv => ((a + a_inv = Pos Z), (a_inv + a = Pos Z)))\n PfInv a = MkDPair (negate a) (plusNegateInverseLZ a, plusNegateInverseRZ a)\n CommutativeZ: (a: ZZ) -> (b: ZZ) -> (a + b = b+a)\n CommutativeZ = plusCommutativeZ\n\nZZAssoc: Associative ZZ (*)\nZZAssoc l c r = sym (multAssociativeZ l c r)\n\nZZDist: IsDistributive ZZ (+) (*)\nZZDist l c r = (multDistributesOverPlusRightZ l c r, multDistributesOverPlusLeftZ c r l)\n\nZZMultCommutes: Commutative ZZ (*)\nZZMultCommutes = multCommutativeZ\n\nZZIsCRing: IsCommRing ZZ (+) (*)\nZZIsCRing = ((ZZAbGrp, (ZZAssoc, ZZDist)), ZZMultCommutes)\n\nZZCRing: CRing ZZ\nZZCRing = MkCRing ZZ (+) (*) ZZIsCRing\n", "meta": {"hexsha": "60eec39425d654f057f47ce61fab1e13163bb6a8", "size": 1134, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/RingExamples.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/RingExamples.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/RingExamples.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": 29.8421052632, "max_line_length": 88, "alphanum_fraction": 0.6790123457, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068041, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7361725536941499}} {"text": "module Ex3\n\nimport Data.Vect\n\n%default total\n\nmyLength : List a -> Nat\nmyLength [] = 0\nmyLength (_ :: xs) = 1 + myLength xs\n\nmyReverse : List a -> List a\nmyReverse [] = []\nmyReverse (x :: xs) = myReverse xs ++ [x]\n\nmyMap : (a -> b) -> List a -> List b\nmyMap _ [] = []\nmyMap f (x :: xs) = f x :: myMap f xs\n\nmyVectMap : (a -> b) -> Vect n a -> Vect n b\nmyVectMap _ [] = []\nmyVectMap f (x :: xs) = f x :: myVectMap f xs\n\ntransposeMatrix : { n : _ } -> Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMatrix [] = replicate n []\ntransposeMatrix (x :: xs) = let xsTrans = transposeMatrix xs in\n zipWith (::) x xsTrans\n\naddMatrix : Num elem => Vect m (Vect n elem) -> Vect m (Vect n elem) -> Vect m (Vect n elem)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (+) x y :: addMatrix xs ys\n\nsubMatrix : (Neg elem, Num elem) => Vect m (Vect n elem) -> Vect m (Vect n elem) -> Vect m (Vect n elem)\nsubMatrix [] [] = []\nsubMatrix (x :: xs) (y :: ys) = zipWith (-) x y :: subMatrix xs ys\n\nmultMatrix : Num elem => { m, n, o : _ } -> Vect m (Vect n elem) -> Vect n (Vect o elem) -> Vect m (Vect o elem)\nmultMatrix xs ys = let ysTrans = transposeMatrix ys in\n aux xs ysTrans\n\n where\n dotProduct : { n : _ } -> Vect n elem -> Vect n elem -> elem\n dotProduct [] [] = 0\n dotProduct (x :: xs) (y :: ys) = x * y + dotProduct xs ys\n\n aux : {m, n, o : _} -> Vect m (Vect n elem) -> Vect o (Vect n elem) -> Vect m (Vect o elem)\n aux [] _ = []\n aux (x :: xs) ys = map (\\y => dotProduct x y) ys :: aux xs ys\n", "meta": {"hexsha": "67d1021d8748c654a12268933557f052999d8632", "size": 1576, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter3/Ex3.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter3/Ex3.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": "chapter3/Ex3.idr", "max_forks_repo_name": "timmyjose-study/tdd-with-idris", "max_forks_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": 32.8333333333, "max_line_length": 112, "alphanum_fraction": 0.5513959391, "num_tokens": 516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7360143842666064}} {"text": "\nmodule Bltnat\n\nhowdy : Nat\nhowdy = 25\n\npublic export\nbeq_nat : Nat -> Nat -> Bool\nbeq_nat Z Z = True\nbeq_nat Z (S k) = False\nbeq_nat (S k) Z = False\nbeq_nat (S k) (S j) = beq_nat k j\n\n\nleb : Nat -> Nat -> Bool\nleb Z _ = True\nleb (S k) (S j) = leb k j\nleb _ _ = False\n-- alternate and with better ordering: leb (S k) Z = False\n\ntl1 : leb 2 2 = True\ntl1 = Refl\ntl2 : leb 2 4 = True\ntl2 = Refl\ntl3 : leb 2555 1 = False\ntl3 = Refl\n\nblt_nat : Nat -> Nat -> Bool\nblt_nat k j = case beq_nat k j of\n False => leb k j\n True => False\n\ntblt1 : blt_nat 2 2 = False\ntblt1 = Refl\ntblt2 : blt_nat 2 4 = True\ntblt2 = Refl\ntblt3 : blt_nat 2342 2 = False\ntblt3 = Refl\n", "meta": {"hexsha": "da2d480ec9003ea3559c1a206971fb3a1f8f46af", "size": 687, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Answers/Chapter_2/Bltnat.idr", "max_stars_repo_name": "robkorn/idris-software-foundations-problems", "max_stars_repo_head_hexsha": "bd5b10c9c361ac8feea29f41745f4bb386c3b06d", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Answers/Chapter_2/Bltnat.idr", "max_issues_repo_name": "robkorn/idris-software-foundations-problems", "max_issues_repo_head_hexsha": "bd5b10c9c361ac8feea29f41745f4bb386c3b06d", "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": "Answers/Chapter_2/Bltnat.idr", "max_forks_repo_name": "robkorn/idris-software-foundations-problems", "max_forks_repo_head_hexsha": "bd5b10c9c361ac8feea29f41745f4bb386c3b06d", "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": 17.6153846154, "max_line_length": 58, "alphanum_fraction": 0.5982532751, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806522, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.735555445943187}} {"text": "module Chapter4\nimport Data.Vect\n\ndata Bool = False | True\n\n-- Enumeration types. Literally an enum from C.\n{-\nFrom wiki:\n> An enumerated type can be seen as a degenerate case: a tagged union of unit\n> types. It corresponds to a set of nullary constructors and may be implemented\n> as a simple tag variable, since it holds no additional data besides the value\n> of the tag.\n-}\ndata Direction = North\n | East\n | South\n | West\n\nturnClockwise : Direction -> Direction\nturnClockwise North = East\nturnClockwise East = South\nturnClockwise South = West\nturnClockwise West = North\n\n-- Union types. Why are they called union? This is different\n-- from a union in C.\n-- From above, we see that this is basically a union of 'product types'.\n{-\nFrom wiki:\n> The expression of an instance of a product type will be a tuple, and\n> is called a \"tuple type\" of expression. A product of types is a direct\n> product of two or more types.\nIn other words it is an union of structs (which it is).\n-}\n-- With documentation. Note that we first have the | separator\n-- and right after we have the ||| for documentation.\ndata Shape = ||| Triangle with base and height\n Triangle Double Double\n | ||| Rectangle with width and height\n Rectangle Double Double\n | ||| Circle with radius.\n Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = (base * height) / 2\narea (Rectangle width height) = width * height\narea (Circle radius) = pi * radius * radius\n\ndata Shape2 : Type where\n -- need to use 2 suffix else we get a conflict with above.\n Triangle2 : Double -> Double -> Shape2\n Rectangle2 : Double -> Double -> Shape2\n Circle2 : Double -> Shape2\n\n-- Recursive types\ndata MyNat = MyZ | MyS MyNat -- Peano arithmetic <3\n\n\ndata Picture = Primitive Shape\n | Combine Picture Picture\n | Rotate Double Picture\n | Translate Double Double Picture\n\ntestPicture : Picture\ntestPicture = Combine\n (Translate 5 5 (Primitive (Rectangle 20 10)))\n (Combine (Translate 35 5 (Primitive (Circle 5)))\n (Translate 15 25 (Primitive (Triangle 10 10))))\n\npictureArea : Picture -> Double\npictureArea (Primitive s) = area s\npictureArea (Combine p1 p2) = pictureArea p1 + pictureArea p2\npictureArea (Rotate r p) = pictureArea p -- pictureArea ?h will be autocompleted\npictureArea (Translate x y p) = pictureArea p\n\ndata Infinite = Forever Infinite -- this typechecks though! why?\n\n\n-- Generic data types\n-- These are \"templates\" in C++ world. They don't exist in C land, except\n-- for maybe arrays/pointers of type T.\n\ndata Biggest = NoTriangle | Size Double -- really this is maybe.\n\nbiggestTriangle : Picture -> Biggest\n-- would have been nice to introduce the @ syntax before. I knew it from Haskell.\nbiggestTriangle (Primitive (t@(Triangle x y))) = Size (area t)\nbiggestTriangle (Primitive (Rectangle x y)) = NoTriangle\nbiggestTriangle (Primitive (Circle x)) = NoTriangle\n-- Holly carp that is manual!\n-- need to use >>=\nbiggestTriangle (Combine x y) = case biggestTriangle x of\n NoTriangle => case biggestY of\n NoTriangle => NoTriangle\n Size size2 => Size size2\n Size size => case biggestY of\n NoTriangle => Size size\n Size size2 => Size (max size size2)\n where \n biggestY : Biggest\n biggestY = biggestTriangle y\nbiggestTriangle (Rotate r p) = biggestTriangle p\nbiggestTriangle (Translate x y p) = biggestTriangle p\n\n--data Maybe type = Nothing | Just type\n\nsafeDivide : Double -> Double -> Maybe Double\nsafeDivide x y = if y /= 0 then Just (x / y)\n else Nothing\n\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n%name Tree tree, tree1\n\ninsert : Ord a => a -> Tree a -> Tree a\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left y right) = case compare x y of\n LT => Node (insert x left) y right\n EQ => orig -- now we introduce @ patterns\n GT => Node left y (insert x right)\n\n\ndata BSTree : Type -> Type where\n BEmpty : Ord a => BSTree a\n BNode : Ord a => (left : BSTree a) -> (val : a) -> (right : BSTree a) -> BSTree a\n\ninsert2 : a -> BSTree a -> BSTree a\ninsert2 x BEmpty = BNode BEmpty x BEmpty\ninsert2 x orig@(BNode left val right) = case compare x val of\n LT => BNode (insert2 x left) val right\n EQ => orig\n GT => BNode left val (insert2 x right)\n\n-- Exercises!\n-- Ex1\nlistToTree : Ord a => List a -> Tree a\nlistToTree [] = Empty\nlistToTree (x :: xs) = insert x (listToTree xs)\n\n-- Ex2\ntreeToList : Tree a -> List a\ntreeToList Empty = []\ntreeToList (Node left x right) = treeToList left\n ++\n x :: treeToList right\n\n-- Ex3 (classic)\ndata Expr : Type where\n Val : Int -> Expr\n Add : (t1 : Expr) -> (t2 : Expr) -> Expr\n Sub : (s1 : Expr) -> (s2 : Expr) -> Expr\n Mul : (f1 : Expr) -> (f2 : Expr) -> Expr\n\n\nevaluate : Expr -> Int\nevaluate (Val x) = x\nevaluate (Add t1 t2) = evaluate t1 + evaluate t2\nevaluate (Sub s1 s2) = evaluate s1 - evaluate s2\nevaluate (Mul f1 f2) = evaluate f1 * evaluate f2\n\nmaxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe Nothing y = y\nmaxMaybe (Just x) Nothing = Just x\nmaxMaybe (Just x) (Just y) = Just (max x y)\n\nbiggestTriangle2 : Picture -> Maybe Double\nbiggestTriangle2 (Primitive t@(Triangle x y)) = Just (area t)\nbiggestTriangle2 (Primitive (Rectangle x y)) = Nothing\nbiggestTriangle2 (Primitive (Circle x)) = Nothing\nbiggestTriangle2 (Combine p1 p2) = maxMaybe (biggestTriangle2 p1) (biggestTriangle2 p2)\nbiggestTriangle2 (Rotate r p) = biggestTriangle2 p\nbiggestTriangle2 (Translate x y p) = biggestTriangle2 p\n\n-- Dependent types. Woot!\n-- Redefined in ex1\n--data PowerSource = Petrol | Pedal\n \n-- How is this type fundamentally different from Maybe a?\n--data Vehicle : PowerSource -> Type where\n-- Bicycle : Vehicle Pedal\n-- Car : (fuel : Nat) -> Vehicle Petrol\n-- Bus : (fuel : Nat) -> Vehicle Petrol\n--\n--wheels : Vehicle power -> Nat\n--wheels Bicycle = 2\n--wheels (Car fuel) = 4\n--wheels (Bus fuel) = 4\n--\n--refuel : Vehicle Petrol -> Vehicle Petrol\n--refuel (Car fuel) = Car (fuel + 20)\n--refuel (Bus fuel) = Car (fuel + 10)\n--refuel Bicycle impossible\n\ndata MyWeirdType : Type -> Type where\n A : MyWeirdType (Maybe Int)\n B : Nat -> MyWeirdType Double\n C : Nat -> MyWeirdType (Maybe Double)\n\nmyWeirdFunction1 : MyWeirdType Double\nmyWeirdFunction1 = B 5\n\nmyWeirdFunction2 : a -> MyWeirdType a\nmyWeirdFunction2 x = ?myWeirdFunction2_rhs -- can this be defined in any way?\n\n-- See Vect.idr\n\n-- Ex1,2\ndata PowerSource = Pedal | Petrol | Electric\ndata Vehicle : PowerSource -> Type where\n Bicycle : Vehicle Pedal\n Unicycle : Vehicle Pedal\n Motorcycle : (fuel : Nat) -> Vehicle Petrol\n PetrolCar : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n Tram : Vehicle Electric\n ElectricCar : Vehicle Electric\n-- Feels like a slightly contrived example...\n-- there is power in it in terms of how depending on the PowerSource\n-- Vehicle has a different definition (i.e. in terms of fuel).\n\n\nwheels : Vehicle p -> Nat\nwheels Bicycle = 2\nwheels Unicycle = 1\nwheels (Motorcycle fuel) = 2\nwheels (PetrolCar fuel) = 4\nwheels (Bus fuel) = 4\n\n-- Ex 3,4\nvectTake : (k : Fin n) -> Vect n a -> Vect (finToNat k) a\nvectTake FZ xs = []\n--vectTake (FS k') xs = ?vectTake_rhs_2 -- case on xs (it can't be [])\n--vectTake (FS k') (x :: xs) = ?vectTake_rhs_1 -- search on ?rhs\nvectTake (FS k') (x :: xs) = x :: vectTake k' xs -- BAM programs that write themselves.\n\n-- Remember, types are proofs so you can freely substitute 'proof'\n-- with the word type\ndata LT : Nat -> Nat -> Type where\n LTZero : Chapter4.LT Z (S n)\n LTSucc : Chapter4.LT a b -> Chapter4.LT a (S b)\n\n-- I like this version since it clearly shows what we need.\n-- It is not as easy to workwith though.\nvectTake' : LTE k n -> Vect n a -> Vect k a\nvectTake' LTEZero xs = []\nvectTake' (LTESucc k') (x :: xs) = x :: vectTake' k' xs\n\n-- Ex5\nsumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos xs ys = map (\\i => (Data.Vect.index i xs) + (Data.Vect.index i ys))\n (integerToFin pos n)\n\n-- Now go to DataStore.idr\n", "meta": {"hexsha": "6d7f0f4eb9e89db001bf39866dbf7d0080fb0c2b", "size": 8859, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4.idr", "max_stars_repo_name": "neduard/type-driven-development", "max_stars_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "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": "Chapter4.idr", "max_issues_repo_name": "neduard/type-driven-development", "max_issues_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "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": "Chapter4.idr", "max_forks_repo_name": "neduard/type-driven-development", "max_forks_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "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": 34.8779527559, "max_line_length": 90, "alphanum_fraction": 0.6174511796, "num_tokens": 2334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7353608623672183}} {"text": "module Rationals\n\n--Type for divisibility\ndata isDivisor : Integer -> Integer -> Type where\n AllDivZ : (m : Integer) -> isDivisor m 0\n OneDivAll : (m : Integer) -> isDivisor 1 m\n MulDiv : (c : Integer) -> isDivisor n m -> isDivisor ((\\l => l*c) n) ((\\l => l*c) m)\n\nisNotZero : Nat -> Bool\nisNotZero Z = False\nisNotZero (S k) = True\n\nisFactorInt : Integer -> Integer -> Type --Needed for defining Integer division\nisFactorInt m n = (k : Integer ** (m * k = n))\n\ndivides : (m: Integer) -> (n: Integer) -> (k: Integer ** (m * k = n)) -> Integer\ndivides m n k = (fst k)\n\nPair : Type\nPair = (Integer, Integer)\n\nEucl: (a: Nat) -> (b: Nat) -> (Nat, Nat) --Euclidean algorithm implemented by Chinmaya\nEucl Z b = (0,0)\nEucl (S k) b = case (lte (S (S k)) b) of\n False => (S(fst(Eucl (minus (S k) b) b)), snd(Eucl (minus (S k) b) b))\n True => (0, S k)\n{-\ngcdab : Nat -> Nat -> Nat -- Produces the GCD of two numbers. This will be useful to produce the simplified form of a rational number.\ngcdab b Z = b\ngcdab a b = gcdab b (snd (Eucl a b))\n-}\n\n--Integer implemetation of gcd\ngccd : (Integer, Integer) -> Integer\ngccd (a, b) = if (isNotZero (toNat b)) then next else a where\n next = gccd (b, toIntegerNat (modNat (toNat a) (toNat b)))\n\ndata NotZero : Integer -> Type where --Proof that a number is not zero, needed to construct Q\n OneNotZero : NotZero 1\n NegativeNotZero : ( n: Integer ) -> NotZero n -> NotZero (-n)\n PositiveNotZero : ( m: Integer ) -> LTE 1 (fromIntegerNat m) -> NotZero m\n\n--Type for equality of two Rationals\ndata EqRat : Pair -> Pair -> Type where\n IdEq : (m : Pair) -> EqRat m m\n MulEq : (c : Integer) -> EqRat n m -> EqRat ((fst n)*c,(snd n)*c) m\n\nmake_rational : (p: Nat) -> (q: Integer) -> NotZero q -> Pair\nmake_rational p q x = (toIntegerNat(p), q)\n\nInclusionMap : (n : Nat) -> Pair --Includes the naturals in Q\nInclusionMap n = make_rational n 1 OneNotZero\n\nAddRationals : (x: Pair) -> NotZero (snd x) -> (y: Pair) -> NotZero (snd y) -> Pair\nAddRationals x a y b = ((fst x)*(snd y) + (snd x)*(fst y), (snd x)*(snd y))\n\nMultiplyRationals : (x: Pair) -> NotZero (snd x) -> (y: Pair) -> NotZero (snd y) -> Pair\nMultiplyRationals x a y b =((fst x)*(fst y), (snd x)*(snd y))\n\n--Need proof that MultInverse x * x = 1\nMultInverse : (x: Pair) -> NotZero (fst x) -> NotZero (snd x) -> Pair\nMultInverse x y z = ((snd x), (fst x))\n\nAddInverse : (x: Pair) -> NotZero (snd x) -> Pair\nAddInverse x a = (-(fst x), (snd x))\n\nSubtraction : (x: Pair) -> NotZero (snd x) -> (y: Pair) -> NotZero (snd y) -> Pair\nSubtraction x a y b = AddRationals x a (AddInverse y b) b\n\nDivision : (x: Pair) -> NotZero (snd x) -> (y: Pair) -> NotZero (fst y) -> NotZero (snd y) -> Pair\nDivision x a y b c = MultiplyRationals x a (MultInverse y b c) b\n\n--SimplifyRational : (x: Pair) -> NotZero (snd x) -> Pair\n--SimplifyRational x a = (divides (gcdab fromIntegerNat((fst x)) fromIntegerNat((snd x))) ___ (fst x), divides (gcdab fromIntegerNat((fst x)) fromIntegerNat((snd x)) __ (snd x))\n\n--To prove that the SimplifyRational works, we can just check if the output is equal to the input\n-- To be done\nsimplifyRational : (x : Pair) -> Pair\nsimplifyRational (a, b) = (sa, sb) where\n sa = cast {from=Double} {to=Integer} (da / g) where\n da = cast {from=Integer} {to=Double} a\n g = cast {from=Integer} {to=Double} (gccd (a,b))\n sb = cast {from=Double} {to=Integer} (db / g) where\n db = cast {from=Integer} {to=Double} b\n g = cast {from=Integer} {to=Double} (gccd (a,b))\n\n--Above, I will need to supply a proof that the GCD divides the two numbers. Then, the function defined above will produce the rational in simplified form.\n", "meta": {"hexsha": "c92d638a0e61ddeecfe109225b26bf272663331a", "size": 3668, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Rationals.idr", "max_stars_repo_name": "rohit3499/LTS2019", "max_stars_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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": "Rationals.idr", "max_issues_repo_name": "rohit3499/LTS2019", "max_issues_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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": "Rationals.idr", "max_forks_repo_name": "rohit3499/LTS2019", "max_forks_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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.6818181818, "max_line_length": 177, "alphanum_fraction": 0.6294983642, "num_tokens": 1251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7353574230087507}} {"text": "-- The Great Theorem Prover Showdown (https://github.com/hwayne/lets-prove-leftpad/)\n--\n-- Code here is nearly completely copied from @porglezomp's Idris implementation, just for the\n-- purpose of self edification.\n\nmodule LeftPad\n\nimport Data.Vect\n\n-- As I am totally new to theorem proving, I hereby write down some confusions about this proof:\n--\n-- * This implementation seems to sidestep the proof of the post-condition that the suffix does be\n-- the original string. Is it still sound?\n-- * The use of dependent pair seems redundant?\n-- * Is `rewrite` deprecated by the new Elaborator Reflection system?\n\n-- `minus` is saturating subtraction\n-- `maximum` has branch `maximum Z m` but not `maximum m Z`\n-- The 3rd case:\n-- - Goal := maximum (S k) (S n) = (S n - S k) + S k\n-- - maximum (S k) (S n) = S (maximum k n)\n-- - Goal => S (maximum k n) = (S n - S k) + S k\n-- - Induction hypothesis := maximum k n = (n - k) + k\n-- - Goal => S ((n - k) + k) = (S n - S k) + S k\n--\n-- - plusSuccRightSucc l r := S (l + r) = l + S r\n-- - plusSuccRightSucc (n - k) k => S ((n - k) + k) = (n - k) + S k\n-- - Goal => (n - k) + S k = (S n - S k) + S k\n-- - minus (S left) (S right) = minus left right\n-- - Goal => trivial\n\neq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k\neq_max n Z = rewrite minusZeroRight n in\n rewrite plusZeroRightNeutral n in\n Refl\neq_max Z (S _) = Refl\neq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in\n rewrite eq_max n k in\n Refl\n\nleftPad : (padChar : Char) -> (n : Nat) -> (xs : Vect k Char) -> Vect (maximum k n) Char\nleftPad {k} padChar n xs = rewrite eq_max n k\n in\n replicate (n `minus` k) padChar ++ xs\n", "meta": {"hexsha": "d0bd523a1b294b0b0f6e66ada6ae7c3ca6557064", "size": 1795, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "LeftPadProof/LeftPad.idr", "max_stars_repo_name": "gyk/TrivialSolutions", "max_stars_repo_head_hexsha": "dc461ebfca5756ac261576785c227d77d578cb33", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-07T13:20:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-31T05:51:37.000Z", "max_issues_repo_path": "LeftPadProof/LeftPad.idr", "max_issues_repo_name": "gyk/TrivialSolutions", "max_issues_repo_head_hexsha": "dc461ebfca5756ac261576785c227d77d578cb33", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LeftPadProof/LeftPad.idr", "max_forks_repo_name": "gyk/TrivialSolutions", "max_forks_repo_head_hexsha": "dc461ebfca5756ac261576785c227d77d578cb33", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.8888888889, "max_line_length": 98, "alphanum_fraction": 0.582729805, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7353009363770202}} {"text": "\nmodule RemoveElem\n\nimport Data.Vect\n\n\n-- Dependent pair implementation of removeElem for fun\ndepPRemElem : DecEq a => (value : a) -> (xs : Vect n a) -> (len ** Vect len a)\ndepPRemElem value [] = (_ ** [])\ndepPRemElem value (x :: xs) = case decEq value x of\n (Yes prf) => (_ ** xs)\n (No contra) => (_ ** (x :: (snd $ depPRemElem value xs)))\n\nmaryInVector : Elem \"Mary\" [\"Pete\", \"Bob\", \"Mary\"]\nmaryInVector = There (There Here)\n\nremoveElem : (value : a) -> (xs : Vect (S n) a) -> (prf : Elem value xs) -> Vect n a\nremoveElem value (value :: ys) Here = ys\nremoveElem {n = Z} value (y :: []) (There later) = absurd later\nremoveElem {n = (S k)} value (y :: ys) (There later) = y :: (removeElem value ys later)\n\nremoveElem_auto : (value : a) -> (xs : Vect (S n) a) -> {auto prf : Elem value xs} -> Vect n a\nremoveElem_auto value xs {prf} = removeElem value xs prf\n\npublic export\nremoveElemAuto : (value : a) -> (xs : Vect (S n) a) -> {auto prf : Elem value xs} -> Vect n a\nremoveElemAuto value (value :: ys) {prf = Here} = ys\nremoveElemAuto {n = Z} value (y :: []) {prf = (There later)} = absurd later\nremoveElemAuto {n = (S k)} value (y :: ys) {prf = (There later)} = y :: (removeElemAuto value ys)\n", "meta": {"hexsha": "8414c806ca00bf191f8408c5bcd69344b4e717e1", "size": 1263, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter9/removeElem.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter9/removeElem.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter9/removeElem.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 42.1, "max_line_length": 97, "alphanum_fraction": 0.5843230404, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.735300921925149}} {"text": "module Main\n\npythag : Int -> List (Int, Int, Int)\npythag n = [ (x, y, z) | z <- [1..n], y <- [1..z], x <- [1..y],\n x*x + y*y == z*z ]\n\nmain : IO ()\nmain = putStrLn (show (pythag 50))\n\n", "meta": {"hexsha": "7e79ead2000c78979251d1175e815d0810f9eb62", "size": 210, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/idris-dev/sugar002/test009.idr", "max_stars_repo_name": "grin-compiler/idris-grin", "max_stars_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2019-06-06T10:35:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T08:48:30.000Z", "max_issues_repo_path": "test/idris-dev/sugar002/test009.idr", "max_issues_repo_name": "grin-compiler/idris-grin", "max_issues_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-11-21T20:45:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T12:29:23.000Z", "max_forks_repo_path": "test/idris-dev/sugar002/test009.idr", "max_forks_repo_name": "grin-compiler/idris-grin", "max_forks_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-14T13:14:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-07T06:20:45.000Z", "avg_line_length": 21.0, "max_line_length": 63, "alphanum_fraction": 0.4142857143, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7352726463781234}} {"text": "module Main\n\nimport Data.Vect\n\n{-\n This actually won't type check.\n\n Even though `a` is implementing the Decidable Equality interface,\n at some point the recursion might end up calling `removeElem value []`\n which this function is not defined for (since [] is a Vect Z a).\n\n So there's really no guarantee that the value will appear in the vector,\n and thus it's possible to reach the end of the vector without ever finding it.\n\n Some options here would be\n\n 1. to consider the case for `[]`, and change the signature to return\n `Maybe (Vect n a)` -- if we reach the empty case, we might as well return\n Nothing.\n\n 2. Return a dependant pair (length ** Vect lenght a) so we don't make an\n assumption on the length\n\n 3. Have a type-level predicate that ensures that the element is in the vector\n-}\nremoveElem__nope : DecEq a => (value : a) -> (xs : Vect (S n) a) -> Vect n a\nremoveElem__nope value (x :: xs) = case decEq value x of\n Yes prf => xs\n No contr => ?x_removeElem_value_xs\n\n{-\n Let's implement option 3 by defining a specific type that tells us that a\n given element is indeed part of the vector\n\n Elem is actually already part of Data.Vect, so here it's defined as Elem'\n but we'll use Data.Vect.Elem instead\n-}\n\ndata Elem' : a -> Vect k a -> Type where\n -- x is the first value of the vector\n Here : Elem' x (x :: xs)\n\n -- if x is in xs, it's also in y :: xs\n There : (later : Elem' x xs) -> Elem' x (y :: xs)\n\noneInVector : Elem 1 [1,2,3]\noneInVector = Here\n\nsomewhereElseInVector : Elem 1 [2,3,1]\nsomewhereElseInVector = There (There Here)\n\nnotInVector : Elem 1 [3,4]\nnotInVector = There (There ?notInVector_rhs2)\n\nremoveElemWithProof : (value : a) ->\n (xs : Vect (S n) a ) ->\n (prf : Elem value xs) ->\n Vect n a\nremoveElemWithProof value (value :: ys) Here = ys\nremoveElemWithProof { n = Z } value (y :: []) (There later) = absurd later\nremoveElemWithProof { n = (S k) } value (y :: ys) (There later) =\n y :: removeElemWithProof value ys later\n\nremoveAutoProofed : (value : a) ->\n (xs : Vect (S n) a) ->\n {auto prf : Elem value xs} ->\n Vect n a\nremoveAutoProofed value xs {prf} = removeElemWithProof value xs prf\n\nremoveElem : (value : a) ->\n (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{-\n Now let's try to make a Letter data type that will only accept being\n constructed with alpha characters\n-}\n\n\nAlphabet : Vect 52 Char\nAlphabet = ['a',\n 'b',\n 'c',\n 'd',\n 'e',\n 'f',\n 'g',\n 'h',\n 'i',\n 'j',\n 'k',\n 'l',\n 'm',\n 'n',\n 'o',\n 'p',\n 'q',\n 'r',\n 's',\n 't',\n 'u',\n 'v',\n 'w',\n 'x',\n 'y',\n 'z',\n 'A',\n 'B',\n 'C',\n 'D',\n 'E',\n 'F',\n 'G',\n 'H',\n 'I',\n 'J',\n 'K',\n 'L',\n 'M',\n 'N',\n 'O',\n 'P',\n 'Q',\n 'R',\n 'S',\n 'T',\n 'U',\n 'V',\n 'W',\n 'X',\n 'Y',\n 'Z']\n\ndata Letter : Char -> Type where\n MkLetter : (c : Char) -> { auto prf : Elem c Alphabet } -> Letter c\n", "meta": {"hexsha": "4634b1241b2f63ab1b4f307adb996b528c97bd06", "size": 3770, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/9-Predicates.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/9-Predicates.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/9-Predicates.idr", "max_forks_repo_name": "ostera/asdf", "max_forks_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "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.7375886525, "max_line_length": 80, "alphanum_fraction": 0.4968169761, "num_tokens": 1028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7352183607181286}} {"text": "module SplayHeap\n\nimport Heap\n\n%default total\n%access private\n\nexport\ndata SplayHeap a = E | T (SplayHeap a) a (SplayHeap a)\n\npartition : Ord a => a -> SplayHeap a -> (SplayHeap a, SplayHeap a)\npartition pivot E = (E, E)\npartition pivot t@(T a x b) =\n if x <= pivot then\n case b of\n E => (t, E)\n T b1 y b2 =>\n if y <= pivot then\n let (small, big) = partition pivot $ assert_smaller t b2\n in (T (T a x b1) y small, big)\n else\n let (small, big) = partition pivot $ assert_smaller t b1\n in (T a x small, T big y b2)\n else\n case a of\n E => (E, t)\n T a1 y a2 =>\n if y <= pivot then\n let (small, big) = partition pivot $ assert_smaller t a2\n in (T a1 y small, T big x b)\n else\n let (small, big) = partition pivot $ assert_smaller t a1\n in (small, T (T big y a2) x b)\n\nexport\nHeap SplayHeap where\n empty = E\n isEmpty E = True\n isEmpty _ = False\n\n insert x t = let (a, b) = partition x t in T a x b\n\n merge E t = t\n merge (T a x b) t = let (ta, tb) = partition x t\n in T (assert_total $ merge ta a) x (assert_total $ merge tb b)\n\n findMin E = idris_crash \"empty heap\"\n findMin (T E x b) = x\n findMin (T a x b) = findMin a\n\n deleteMin E = idris_crash \"empty heap\"\n deleteMin (T E x b) = b\n deleteMin (T (T E x b) y c) = T b y c\n deleteMin (T (T a x b) y c) = T (deleteMin a) x (T b y c)\n", "meta": {"hexsha": "f31a615cc15c4cd8255ada92f166f04251905ce9", "size": 1438, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/SplayHeap.idr", "max_stars_repo_name": "ska80/idris-okasaki-pfds", "max_stars_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-08T00:55:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-08T00:55:51.000Z", "max_issues_repo_path": "src/SplayHeap.idr", "max_issues_repo_name": "ska80/idris-okasaki-pfds", "max_issues_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_issues_repo_licenses": ["CC0-1.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": "src/SplayHeap.idr", "max_forks_repo_name": "ska80/idris-okasaki-pfds", "max_forks_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1454545455, "max_line_length": 67, "alphanum_fraction": 0.5625869263, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7349621483205334}} {"text": "module Setoid\n\n%default total\n%access public export\n\nReflx: {A : Type} -> (R: A -> A -> Type) -> Type\nReflx {A} R = (x : A) -> R x x\n\n\nSymm: {A : Type} -> (R: A -> A -> Type) -> Type\nSymm {A} R = (x : A) -> (y : A) -> R x y -> R y x\n\n\nTrans: {A : Type} -> (R: A -> A -> Type) -> Type\nTrans {A} R = (x : A) -> (y : A) -> (z : A) -> R x y -> R y z -> R x z\n\n\ndata IsEquivalence: {A : Type} -> (R: A -> A -> Type) -> Type where\n EqProof: {A: Type} -> (R: A -> A -> Type) -> Reflx {A} R -> Symm {A} R -> Trans {A} R -> IsEquivalence {A} R\n\n\nrecord Setoid where\n constructor MkSetoid\n Carrier: Type\n Equivalence: Carrier -> Carrier -> Type\n isEquivalence: IsEquivalence Equivalence\n", "meta": {"hexsha": "34490d2367d83ffb8a01f9ba2aa7735f89483a4c", "size": 692, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "hw6/Setoid.idr", "max_stars_repo_name": "lytr777/tt", "max_stars_repo_head_hexsha": "f06810f3d6b33ad0601e3bf4b5f65dca98eafb1b", "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": "hw6/Setoid.idr", "max_issues_repo_name": "lytr777/tt", "max_issues_repo_head_hexsha": "f06810f3d6b33ad0601e3bf4b5f65dca98eafb1b", "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": "hw6/Setoid.idr", "max_forks_repo_name": "lytr777/tt", "max_forks_repo_head_hexsha": "f06810f3d6b33ad0601e3bf4b5f65dca98eafb1b", "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": 25.6296296296, "max_line_length": 112, "alphanum_fraction": 0.5187861272, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350351, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.7349394927425604}} {"text": "-- Untyped lambda calculus implemntation in Idris\n\ndata Term\n = Var Nat -- A variable is represented by its de-bruijn index\n | Abs Term -- An abstraction introduces a new function\n | App Term Term -- One term applied to another\n\n\n-- Variables are either free or bound\ndata VarType\n = Free\n | Bound\n\n\n-- Turns the type into a function that can be used to determine\n-- whether a variable with brujin index 'i' within 'n' abstractions\n-- is Free/Bound. ('i' -> 'n' -> Bool)\nvarPred : VarType -> Nat -> Nat -> Bool\nvarPred Free = (>)\nvarPred Bound = (==)\n\n\n-- Iterates through the AST of a Term, applying 'f' on\n-- variables of type 'ty'.\ntermMap : VarType -> (Nat -> Nat -> Term) -> Term -> Term\ntermMap ty f = go 0 where\n -- 'n' represents the number of abstractions the current term is\n go : Nat -> Term -> Term\n go n (Var i) with (varPred ty i n)\n | True = f n i -- If the variable matches the desired type, apply f\n | False = Var i -- Else leave it unchanged\n go n (Abs body) = Abs $ go (succ n) body -- Recurse, incrementing n as we will be under another abstraction\n go n (App t1 t2) = App (go n t1) (go n t2) -- Function application does not introduce an abstraction, so leave n unchanged\n\n\n-- Apply a function to all of the indices of free variables\nmapFreeIndices : (Nat -> Nat) -> Term -> Term\nmapFreeIndices f t = termMap Free (const $ Var . f) t\n\n\n-- Substitute 't1' into 't2' at the top level (replacing variables with index 0)\nsubstitute : Term -> Term -> Term\nsubstitute t1 t2 = termMap Bound (\\n => const $ mapFreeIndices (+n) t1) t2\n\n\n-- Perform a beta reduction (aka function application). First decrement all\n-- free variable indices in the body, since function application removes the\n-- top level abstraction. Then substitute the function argument into the body.\nbetaReduce : Term -> Term -> Term\nbetaReduce body arg = substitute arg $ mapFreeIndices Nat.pred body\n\n\n-- Perform one reductive step. If no step could be applied, return Nothing\nsimplify : Term -> Maybe Term\nsimplify (App (Abs body) arg@(Abs _)) = Just $ betaReduce body arg -- Use function application if possible\nsimplify (App f@(Abs _) arg) = App f <$> simplify arg -- Simplify the argument, so function application can be used next\nsimplify (App f arg) = flip App arg <$> simplify f -- Simplify the function, so function application can be used next\nsimplify t = Nothing -- No simplification rules apply, so return Nothing\n\n\n-- Evaluate a term down to it's normal form. This uses strict evaluation.\n-- Note that this may not terminate: this a \"feature\" of untyped lc.\n-- Here we keep simplifying until no more simplifying steps are available.\neval : Term -> Term\neval t = maybe t eval $ simplify t\n", "meta": {"hexsha": "5c0471d4ee4e195a609b02984e4ddf9fde9c303f", "size": 2911, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Main.idr", "max_stars_repo_name": "eayus/untyped-lc", "max_stars_repo_head_hexsha": "e2ff36d51fa48e4b724c6110e638192b849a2c62", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-28T15:02:20.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-28T15:02:20.000Z", "max_issues_repo_path": "Main.idr", "max_issues_repo_name": "eayus/untyped-lc", "max_issues_repo_head_hexsha": "e2ff36d51fa48e4b724c6110e638192b849a2c62", "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": "eayus/untyped-lc", "max_forks_repo_head_hexsha": "e2ff36d51fa48e4b724c6110e638192b849a2c62", "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": 44.1060606061, "max_line_length": 144, "alphanum_fraction": 0.656475438, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.734224322060442}} {"text": "> data Elem : a -> List a -> Type where\n> Here : Elem x (x :: xs)\n> There : Elem x xs -> Elem x (y :: xs)\n\n> interface DecEq a where\n> decEq : (x : a) -> (y : a) -> Dec (x = y)\n\n> zeroNotSucc : Z = (S k) -> Void\n> zeroNotSucc Refl impossible\n\n> recNotEq : (k = j -> Void) -> (S k) = (S j) -> Void\n\n> DecEq Nat where\n> decEq Z Z = Yes Refl\n> decEq Z (S k) = No zeroNotSucc\n> decEq (S k) Z = No ?succNotZero\n> decEq (S k) (S j) with (decEq k j)\n> decEq (S j) (S j) | (Yes Refl) = Yes Refl\n> decEq (S k) (S j) | (No contra) = No ?recNotEqLift\n\n> isElem : DecEq a => (x : a) -> (xs : List a) -> Maybe (Elem x xs)\n> isElem x [] = Nothing\n> isElem x (y :: xs) with (decEq x y)\n> isElem y (y :: xs) | (Yes Refl) = Just Here\n> isElem x (y :: xs) | (No contra) with (isElem x xs)\n> isElem x (y :: xs) | (No contra) | Nothing = Nothing\n> isElem x (y :: xs) | (No contra) | (Just z) = Just (There z)\n", "meta": {"hexsha": "e7c2c8c867cf4e3861806a3394f94d6068568bda", "size": 929, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/literate009/WithLift.lidr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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/literate009/WithLift.lidr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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/literate009/WithLift.lidr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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.1785714286, "max_line_length": 67, "alphanum_fraction": 0.5231431647, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7339283737696302}} {"text": "module Control.Algebra.Laws\n\nimport Control.Algebra\n\n%default total\n\n-- Monoids\n\n||| Inverses are unique.\npublic export\nuniqueInverse : MonoidV ty => (x, y, z : ty) ->\n y <+> x = neutral {ty} -> x <+> z = neutral {ty} -> y = z\nuniqueInverse x y z p q =\n rewrite sym $ monoidNeutralIsNeutralL y in\n rewrite sym q in\n rewrite semigroupOpIsAssociative y x z in\n rewrite p in\n rewrite monoidNeutralIsNeutralR z in\n Refl\n\n-- Groups\n\n||| Only identity is self-squaring.\npublic export\nselfSquareId : Group ty => (x : ty) ->\n x <+> x = x -> x = neutral {ty}\nselfSquareId x p =\n rewrite sym $ monoidNeutralIsNeutralR x in\n rewrite sym $ groupInverseIsInverseR x in\n rewrite sym $ semigroupOpIsAssociative (inverse x) x x in\n rewrite p in\n Refl\n\n||| Inverse elements commute.\npublic export\ninverseCommute : Group ty => (x, y : ty) ->\n y <+> x = neutral {ty} -> x <+> y = neutral {ty}\ninverseCommute x y p = selfSquareId (x <+> y) prop where\n prop : (x <+> y) <+> (x <+> y) = x <+> y\n prop =\n rewrite sym $ semigroupOpIsAssociative x y (x <+> y) in\n rewrite semigroupOpIsAssociative y x y in\n rewrite p in\n rewrite monoidNeutralIsNeutralR y in\n Refl\n\n||| Every element has a right inverse.\npublic export\ngroupInverseIsInverseL : Group ty => (x : ty) ->\n x <+> inverse x = neutral {ty}\ngroupInverseIsInverseL x =\n inverseCommute x (inverse x) (groupInverseIsInverseR x)\n\n||| -(-x) = x\npublic export\ninverseSquaredIsIdentity : Group ty => (x : ty) ->\n inverse (inverse x) = x\ninverseSquaredIsIdentity {ty} x =\n uniqueInverse\n (inverse x)\n (inverse $ inverse x)\n x\n (groupInverseIsInverseR $ inverse x)\n (groupInverseIsInverseR x)\n\n||| If every square in a group is identity, the group is commutative.\npublic export\nsquareIdCommutative : Group ty => (x, y : ty) ->\n ((a : ty) -> a <+> a = neutral {ty}) ->\n x <+> y = y <+> x\nsquareIdCommutative x y p =\n uniqueInverse (x <+> y) (x <+> y) (y <+> x) (p (x <+> y)) prop where\n prop : (x <+> y) <+> (y <+> x) = neutral {ty}\n prop =\n rewrite sym $ semigroupOpIsAssociative x y (y <+> x) in\n rewrite semigroupOpIsAssociative y y x in\n rewrite p y in\n rewrite monoidNeutralIsNeutralR x in\n p x\n\n||| -0 = 0\npublic export\ninverseNeutralIsNeutral : Group ty =>\n inverse (neutral {ty}) = neutral {ty}\ninverseNeutralIsNeutral {ty} =\n rewrite sym $ cong inverse (groupInverseIsInverseL (neutral {ty})) in\n rewrite monoidNeutralIsNeutralR $ inverse (neutral {ty}) in\n inverseSquaredIsIdentity (neutral {ty})\n\n-- ||| -(x + y) = -y + -x\n-- public export\n-- inverseOfSum : Group ty => (l, r : ty) ->\n-- inverse (l <+> r) = inverse r <+> inverse l\n-- inverseOfSum {ty} l r =\n-- -- expand\n-- rewrite sym $ monoidNeutralIsNeutralR $ inverse $ l <+> r in\n-- rewrite sym $ groupInverseIsInverseR r in\n-- rewrite sym $ monoidNeutralIsNeutralL $ inverse r in\n-- rewrite sym $ groupInverseIsInverseR l in\n-- -- shuffle\n-- rewrite semigroupOpIsAssociative (inverse r) (inverse l) l in\n-- rewrite sym $ semigroupOpIsAssociative (inverse r <+> inverse l) l r in\n-- rewrite sym $ semigroupOpIsAssociative (inverse r <+> inverse l) (l <+> r) (inverse $ l <+> r) in\n-- -- contract\n-- rewrite sym $ monoidNeutralIsNeutralL $ inverse l in\n-- rewrite groupInverseIsInverseL $ l <+> r in\n-- rewrite sym $ semigroupOpIsAssociative (inverse r <+> (inverse l <+> neutral)) l (inverse l <+> neutral) in\n-- rewrite semigroupOpIsAssociative l (inverse l) neutral in\n-- rewrite groupInverseIsInverseL l in\n-- rewrite monoidNeutralIsNeutralL $ the ty neutral in\n-- Refl\n\n||| y = z if x + y = x + z\npublic export\ncancelLeft : Group ty => (x, y, z : ty) ->\n x <+> y = x <+> z -> y = z\ncancelLeft x y z p =\n rewrite sym $ monoidNeutralIsNeutralR y in\n rewrite sym $ groupInverseIsInverseR x in\n rewrite sym $ semigroupOpIsAssociative (inverse x) x y in\n rewrite p in\n rewrite semigroupOpIsAssociative (inverse x) x z in\n rewrite groupInverseIsInverseR x in\n monoidNeutralIsNeutralR z\n\n||| y = z if y + x = z + x.\npublic export\ncancelRight : Group ty => (x, y, z : ty) ->\n y <+> x = z <+> x -> y = z\ncancelRight x y z p =\n rewrite sym $ monoidNeutralIsNeutralL y in\n rewrite sym $ groupInverseIsInverseL x in\n rewrite semigroupOpIsAssociative y x (inverse x) in\n rewrite p in\n rewrite sym $ semigroupOpIsAssociative z x (inverse x) in\n rewrite groupInverseIsInverseL x in\n monoidNeutralIsNeutralL z\n\n||| ab = 0 -> a = b^-1\npublic export\nneutralProductInverseR : Group ty => (a, b : ty) ->\n a <+> b = neutral {ty} -> a = inverse b\nneutralProductInverseR a b prf =\n cancelRight b a (inverse b) $\n trans prf $ sym $ groupInverseIsInverseR b\n\n||| ab = 0 -> a^-1 = b\npublic export\nneutralProductInverseL : Group ty => (a, b : ty) ->\n a <+> b = neutral {ty} -> inverse a = b\nneutralProductInverseL a b prf =\n cancelLeft a (inverse a) b $\n trans (groupInverseIsInverseL a) $ sym prf\n\n||| For any a and b, ax = b and ya = b have solutions.\npublic export\nlatinSquareProperty : Group ty => (a, b : ty) ->\n ((x : ty ** a <+> x = b),\n (y : ty ** y <+> a = b))\nlatinSquareProperty a b =\n ((((inverse a) <+> b) **\n rewrite semigroupOpIsAssociative a (inverse a) b in\n rewrite groupInverseIsInverseL a in\n monoidNeutralIsNeutralR b),\n (b <+> (inverse a) **\n rewrite sym $ semigroupOpIsAssociative b (inverse a) a in\n rewrite groupInverseIsInverseR a in\n monoidNeutralIsNeutralL b))\n\n||| For any a, b, x, the solution to ax = b is unique.\npublic export\nuniqueSolutionR : Group ty => (a, b, x, y : ty) ->\n a <+> x = b -> a <+> y = b -> x = y\nuniqueSolutionR a b x y p q = cancelLeft a x y $ trans p (sym q)\n\n||| For any a, b, y, the solution to ya = b is unique.\npublic export\nuniqueSolutionL : Group t => (a, b, x, y : t) ->\n x <+> a = b -> y <+> a = b -> x = y\nuniqueSolutionL a b x y p q = cancelRight a x y $ trans p (sym q)\n\n-- ||| -(x + y) = -x + -y\n-- public export\n-- inverseDistributesOverGroupOp : AbelianGroup ty => (l, r : ty) ->\n-- inverse (l <+> r) = inverse l <+> inverse r\n-- inverseDistributesOverGroupOp l r =\n-- rewrite groupOpIsCommutative (inverse l) (inverse r) in\n-- inverseOfSum l r\n\n||| Homomorphism preserves neutral.\npublic export\nhomoNeutral : GroupHomomorphism a b =>\n to (neutral {ty=a}) = neutral {ty=b}\nhomoNeutral =\n selfSquareId (to neutral) $\n trans (sym $ toGroup neutral neutral) $\n cong to $ monoidNeutralIsNeutralL neutral\n\n||| Homomorphism preserves inverses.\npublic export\nhomoInverse : GroupHomomorphism a b => (x : a) ->\n the b (to $ inverse x) = the b (inverse $ to x)\nhomoInverse x =\n cancelRight (to x) (to $ inverse x) (inverse $ to x) $\n trans (sym $ toGroup (inverse x) x) $\n trans (cong to $ groupInverseIsInverseR x) $\n trans homoNeutral $\n sym $ groupInverseIsInverseR (to x)\n\n-- Rings\n\n||| 0x = x\npublic export\nmultNeutralAbsorbingL : Ring ty => (r : ty) ->\n neutral {ty} <.> r = neutral {ty}\nmultNeutralAbsorbingL {ty} r =\n rewrite sym $ monoidNeutralIsNeutralR $ neutral <.> r in\n rewrite sym $ groupInverseIsInverseR $ neutral <.> r in\n rewrite sym $ semigroupOpIsAssociative (inverse $ neutral <.> r) (neutral <.> r) (((inverse $ neutral <.> r) <+> (neutral <.> r)) <.> r) in\n rewrite groupInverseIsInverseR $ neutral <.> r in\n rewrite sym $ ringOpIsDistributiveR neutral neutral r in\n rewrite monoidNeutralIsNeutralR $ the ty neutral in\n groupInverseIsInverseR $ neutral <.> r\n\n||| x0 = 0\npublic export\nmultNeutralAbsorbingR : Ring ty => (l : ty) ->\n l <.> neutral {ty} = neutral {ty}\nmultNeutralAbsorbingR {ty} l =\n rewrite sym $ monoidNeutralIsNeutralL $ l <.> neutral in\n rewrite sym $ groupInverseIsInverseL $ l <.> neutral in\n rewrite semigroupOpIsAssociative (l <.> ((l <.> neutral) <+> (inverse $ l <.> neutral))) (l <.> neutral) (inverse $ l <.> neutral) in\n rewrite groupInverseIsInverseL $ l <.> neutral in\n rewrite sym $ ringOpIsDistributiveL l neutral neutral in\n rewrite monoidNeutralIsNeutralL $ the ty neutral in\n groupInverseIsInverseL $ l <.> neutral\n\n||| (-x)y = -(xy)\npublic export\nmultInverseInversesL : Ring ty => (l, r : ty) ->\n inverse l <.> r = inverse (l <.> r)\nmultInverseInversesL l r =\n rewrite sym $ monoidNeutralIsNeutralR $ inverse l <.> r in\n rewrite sym $ groupInverseIsInverseR $ l <.> r in\n rewrite sym $ semigroupOpIsAssociative (inverse $ l <.> r) (l <.> r) (inverse l <.> r) in\n rewrite sym $ ringOpIsDistributiveR l (inverse l) r in\n rewrite groupInverseIsInverseL l in\n rewrite multNeutralAbsorbingL r in\n monoidNeutralIsNeutralL $ inverse $ l <.> r\n\n||| x(-y) = -(xy)\npublic export\nmultInverseInversesR : Ring ty => (l, r : ty) ->\n l <.> inverse r = inverse (l <.> r)\nmultInverseInversesR l r =\n rewrite sym $ monoidNeutralIsNeutralL $ l <.> (inverse r) in\n rewrite sym $ groupInverseIsInverseL (l <.> r) in\n rewrite semigroupOpIsAssociative (l <.> (inverse r)) (l <.> r) (inverse $ l <.> r) in\n rewrite sym $ ringOpIsDistributiveL l (inverse r) r in\n rewrite groupInverseIsInverseR r in\n rewrite multNeutralAbsorbingR l in\n monoidNeutralIsNeutralR $ inverse $ l <.> r\n\n||| (-x)(-y) = xy\npublic export\nmultNegativeByNegativeIsPositive : Ring ty => (l, r : ty) ->\n inverse l <.> inverse r = l <.> r\nmultNegativeByNegativeIsPositive l r =\n rewrite multInverseInversesR (inverse l) r in\n rewrite sym $ multInverseInversesL (inverse l) r in\n rewrite inverseSquaredIsIdentity l in\n Refl\n\n||| (-1)x = -x\npublic export\ninverseOfUnityR : RingWithUnity ty => (x : ty) ->\n inverse (unity {ty}) <.> x = inverse x\ninverseOfUnityR x =\n rewrite multInverseInversesL unity x in\n rewrite unityIsRingIdR x in\n Refl\n\n||| x(-1) = -x\npublic export\ninverseOfUnityL : RingWithUnity ty => (x : ty) ->\n x <.> inverse (unity {ty}) = inverse x\ninverseOfUnityL x =\n rewrite multInverseInversesR x unity in\n rewrite unityIsRingIdL x in\n Refl\n", "meta": {"hexsha": "66b1d82017e41ffe62d44b8fbed00f32bb44d622", "size": 10053, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Control/Algebra/Laws.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/libs/contrib/Control/Algebra/Laws.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/libs/contrib/Control/Algebra/Laws.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": 34.5463917526, "max_line_length": 141, "alphanum_fraction": 0.6477668358, "num_tokens": 3187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7338410438402897}} {"text": "data Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n\n\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case m == len of\n False => Nothing\n True => Just ?input\n\n\n\n\ndata EqNat : Nat -> Nat -> Type where\n Same : (x : Nat) -> EqNat x x\n\nsameS : (k : Nat) -> (j : Nat) -> (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS k k (Same k) = Same (S k)\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat Z Z = Just (Same Z)\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just eq => Just (sameS _ _ eq)\n\n\n{-\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case checkEqNat m len of\n Nothing => Nothing\n Just (Same _) => Just ?input\n-- Just (Same m) => Just input\n\n-}\n", "meta": {"hexsha": "ba22b1448f868864a90fc96642462ad572de8706", "size": 1130, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZPF/Slajdy19/PlikiIdrisa/ExactLength.idr", "max_stars_repo_name": "wdomitrz/Coq-Exercises", "max_stars_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/ExactLength.idr", "max_issues_repo_name": "wdomitrz/Coq-Exercises", "max_issues_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/ExactLength.idr", "max_forks_repo_name": "wdomitrz/Coq-Exercises", "max_forks_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": 29.7368421053, "max_line_length": 71, "alphanum_fraction": 0.4690265487, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.73380538493725}} {"text": "\n\npublic export\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (num1 = num2)\ncheckEqNat Z Z = Just Refl\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just prf => Just $ cong prf\n\n-- Ex 8.1 #1\nsame_cons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys\nsame_cons prf = cong prf\n-- Or alternative:\n-- same_cons Refl = Refl\n\n-- Ex 8.1 #2\nsame_lists : {xs : List a} -> {ys : List a} -> x = y -> xs = ys -> x :: xs = y :: ys\nsame_lists Refl Refl = Refl\n\n-- Ex 8.1 #3\ndata ThreeEq : a -> b -> c -> Type where\n CreateThreeEq : ThreeEq z z z\n\n-- Ex 8.1 #4\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS z z z CreateThreeEq = CreateThreeEq\n", "meta": {"hexsha": "74b1e7ba8727044e9b85ecf177e1fdfe4971c3a6", "size": 818, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter8/CheckEqMaybe.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter8/CheckEqMaybe.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter8/CheckEqMaybe.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 28.2068965517, "max_line_length": 84, "alphanum_fraction": 0.5537897311, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.7335197090534041}} {"text": "module Data.Fin.Extra\n\nimport Data.Fin\nimport Data.Nat\n\n%default total\n\n||| Proof that an element **n** of Fin **m** , when converted to Nat is smaller than the bound **m**.\nexport\nelemSmallerThanBound : (n : Fin m) -> LT (finToNat n) m\nelemSmallerThanBound FZ = LTESucc LTEZero\nelemSmallerThanBound (FS x) = LTESucc (elemSmallerThanBound x)\n\n||| Proof that application of finToNat the last element of Fin **S n** gives **n**.\nexport\nfinToNatLastIsBound : {n : Nat} -> finToNat (Fin.last {n}) = n\nfinToNatLastIsBound {n=Z} = Refl\nfinToNatLastIsBound {n=S k} = rewrite finToNatLastIsBound {n=k} in Refl\n\n||| Proof that an element **n** of Fin **m** , when converted to Nat is smaller than the bound **m**.\nexport\nfinToNatWeakenNeutral : {m : Nat} -> {n : Fin m} -> finToNat (weaken n) = finToNat n\nfinToNatWeakenNeutral {n=FZ} = Refl\nfinToNatWeakenNeutral {m=S (S _)} {n=FS _} = cong S finToNatWeakenNeutral\n\n-- ||| Proof that it's possible to strengthen a weakened element of Fin **m**.\n-- export\n-- strengthenWeakenNeutral : {m : Nat} -> (n : Fin m) -> strengthen (weaken n) = Right n\n-- strengthenWeakenNeutral {m=S _} FZ = Refl\n-- strengthenWeakenNeutral {m=S (S _)} (FS k) = rewrite strengthenWeakenNeutral k in Refl\n\n||| Proof that it's not possible to strengthen the last element of Fin **n**.\nexport\nstrengthenLastIsLeft : {n : Nat} -> strengthen (Fin.last {n}) = Left (Fin.last {n})\nstrengthenLastIsLeft {n=Z} = Refl\nstrengthenLastIsLeft {n=S k} = rewrite strengthenLastIsLeft {n=k} in Refl\n\n||| Enumerate elements of Fin **n** backwards.\nexport\ninvFin : {n : Nat} -> Fin n -> Fin n\ninvFin FZ = last\ninvFin {n=S (S _)} (FS k) = weaken (invFin k)\n\n||| Proof that an inverse of a weakened element of Fin **n** is a successive of an inverse of an original element.\nexport\ninvWeakenIsSucc : {n : Nat} -> (m : Fin n) -> invFin (weaken m) = FS (invFin m)\ninvWeakenIsSucc FZ = Refl\ninvWeakenIsSucc {n=S (S _)} (FS k) = rewrite invWeakenIsSucc k in Refl\n\n||| Proof that double inversion of Fin **n** gives the original.\nexport\ndoubleInvFinSame : {n : Nat} -> (m : Fin n) -> invFin (invFin m) = m\ndoubleInvFinSame {n=S Z} FZ = Refl\ndoubleInvFinSame {n=S (S k)} FZ = rewrite doubleInvFinSame {n=S k} FZ in Refl\ndoubleInvFinSame {n=S (S _)} (FS x) = trans (invWeakenIsSucc $ invFin x) (cong FS $ doubleInvFinSame x)\n\n||| Proof that an inverse of the last element of Fin (S **n**) in FZ.\nexport\ninvLastIsFZ : {n : Nat} -> invFin (Fin.last {n}) = FZ\ninvLastIsFZ {n=Z} = Refl\ninvLastIsFZ {n=S k} = rewrite invLastIsFZ {n=k} in Refl\n\n-- ||| Proof that it's possible to strengthen an inverse of a succesive element of Fin **n**.\n-- export\n-- strengthenNotLastIsRight : (m : Fin (S n)) -> strengthen (invFin (FS m)) = Right (invFin m)\n-- strengthenNotLastIsRight m = strengthenWeakenNeutral (invFin m)\n--\n||| Either tightens the bound on a Fin or proves that it's the last.\nexport\nstrengthen' : {n : Nat} -> (m : Fin (S n)) -> Either (m = Fin.last) (m' : Fin n ** finToNat m = finToNat m')\nstrengthen' {n = Z} FZ = Left Refl\nstrengthen' {n = S k} FZ = Right (FZ ** Refl)\nstrengthen' {n = S k} (FS m) = case strengthen' m of\n Left eq => Left $ cong FS eq\n Right (m' ** eq) => Right (FS m' ** cong S eq)\n\n||| A view of Nat as a quotient of some number and a finite remainder.\npublic export\ndata FractionView : (n : Nat) -> (d : Nat) -> Type where\n Fraction : (n : Nat) -> (d : Nat) -> {auto ok: GT d Z} ->\n (q : Nat) -> (r : Fin d) ->\n q * d + finToNat r = n -> FractionView n d\n\n||| Converts Nat to the fractional view with a non-zero divisor.\nexport\ndivMod : (n, d : Nat) -> {auto ok: GT d Z} -> FractionView n d\ndivMod Z (S d) = Fraction Z (S d) Z FZ Refl\ndivMod {ok=_} (S n) (S d) =\n let Fraction {ok=ok} n (S d) q r eq = divMod n (S d) in\n case strengthen' r of\n Left eq' => Fraction {ok=ok} (S n) (S d) (S q) FZ $\n rewrite sym eq in\n rewrite trans (cong finToNat eq') finToNatLastIsBound in\n cong S $ trans\n (plusZeroRightNeutral (d + q * S d))\n (plusCommutative d (q * S d))\n Right (r' ** eq') => Fraction {ok=ok} (S n) (S d) q (FS r') $\n rewrite sym $ plusSuccRightSucc (q * S d) (finToNat r') in\n cong S $ trans (sym $ cong (plus (q * S d)) eq') eq\n", "meta": {"hexsha": "cd663303611469e0844bd0d80ad6a7cca004ff1b", "size": 4323, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/Fin/Extra.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/contrib/Data/Fin/Extra.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/contrib/Data/Fin/Extra.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": 43.23, "max_line_length": 114, "alphanum_fraction": 0.6340504279, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7334625076330812}} {"text": "-- Matrix.idr\n--\n-- Matrix arithmetics with dependent types\n\nmodule Matrix\n\nimport Data.Vect\n\n-- matrix addition\naddMatrix : Num numType =>\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType)\n\n-- matrix multiplication\nmultMatrix : Num numType =>\n Vect n (Vect m numType) ->\n Vect m (Vect p numType) ->\n Vect n (Vect p numType)\n\n-- transpose matrix\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntransposeHelper : (x : Vect n elem) -> (xsTrans : Vect n (Vect len elem)) ->\n Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n transposeHelper x xsTrans\n\n\n", "meta": {"hexsha": "99a0f4026c406289df44b66d5fa120f7b6dca32f", "size": 962, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_3/Matrix.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_3/Matrix.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_3/Matrix.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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.7222222222, "max_line_length": 76, "alphanum_fraction": 0.6018711019, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7332639363715462}} {"text": "-- tryIndex.idr\n--\n-- Demonstrates Fin type for indexing Vect\n--\n\nimport Data.Vect\n\n||| Returns the element at given index or Nothing if out-of-bounds\ntryIndex : Integer -> Vect n a -> Maybe a\ntryIndex {n} i xs = case integerToFin i n of\n Nothing => Nothing\n (Just idx) => Just (index idx xs)\n\n\n\n\n\n", "meta": {"hexsha": "ebf62003539abed0724e5e55e5d8517c196aa991", "size": 346, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_4/TryIndex.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/TryIndex.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/TryIndex.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": 19.2222222222, "max_line_length": 66, "alphanum_fraction": 0.5895953757, "num_tokens": 83, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7332001721789985}} {"text": "module Lists\n\n%access public export\n%default total\n\n\n--proof that something is an element of the list\ntotal\nisElementOfList : (typ : Type) -> (ls : List typ) -> (a : typ) -> Type\nisElementOfList typ ls a = (n : Nat ** (fromMaybe (index' n ls) = a))\n\n--proof that right addition preserves equality (somehow cong was messing up)\ntotal\naddl: (x: Type) -> (z: List x) -> (l = y) -> (l ++ z = y ++ z)\naddl x z Refl = Refl\n\n-- Proof that the auxiliary reverseOnto used to define rev behaves the way it should (semi-pseudo-contravariantly as I choose to call it)\ntotal\nrevontoeq: (x: Type) -> (y: List x) -> (l: List x) -> ((reverseOnto y l) = ((reverseOnto [] l) ++ y))\nrevontoeq x y [] = Refl\nrevontoeq x [] (z :: xs) = sym (appendNilRightNeutral (reverseOnto [] (z::xs)))\nrevontoeq x (y :: ys) (z :: xs) = trans (trans (revontoeq x (z::y::ys) xs) ((appendAssociative (reverseOnto [] xs) [z] (y::ys)))) (sym (addl x (y::ys) (revontoeq x [z] xs)))\n\n--Proof that reverse is pseudo-contravariant on concatenation\ntotal\nreviscontra: (x: Type) -> (y: List x) -> (l: List x) -> (reverse(y++l) = reverse(l)++reverse(y))\nreviscontra x [] z = sym (appendNilRightNeutral (reverseOnto [] z))\nreviscontra x (y :: xs) z = trans (trans (trans (revontoeq x [y] (xs++z)) (addl x [y] (reviscontra x xs z))) (sym (appendAssociative (reverse z) (reverse xs) [y]))) (cong(sym (revontoeq x [y] xs)))\n\n-- Proof that the reverse function is self-inverse\ntotal\nreveq: (x: Type) -> (l: List x) -> (l = reverse(reverse l))\nreveq x [] = Refl\nreveq x (y :: xs) = sym (trans (trans (cong(reviscontra x [y] xs)) (reviscontra x (reverse xs) (reverse [y]))) (cong(sym (reveq x xs))))\n", "meta": {"hexsha": "e547d06eef31c7db29a20130aff976d3f25a0254", "size": 1649, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Lists.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/Lists.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/Lists.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": 47.1142857143, "max_line_length": 197, "alphanum_fraction": 0.640388114, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.733169260634127}} {"text": "data Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n(++) : Vect n a -> Vect m a -> Vect (n + m) a\n(++) Nil ys = ys\n(++) (x :: xs) ys = x :: xs ++ ys\n\ndata Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\nindex : Fin n -> Vect n a -> a\nindex FZ (x :: xs) = x\nindex (FS k) (x :: xs) = index k xs\n\nfilter : (a -> Bool) -> Vect n a -> (p ** Vect p a)\nfilter p Nil = (_ ** [])\nfilter p (x :: xs)\n = case filter p xs of\n (_ ** xs') => if p x then (_ ** x :: xs')\n else (_ ** xs')\n\ncons : t -> (x : Nat ** Vect x t) -> (x : Nat ** Vect x t)\ncons val xs\n = record { fst = S (fst xs),\n snd = (val :: snd xs) } xs\n\ncons' : t -> (x : Nat ** Vect x t) -> (x : Nat ** Vect x t)\ncons' val\n = record { fst $= S,\n snd $= (val ::) }\n\nShow a => Show (Vect n a) where\n show xs = \"[\" ++ show' xs ++ \"]\" where\n show' : forall n . Vect n a -> String\n show' Nil = \"\"\n show' (x :: Nil) = show x\n show' (x :: xs) = show x ++ \", \" ++ show' xs\n\n", "meta": {"hexsha": "810cef1256dd40e66cc0d8f25e370243158837e4", "size": 1112, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/samples/Vect.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/samples/Vect.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/samples/Vect.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": 27.1219512195, "max_line_length": 59, "alphanum_fraction": 0.4100719424, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7331370857473247}} {"text": "> module Num.Refinements\n\n\n> %default total\n\n> %access public export\n\n\n> |||\n> interface (Num t) => NumPlusZeroNeutral t where\n> plusZeroLeftNeutral : (x : t) -> 0 + x = x\n> plusZeroRightNeutral : (x : t) -> x + 0 = x\n\n\n> |||\n> interface (NumPlusZeroNeutral t) => NumPlusAssociative t where\n> -- interface (Num t) => NumPlusAssociative t where\n> plusAssociative : (x, y, z : t) -> x + (y + z) = (x + y) + z\n\n\n> |||\n> interface (NumPlusAssociative t) => NumMultZeroOne t where\n> -- interface (Num t) => NumMultZeroOne t where\n> multZeroRightZero : (x : t) -> x * 0 = 0\n> multZeroLeftZero : (x : t) -> 0 * x = 0\n> multOneRightNeutral : (x : t) -> x * 1 = x\n> multOneLeftNeutral : (x : t) -> 1 * x = x\n\n\n> |||\n> interface (NumMultZeroOne t) => NumMultDistributesOverPlus t where\n> -- interface (Num t) => NumMultDistributesOverPlus t where\n> multDistributesOverPlusRight : (x, y, z : t) -> x * (y + z) = (x * y) + (x * z)\n> multDistributesOverPlusLeft : (x, y, z : t) -> (x + y) * z = (x * z) + (y * z)\n", "meta": {"hexsha": "b94017b8ce2e75404da81ccef57413538baf8e0d", "size": 1026, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Num/Refinements.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Num/Refinements.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Num/Refinements.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3142857143, "max_line_length": 83, "alphanum_fraction": 0.5838206628, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802529509909, "lm_q2_score": 0.798186784940666, "lm_q1q2_score": 0.7331188001344411}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 9\n\n-- check that all functions are total\n %default total\n\n--\n-- section 9.1\n--\n\ndata Elem' : a -> List a -> Type where\n Here : Elem' x (x :: xs)\n There : Elem' x xs -> Elem' x (y :: xs)\n\n-- > the (Elem' 2 [1, 2, 4]) (There Here)\n-- There Here : Elem' 2 [1, 2, 4]\n-- > the (Elem' 7 [1, 2, 4]) (There Here)\n-- (input):1:26-35:When checking an application of constructor Main.There:\n-- Type mismatch between\n-- Elem' 2 [2, 4] (Type of Here)\n-- and\n-- Elem' 7 [2, 4] (Expected type)\n--\n-- Specifically:\n-- Type mismatch between\n-- 2\n-- and\n-- 7\n\ndata Last : List a -> a -> Type where\n LastOne : Last [value] value\n LastCons : (prf : Last xs value) -> Last (x :: xs) value\n\n-- > the (Last [1,2,3] 3) $ LastCons (LastCons LastOne)\n-- LastCons (LastCons LastOne) : Last [1, 2, 3] 3\n\nnoLastInEmpty : Last [] value -> Void\nnoLastInEmpty LastOne impossible\nnoLastInEmpty (LastCons _) impossible\n\nnoLastInLast : (contra : (x = value) -> Void) -> Last [x] value -> Void\nnoLastInLast contra LastOne = contra Refl\nnoLastInLast _ (LastCons LastOne) impossible\nnoLastInLast _ (LastCons (LastCons _)) impossible\n\nnoLastRec : (contra : Last (x :: xs) value -> Void) ->\n Last (y :: (x :: xs)) value -> Void\nnoLastRec contra (LastCons prf) = contra prf\n\nisLast : DecEq a => (xs : List a) -> (value : a) -> Dec (Last xs value)\nisLast [] value = No noLastInEmpty\nisLast [x] value = case decEq x value of\n (Yes Refl) => Yes LastOne\n (No contra) => No (noLastInLast contra)\nisLast (y :: x :: xs) value = case isLast (x :: xs) value of\n (Yes prf) => Yes (LastCons prf)\n (No contra) => No (noLastRec contra)\n", "meta": {"hexsha": "e5278207ccd2c1a8eb4f8ae964c69bfdaf211a71", "size": 1914, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter9.idr", "max_stars_repo_name": "gdevanla/idris-learn", "max_stars_repo_head_hexsha": "3348f611f6807e3e88dcd63951c713a327325c2a", "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": "Chapter9.idr", "max_issues_repo_name": "gdevanla/idris-learn", "max_issues_repo_head_hexsha": "3348f611f6807e3e88dcd63951c713a327325c2a", "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": "Chapter9.idr", "max_forks_repo_name": "gdevanla/idris-learn", "max_forks_repo_head_hexsha": "3348f611f6807e3e88dcd63951c713a327325c2a", "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.0, "max_line_length": 74, "alphanum_fraction": 0.5485893417, "num_tokens": 580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.733050375631688}} {"text": "module SkewBinaryRandomAccessList\n\nimport RandomAccessList\n\n%default total\n%access private\n\ndata Tree a = Leaf a | Node a (Tree a) (Tree a)\n\nexport\ndata SkewList a = SL (List (Int, Tree a))\n\nncCons : a -> List (Int, Tree a) -> SkewList a\nncCons x ts = SL ((1, Leaf x) :: ts)\n\nexport\nRandomAccessList SkewList where\n empty = SL []\n isEmpty (SL ts) = isNil ts\n\n cons x (SL ts@((w1, t1) :: (w2, t2) :: tts)) =\n if w1 == w2 then SL ((1 + w1 + w2, Node x t1 t2) :: tts) else ncCons x ts\n cons x (SL ts) = ncCons x ts\n\n head (SL []) = idris_crash \"empty list\"\n head (SL ((_, Leaf x) :: ts)) = x\n head (SL ((w, Node x t1 t2) :: ts)) = x\n\n tail (SL []) = ?RandomAccessList_rhs_1\n tail (SL ((_, Leaf x) :: ts)) = SL ts\n tail (SL ((w, Node x t1 t2) :: ts)) = let hw = assert_total $ w `div` 2 in\n SL ((hw, t1) :: (hw, t2) :: ts)\n\n lookup i (SL ts) = look i ts\n where\n lookTree : Int -> Int -> Tree a -> a\n lookTree _ 0 (Leaf x) = x\n lookTree _ i (Leaf x) = idris_crash \"bad subscript\"\n lookTree w 0 (Node x t1 t2) = x\n lookTree w i (Node x t1 t2) = let w' = assert_total $ w `div` 2 in\n if i <= w' then lookTree w' (i - 1) t1 else lookTree w' (i - 1 - w') t2\n\n look i [] = idris_crash \"bad subscript\"\n look i ((w, t) :: ts) =\n if i < w then lookTree w i t else look (i - w) ts\n\n update i y (SL ts) = SL (upd i ts)\n where\n updTree : Int -> Int -> Tree a -> Tree a\n updTree _ 0 (Leaf x) = Leaf y\n updTree _ i (Leaf x) = idris_crash \"bad subscript\"\n updTree w 0 (Node x t1 t2) = Node y t1 t2\n updTree w i (Node x t1 t2) = let w' = assert_total $ w `div` 2 in\n if i <= w' then Node x (updTree w' (i - 1) t1) t2\n else Node x t1 (updTree w' (i - 1 - w') t2)\n\n upd i [] = idris_crash \"bad subscript\"\n upd i ((w, t) :: ts) =\n if i < w then (w, updTree w i t) :: ts else (w, t) :: upd (i - w) ts\n", "meta": {"hexsha": "a32e130803a5aa55bc10c4438843a2b0afbcde12", "size": 1878, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/SkewBinaryRandomAccessList.idr", "max_stars_repo_name": "ska80/idris-okasaki-pfds", "max_stars_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-08T00:55:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-08T00:55:51.000Z", "max_issues_repo_path": "src/SkewBinaryRandomAccessList.idr", "max_issues_repo_name": "ska80/idris-okasaki-pfds", "max_issues_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_issues_repo_licenses": ["CC0-1.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": "src/SkewBinaryRandomAccessList.idr", "max_forks_repo_name": "ska80/idris-okasaki-pfds", "max_forks_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3, "max_line_length": 77, "alphanum_fraction": 0.5569755059, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7330503586465821}} {"text": "||| Matrix operations with vector space dimensionalities enforced\n||| at the type level. Uses operations from classes in `Control.Algebra`\n||| and `Control.Algebra.VectorSpace`.\nmodule Data.Matrix.Algebraic\n\nimport public Control.Algebra\nimport public Control.Algebra.VectorSpace\nimport public Control.Algebra.NumericInstances\n\nimport public Data.Matrix\n\n\n%default total\n\ninfixr 2 <:> -- vector inner product\ninfixr 2 >< -- vector outer product\ninfixr 2 <<>> -- matrix commutator\ninfixr 2 >><< -- matrix anticommutator\ninfixl 3 <\\> -- row times a matrix\ninfixr 4 -- matrix times a column\ninfixr 5 <> -- matrix multiplication\ninfixr 7 \\&\\ -- vector tensor product\ninfixr 7 <&> -- matrix tensor product\n\n-----------------------------------------------------------------------\n-- Vectors as members of algebraic classes\n-----------------------------------------------------------------------\n\ninstance Semigroup a => Semigroup (Vect n a) where\n (<+>)= zipWith (<+>)\n\ninstance Monoid a => Monoid (Vect n a) where\n neutral = replicate _ neutral\n\ninstance Group a => Group (Vect n a) where\n inverse = map inverse\n\ninstance AbelianGroup a => AbelianGroup (Vect n a) where {}\n\ninstance Ring a => Ring (Vect n a) where\n (<.>) = zipWith (<.>)\n\ninstance RingWithUnity a => RingWithUnity (Vect n a) where\n unity = replicate _ unity\n\ninstance RingWithUnity a => Module a (Vect n a) where\n (<#>) r = map (r <.>)\n\ninstance RingWithUnity a => Module a (Vect n (Vect l a)) where\n (<#>) r = map (r <#>)\n-- should be Module a b => Module a (Vect n b), but results in 'overlapping instance'\n\n-----------------------------------------------------------------------\n-- (Ring) Vector functions\n-----------------------------------------------------------------------\n\n||| Inner product of ring vectors\n(<:>) : Ring a => Vect n a -> Vect n a -> a\n(<:>) w v = foldr (<+>) neutral (zipWith (<.>) w v)\n\n||| Tensor multiply (⊗) ring vectors\n(\\&\\) : Ring a => Vect n a -> Vect m a -> Vect (n * m) a\n(\\&\\) {n} {m} v w = zipWith (<.>) (oextend m v) (orep n w) where\n orep : (n : Nat) -> Vect m a -> Vect (n * m) a\n orep n v = concat $ replicate n v\n oextend : (n : Nat) -> Vect k a -> Vect (k * n) a\n oextend n w = concat $ map (replicate n) w\n\n||| Standard basis vector with one nonzero entry, ring data type and vector-length unfixed\nbasis : RingWithUnity a => (Fin d) -> Vect d a\nbasis i = replaceAt i unity neutral\n\n-----------------------------------------------------------------------\n-- Ring Matrix functions\n-----------------------------------------------------------------------\n\n||| Matrix times a column vector\n() : Ring a => Matrix n m a -> Vect m a -> Vect n a\n() m v = map (v <:>) m\n\n||| Matrix times a row vector\n(<\\>) : Ring a => Vect n a -> Matrix n m a -> Vect m a\n(<\\>) r = map (r <:>) . transpose\n\n||| Matrix multiplication\n(<>) : Ring a => Matrix n k a ->\n Matrix k m a ->\n Matrix n m a\n(<>) m1 m2 = map (<\\> m2) m1\n\n||| Tensor multiply (⊗) for ring matrices\n(<&>) : Ring a => Matrix h1 w1 a -> Matrix h2 w2 a -> Matrix (h1 * h2) (w1 * w2) a\n(<&>) m1 m2 = zipWith (\\&\\) (stepOne m1 m2) (stepTwo m1 m2) where\n stepOne : Matrix h1 w1 a -> Matrix h2 w2 a -> Matrix (h1 * h2) w1 a\n stepOne {h2} m1 m2 = concat $ map (replicate h2) m1\n stepTwo : Matrix h1 w1 a -> Matrix h2 w2 a -> Matrix (h1 * h2) w2 a\n stepTwo {h1} m1 m2 = concat $ replicate h1 m2\n\n||| Outer product between ring vectors\n(><) : Ring a => Vect n a -> Vect m a -> Matrix n m a\n(><) x y = col x <> row y\n\n||| Matrix commutator\n(<<>>) : Ring a => Matrix n n a -> Matrix n n a -> Matrix n n a\n(<<>>) m1 m2 = (m1 <> m2) <-> (m2 <> m1)\n\n||| Matrix anti-commutator\n(>><<) : Ring a => Matrix n n a -> Matrix n n a -> Matrix n n a\n(>><<) m1 m2 = (m1 <> m2) <+> (m2 <> m1)\n\n||| Identity matrix\nId : RingWithUnity a => Matrix d d a\nId = map (\\n => basis n) (fins _)\n\n||| Square matrix from diagonal elements\ndiag_ : Monoid a => Vect n a -> Matrix n n a\ndiag_ = zipWith (\\f => \\x => replaceAt f x neutral) (fins _)\n\n||| Combine two matrices to make a new matrix in block diagonal form\nblockDiag : Monoid a => Matrix n n a -> Matrix m m a -> Matrix (n+m) (n+m) a\nblockDiag g h = map (++ replicate _ neutral) g ++ map ((replicate _ neutral) ++) h\n\n\n-----------------------------------------------------------------------\n-- Determinants\n-----------------------------------------------------------------------\n\n||| Alternating sum\naltSum : Group a => Vect n a -> a\naltSum (x::y::zs) = (x <-> y) <+> altSum zs\naltSum [x] = x\naltSum [] = neutral\n\n||| Determinant of a 2-by-2 matrix\ndet2 : Ring a => Matrix 2 2 a -> a\ndet2 [[x1,x2],[y1,y2]] = x1 <.> y2 <-> x2 <.> y1\n\n||| Determinant of a square matrix\ndet : Ring a => Matrix (S (S n)) (S (S n)) a -> a\ndet {n} m = case n of\n Z => det2 m\n (S k) => altSum . map (\\c => indices FZ c m <.> det (subMatrix FZ c m))\n $ fins (S (S (S k)))\n\n-----------------------------------------------------------------------\n-- Matrix Algebra Properties\n-----------------------------------------------------------------------\n\n-- TODO: Prove properties of matrix algebra for 'Verified' algebraic classes\n", "meta": {"hexsha": "864d1d7fbff1e2cf49eccf034f67f465af6aa322", "size": 5274, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Matrix/Algebraic.idr", "max_stars_repo_name": "fieldstrength/xquant", "max_stars_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-06-16T23:34:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-26T04:22:56.000Z", "max_issues_repo_path": "src/Data/Matrix/Algebraic.idr", "max_issues_repo_name": "fieldstrength/xquant", "max_issues_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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/Matrix/Algebraic.idr", "max_forks_repo_name": "fieldstrength/xquant", "max_forks_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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": 35.16, "max_line_length": 90, "alphanum_fraction": 0.5119453925, "num_tokens": 1516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7327477879920586}} {"text": "module BoundedGCD\n\n\n%default total\n%access public export\n\nnotLTEimpliesLT : (a: Nat) -> (b: Nat) -> (LTE a b -> Void) -> LTE (S b) a\nnotLTEimpliesLT Z b contra = void (contra (LTEZero))\nnotLTEimpliesLT (S k) Z f = LTESucc (LTEZero)\nnotLTEimpliesLT (S k) (S j) contra =\n LTESucc (notLTEimpliesLT k j previousContra) where\n previousContra = \\evidence : (LTE k j) => contra (LTESucc evidence)\n\nsubWithBound: (n: Nat) -> (m: Nat) -> (LTE m n) -> (k: Nat ** LTE k n)\nsubWithBound n Z LTEZero = (n ** lteRefl)\nsubWithBound (S p) (S q) (LTESucc pf) = case subWithBound p q pf of\n (x ** pf) =>\n (x ** lteSuccRight pf)\n\nboundedGCD : (bnd: Nat) -> (n: Nat) -> (m: Nat) -> (LTE n bnd) -> (LTE (S m) bnd) -> Nat\nboundedGCD (S b) Z m x (LTESucc y) = m\nboundedGCD (S b) (S k) Z x (LTESucc y) = (S k)\nboundedGCD (S b) (S Z) (S j) (LTESucc x) (LTESucc y) = S Z\nboundedGCD (S b) (S k) (S Z) (LTESucc x) (LTESucc y) = S Z\nboundedGCD (S b) (S (S (k))) (S (S (j))) (LTESucc x) (LTESucc y) =\n case isLTE j k of\n (Yes prf) => case subWithBound k j prf of\n (diff ** pf) => boundedGCD b (S (S j)) diff y (lteTransitive (LTESucc pf) x)\n (No contra) =>\n let\n ineq = notLTEimpliesLT j k contra\n in\n boundedGCD b (S (S j)) (S (S k)) y (lteTransitive (LTESucc (LTESucc ineq)) y)\n\ngcdAlgo : Nat -> Nat -> Nat\ngcdAlgo k j = case isLTE (S j) k of\n (Yes prf) => boundedGCD k k j lteRefl prf\n (No contra) =>\n let\n ineq = notLTEimpliesLT (S j) k contra\n in\n boundedGCD (S j) k j (lteSuccLeft ineq) lteRefl\n", "meta": {"hexsha": "6b367cb7895f390ea41cb4b19a078b63008e56bd", "size": 1772, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/BoundedGCD.idr", "max_stars_repo_name": "rathivrunda/LTS2019", "max_stars_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": "Code/BoundedGCD.idr", "max_issues_repo_name": "rathivrunda/LTS2019", "max_issues_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": "Code/BoundedGCD.idr", "max_forks_repo_name": "rathivrunda/LTS2019", "max_forks_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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.2093023256, "max_line_length": 103, "alphanum_fraction": 0.5191873589, "num_tokens": 625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7325538764682461}} {"text": "module Decidable.Finite.Fin\n\nimport Data.Nat\nimport Data.Nat.Order\nimport Data.Fin\nimport Decidable.Decidable.Extra\nimport Data.Fin.Extra\n\n||| Given a decidable predicate on Fin n,\n||| it's decidable whether any number in Fin n satisfies it.\npublic export\nfiniteDecEx : {n : Nat} -> {0 p : Fin n -> Type} ->\n (pdec : (k : Fin n) -> Dec (p k)) ->\n Dec (k ** p k)\nfiniteDecEx {n = Z} pdec = No (absurd . fst)\nfiniteDecEx {n = S n} pdec =\n case pdec FZ of\n Yes pz => Yes (FZ ** pz)\n No npz => case finiteDecEx {n = n} (\\ k => pdec (FS k)) of\n Yes (k ** pk) => Yes (FS k ** pk)\n No npk => No $ \\case\n (FZ ** pz) => absurd (npz pz)\n (FS k ** pk) => absurd (npk (k ** pk))\n\n\n\n||| Given a decidable predicate on Fin n,\n||| it's decidable whether all numbers in Fin n satisfy it.\npublic export\nfiniteDecAll : {n : Nat} -> {0 p : Fin n -> Type} ->\n (pdec : (k : Fin n) -> Dec (p k)) ->\n Dec ((k : Fin n) -> p k)\nfiniteDecAll pdec = notExistsNotForall pdec $ finiteDecEx (\\ x => negateDec (pdec x))\n", "meta": {"hexsha": "866bf707cc784de18d027551b565289ffa15923b", "size": 1025, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Decidable/Finite/Fin.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": "libs/contrib/Decidable/Finite/Fin.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": "libs/contrib/Decidable/Finite/Fin.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": 30.1470588235, "max_line_length": 86, "alphanum_fraction": 0.5912195122, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7324184402137736}} {"text": "module TakeN\n\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n\ntotal\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z xs = Exact []\ntakeN (S k) [] = Fewer\n-- takeN (S k) (x :: xs) = case takeN k xs of\n-- Fewer => Fewer\n-- Exact n_xs => Exact (x :: n_xs)\ntakeN (S k) (x :: xs) with (takeN k xs)\n takeN (S k) (x :: xs) | Fewer = Fewer\n takeN (S k) (x :: _) | Exact n_xs = Exact (x :: n_xs)\n\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\nhalves : List a -> (List a, List a)\nhalves xs with (takeN ((length xs) `div` 2) xs)\n halves _ | Fewer = ([], []) -- impossible?\n halves (lft ++ rgt) | Exact _ = (lft, rgt)\n", "meta": {"hexsha": "63dfb2e247bbb9934d2a64efb6b72883047afac5", "size": 818, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/TakeN.idr", "max_stars_repo_name": "tekerson/type-driven-development", "max_stars_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-23T04:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-23T04:46:42.000Z", "max_issues_repo_path": "Chapter-10/TakeN.idr", "max_issues_repo_name": "tekerson/type-driven-development", "max_issues_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": "Chapter-10/TakeN.idr", "max_forks_repo_name": "tekerson/type-driven-development", "max_forks_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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.2962962963, "max_line_length": 68, "alphanum_fraction": 0.5611246944, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172587090975, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7324156211020245}} {"text": "module Main\n\nimport Data.Vect\n\nreadVectLen : (len : Nat) -> IO (Vect len String)\nreadVectLen Z = pure []\nreadVectLen (S k) = do x <- getLine\n xs <- readVectLen k\n pure (x :: xs)\n\ndata VectUnknown : Type -> Type where\n MkVect : (len : Nat) -> Vect len a -> VectUnknown a\n\n-- We can use implicit underscore notation because there is only one valid value for length in the below\nreadVect : IO (VectUnknown String)\nreadVect = do x <- getLine\n if (x == \"\") then pure (MkVect _ [])\n else do MkVect _ xs <- readVect\n pure (MkVect _ (x :: xs))\n\nreadVectPair : IO (len ** Vect len String)\nreadVectPair = do x <- getLine\n if (x == \"\") then pure (_ ** [])\n else do (_ ** xs) <- readVectPair\n pure (_ ** (x :: xs))\n\nprintVect : Show a => VectUnknown a -> IO ()\nprintVect (MkVect len xs) = putStrLn (show xs ++ \" (length \" ++ show len ++ \")\")\n\n-- We cannot use the below format to define VectUnknown because we need to state the length of the Vector\n-- data MyVectUnknown = MyMkVect Nat Vect\n\nzipInputs : IO ()\nzipInputs = do putStrLn \"Enter first vector (blank line to end):\"\n (len1 ** vec1) <- readVectPair\n putStrLn \"Enter second vector (blank line to end):\"\n (len2 ** vec2) <- readVectPair\n case exactLength len1 vec2 of\n Nothing => putStrLn \"Vectors are of different lengths\"\n (Just vec2') => printLn (zip vec1 vec2')\n", "meta": {"hexsha": "db5b080b7f6bd67cade10e83858b364bfa1b9a56", "size": 1563, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ReadVect.idr", "max_stars_repo_name": "balajisivaraman/idris-book", "max_stars_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-06T12:38:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-06T12:38:55.000Z", "max_issues_repo_path": "ReadVect.idr", "max_issues_repo_name": "balajisivaraman/idris-book", "max_issues_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "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": "ReadVect.idr", "max_forks_repo_name": "balajisivaraman/idris-book", "max_forks_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-04T17:48:35.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-04T17:48:35.000Z", "avg_line_length": 38.1219512195, "max_line_length": 105, "alphanum_fraction": 0.5611004479, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7321445334265029}} {"text": "module Main\n\ndata Binary : Nat -> Type where\n BEnd : Binary Z\n BO : Binary n -> Binary (n + n)\n BI : Binary n -> Binary (S (n + n))\n\nShow (Binary n) where\n show (BO x) = show x ++ \"0\"\n show (BI x) = show x ++ \"1\"\n show BEnd = \"\"\n\ndata Parity : Nat -> Type where\n Even : Parity (n + n)\n Odd : Parity (S (n + n))\n\ntotal\nparity : (n:Nat) -> Parity n\nparity Z = Even {n=Z}\nparity (S Z) = Odd {n=Z}\nparity (S (S k)) with (parity k)\n parity (S (S (j + j))) | Even ?= Even {n=S j}\n parity (S (S (S (j + j)))) | Odd ?= Odd {n=S j}\n\n\nnatToBin : (n:Nat) -> Binary n\nnatToBin Z = BEnd\nnatToBin (S k) with (parity k)\n natToBin (S (j + j)) | Even = BI (natToBin j)\n natToBin (S (S (j + j))) | Odd ?= BO (natToBin (S j))\n\nintToNat : Int -> Nat\nintToNat 0 = Z\nintToNat x = if (x>0) then (S (intToNat (x-1))) else Z\n\nmain : IO ()\nmain = do putStr \"Enter a number: \"\n x <- getLine\n print (natToBin (fromInteger (cast x)))\n putStrLn \"\"\n\n---------- Proofs ----------\n\nMain.natToBin_lemma_1 = proof\n intros\n rewrite plusSuccRightSucc j j\n rewrite sym (plusSuccRightSucc j j)\n trivial\n\n\nparity_lemma_1 = proof\n intros\n rewrite sym (plusSuccRightSucc j j)\n trivial\n\n\nparity_lemma_2 = proof {\n intro;\n intro;\n rewrite sym (plusSuccRightSucc j j);\n trivial;\n}\n", "meta": {"hexsha": "5ffb22045a2050b175cf6923d0eacffdd5afce39", "size": 1336, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZPF/Slajdy19/PlikiIdrisa/binary.idr", "max_stars_repo_name": "wdomitrz/Coq-Exercises", "max_stars_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/binary.idr", "max_issues_repo_name": "wdomitrz/Coq-Exercises", "max_issues_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": "ZPF/Slajdy19/PlikiIdrisa/binary.idr", "max_forks_repo_name": "wdomitrz/Coq-Exercises", "max_forks_repo_head_hexsha": "86d6ae9488901a0f61d45234a6b1c2c684cf60ef", "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": 21.2063492063, "max_line_length": 57, "alphanum_fraction": 0.5583832335, "num_tokens": 476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7320118227536984}} {"text": "import Data.Fin\n\ndata PowerSource = Petrol | Pedal\n\n||| Vehicle here is a function from PowerSource to a type\ndata Vehicle : PowerSource -> Type where\n Bycicle : Vehicle Pedal\n Car : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n\nwheels : Vehicle power -> Nat\nwheels Bycicle = 2\nwheels (Car fuel) = 4\nwheels (Bus fuel) = 4\n\nrefuel : Vehicle Petrol -> Vehicle Petrol\nrefuel (Car fuel) = Car 100\nrefuel (Bus fuel) = Car 200\nrefuel Bycicle impossible\n\n||| After looking into the definition of `integerToFin` in\n||| https://github.com/idris-lang/Idris-dev/blob/master/libs/base/Data/Fin.idr\n||| it seems that my original approach wasn't that far off, but maybe...\nintegerToFin : Integer -> (n : Nat) -> Maybe (Fin n)\nintegerToFin x Z = Nothing\nintegerToFin x n = if x >= 0 then natToFin (cast x) n else Nothing\n\nintegerToFin' : Integer -> (n : Nat) -> Maybe (Fin n)\nintegerToFin' x Z = Nothing\nintegerToFin' x n = case compare (cast x) n of\n GT => Nothing\n EQ => Nothing\n -- LT => Just (the (Fin n) (cast x))\n -- what's the way?\n", "meta": {"hexsha": "21d2155b811c9b944db31a9bfcbc42177bfce150", "size": 1152, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/4.2-DependantTypes.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/4.2-DependantTypes.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/4.2-DependantTypes.idr", "max_forks_repo_name": "ostera/asdf", "max_forks_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "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.9142857143, "max_line_length": 78, "alphanum_fraction": 0.6284722222, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7319902409242081}} {"text": "||| Complex number.\n|||\n||| Copyright 2021, HATTORI, Hiroki\n||| This file is released under the MIT license, see LICENSE for more detail.\n|||\nmodule Data.Complex\n\nimport Generics.Derive\n%language ElabReflection\n\n-- --------------------------------------------------------------------------\n\npublic export\nrecord Complex t where\n constructor MkComplex\n real : t\n imag : t\n\n\nexport\nShow t => Show (Complex t) where\n show x = show x.real ++ \" + \" ++ show x.imag ++ \"i\"\n\nexport\nFunctor Complex where\n map f x = MkComplex (f x.real) (f x.imag)\n\n%runElab derive \"Complex\" [Generic, Meta, Eq]\n\nexport\n(Neg t, Num t) => Num (Complex t) where\n x + y = MkComplex (x.real + y.real) (x.imag + y.imag)\n x * y = MkComplex (x.real * y.real - x.imag * y.imag)\n (x.real * y.imag + x.imag * y.real)\n fromInteger x = MkComplex (fromInteger x) (fromInteger 0)\n\n\nexport\nNeg t => Neg (Complex t) where\n negate x = MkComplex (negate x.real) (negate x.imag)\n x - y = MkComplex (x.real - y.real) (x.imag - y.imag)\n\n\nexport\nisReal : (Num t, Eq t) => Complex t -> Bool\nisReal x = x.imag == fromInteger 0\n\n\nexport\nisImage : (Num t, Eq t) => Complex t -> Bool\n\n\n\nexport\nplus_commutative : (Num t, Neg t)\n => {x, y:Complex t}\n -> {comm_t: {a,b:t} -> (a + b) = (b + a)}\n -> (x + y) = (y + x)\nplus_commutative = rewrite (comm_t {a=x.real} {b=y.real})\n in rewrite (comm_t {a=x.imag} {b=y.imag})\n in Refl\n\n\nplus_assosiative : (Num t, Neg t)\n => {x, y:Complex t}\n -> {assoc_t: {a,b,c:t} -> (a + b) + c = a + (b + c)}\n -> (x + y) + z = x + (y + z)\nplus_assosiative = rewrite (assoc_t {a=x.real} {b=y.real} {c=z.real})\n in rewrite (assoc_t {a=x.imag} {b=y.imag} {c=z.imag})\n in Refl\n\n\n\nmult_commutative : (Num t, Neg t)\n => {x, y:Complex t}\n -> {mult_comm_t: {a,b:t} -> a * b = b * a}\n -> {plus_comm_t: {a,b:t} -> a + b = b + a}\n -> (x * y) = (y * x)\nmult_commutative = rewrite (mult_comm_t {a=x.real} {b=y.real})\n in rewrite (mult_comm_t {a=x.imag} {b=y.imag})\n in rewrite (mult_comm_t {a=x.real} {b=y.imag})\n in rewrite (mult_comm_t {a=x.imag} {b=y.real})\n in rewrite (plus_comm_t {a=(y.imag * x.real)} {b=(y.real * x.imag)})\n in Refl\n\n\ndistributive : (Num t, Neg t)\n => {x, y:Complex t}\n -> {dist_t: {a,b,c:t} -> a * (b + c) = a * b + a * c}\n -> {plus_commu_t: {a,b:t} -> a + b = b + a}\n -> x * (y + z) = x * y + x * z\ndistributive = rewrite (dist_t {a=x.real} {b=y.real} {c=z.real})\n in rewrite (dist_t {a=x.imag} {b=y.imag} {c=z.imag})\n in rewrite (dist_t {a=x.real} {b=y.imag} {c=z.imag})\n in rewrite (dist_t {a=x.imag} {b=y.real} {c=z.real})\n in ?lhs_distributive\n\n\n\n-- --------------------------------------------------------------------------\n\nexport\nconjugate : Neg t => Complex t -> Complex t\nconjugate x = MkComplex x.real (negate x.imag)\n\n\nconjugate_distributive : (Num t, Neg t)\n => {x, y: Complex t}\n -> {pr: {a,b:t} -> negate (a + b) = negate a + negate b}\n -> conjugate (x + y) = conjugate x + conjugate y\nconjugate_distributive = rewrite (pr {a =x.imag} {b=y.imag}) in Refl\n\n\n\n\n\n-- --------------------------------------------------------------------------\n-- vim: tw=80 sw=2 expandtab :\n", "meta": {"hexsha": "4b2cd5c12f5d3ed274520ee52fa59534b1cb7d86", "size": 3331, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2-missing-numeric/src/Data/Complex.idr", "max_stars_repo_name": "seagull-kamome/idris2-missing", "max_stars_repo_head_hexsha": "ef0355d0ce0a7381e30b752e25c0aa6319f7a81a", "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": "idris2-missing-numeric/src/Data/Complex.idr", "max_issues_repo_name": "seagull-kamome/idris2-missing", "max_issues_repo_head_hexsha": "ef0355d0ce0a7381e30b752e25c0aa6319f7a81a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-02-03T11:05:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-01T12:42:01.000Z", "max_forks_repo_path": "idris2-missing-numeric/src/Data/Complex.idr", "max_forks_repo_name": "seagull-kamome/idris2-missing", "max_forks_repo_head_hexsha": "ef0355d0ce0a7381e30b752e25c0aa6319f7a81a", "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": 27.9915966387, "max_line_length": 84, "alphanum_fraction": 0.5109576704, "num_tokens": 1062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7319476496795516}} {"text": "module Data.List.Palindrome\n\nimport Data.List\nimport Data.List.Views\nimport Data.List.Views.Extra\nimport Data.List.Reverse\nimport Data.List.Equalities\n\n%hide Prelude.reverse\n%default total\n\n||| Do geese see God?\npublic export\ndata Palindrome : (xs : List a) -> Type where\n Empty : Palindrome []\n Single : Palindrome [_]\n Multi : Palindrome xs -> Palindrome (x :: (xs `snoc` x))\n\n||| A Palindrome reversed is itself.\nexport\npalindromeReverse : (xs : List a) -> Palindrome xs -> reverse xs = xs\npalindromeReverse [] Empty = Refl\npalindromeReverse [_] Single = Refl\npalindromeReverse ([x] ++ ys ++ [x]) (Multi pf) =\n rewrite reverseAppend ([x] ++ ys) [x] in\n rewrite reverseAppend [x] ys in\n rewrite palindromeReverse ys pf in\n Refl\n\nprivate\nreversePalindromeEqualsLemma\n : (x, x' : a)\n -> (xs : List a)\n -> reverse (x :: (xs ++ [x'])) = (x :: (xs ++ [x']))\n -> (reverse xs = xs, x = x')\nreversePalindromeEqualsLemma x x' xs prf = equateInnerAndOuter flipHeadX\n where\n flipHeadX : reverse (xs ++ [x']) ++ [x] = x :: (xs ++ [x'])\n flipHeadX = rewrite (sym (reverseCons x (xs ++ [x']))) in prf\n flipLastX' : reverse (xs ++ [x']) = x :: xs -> (x' :: reverse xs) = (x :: xs)\n flipLastX' prf = rewrite (sym $ reverseAppend xs [x']) in prf\n cancelOuter : (reverse (xs ++ [x'])) = x :: xs -> reverse xs = xs\n cancelOuter prf = snd (consInjective (flipLastX' prf))\n equateInnerAndOuter\n : reverse (xs ++ [x']) ++ [x] = (x :: xs) ++ [x']\n -> (reverse xs = xs, x = x')\n equateInnerAndOuter prf =\n let (prf', xEqualsX') = snocInjective prf\n in (cancelOuter prf', xEqualsX')\n\n||| Only Palindromes are equal to their own reverse.\nexport\nreversePalindrome : (xs : List a) -> reverse xs = xs -> Palindrome xs\nreversePalindrome input prf with (vList input)\n reversePalindrome [] _ | VNil = Empty\n reversePalindrome [x] _ | VOne = Single\n reversePalindrome (x :: (inner `snoc` y)) prf | VCons rec with (reversePalindromeEqualsLemma x y inner prf)\n reversePalindrome (x :: (inner `snoc` y)) prf | VCons rec | (revInnerIsIdentical, xIsY) =\n rewrite xIsY in\n Multi $ reversePalindrome inner revInnerIsIdentical | Force rec\n", "meta": {"hexsha": "dd04ae5aaba87761709c9eec6264d5af307ea38e", "size": 2189, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/List/Palindrome.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/contrib/Data/List/Palindrome.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/contrib/Data/List/Palindrome.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": 35.8852459016, "max_line_length": 109, "alphanum_fraction": 0.6418455916, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7319297801537714}} {"text": "module Quotient_Group\n\nimport Monoid\nimport Group\nimport Group_property\nimport Group_property2\n\n%access public export\n\n||| Given a map f : g -> h, the image of f along with the proofs\ntotal\nImageOf : (x : Type) -> (y : Type) -> (f : x -> y) -> Type\nImageOf x y f = (b : y ** (a : x ** ( (f a) = b)))\n\n||| Generates the (right) coset over h of a given element in g\ntotal\nCoset: (h : Type) -> ((+) : h -> h -> h) -> (pf1 : IsGroup h (+)) -> \n (g : Type) -> ((*) : g -> g -> g) -> (pf2 : IsGroup g (*)) -> \n (Subgroup h (+) pf1 g (*) pf2) -> (a : g) -> Type\n \nCoset h (+) pf1 g (*) pf2 (f ** pfSub) a = (y : g ** (y1 : ImageOf h g f ** ((fst y1)*a = y)))\n--Imgfn h g (\\r => a*(fst(sbgrp) r))\n\n||| The property that a particular element is in the coset\ntotal\nIs_in_Coset : (h : Type) -> ((+) : h -> h -> h) -> (pf1 : IsGroup h (+)) -> \n (g : Type) -> ((*) : g -> g -> g) -> (pf2 : IsGroup g (*)) -> \n (Subgroup h (+) pf1 g (*) pf2) -> (a : g) -> (b : g) -> Type\n \nIs_in_Coset h (+) pf1 g (*) pf2 (f ** pfSub) a b = (y1 : ImageOf h g f ** ((fst y1)*a = b))\n\n||| If b is in the coset of a, then a is in the coset of b\ntotal\nCoset_property_1 : (h : Type) -> ((+) : h -> h -> h) -> (pf1 : IsGroup h (+)) -> \n (g : Type) -> ((*) : g -> g -> g) -> (pf2 : IsGroup g (*)) -> \n (Subgroup h (+) pf1 g (*) pf2) -> (a : g) -> (b : g) ->\n (Is_in_Coset h (+) pf1 g (*) pf2 (f ** pfSub) a b) ->\n (Is_in_Coset h (+) pf1 g (*) pf2 (f ** pfSub) b a)\n\nCoset_property_1 h (+) pfh g (*) pfg pfSub a b pf_a_in_Cb = let\n y = fst (fst pf_a_in_Cb)\n x = fst (snd (fst pf_a_in_Cb))\n pf_fx_is_y = (snd (snd (fst pf_a_in_Cb))) -- proof that (f x) = y\n pfy = snd pf_a_in_Cb -- proof that y*a = b\n \n f = (fst pfSub) -- the inclusion map from h to g\n pfhom = (fst (snd pfSub)) -- proof that f is a homomorphism \n \n x1 = Inv h (+) pfh x\n y1.1 = (f x1)\n y1.2 = Inv g (*) pfg y \n pf_y12_eq = (Group_property_8 h (+) pfh g (*) pfg f pfhom x1) -- proof that \n -- y1.1 = y1.2\t \n \n \n in \n ?rhs \n \n{-\n||| Property 2 - A proof that C(a) * C(b) and C(a*b) are equal as sets\ntotal\nCoset_property_2 : (h : Type) -> ((+) : h -> h -> h) -> (pf1 : IsGroup h (+)) -> \n (g : Type) -> ((*) : g -> g -> g) -> (pf2 : IsGroup g (*)) -> \n (Subgroup h (+) pf1 g (*) pf2) -> Type \n-} \n \n \n \n \n \n \n \n", "meta": {"hexsha": "e3d8e54f5818cc834dd9a8ff17c7d39eace442ba", "size": 3726, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Quotient_Group.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Quotient_Group.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/Quotient_Group.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 51.0410958904, "max_line_length": 136, "alphanum_fraction": 0.3048845947, "num_tokens": 923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7317210340259599}} {"text": "module Instances.ZZ\n\nimport public Data.ZZ\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.OrderedGroup\nimport Specifications.DiscreteOrderedGroup\nimport Specifications.OrderedRing\nimport Symmetry.Abelian\nimport Instances.Notation\nimport public Instances.OrderZZ\n\n%default total\n%access public export\n\nimplementation Ringops ZZ where\n Zero = Pos 0\n One = Pos 1\n\nzzMonoid : specifyMonoid {s = ZZ}\nzzMonoid = MkMonoid plusAssociativeZ plusZeroLeftNeutralZ plusZeroRightNeutralZ\n\nzzGroup : specifyGroup {s = ZZ}\nzzGroup = MkGroup zzMonoid plusNegateInverseRZ plusNegateInverseLZ\n\nzzPartialOrder : specifyPartialOrder {leq = LTEZ}\nzzPartialOrder = MkPartialOrder lteReflZ lteTransitiveZ lteAntisymmetricZ\n\nzzTotalOrder : specifyTotalOrder {leq = LTEZ}\nzzTotalOrder = MkTotalOrder zzPartialOrder lteTotalZ\n\nzzPartiallyOrderedMagma : specifyPartiallyOrderedMagma {leq = LTEZ}\nzzPartiallyOrderedMagma = MkPartiallyOrderedMagma zzPartialOrder\n lteLeftTranslationInvariantZ $\n abelianTranslationInvariantLR plusCommutativeZ lteLeftTranslationInvariantZ\n\nzzPartiallyOrderedGroup : specifyPartiallyOrderedGroup {leq = LTEZ}\nzzPartiallyOrderedGroup = MkPartiallyOrderedGroup zzGroup\n zzPartiallyOrderedMagma\n\nzzOrderedGroup : specifyOrderedGroup {leq = LTEZ}\nzzOrderedGroup = MkOrderedGroup zzPartiallyOrderedGroup lteTotalZ\n\nzzDiscreteOrderedGroup : specifyDiscreteOrderedGroup {leq = LTEZ}\nzzDiscreteOrderedGroup = MkDiscreteOrderedGroup zzOrderedGroup\n plusCommutativeZ lteDiscreteZ\n\nzzRing : specifyRing {s = ZZ}\nzzRing = MkRing\n (MkPreRing\n multDistributesOverPlusRightZ\n multDistributesOverPlusLeftZ\n plusCommutativeZ)\n zzGroup\n multAssociativeZ\n\nzzOrderedRing : specifyOrderedRing {leq = LTEZ}\nzzOrderedRing = MkOrderedRing\n (MkPartiallyOrderedRing zzRing zzPartiallyOrderedMagma)\n lteTotalZ\n\nzzDiscreteOrderedRing : specifyDiscreteOrderedRing {leq = LTEZ}\nzzDiscreteOrderedRing = MkDiscreteOrderedRing zzOrderedRing\n lteDiscreteZ multOneLeftNeutralZ multOneRightNeutralZ (LtePosPos LTEZero)\n", "meta": {"hexsha": "e606bbf39861a8185c03fec2d5c70a788629a013", "size": 2026, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Instances/ZZ.idr", "max_stars_repo_name": "jeroennoels/verified-algebra", "max_stars_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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/Instances/ZZ.idr", "max_issues_repo_name": "jeroennoels/verified-algebra", "max_issues_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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/Instances/ZZ.idr", "max_forks_repo_name": "jeroennoels/verified-algebra", "max_forks_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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.1692307692, "max_line_length": 79, "alphanum_fraction": 0.8499506417, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7317210224100711}} {"text": "module xquant.Core.Helicity\n\nimport xquant.Core.Types\nimport Data.Matrix.Numeric\n\n%default total\n\n\n---- Helicity type synonyms ----\n\nBispinor : Type\nBispinor = Matrix 2 2 Amp\n\nGamma : Type\nGamma = Matrix 4 4 Amp\n\n---- Constant bispinors: Pauli matrices, antisym tensor ----\n\nprivate i : Amp\ni = 0 :+ 1\n\n%access public\n\nsx : Bispinor\nsx = [[0,1],[1,0]]\n\nsy : Bispinor\nsy = [[0,i],[-i,0]]\n\nsz : Bispinor\nsz = [[1,0],[0,-1]]\n\nep : Bispinor\nep = [[0,-1],[1,0]]\n\n\n---- Momentum bispinors σ(p) ----\n\n||| Produce a bispinor from a Minkowski 4-vector\nbispin : Mink -> Bispinor\nbispin [e,px,py,pz] = (e <#> Id)\n + (px <#> sx)\n + (py <#> sy)\n + (pz <#> sz)\n\n\n||| Produce a bispinor from a Minkowski 4-vector;\n||| Upstairs spinor index (barred) version\nbispin' : Mink -> Bispinor\nbispin' [e,px,py,pz] = (e <#> Id)\n - (px <#> sx)\n - (py <#> sy)\n - (pz <#> sz)\n\n||| Minkowski inner product\nmink : Mink -> Mink -> Amp\nmink (x0 :: xs) (y0 :: ys) = -(x0 * y0) + (xs <:> ys)\n\n|||\neta : Gamma\neta = diag_ [-1,1,1,1]\n\ngx : Matrix 4 4 Amp\ngx = concatMatrix [[0,-sx],[sx,0]]\n\ngy : Matrix 4 4 Amp\ngy = concatMatrix [[0,-sy],[sy,0]]\n\ngz : Matrix 4 4 Amp\ngz = concatMatrix [[0,-sz],[sz,0]]\n\ng0 : Matrix 4 4 Amp\ng0 = concatMatrix {x=2} [[0,Id],[Id,0]]\n\n||| Feynman slash: Dot a minkowski vector\n||| into the gamma matrix vector\nslash : Mink -> Matrix 4 4 Amp\nslash [e,x,y,z] = (e <#> Id)\n + (x <#> gx)\n + (y <#> gy)\n + (z <#> gz)\n\n||| 4 standard gamma matrices for D=4\ngammas : Vect 4 Gamma\ngammas = [g0,gx,gy,gz]\n\n\n||| implicit conversion from Float to Complex Float\nprivate implicit toCF : Fl -> Amp\ntoCF x = x :+ 0\n\n\ng5 : Gamma\ng5 = i <#> foldr1 (<>) gammas\n\n||| Left-handed spinor projection\npL : Gamma\npL = 0.5 <#> (1 - g5)\n\n||| Right-handed spinor projection\npR : Gamma\npR = 0.5 <#> (1 + g5)\n\n\n||| Generate a vector from function\nvecGen : (Fin n -> a) -> Vect n a\nvecGen f = map f (fins _)\n\n||| Generate a matrix from function\nmatGen : (Fin n -> Fin m -> a) -> Matrix n m a\nmatGen f = vecGen <$> vecGen f\n\n||| Spin matrix\nspin : Fin 4 -> Fin 4 -> Gamma\nspin j k = i*(1/4) <#> index j gammas <<>> index k gammas\n", "meta": {"hexsha": "25abf23509cdb350c667829af64b74f8444cb25a", "size": 2256, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/xquant/Core/Helicity.idr", "max_stars_repo_name": "fieldstrength/xquant", "max_stars_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-06-16T23:34:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-26T04:22:56.000Z", "max_issues_repo_path": "src/xquant/Core/Helicity.idr", "max_issues_repo_name": "fieldstrength/xquant", "max_issues_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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/xquant/Core/Helicity.idr", "max_forks_repo_name": "fieldstrength/xquant", "max_forks_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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": 19.4482758621, "max_line_length": 60, "alphanum_fraction": 0.547429078, "num_tokens": 838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7315222608903648}} {"text": "module Extra.Scientific\n\nprivate\npow : Integer -> Integer -> Integer\npow a 0 = 1\npow a b = if b < 0 then 0 else a * pow a (b - 1)\n\nprivate\nbin10Index : Integer -> Integer\nbin10Index n = helper 0\n where\n helper : Integer -> Integer\n helper a = if n < pow 10 a then a else helper (a + 1)\n\n||| Scientific notation representation in the form of `coefficient*10^(exponentation)`\npublic export\ndata Scientific : Type where\n MkScientific : (coefficient : Integer) -> (exponentation : Integer) -> Scientific\n\nexport\nShow Scientific where\n show (MkScientific m n) = show m <+> \"e\" <+> show n\n\nexport\nNum Scientific where\n (MkScientific c1 e1) + (MkScientific c2 e2) =\n if e1 < e2\n then MkScientific (c1 + c2 * (10 `pow` (e2 - e1))) e1\n else MkScientific (c1 * (10 `pow` (e1 - e2)) + c2) e2\n (MkScientific m n) * (MkScientific m' n') = MkScientific (m * m') (n * n')\n fromInteger i = MkScientific i 0\n\nexport\nNeg Scientific where\n negate (MkScientific c e) = MkScientific (-c) e\n\n||| Convert a integer into a `Scientific` with its most significant digit moved to just after the decimal point\nexport\nasDecimal : Integer -> Scientific\nasDecimal n = MkScientific n (negate (bin10Index n))\n\nexport\ntoDouble : Scientific -> Double\ntoDouble (MkScientific m n) = cast m * (10 `pow` cast n)\n", "meta": {"hexsha": "c47cc3b3e13913556a22ec51255dc06d005a109e", "size": 1291, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Extra/Scientific.idr", "max_stars_repo_name": "tensorknower69/idris2-extra", "max_stars_repo_head_hexsha": "b856915276987758da8c38865b4b336079bc1e9a", "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/Extra/Scientific.idr", "max_issues_repo_name": "tensorknower69/idris2-extra", "max_issues_repo_head_hexsha": "b856915276987758da8c38865b4b336079bc1e9a", "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/Extra/Scientific.idr", "max_forks_repo_name": "tensorknower69/idris2-extra", "max_forks_repo_head_hexsha": "b856915276987758da8c38865b4b336079bc1e9a", "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.6888888889, "max_line_length": 111, "alphanum_fraction": 0.6870642912, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.7879311981328134, "lm_q1q2_score": 0.7315222538964092}} {"text": "\nimport Data.Vect\n\ntryIndex : Integer -> Vect n a -> Maybe a\ntryIndex {n} i xs = case integerToFin i n of\n Nothing => Nothing\n (Just idx) => Just (index idx xs)\n\n\nvectTake : (num : Fin (S n)) -> Vect n a -> Vect (finToNat num) a\nvectTake FZ _ = []\nvectTake (FS y) (x :: xs) = x :: vectTake y xs\n", "meta": {"hexsha": "1c7753131ce085fb3842453f0184eabf635efee9", "size": 343, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/vectIndex.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter4/vectIndex.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter4/vectIndex.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 26.3846153846, "max_line_length": 65, "alphanum_fraction": 0.5335276968, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7312265710156051}} {"text": "\nmodule CheckEqDec\n\ndata Vect : Nat -> (elem : Type) -> Type where\n Nil : Vect Z elem\n (::) : elem -> Vect n elem -> Vect (1 + n) elem\n\nzeroNotSuc : (0 = S k) -> Void\nzeroNotSuc Refl impossible\n\nsucNotZero : (S k = 0) -> Void\nsucNotZero Refl impossible\n\nnoRec : (contra : (k = j) -> Void) -> (S k = S j) -> Void\nnoRec contra Refl = contra Refl\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Dec (num1 = num2)\ncheckEqNat Z Z = Yes Refl\ncheckEqNat Z (S k) = No zeroNotSuc\ncheckEqNat (S k) Z = No sucNotZero\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n (Yes prf) => Yes (cong prf)\n (No contra) => No (noRec contra)\n\n\n-- Ex 8.3 #1\nheadUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} -> (contra : (x = y) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\nheadUnequal contra Refl = contra Refl\n\ntailUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} -> (contra : (xs = ys) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\ntailUnequal contra Refl = contra Refl\n\n-- Ex 8.3 #2\nDecEq a => DecEq (Vect n a) where\n decEq [] [] = Yes Refl\n decEq (x :: xs) (y :: ys) = case decEq x y of\n (Yes prf1) => case decEq xs ys of\n (Yes prf2) => Yes $ rewrite prf1 in rewrite prf2 in Refl\n (No contra2) => No $ tailUnequal contra2\n (No contra1) => No $ headUnequal contra1\n", "meta": {"hexsha": "5b825c264c3a4c869a18753050e57ec3adfc00e2", "size": 1487, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter8/CheckEqDec.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter8/CheckEqDec.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter8/CheckEqDec.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 36.2682926829, "max_line_length": 126, "alphanum_fraction": 0.5016812374, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7311816869875001}} {"text": "module Linear\n\nimport ZZ\nimport Rationals\nimport Data.Vect\n\n%access public export\n\ndata SolExists : Type where\n YesExists : SolExists\n DNExist : SolExists\n\nisFactor : Nat -> Nat -> Type\nisFactor m n = (k : Nat ** (m * k = n)) -- will be useful in solving Diophantine equations:\n -- if the denominator is a factor of the numerator, there is an integer solution\n\nis_a_zero: (a: ZZ) -> Bool\nis_a_zero (Pos Z) = True\nis_a_zero (Pos (S k)) = False\nis_a_zero (NegS k) = False\n\nApZZ : (f: ZZ -> ZZ)-> n = m -> f n = f m -- like apNat, but for ZZ\nApZZ f Refl = Refl\n\n-- Helper functions for the case ax = 0 --\n\nZeroSum: (a: ZZ) -> (b: ZZ) -> (a = 0) -> (b = 0) -> (a + b = 0) --sum of two zeroes is zero\nZeroSum (fromInt(0)) (fromInt(0)) Refl Refl = Refl\n\ntriviality1: (a: ZZ) -> (b: ZZ) -> (b = 0) -> (a*b=0) -- premultiplying 0 by anything returns 0\ntriviality1 a b prf = trans (apZZ (\\x => a*x) b 0 prf) (multZeroRightZeroZ(a))\n\ntriviality2: (a: ZZ) -> (0*a=0) -- 0 times anything is zero\ntriviality2 a = multZeroLeftZeroZ(a)\n\ntriviality3: (a: ZZ) -> (a*0=0) -- 0 times anything is zero\ntriviality3 a = multZeroRightZeroZ(a)\n\nZeroProof: (a: ZZ) -> (b: ZZ) -> (b = 0) -> (0*a + 1*b = 0) -- shows that the rational number (0,1) satisfies ax = 0\nZeroProof a b prf = trans (trans (ApZZ (\\x=> x + 1*b) (triviality2 a)) (ApZZ (\\x => 0 + x) (triviality1 1 b prf))) (ZeroSum 0 0 Refl Refl)\n\n-- Helper functions for the case ax + b = 0\n\ntriviality4: (a: ZZ) -> (b: ZZ) -> (a*b = b*a)\ntriviality4 a b = multCommutativeZ a (b)\n\ntriviality5: (a: ZZ) -> (b: ZZ) -> (a*(-b)+b*a = a*(-b) + a*b )\ntriviality5 a b = ApZZ (\\x=> a*(-b) + x) (triviality4 b a)\n\ntriviality6: (a: ZZ) -> (b: ZZ) -> ( (a*(-b)) + (a*b) = a*( (-b)+b ) )\ntriviality6 a b = sym ( multDistributesOverPlusRightZ a (-b) b )\n\ntriviality7: (a: ZZ) -> (b: ZZ) -> ( a*((-b) + b) = 0)\ntriviality7 a b = trans (ApZZ (\\x => a*x) (plusNegateInverseRZ(b))) (triviality3(a))\n\nSolutionProof: (a: ZZ) -> (b: ZZ) -> (a*(-b)+b*a=0)\nSolutionProof a b = trans (trans (triviality5 a b) (triviality6 a b)) (triviality7 a b)\n\n--Solving a linear equation ax + b = 0 in the case when b = 0 (Basically, this shows that ax=0 is uniquely solved by (0,1))\n\ntrivialeqSolver : (a: ZZ) -> (b : ZZ) -> (b = 0) -> Either (x : ZZPair ** (SolExists, (fst x)*a + (snd x)*b = 0)) (SolExists)\ntrivialeqSolver a b prf = Left ((0,1) ** (YesExists, (ZeroProof a b prf)))\n\n-- Solving the linear equation ax+b = 0 in general\n\neqSolver : (a: ZZ) -> (b : ZZ) -> (ZZNotZero b) -> Either (x : ZZPair ** (SolExists, a*(fst x) + b*(snd x) = 0)) (SolExists)\neqSolver a b prf = case (is_a_zero(a)) of\n (True) => Right (DNExist)\n (False) => Left ((-b, a) ** (YesExists, (SolutionProof a b))) -- The solution is (-b/a), a rational number, with proof.\n\n-- Helper functions for ax + b = c\n\nhelper1: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (a*(c+(-b))= a*c + a*(-b))\nhelper1 a b c = multDistributesOverPlusRightZ (a) (c) (-b)\n\nhelper2: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> ( a*(c-b) + b*a = a*c+ a*(-b)+ b*a )\nhelper2 a b c = ApZZ (\\x => x+ b*a) (helper1 (a) (b) (c))\n\nhelper3: (a: ZZ) -> (b: ZZ) -> (a*(-b)+b*a= 0)\nhelper3 a b = trans (trans (triviality5 a b) (triviality6 a b)) (triviality7 a b)\n\nhelper4: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (a*c + a*(-b) + b*a = a*c)\nhelper4 a b c = rewrite sym (plusAssociativeZ (a*c) (a*(-b)) (b*a)) in\n rewrite helper3 a b in\n rewrite plusZeroRightNeutralZ (multZ a c) in Refl\n\nGeneralProof: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> ( a*(c-b) + b*a = a*c )\nGeneralProof a b c = trans (helper2 a b c) (helper4 a b c)\n\n-- Solving the linear equation ax + b = c (2x +3 = 7, for example) over the rationals\n\nGeneralEqSolver: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (a0: ZZNotZero a) -> (b0: ZZNotZero b) -> (c0: ZZNotZero c) ->\n(x : ZZPair ** (SolExists, a*(fst x) + b*(snd x) = (snd x)*c))\nGeneralEqSolver a b c a0 b0 c0 = ( ( (c-b) , a ) ** (YesExists, (GeneralProof a b c) )) -- Solves the equation with proof\n\n-- Now, we can use the rational solution of the linear equation ax + b = c to check whether this equation has an integer\n-- solution; if it did, the denominator of the rational solution would divide the numerator. If it didn't, the equation\n-- would have no solutions in the integers.\n", "meta": {"hexsha": "4194e90614619586aba4ed2e3cf956a06d080290", "size": 4274, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/Linear.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "_local-site/Code/Linear.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "_local-site/Code/Linear.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 43.1717171717, "max_line_length": 138, "alphanum_fraction": 0.5907814693, "num_tokens": 1620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7309876813475187}} {"text": "-- Shape.idr\n--\n-- Demonstrate union data types\n\nmodule Shape\n\n||| Represents shapes\npublic export\ndata Shape = ||| A triangle, with its base and height\n Triangle Double Double\n | ||| A rectangle, with length and height\n Rectangle Double Double\n | ||| A circle, with radius\n Circle Double\n\n%name Shape shape, shape1, shape2\n\n||| Calculates area of given shape\nexport\narea : Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\n", "meta": {"hexsha": "798bc1441b72b6cc2487e36d819a8bf850864ab2", "size": 590, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_4/Shape.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/Shape.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/Shape.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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.6, "max_line_length": 53, "alphanum_fraction": 0.6491525424, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7309422995180632}} {"text": "-- Exercises_4_1.idr\n--\n-- Exercises for generic types\n\nimport Tree\nimport Shape\nimport Picture\n\n||| Converts given List to a binary Tree\nlistToTree : Ord elem => List elem -> Tree elem\nlistToTree [] = Empty\nlistToTree (x :: xs) = insert x (listToTree xs)\n\n\n||| Converts given Tree to an ordered List\ntreeToList : Tree a -> List a\ntreeToList Empty = []\ntreeToList (Node left x right) = let leftList = treeToList left\n rightList = treeToList right in\n leftList ++ [x] ++ rightList\n\n\n-- Integer arithmetic\n-- ==================\n\n||| Data type for arithmetic expression(s)\ndata Expr = ||| Int value\n Val Int\n | ||| Arithmetic addition of two expressions\n Add Expr Expr\n | ||| Arithmetic substraction of two expressions\n Sub Expr Expr\n | ||| Arithmetic multiplication of two expressions\n Mult Expr Expr\n\n||| Evaluates given arithmentic expression\nevaluate : Expr -> Int\nevaluate (Val x) = x\nevaluate (Add x y) = (evaluate x) + (evaluate y)\nevaluate (Sub x y) = (evaluate x) - (evaluate y)\nevaluate (Mult x y) = (evaluate x) * (evaluate y)\n\n\n-- Maybe comparator\n-- ================\nmaxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe Nothing Nothing = Nothing\nmaxMaybe Nothing (Just y) = Just y\nmaxMaybe (Just x) Nothing = Just x\nmaxMaybe (Just x) (Just y) = case compare x y of\n LT => Just y\n EQ => Just x\n GT => Just x\n\n\n-- Biggest triangle of picture\n-- ===========================\nbiggestTriangle : Picture -> Maybe Double\nbiggestTriangle (Primitive triangle@(Triangle _ _)) = Just (area triangle)\nbiggestTriangle (Primitive _) = Nothing\nbiggestTriangle (Combine pic pic1) = maxMaybe (biggestTriangle pic) (biggestTriangle pic1)\nbiggestTriangle (Rotate x pic) = biggestTriangle pic\nbiggestTriangle (Translate x y pic) = biggestTriangle pic\n\n\ntestPic1 : Picture\ntestPic1 = Combine (Primitive (Triangle 2 3))\n (Primitive (Triangle 2 4))\ntestPic2 : Picture\ntestPic2 = Combine (Primitive (Rectangle 1 3))\n (Primitive (Circle 4))\n\n", "meta": {"hexsha": "ac71a9e8dd6e74007ac3720a738eb34e7c181a62", "size": 2210, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_4/Exercises_4_1.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/Exercises_4_1.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/Exercises_4_1.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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.2739726027, "max_line_length": 90, "alphanum_fraction": 0.6067873303, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7305621382167332}} {"text": "import Data.Vect\n\nproofNil : Vect n elem -> Vect (n + 0) elem\nproofNil {n} xs = rewrite plusZeroRightNeutral n in xs\n\nproofNext : Vect (1 + n + k) elem -> Vect (n + (1 + k)) elem\nproofNext {n} {k} xs =\n let hypothesis = sym $ plusSuccRightSucc n k \n in rewrite hypothesis \n in xs\n\ngo : Vect n elem -> Vect m elem -> Vect (n+m) elem\ngo acc [] = proofNil acc\ngo acc (x :: xs) = proofNext (go (x::acc) xs)\n\ntotal myReverse : Vect len elem -> Vect len elem\nmyReverse xs = go [] xs\n\n-- total invalidReverseList : List a -> List a\n-- invalidReverseList input = []\n\nexample: Vect 4 String\nexample = [\"1\", \"2\", \"3\", \"4\"]\n\nresult: Vect 4 String\nresult = myReverse example", "meta": {"hexsha": "7d8cada1a1c909dabe1aed13c48333d053eaa4c2", "size": 672, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ReverseVec.idr", "max_stars_repo_name": "coffius/idris-exercises", "max_stars_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "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": "ReverseVec.idr", "max_issues_repo_name": "coffius/idris-exercises", "max_issues_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "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": "ReverseVec.idr", "max_forks_repo_name": "coffius/idris-exercises", "max_forks_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "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": 25.8461538462, "max_line_length": 60, "alphanum_fraction": 0.6428571429, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.730562128072495}} {"text": "\nzeroNotSucc : 0 = S k -> Void\nzeroNotSucc Refl impossible\n\nsuccNotZero : S k = 0 -> Void\nsuccNotZero Refl impossible\n\nnoRec : (k = j -> Void) -> S k = S j -> Void\nnoRec contra Refl = contra Refl\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Dec (num1 = num2)\ncheckEqNat 0 0 = Yes Refl\ncheckEqNat 0 (S k) = No zeroNotSucc\ncheckEqNat (S k) 0 = No succNotZero\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Yes prf => Yes (cong S prf)\n No contra => No (noRec contra)\n\n\n\n", "meta": {"hexsha": "81aaff345e2082fa2f4aee2dd90f642d2d3ea7f1", "size": 528, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch8/CheckEqNat.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "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/ch8/CheckEqNat.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": "src/ch8/CheckEqNat.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": 25.1428571429, "max_line_length": 62, "alphanum_fraction": 0.5795454545, "num_tokens": 182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750466836961, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7304885982104927}} {"text": "module Cordial.Model.Common.Whole\n\n%default total\n%access public export\n\n\ndata Whole : Type where\n W : (n : Nat) -> (prf : IsSucc n) -> Whole\n\ndata IsOne : Whole -> Type where\n ItIsOne : IsOne (W (S Z) ItIsSucc)\n\nwholeIsNotOne : Not (IsOne $ W (S (S n)) ItIsSucc)\nwholeIsNotOne ItIsOne impossible\n\nisOne : (w : Whole) -> Dec (IsOne w)\nisOne (W n prf) with (prf)\n isOne (W (S k) prf) | ItIsSucc with (k)\n isOne (W (S k) prf) | ItIsSucc | Z = Yes ItIsOne\n isOne (W (S k) prf) | ItIsSucc | (S j) = No wholeIsNotOne\n\n\ndata IsGreaterThanOne : Whole -> Type where\n IsGT1 : (LTE 2 (S n)) -> IsGreaterThanOne (W (S n) ItIsSucc)\n\nwholeIsOne : Not (IsGreaterThanOne $ W (S Z) ItIsSucc)\nwholeIsOne (IsGT1 (LTESucc LTEZero)) impossible\nwholeIsOne (IsGT1 (LTESucc (LTESucc _))) impossible\n\ndecEqWholeNotEqual : (contra : (k = j) -> Void) -> (W (S k) ItIsSucc = W (S j) ItIsSucc) -> Void\ndecEqWholeNotEqual contra Refl = contra Refl\n\nisGreaterThanOne : (w : Whole) -> Dec (IsGreaterThanOne w)\nisGreaterThanOne (W n prf) with (prf)\n isGreaterThanOne (W (S k) prf) | ItIsSucc with (isLTE 2 (S k))\n isGreaterThanOne (W (S k) prf) | ItIsSucc | (Yes x) = Yes (IsGT1 x)\n isGreaterThanOne (W (S k) prf) | ItIsSucc | (No contra) with (k)\n isGreaterThanOne (W (S k) prf) | ItIsSucc | (No contra) | Z = No wholeIsOne\n isGreaterThanOne (W (S k) prf) | ItIsSucc | (No contra) | (S j) = Yes (IsGT1 (LTESucc (LTESucc LTEZero)))\n\n\nDecEq Whole where\n decEq (W (S k) ItIsSucc) (W (S j) ItIsSucc) with (decEq k j)\n decEq (W (S j) ItIsSucc) (W (S j) ItIsSucc) | (Yes Refl) = Yes Refl\n decEq (W (S k) ItIsSucc) (W (S j) ItIsSucc) | (No contra) = No (decEqWholeNotEqual contra)\n\n\ntoNat : Whole -> Nat\ntoNat (W n prf) = n\n\n\nfromNat : (x : Nat) -> {auto prf : IsSucc x} -> Whole\nfromNat x {prf} = W x prf\n\ndata LTE : Whole -> Whole -> Type where\n IsLTE : (prf : LTE min max)\n -> LTE (W min prfA) (W mac prfB)\n\nShow Whole where\n show (W n prf) = show n\n\nEq Whole where\n (W l prfL) == (W r prfR) = l == r\n\nCast Whole Integer where\n cast (W w prf) = toIntegerNat w\n\nOrd Whole where\n compare (W l prfL) (W r prfR) = compare l r\n", "meta": {"hexsha": "d5c0423fb7ec2e9b52c10b4894cdc3778571b6db", "size": 2132, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Cordial/Model/Common/Whole.idr", "max_stars_repo_name": "border-patrol/cordial", "max_stars_repo_head_hexsha": "7d1d885f7cb2ab66878dc93042177e1043cb13de", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-01-12T23:36:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-13T07:09:42.000Z", "max_issues_repo_path": "src/Cordial/Model/Common/Whole.idr", "max_issues_repo_name": "border-patrol/cordial", "max_issues_repo_head_hexsha": "7d1d885f7cb2ab66878dc93042177e1043cb13de", "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/Cordial/Model/Common/Whole.idr", "max_forks_repo_name": "border-patrol/cordial", "max_forks_repo_head_hexsha": "7d1d885f7cb2ab66878dc93042177e1043cb13de", "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": 30.4571428571, "max_line_length": 111, "alphanum_fraction": 0.6383677298, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7300500555138457}} {"text": "nat_induction : \n (prop : Nat -> Type) -> -- Property to show\n (prop Z) -> -- Base case\n ((k : Nat) -> prop k -> prop (S k)) -> -- Inductive step\n (x : Nat) -> -- Show for all x\n prop x\nnat_induction prop p_Z p_S Z = p_Z\nnat_induction prop p_Z p_S (S k) = p_S k (nat_induction prop p_Z p_S k)\n\nplus_ind : Nat -> Nat -> Nat\nplus_ind n m\n = nat_induction (\\x => Nat)\n m -- Base case, plus_ind Z m\n (\\k, k_rec => S k_rec) -- Inductive step plus_ind (S k) m\n -- where k_rec = plus_ind k m\n n\n\n", "meta": {"hexsha": "95cc51ae68d3f8a237e6cc8ec0679a4c0941e49e", "size": 690, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/samples/proofs/induction.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/samples/proofs/induction.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/samples/proofs/induction.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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.3333333333, "max_line_length": 76, "alphanum_fraction": 0.4333333333, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.730050046955875}} {"text": "-- Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.\n\nsumOfSquares : Int -> Int\nsumOfSquares n = sum (map (\\x => x*x) [1..n])\n\nsquareOfSums : Int -> Int\nsquareOfSums n = (\\x => x*x) (sum [1..n])\n\nmain : IO ()\nmain = print ((squareOfSums 100) - (sumOfSquares 100))\n\n", "meta": {"hexsha": "c60601b1cfb34a8083eb4c42577aa864be25e2b4", "size": 334, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "quint/euler006.idr", "max_stars_repo_name": "edu-di-wu/project-euler", "max_stars_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "quint/euler006.idr", "max_issues_repo_name": "edu-di-wu/project-euler", "max_issues_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "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": "quint/euler006.idr", "max_forks_repo_name": "edu-di-wu/project-euler", "max_forks_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "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": 27.8333333333, "max_line_length": 121, "alphanum_fraction": 0.6646706587, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305318133553, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.729930685785742}} {"text": "||| Implementation of ordering relations for `Fin`ite numbers\nmodule Data.Fin.Order\n\nimport Control.Relation\nimport Control.Order\nimport Data.Fin\nimport Data.Fun\nimport Data.Rel\nimport Data.Nat\nimport Data.Nat.Order\nimport Decidable.Decidable\n\n%default total\n\nusing (k : Nat)\n\n public export\n data FinLTE : Fin k -> Fin k -> Type where\n FromNatPrf : {m, n : Fin k} -> LTE (finToNat m) (finToNat n) -> FinLTE m n\n\n public export\n Transitive (Fin k) FinLTE where\n transitive (FromNatPrf xy) (FromNatPrf yz) =\n FromNatPrf $ transitive {rel = LTE} xy yz\n\n public export\n Reflexive (Fin k) FinLTE where\n reflexive = FromNatPrf $ reflexive {rel = LTE}\n\n public export\n Preorder (Fin k) FinLTE where\n\n public export\n Antisymmetric (Fin k) FinLTE where\n antisymmetric {x} {y} (FromNatPrf xy) (FromNatPrf yx) =\n finToNatInjective x y $\n antisymmetric {rel = LTE} xy yx\n\n public export\n PartialOrder (Fin k) FinLTE where\n\n public export\n Connex (Fin k) FinLTE where\n connex {x = FZ} _ = Left $ FromNatPrf LTEZero\n connex {y = FZ} _ = Right $ FromNatPrf LTEZero\n connex {x = FS k} {y = FS j} prf =\n case connex {rel = FinLTE} $ prf . (cong FS) of\n Left (FromNatPrf p) => Left $ FromNatPrf $ LTESucc p\n Right (FromNatPrf p) => Right $ FromNatPrf $ LTESucc p\n\n public export\n Decidable 2 [Fin k, Fin k] FinLTE where\n decide m n with (decideLTE (finToNat m) (finToNat n))\n decide m n | Yes prf = Yes (FromNatPrf prf)\n decide m n | No disprf = No (\\ (FromNatPrf prf) => disprf prf)\n", "meta": {"hexsha": "e4ac8e32cc10f8375fa0ecec2e30616a4b3eaac0", "size": 1561, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Data/Fin/Order.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": "libs/base/Data/Fin/Order.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": "libs/base/Data/Fin/Order.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": 27.875, "max_line_length": 78, "alphanum_fraction": 0.66623959, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7299224410121007}} {"text": "module Toolkit.Data.Nat\n\nimport Decidable.Equality\n\n%default total\n\npublic export\ntoNat : Int -> Nat\ntoNat = (integerToNat . cast)\n\n\npublic export\ndata Plus : (x,y,z : Nat) -> Type where\n Zero : Plus Z y y\n One : Plus n x z\n -> Plus (S n) x (S z)\n\nexport\nplus : (x,y : Nat) -> DPair Nat (Plus x y)\nplus Z y\n = MkDPair y Zero\n\nplus (S k) y with (Nat.plus k y)\n plus (S k) y | (MkDPair fst snd)\n = MkDPair (S fst) (One snd)\n\n\nresWhenZeroIsMore : (y = z -> Void) -> Plus 0 y z -> Void\nresWhenZeroIsMore f Zero = f Refl\n\nresWhenOneIsZero : Plus (S k) y 0 -> Void\nresWhenOneIsZero Zero impossible\nresWhenOneIsZero (One x) impossible\n\nexport\nisPlus : (x,y,z : Nat) -> Dec (Plus x y z)\nisPlus Z y z with (decEq y z)\n isPlus Z y y | (Yes Refl)\n = Yes Zero\n\n isPlus Z y z | (No contra)\n = No (resWhenZeroIsMore contra)\n\nisPlus (S k) y 0 = No resWhenOneIsZero\n\nisPlus (S k) y (S j) with (isPlus k y j)\n isPlus (S k) y (S j) | (Yes prf)\n = Yes (One prf)\n\n isPlus (S k) y (S j) | (No contra)\n = No (\\(One prf) => contra prf)\n\n-- [ EOF ]\n", "meta": {"hexsha": "14b7d9050a37841f9297a37a1ab01bc3a94c9317", "size": 1062, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/Nat.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/Nat.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/Nat.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": 19.6666666667, "max_line_length": 57, "alphanum_fraction": 0.6092278719, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7298636135578569}} {"text": "module TypesAndFunctions\n\n%default total\n\npublic export\nappEq : {a, b : Type} -> {f, g : a -> b} -> {x : a} -> f = g -> f x = g x\nappEq Refl = Refl\n\npublic export\nFunctionalExtensionality : (a, b : Type) -> Type\nFunctionalExtensionality a b =\n {f, g : a -> b} -> ((x : a) -> f x = g x) -> f = g\n\npublic export\nIsLeftInverse : {a, b : Type} -> (a -> b) -> (b -> a) -> Type\nIsLeftInverse f g = (x : a) -> g (f x) = x\n\npublic export\nHasLeftInverseImpliesInjective :\n {a, b : Type} -> {f : a -> b} -> {g : b -> a} ->\n IsLeftInverse f g ->\n {x, x' : a} -> f x = f x' -> x = x'\nHasLeftInverseImpliesInjective isLeftInv {x} {x'} fxeq =\n trans (sym (isLeftInv x)) (trans (cong g fxeq) (isLeftInv x'))\n\npublic export\nIsRightInverse : {a, b : Type} -> (a -> b) -> (b -> a) -> Type\nIsRightInverse {a} {b} f g = IsLeftInverse {b=a} {a=b} g f\n\npublic export\nIsInverse : {a, b : Type} -> (a -> b) -> (b -> a) -> Type\nIsInverse f g = (IsLeftInverse f g, IsRightInverse f g)\n\npublic export\nisInverseSym : {a, b : Type} -> {f : a -> b} -> {g : b -> a} ->\n IsInverse f g -> IsInverse g f\nisInverseSym (isLeftInv, isRightInv) = (isRightInv, isLeftInv)\n\npublic export\nIsBijection : {a, b : Type} -> (a -> b) -> Type\nIsBijection {a} {b} f = DPair (b -> a) (IsInverse f)\n\npublic export\nBijection : (a, b : Type) -> Type\nBijection a b = DPair (a -> b) IsBijection\n\npublic export\nIsBijectionForEach : {a : Type} -> {b, c : a -> Type} ->\n ((x : a) -> b x -> c x) -> Type\nIsBijectionForEach f = (x : a) -> IsBijection (f x)\n\npublic export\nForEachInverse : {a : Type} -> {b, c : a -> Type} ->\n {f : (x : a) -> b x -> c x} -> IsBijectionForEach f ->\n ((x : a) -> c x -> b x)\nForEachInverse isBijection x cx = fst (isBijection x) cx\n\npublic export\nForEachInverseIsInverse : {a : Type} -> {b, c : a -> Type} ->\n {f : (x : a) -> b x -> c x} -> (isBijection : IsBijectionForEach f) ->\n ((x : a) -> IsInverse (f x) (ForEachInverse {f} isBijection x))\nForEachInverseIsInverse isBijection x =\n let isBijectionX = snd (isBijection x) in\n (\\bx => fst isBijectionX bx, \\cx => snd isBijectionX cx)\n\npublic export\nforEachInverseSym : {a : Type} -> {b, c : a -> Type} ->\n {f : (x : a) -> b x -> c x} -> (isBijection : IsBijectionForEach f) ->\n IsBijectionForEach {a} {b=c} {c=b} (ForEachInverse {f} isBijection)\nforEachInverseSym isBijection x =\n (f x ** (snd (snd (isBijection x)), fst (snd (isBijection x))))\n", "meta": {"hexsha": "e936b4c02575e098e9b08d1ceb8672478ec861aa", "size": 2399, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/TypesAndFunctions.idr", "max_stars_repo_name": "rokopt/dao-fp-exercises", "max_stars_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-01-17T17:12:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:52:36.000Z", "max_issues_repo_path": "src/TypesAndFunctions.idr", "max_issues_repo_name": "rokopt/dao-fp-exercises", "max_issues_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "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/TypesAndFunctions.idr", "max_forks_repo_name": "rokopt/dao-fp-exercises", "max_forks_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-17T17:12:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T17:12:19.000Z", "avg_line_length": 33.3194444444, "max_line_length": 73, "alphanum_fraction": 0.5852438516, "num_tokens": 903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7298592899336412}} {"text": "module Primes\n\nimport NatUtils\nimport gcd\nimport NatOrder\n\n%access public export\n%default total\n\n--isDivisible a b can be constucted if b divides a\nisDivisible : Nat -> Nat -> Type\nisDivisible a b = (n : Nat ** (GT n 0, a = b * n))\n\n--1 divides everything\noneDiv : (a : Nat) -> {auto x : GT a 0} -> isDivisible a 1\noneDiv a {x=pf} = (a ** (pf , rewrite plusZeroRightNeutral a in Refl))\n\n--If 1|a => 1*c | a*c\nmulDiv : (a, c : Nat) -> {auto pf1 : GT a 0} -> {auto pf2 : GT c 0} ->\n isDivisible a 1 -> isDivisible (a * c) c\nmulDiv a c {pf1=p} x = (a ** (p ,rewrite multCommutative a c in Refl))\n\n\n--Either(a=b)(_) <=> Either (S a = S b)(_)\nhelp1 : {a : Nat} -> {b : Nat} ->\n Either (a = b) (Either (LT (S a) (S b)) (LT (S b) (S a))) ->\n Either (S a = S b) (Either (LT (S a) (S b)) (LT (S b) (S a)))\nhelp1 {a} {b} (Left l) = Left (eqSucc a b l)\nhelp1 (Right r) = Right r\n\n--Either(_)(Either(Sa Either (_)(Either(a {b : Nat} ->\n Either (a = b) (Either (LT a b) (LT (S b) (S a))) ->\n Either (a = b) (Either (LT (S a) (S b)) (LT (S b) (S a)))\nhelp2 (Left l) = Left l\nhelp2 {a} {b} (Right (Left l)) = Right(Left (LTESucc l))\nhelp2 (Right (Right r)) = Right (Right r)\n\n--Either(_)(Either(_)(Sb Either (_)(Either(_)(b {b : Nat} ->\n Either (a = b) (Either (LT a b) (LT b a)) ->\n Either (a = b) (Either (LT a b) (LT (S b) (S a)))\nhelp3 (Left l) = Left l\nhelp3 (Right (Left l)) = Right(Left l)\nhelp3 {a} {b} (Right (Right r)) = Right (Right (LTESucc r))\n\n|||Either a = b, a < b, or a > b\ntotOrdNat : (a : Nat) -> (b : Nat) ->\n Either (a = b) (Either (LT a b) (LT b a))\ntotOrdNat Z Z = Left Refl\ntotOrdNat Z (S k) = Right (Left (LTESucc LTEZero))\ntotOrdNat (S k) Z = Right (Right (LTESucc LTEZero))\ntotOrdNat (S k) (S j) = help1 (help2 (help3 (totOrdNat k j)))\n\n--LTE a b => LTE a*n b*n\nmultRightLTE : (a,b : Nat) -> (n : Nat) -> GT n 0 ->\n LTE a b -> LTE (a*n) (b*n)\nmultRightLTE a b (S Z) (LTESucc LTEZero) lteab =\n rewrite multOneRightNeutral a in\n rewrite multOneRightNeutral b in\n lteab\nmultRightLTE a b (S (S k)) (LTESucc LTEZero{right=(S k)}) lteab =\n rewrite multRightSuccPlus a (S k) in\n rewrite multRightSuccPlus b (S k) in\n ltePlusIsLTE lteab\n (multRightLTE a b (S k) (LTESucc LTEZero{right=k}) lteab)\n\n--If a = b*n, b <= a\naEqProdImpAGtB : (a,b,n : Nat) -> GT n 0 -> (a = b*n) -> LTE b a\naEqProdImpAGtB _ _ Z LTEZero _ impossible\naEqProdImpAGtB _ _ Z (LTESucc _) _ impossible\naEqProdImpAGtB (b * (S k)) b (S k) x Refl = case b of\n Z => LTEZero\n (S m) =>\n rewrite sym (multOneLeftNeutral (S m)) in\n rewrite multCommutative (S m) (S k) in\n rewrite multDistributesOverPlusRight k (S Z) m in\n rewrite plusCommutative (k*1) (k*m) in\n rewrite plusAssociative m (k*m) (k*1) in\n rewrite plusCommutative (m + k*m) (k*1) in\n rewrite sym (multDistributesOverPlusRight (S k) 1 m) in\n multRightLTE 1 (S k) (S m) (LTESucc (LTEZero)) x\n\n--If b | a => b <= a\nbDivAImpAGtB : (a,b,n : Nat) -> isDivisible a b -> LTE b a\nbDivAImpAGtB a b n (x ** pf) = case (fst pf) of\n (LTESucc LTEZero{right=k}) => aEqProdImpAGtB a b (S k) (fst pf) (snd pf)\n\n--GT implies Not LTE\ngtImpliesNotLTE : GT a b -> Not (LTE a b)\ngtImpliesNotLTE {a=Z} {b=_} LTEZero impossible\ngtImpliesNotLTE {a=Z} {b=_} (LTESucc _) impossible\ngtImpliesNotLTE {a=(S k)} {b=Z} x = case isLTE (S k) Z of\n (Yes prf) => absurd\n (No contra) => contra\ngtImpliesNotLTE {a=(S k)} {b=(S j)} x = case isLTE (S k) (S j) of\n (Yes prf) => void\n (gtImpliesNotLTE (fromLteSucc x) (fromLteSucc prf))\n (No contra) => contra\n\n--If b > a => b does not divide a\nbGtAImpNotbDivA : (a,b,n : Nat) -> GT b a -> (isDivisible a b -> Void)\nbGtAImpNotbDivA a b n x = impliesContrapositive\n (isDivisible a b)\n (LTE b a)\n (bDivAImpAGtB a b n)\n (gtImpliesNotLTE x)\n\n--(S (S k)) = 0 is not possible\nzNotEqSS : (k : Nat) -> ((S (S k)) = 0 -> Void)\nzNotEqSS Z = absurd\nzNotEqSS (S k) = absurd\n\n--isDivisible p 0 => (S (S k)) = 0\nhelp4 : (p : Nat) -> LTE 2 p -> isDivisible p 0 -> p = 0\nhelp4 Z LTEZero _ impossible\nhelp4 Z (LTESucc _) _ impossible\nhelp4 (S Z) (LTESucc LTEZero) _ impossible\nhelp4 (S Z) (LTESucc (LTESucc _)) _ impossible\nhelp4 (S (S k)) (LTESucc (LTESucc LTEZero)) x = snd (snd x)\n\n\n--If x = 0, and p >= 2, x cannot divide p\nzNotDivp : (p : Nat) -> LTE 2 p -> ((isDivisible p 0) -> Void)\nzNotDivp Z LTEZero impossible\nzNotDivp Z (LTESucc _) impossible\nzNotDivp (S Z) (LTESucc LTEZero) impossible\nzNotDivp (S Z) (LTESucc (LTESucc _)) impossible\nzNotDivp (S (S k)) (LTESucc (LTESucc LTEZero)) =\n impliesContrapositive\n (isDivisible (S (S k)) 0)\n ((S (S k)) = 0)\n (help4 (S (S k)) (LTESucc (LTESucc LTEZero)))\n (zNotEqSS k)\n\n-- Helping out metaHelp\nmetaMetaHelp5 : (j : Nat) -> (S (j+0)) = (S j)\nmetaMetaHelp5 Z = Refl\nmetaMetaHelp5 (S k) = rewrite plusZeroRightNeutral k in Refl\n\n--Helping out help5\nmetaHelp5 : (S (S k)) = (S (j+0)) -> (S (S k)) = (S (j))\nmetaHelp5 {j} prf = rewrite sym (metaMetaHelp5 j) in prf\n\n\n-- Helping out the absurd case\nhelp5: (S (S k)) = (S (j+0)) -> LT (S j) (S (S k)) -> LTE (S Z) 0\nhelp5 {k} {j} prf x = lteMinusConstantRight {c=(S j)}\n (rewrite sym (metaMetaHelp5 j) in\n rewrite sym prf in\n rewrite eqSucc (S (S k)) (S j) (metaHelp5 prf) in\n x)\n\n--If a divides b => b=a*n\nbDivAImpBEqAN : (a,b : Nat) -> isDivisible b a -> (k : Nat ** b = a * k)\nbDivAImpBEqAN a b (p ** (proofGT, proofEq)) = (p ** proofEq)\n\n--To help out help6\nmetaHelp6 : (p : Nat) -> (x : Nat) -> (c : Nat) ->\n (p = x*c) -> q = c -> (p = q*x)\nmetaHelp6 p x c prf prf1 = rewrite prf1 in\n rewrite multCommutative c x in prf\n\n--To help out a case in notDivIfRem\nhelp6 : (p : Nat) -> (x : Nat) -> (c : Nat) ->\n (p = q*x) -> (p = (S r) + q*x) ->\n (Z = (S r))\nhelp6 p x c {q} {r} p1 p2 = plusRightCancel Z (S r) (q*x) (trans (sym p1) p2)\n\n--To help out another case of notDivIfRem\nhelp7 : (p : Nat) -> (x : Nat) -> (c : Nat) -> (k : Nat) -> (r : Nat) ->\n c + k = q -> p = x*c -> p = (S r) + q*x ->\n Z = (S r) + k*x\nhelp7 p x c k r pfSum pfMul pfRem =\n plusRightCancel Z ((S r)+k*x) (c*x)\n (rewrite sym (plusAssociative (S r) (k*x) (c*x)) in\n rewrite plusCommutative (k*x) (c*x) in\n rewrite sym (multDistributesOverPlusLeft c k x) in\n rewrite pfSum in\n rewrite sym (multCommutative x c) in\n rewrite sym (pfMul) in pfRem)\n\n--Helper for help8\nmetahelp8 : (x : Nat) -> (S q) + k = c -> x +(q+k)*x = c*x\nmetahelp8 x prf = rewrite sym prf in Refl\n\n--Last case!\nhelp8 : (p : Nat) -> (x : Nat) -> (c : Nat) -> (k : Nat) ->\n (m : Nat) -> (r : Nat) -> (q : Nat) ->\n (S q) + k = c -> (S (S r)) + m = x -> p = x*c -> p = (S r) + q*x ->\n Z = k*(S r) + (S k)*(S m)\nhelp8 p x c k m r q qLtc srLtx pfMul pfRem =\n plusLeftCancel (S r) Z (k*(S r) + (S k)*(S m))\n (rewrite plusAssociative (S r) (k*(S r)) ((S k)*(S m)) in\n rewrite sym (multDistributesOverPlusRight (S k) (S r) (S m)) in\n rewrite plusAssociative r (S Z) m in\n rewrite plusCommutative r (S Z) in\n rewrite srLtx in\n rewrite sym (plusCommutative (k*x) ((S (S r)) + m)) in\n rewrite srLtx in\n rewrite plusCommutative (k*x) x in\n rewrite plusZeroRightNeutral r in\n plusLeftCancel (q*x) (S r) (x + k*x)\n (rewrite plusAssociative (q*x) x (k*x) in\n rewrite plusCommutative (q*x) x in\n rewrite sym (multDistributesOverPlusLeft (S q) k x) in\n rewrite metahelp8 {q=q} {k=k} {c=c} x qLtc in\n rewrite (multCommutative c x) in\n rewrite sym pfMul in\n rewrite plusCommutative (q*x) (S r) in\n (sym pfRem)))\n\nhelp9 : (k,r,m : Nat) ->\n Z = k*(S r) + (S k)*(S m) -> Z = (S k)*(S m) + k*(S r)\nhelp9 k r m prf = rewrite plusCommutative ((S k)*(S m)) (k*(S r)) in prf\n\n--To help out the last case, by creating a term of an uninhabited type\nnotDivIfRem : (p : Nat) -> (x : Nat) -> (r : Nat) -> {q : Nat} ->\n (p = (S r) + q*x) -> LT (S r) x ->\n (c : Nat ** p = x * c) -> Void\nnotDivIfRem p x r {q=q} prfRem prfLt (c ** prfDiv) =\n case decEq q c of\n (Yes prf) => absurd $\n (help6 p x c (metaHelp6 p x c prfDiv prf) prfRem)\n (No contra) => case totOrdNat q c of\n (Left l) => void (contra l)\n (Right (Left qLtc)) => case (lteToLEQ qLtc) of\n (k ** pf1) => case (lteToLEQ prfLt) of\n (m ** pf2) => absurd $\n help9 k r m\n (help8 p x c k m r q pf1 pf2 prfDiv prfRem)\n (Right (Right qGtc)) => case (lteToLEQ (lteSuccLeft qGtc)) of\n (k ** pf) => absurd $\n (help7 p x c k r pf prfDiv prfRem)\n\n--The usual case for divisibility\nusual : (p : Nat) -> LTE 2 p -> (x : Nat) -> (LT 0 x) -> (LT x p) ->\n (euc : (q : Nat ** (r : Nat ** ((p = r + (q * x)), LT r x)))) ->\n Dec (isDivisible p x)\nusual Z LTEZero _ _ _ _ impossible\nusual Z (LTESucc _) _ _ _ _ impossible\nusual (S Z) (LTESucc LTEZero) _ _ _ _ impossible\nusual (S Z) (LTESucc (LTESucc _)) _ _ _ _ impossible\nusual (S (S _)) (LTESucc (LTESucc LTEZero)) Z LTEZero _ _ impossible\nusual (S (S _)) (LTESucc (LTESucc LTEZero)) Z (LTESucc _) _ _ impossible\nusual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc with (euc)\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | (Z ** (Z ** (pf,_))) = absurd $ pf\n\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | ((S Z) ** (Z ** (pf,_))) = absurd $\n (help5 pf xLtp)\n\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | ((S (S b)) ** (Z ** (pf,_))) =\n Yes ((S (S b)) ** ((LTESucc LTEZero),\n (rewrite multCommutative (S j) (S (S b)) in pf)))\n\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | (_ ** ((S a) ** (pf1,pf2))) = No\n (impliesContrapositive\n (isDivisible (S (S k)) (S j))\n (c : Nat ** (S (S k)) = (S j) * c)\n (bDivAImpBEqAN (S j) (S (S k)))\n (notDivIfRem (S (S k)) (S j) a pf1 pf2))\n\n\n--Decidability for divisibility\ndecDiv : (p : Nat) -> LTE 2 p -> (x : Nat) ->\n {euc : (q : Nat ** (r : Nat ** ((p = r + (q * x)), LT r x)))} ->\n Dec (isDivisible p x)\ndecDiv Z LTEZero _ impossible\ndecDiv Z (LTESucc _) _ impossible\ndecDiv (S Z) (LTESucc LTEZero) _ impossible\ndecDiv (S Z) (LTESucc (LTESucc _)) _ impossible\ndecDiv (S (S k)) (LTESucc (LTESucc LTEZero)) x {euc=big} =\n case totOrdNat (S (S k)) x of\n (Left l) => Yes (1 ** ((LTESucc LTEZero),\n rewrite l in\n rewrite sym (multOneRightNeutral x) in\n Refl))\n (Right (Left l)) => No (bGtAImpNotbDivA\n (S (S k)) x\n (divNatNZ x (S (S k)) SIsNotZ)\n l)\n (Right (Right r)) => case x of\n Z => No (zNotDivp (S (S k)) (LTESucc (LTESucc LTEZero)))\n (S m) => usual (S (S k)) (LTESucc (LTESucc LTEZero)) (S m)\n (LTESucc LTEZero) r big\n\n\n-- creates a list with all the factors of a number upto the second arguement\ngenFact : (n : Nat) -> Nat -> List (k : Nat ** isDivisible n k)\ngenFact Z Z = []\ngenFact Z (S k) = []\ngenFact (S j) Z = []\ngenFact (S Z) (S k) = [(S Z ** oneDiv (S Z))]\ngenFact (S (S j)) (S k) =\n case (decDiv (S (S j)) (LTESucc (LTESucc (LTEZero{right = j}))) (S k)\n {euc=euclidDivide (S (S j)) (S k) SIsNotZ }) of\n (Yes prf) => (genFact (S (S j)) k) ++ [(S k ** prf)]\n (No contra) => (genFact (S (S j)) k)\n\n\n\n--if the List has only 2 elements, i.e 1 and p, then the number is prime. the function outputs a list (secretly genFact)\n-- along with the proof that the length of the list of factors is 2\nisPrimeWithoutProof : (p: Nat) -> {auto pf: LTE 2 p} -> Type\nisPrimeWithoutProof p = length (genFact p p) = 2\n\n-- more than 2 factors implies number is composite\nisCompositeWithoutProof : (n: Nat) -> {auto pf: LTE 2 n} -> Type\nisCompositeWithoutProof n = Prelude.Nat.GT (Prelude.List.length (genFact n n)) 2\n\n\n--prime proof\nisPrime : (p : Nat) -> LTE 2 p -> Type\nisPrime p proofLTE = {k : Nat} -> isDivisible p k -> Either (k=1)(k=p)\n\n\n\n-- Two is a prime\ntwoPr : (isPrime 2 (LTESucc (LTESucc (LTEZero {right =0}))))\ntwoPr {k=Z} (x ** pf) = void (SIsNotZ (snd pf))\ntwoPr {k=(S Z)} (x ** pf) = Left Refl\ntwoPr {k=(S (S Z))} (x ** pf) = Right Refl\ntwoPr {k=(S (S (S k)))} pf = void (bGtAImpNotbDivA 2 (S (S (S k))) k (LTESucc (LTESucc (LTESucc (LTEZero {right = k})))) (pf))\n\n--Composite proof\nisComposite : (n : Nat) -> LTE 2 n -> Type\nisComposite n pflte = (a : Nat ** (b : Nat ** ((GT a 1, GT b 1), n = a*b)))\n\n\n--deciability for Composite numbers\ndecComposite : (n: Nat) -> (pf : LTE 2 n) -> Dec (isComposite n pf)\ndecComposite Z LTEZero impossible\ndecComposite Z (LTESucc _) impossible\ndecComposite (S Z) (LTESucc LTEZero) impossible\ndecComposite (S Z) (LTESucc (LTESucc _)) impossible\ndecComposite (S (S k)) pf = ?decCompositerhs_1\n\n\n\n\n--if 1 LTE 1 a -> (n : Nat) -> LTE 2 n -> (a = a*n) -> Void\naNotEqToMultA _ _ Z LTEZero _ impossible\naNotEqToMultA _ _ Z (LTESucc _) _ impossible\naNotEqToMultA _ _ (S Z) (LTESucc LTEZero) _ impossible\naNotEqToMultA _ _ (S Z) (LTESucc (LTESucc _)) _ impossible\naNotEqToMultA Z LTEZero (S (S _)) _ _ impossible\naNotEqToMultA Z (LTESucc _) (S (S _)) _ _ impossible\naNotEqToMultA (S j) (LTESucc (LTEZero {right = j})) (S (S k)) (LTESucc (LTESucc (LTEZero {right = k}))) prf =\n SIsNotZ {x = j+(k*(S j))} (sym (pfeq)) where\n pfeq = plusLeftCancel (S j) Z ((S k)*(S j)) pfeq1 where\n pfeq1 = rewrite (multCommutative (S (S k)) (S j)) in\n trans (plusZeroRightNeutral (S j)) prf\n\n--helper apNat function\napNat : (f: Nat -> Nat) -> (n: Nat) -> (m: Nat) -> n = m -> f n = f m\napNat f m m Refl = Refl\n\n--n is not both prime and composite\nnotBothPrimeandComp : {n : Nat} -> (pf : LTE 2 n) -> Not (isPrime n pf, isComposite n pf)\nnotBothPrimeandComp {n = Z} LTEZero _ impossible\nnotBothPrimeandComp {n = Z} (LTESucc _) _ impossible\nnotBothPrimeandComp {n = (S Z)} (LTESucc LTEZero) _ impossible\nnotBothPrimeandComp {n = (S Z)} (LTESucc (LTESucc _)) _ impossible\nnotBothPrimeandComp {n = (S (S k))} pftwolten (pfprime , (a ** (b ** ((pfagtone, pfbgtone), pfneqab)))) =\n void (aNotEqToMultA (S (S k)) (lteTransitive (LTESucc (LTEZero {right = (S Z)})) pftwolten) b pfbgtone pfeq) where\n pfeq = (trans pfneqab funceq) where\n funceq = (apNat (\\x=>(x*b)) a (S (S k)) pfaeqn) where\n pfaeqn = case (pfprime (b ** ((lteTransitive (LTESucc (LTEZero {right = (S Z)})) pfbgtone), pfneqab))) of\n Left pf => void ((Prelude.Basics.fst (ltImpliesNotEqNotGT {a=(S Z)} {b = a} pfagtone)) (sym pf))\n Right pf => pf\n\n-- given n >= 2, it is either prime or Composite\neitherPrimeOrComp : {n : Nat} -> (pf : LTE 2 n) -> Either (isPrime n pf)(isComposite n pf)\neitherPrimeOrComp {n = Z} LTEZero impossible\neitherPrimeOrComp {n = Z} (LTESucc _) impossible\neitherPrimeOrComp {n = (S Z)} (LTESucc LTEZero) impossible\neitherPrimeOrComp {n = (S Z)} (LTESucc (LTESucc _)) impossible\neitherPrimeOrComp {n = (S (S k))} pflte = ?rhs_1\n\n -- data Prime : (p : Nat) -> Type where\n -- IsPrime : LTE 2 p -> ((k : Nat) -> isDivisible p k -> Either (k=1)(k=p)) -> Prime p\n\n -- function to check that 2 is prime\n -- twoPr : (k : Nat) -> (isDivisible 2 k) -> Either (k = 1)(k = 2)\n -- twoPr Z (x ** pf) = void (SIsNotZ (snd pf))\n -- twoPr (S Z) (x ** pf) = Left Refl\n -- twoPr (S (S Z)) (x ** pf) = Right Refl\n -- twoPr (S (S (S k))) pf = void (bGtAImpNotbDivA 2 (S (S (S k))) k (LTESucc (LTESucc (LTESucc (LTEZero {right = k})))) (pf))\n --\n -- --two is Prime\n -- twoIsPrime : Prime 2\n -- twoIsPrime = IsPrime (LTESucc (LTESucc (LTEZero {right =0}))) twoPr\n\n\n-- notBothPrimeandComp Z LTEZero _ _ impossible\n-- notBothPrimeandComp Z (LTESucc _) _ _ impossible\n-- notBothPrimeandComp (S Z) (LTESucc LTEZero) _ _ impossible\n-- notBothPrimeandComp (S Z) (LTESucc (LTESucc _)) _ _ impossible\n-- notBothPrimeandComp (S (S k)) pfgt pfprime pfcomp = ?jk\n\n\n\n\n\n--same as oneDiv, but fits the format for the following functions\n-- oneIsFactor : (n : Nat) -> (LTE 1 n) -> (fromMaybe 0 (head' (List Nat)) = (S Z))\n-- oneIsFactor Z LTEZero impossible\n-- oneIsFactor Z (LTESucc _) impossible\n-- oneIsFactor (S k) pf =\n--\n-- -- n is the last element of the list of its factors\n-- nIsFactor : (n : Nat) -> (LTE 1 n) -> (fromMaybe 0 (tail' (genFact n n)) = n)\n-- nIsFactor Z LTEZero impossible\n-- nIsFactor Z (LTESucc _) impossible\n-- nIsFactor (S k) pf = Refl\n\n\n--Spare code\n{-\n--Type for isPrime. A number p is prime if all numbers dividing\n--it are either p or 1. (In the primality checker, I am checking\n--for numbers until p, hence the p case is not included. Will\n--be changed in a future update.)\nisPrime : Nat -> Type\nisPrime p = (LTE 2 p ,\n (x : Nat **\n (isDivisible p x , x = 1)))\n--Does the job, but is not very useful. Will be replaced later.\ncheckPrime : (p : Nat) -> LTE 2 p -> {default (p-1) iter : Nat} ->\n Maybe (isPrime p)\ncheckPrime p pf {iter=Z} = Nothing\ncheckPrime p pf {iter=(S Z)} = Just (pf, ((S Z) ** (oneDiv p, Refl)))\ncheckPrime p pf {iter=(S k)} = case modNatNZ p (S k) SIsNotZ of\n Z => Nothing\n (S m) => checkPrime p pf {iter=k}\n-}\n", "meta": {"hexsha": "e485b3e588a4ad58a47f468f05043d2f7330e85d", "size": 18821, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Primes.idr", "max_stars_repo_name": "rathivrunda/LTS2019", "max_stars_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": "Code/Primes.idr", "max_issues_repo_name": "rathivrunda/LTS2019", "max_issues_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": "Code/Primes.idr", "max_forks_repo_name": "rathivrunda/LTS2019", "max_forks_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": 42.0111607143, "max_line_length": 142, "alphanum_fraction": 0.5381754423, "num_tokens": 6654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7298592800925235}} {"text": "module Data.Int.Algebra\n\nimport Control.Algebra\n\n%access public export\n\n\n--- ||| Return the smallest non-negative representative of the class of a modulo n.\nleastPositiveResidue : (Integral ty, Ord ty) => (a : ty) -> (b : ty) -> ty\nleastPositiveResidue a n = let r = a `mod` n in if r < 0 then r + n else r\n\n\ndata Zn : (n : Nat) -> Type where\n MkZn : Int -> Zn n\n\n\nSemigroup (Zn n) where\n (MkZn x) <+> (MkZn y) = let z = x + y; i = fromNat n in\n MkZn $ if z < i then z else z - i\n\n\nMonoid (Zn n) where\n neutral = MkZn 0\n\n\nGroup (Zn n) where\n inverse (MkZn x) = MkZn (fromNat n - x)\n\n\nEq (Zn n) where\n (MkZn x) == (MkZn y) = x == y\n\n\nDecEq (Zn n) where\n decEq x y =\n case x == y of\n True => Yes primitiveEq\n False => No primitiveNotEq\n where\n primitiveEq : x = y\n primitiveEq = really_believe_me (Refl {x})\n primitiveNotEq : x = y -> Void\n primitiveNotEq prf = believe_me {b = Void} ()\n\n\nShow (Zn n) where\n show (MkZn a) = show (leastPositiveResidue a (fromNat n))\n", "meta": {"hexsha": "574b419d53de2a037c6ddcfc19fe5d8b6947c59b", "size": 1016, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Int/Algebra.idr", "max_stars_repo_name": "yurrriq/gis", "max_stars_repo_head_hexsha": "bf8191b947e750fdab1c953270193bb12129ff95", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-09-24T23:24:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T01:10:25.000Z", "max_issues_repo_path": "src/Data/Int/Algebra.idr", "max_issues_repo_name": "yurrriq/gis", "max_issues_repo_head_hexsha": "bf8191b947e750fdab1c953270193bb12129ff95", "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/Int/Algebra.idr", "max_forks_repo_name": "yurrriq/gis", "max_forks_repo_head_hexsha": "bf8191b947e750fdab1c953270193bb12129ff95", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-24T23:24:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T23:24:20.000Z", "avg_line_length": 21.1666666667, "max_line_length": 83, "alphanum_fraction": 0.6033464567, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7297962105552879}} {"text": "module BiNat.Properties.Induction\n\nimport BiNat\nimport BiNat.Properties.Plus\n\n%access public export\n%default total\n\ncomposeFunctions : {T : BiNat -> Type} -> ((k : BiNat) -> T k -> T (succ k)) ->\n (m, n : BiNat) -> T m -> T (plus m n)\ncomposeFunctions f m J pm = replace (sym $ plusJIsSucc m) (f m pm)\ncomposeFunctions f m (ns -: O) pm =\n replace {P = \\z => T (plus m z)} (sym $ shiftLeftDoubles ns) $\n replace (sym $ plusAssociative m ns ns) $\n composeFunctions f (plus m ns) ns $\n composeFunctions f m ns pm\ncomposeFunctions f m (ns -: I) pm =\n replace {P = \\z => T z} (sym $ plusAssociative m J (ns -: O)) $\n replace {P = \\z => T (plus (plus m J) z)} (sym $ shiftLeftDoubles ns) $\n replace {P = \\z => T z} (sym $ plusAssociative (plus m J) ns ns) $\n composeFunctions f (plus (plus m J) ns) ns $\n composeFunctions f (plus m J) ns $\n replace (sym $ plusJIsSucc m) (f m pm)\n\ninduction : (P : BiNat -> Type) -> ((k : BiNat) -> P k -> P (succ k)) -> P J -> (n : BiNat) -> P n\ninduction prop step pj J = pj\ninduction prop step pj (ns -: n) =\n replace (succOfPred (ns -: n) uninhabited) $\n replace (jPlusIsSucc (pred (ns -: n))) $\n composeFunctions step J (pred (ns -: n)) pj\n", "meta": {"hexsha": "b7e412491f120dcf059005ea10dcf0dd84dbfdad", "size": 1202, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "BiNat/Properties/Induction.idr", "max_stars_repo_name": "SekiT/BiNat", "max_stars_repo_head_hexsha": "1ac44fa9d5f60e1fb6ceee6394d49c0ecd8aebfd", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "BiNat/Properties/Induction.idr", "max_issues_repo_name": "SekiT/BiNat", "max_issues_repo_head_hexsha": "1ac44fa9d5f60e1fb6ceee6394d49c0ecd8aebfd", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BiNat/Properties/Induction.idr", "max_forks_repo_name": "SekiT/BiNat", "max_forks_repo_head_hexsha": "1ac44fa9d5f60e1fb6ceee6394d49c0ecd8aebfd", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7741935484, "max_line_length": 98, "alphanum_fraction": 0.6073211314, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172630429475, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7297935136215766}} {"text": "> module Nat.DivisorOperations\n\n\n> import Nat.Divisor\n\n\n> %default total\n\n> %access public export\n\n\n> ||| Exact integer division\n> quotient : (m : Nat) -> (d : Nat) -> d `Divisor` m -> Nat\n> quotient _ _ (Element q _) = q \n\n\n\n\n", "meta": {"hexsha": "944c775d81711d559b8202571cf852659558c88f", "size": 227, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/DivisorOperations.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Nat/DivisorOperations.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Nat/DivisorOperations.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 11.9473684211, "max_line_length": 59, "alphanum_fraction": 0.6167400881, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178870347124, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7297780777674563}} {"text": "module NatOrder\n\nimport Decidable.Order\n\n%default total\n\n-- data NatOrder : Nat -> Nat -> Type = LessThan (LT x y) | Equal (x = y) | GreaterThan (GT x y)\npublic export\ndata NatOrder : Nat -> Nat -> Type where\n LessThan : LT x y -> NatOrder x y\n Equal : x = y -> NatOrder x y\n GreaterThan : GT x y -> NatOrder x y\n\n-- export\nnotGT : Not (LTE x y) -> GT x y\nnotGT {x = Z} {y = y} contra = void $ contra LTEZero\nnotGT {x = (S k)} {y = Z} contra = LTESucc LTEZero\nnotGT {x = (S kx)} {y = (S ky)} contra =\n let ih = notGT {x=kx} {y=ky} (contra . LTESucc) in\n LTESucc ih\n\n-- export\nnotEqLt : LTE x y -> Not (x = y) -> LT x y\nnotEqLt {x = Z} {y = Z} x_lte_y x_neq_y = void $ x_neq_y Refl\nnotEqLt {x = Z} {y = (S k)} x_lte_y x_neq_y = LTESucc LTEZero\nnotEqLt {x = (S k)} {y = Z} x_lte_y x_neq_y = absurd x_lte_y\nnotEqLt {x = (S kx)} {y = (S ky)} x_lte_y x_neq_y =\n let ih = notEqLt {x=kx} {y=ky} (fromLteSucc x_lte_y) (x_neq_y . cong {f=S}) in\n LTESucc ih\n\n\nexport\ndecideOrder : (x : Nat) -> (y : Nat) -> NatOrder x y\ndecideOrder x y = case decEq x y of\n (Yes prf) => Equal prf\n (No x_neq_y) => case decideLTE x y of\n (Yes x_lte_y) => LessThan (notEqLt x_lte_y x_neq_y)\n (No x_gt_y) => GreaterThan (notGT x_gt_y)\n\nexport\neqDecEq : {x : Nat} -> (prf ** decEq x x = Yes prf)\neqDecEq {x = Z} = (Refl ** Refl)\neqDecEq {x = (S k)} =\n let (prf_k ** eq_prf_k) = eqDecEq {x=k} in\n rewrite eq_prf_k in\n (cong prf_k ** Refl)\n\nexport\nequalDecision : (prf ** decideOrder x x = Equal prf)\nequalDecision {x = Z} = (Refl ** Refl)\nequalDecision {x = (S k)} =\n let (k_k ** eq_prf_k) = equalDecision {x=k} in\n -- rewrite eq_prf_k in\n ?opuqwer\n -- (cong k_k ** ?opupqwer)\n\n\n-- equalDecision {x} =\n-- case decideOrder x x of\n-- (LessThan x) => ?poipqowuier_1\n-- (Equal prf) =>\n-- let (x_x ** eq_prf_x) = eqDecEq {x=x} in\n-- (x_x **\n-- -- rewrite eq_prf_x in\n-- ?pouiqpwerqwer\n-- )\n-- (GreaterThan x) => ?poipqowuier_3\n", "meta": {"hexsha": "7ad7eb4a8e8bd3b9722546d96f3f89799461fb60", "size": 2048, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "public/post_assets/idris/idris-intro/NatOrder.idr", "max_stars_repo_name": "nokeeo/donald-pinckney.github.io", "max_stars_repo_head_hexsha": "b8b2f401b6b33ff418c9ae192f0bfc42e21ee0de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-07-27T22:47:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T16:04:00.000Z", "max_issues_repo_path": "public/post_assets/idris/idris-intro/NatOrder.idr", "max_issues_repo_name": "nokeeo/donald-pinckney.github.io", "max_issues_repo_head_hexsha": "b8b2f401b6b33ff418c9ae192f0bfc42e21ee0de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2018-11-29T04:16:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-01T04:50:06.000Z", "max_forks_repo_path": "public/post_assets/idris/idris-intro/NatOrder.idr", "max_forks_repo_name": "nokeeo/donald-pinckney.github.io", "max_forks_repo_head_hexsha": "b8b2f401b6b33ff418c9ae192f0bfc42e21ee0de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2017-11-22T03:22:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T07:09:09.000Z", "avg_line_length": 30.1176470588, "max_line_length": 96, "alphanum_fraction": 0.5708007812, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7293739591989274}} {"text": "module BinaryRandomAccessList\n\nimport RandomAccessList\n\n%default total\n%access private\n\ndata Tree a = Leaf a | Node Int (Tree a) (Tree a)\ndata Digit a = Zero | One (Tree a)\n\nexport\ndata BinaryList a = BL (List (Digit a))\n\nsize : Tree a -> Int\nsize (Leaf x) = 1\nsize (Node w t1 t2) = w\n\nlink : Tree a -> Tree a -> Tree a\nlink t1 t2 = Node (size t1 + size t2) t1 t2\n\nconsTree : Tree a -> List (Digit a) -> List (Digit a)\nconsTree t [] = [One t]\nconsTree t (Zero :: ts) = One t :: ts\nconsTree t1 (One t2 :: ts) = Zero :: consTree (link t1 t2) ts\n\nunconsTree : List (Digit a) -> (Tree a, List (Digit a))\nunconsTree [] = idris_crash \"empty list\"\nunconsTree [One t] = (t, [])\nunconsTree (One t :: ts) = (t, Zero :: ts)\nunconsTree (Zero :: ts) = case unconsTree ts of\n (Node _ t1 t2, ts') => (t1, One t2 :: ts')\n (Leaf _ , _) => assert_unreachable\n\nexport\nRandomAccessList BinaryList where\n empty = BL []\n isEmpty (BL ts) = isNil ts\n\n cons x (BL ts) = BL (consTree (Leaf x) ts)\n head (BL ts) = assert_total $ let (Leaf x, _) = unconsTree ts in x\n tail (BL ts) = let (_, ts') = unconsTree ts in BL ts'\n\n lookup i (BL ts) = look i ts\n where\n lookTree : Int -> Tree a -> a\n lookTree 0 (Leaf x) = x\n lookTree i (Leaf x) = idris_crash \"bad subscript\"\n lookTree i (Node w t1 t2) = let hw = assert_total $ w `div` 2\n in if i < hw then lookTree i t1 else lookTree (i - hw) t2\n\n look i [] = idris_crash \"bad subscript\"\n look i (Zero :: ts) = look i ts\n look i (One t :: ts) =\n if i < size t then lookTree i t else look (i - size t) ts\n\n update i y (BL ts) = BL (upd i ts)\n where\n updTree : Int -> Tree a -> Tree a\n updTree 0 (Leaf x) = Leaf y\n updTree i (Leaf x) = idris_crash \"bad subscript\"\n updTree i (Node w t1 t2) = let hw = assert_total $ w `div` 2 in\n if i < hw then Node w (updTree i t1) t2\n else Node w t1 (updTree (i - hw) t2)\n\n upd i [] = idris_crash \"bad subscript\"\n upd i (Zero :: ts) = Zero :: upd i ts\n upd i (One t :: ts) =\n if i < size t then One (updTree i t) :: ts\n else One t :: upd (i - size t) ts\n", "meta": {"hexsha": "194dc92c775c6596c8a204005af761f82de32e36", "size": 2160, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/BinaryRandomAccessList.idr", "max_stars_repo_name": "ska80/idris-okasaki-pfds", "max_stars_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-08T00:55:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-08T00:55:51.000Z", "max_issues_repo_path": "src/BinaryRandomAccessList.idr", "max_issues_repo_name": "ska80/idris-okasaki-pfds", "max_issues_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_issues_repo_licenses": ["CC0-1.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": "src/BinaryRandomAccessList.idr", "max_forks_repo_name": "ska80/idris-okasaki-pfds", "max_forks_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8571428571, "max_line_length": 68, "alphanum_fraction": 0.5796296296, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7290874116444555}} {"text": "-- module Main\n\ndata N = Zero | Suc N\n \naddOne : N -> N\naddOne Zero = Suc Zero\naddOne (Suc n) = Suc (Suc n)\n\nOne : N\nOne = Suc Zero\nTwo : N\nTwo = (Suc (Suc Zero))\nThree : N\nThree = addOne Two\nFour : N\nFour = addOne Three\nFive : N\nFive = addOne Four\n\n\nadd : N -> N -> N\nadd Zero s = s\nadd (Suc a) b = add a (Suc b)\n\ndata Vec : (a : Type) -> N -> Type where\n Nil : Vec a Zero\n Cons : a -> Vec a n -> Vec a (Suc n)\n\nempt : Vec N Zero\nempt = Nil\n\ntest : Vec N Two\ntest = Cons One (Cons Two Nil)\n\ntest2 : Vec N Three\ntest2 = Cons Three (Cons Four (Cons Five Nil))\n\ncc : Vec g a -> Vec g b -> Vec g (add a b)\ncc Nil rest = rest\ncc (Cons a rest) b = cc rest (Cons a b)\n\nt3 : Vec N (addOne (addOne (addOne (addOne One))))\nt3 = cc test test2\n", "meta": {"hexsha": "442fe17984588135259876177c142d4b05e8c398", "size": 737, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "simpleIdrisImpl.idr", "max_stars_repo_name": "karljakoblarsson/IdrisToAgda", "max_stars_repo_head_hexsha": "bb87c56b790a99936021f05db35d13127b13502e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-16T23:22:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-29T20:42:43.000Z", "max_issues_repo_path": "simpleIdrisImpl.idr", "max_issues_repo_name": "karljakoblarsson/IdrisToAgda", "max_issues_repo_head_hexsha": "bb87c56b790a99936021f05db35d13127b13502e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-28T17:52:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-28T17:52:42.000Z", "max_forks_repo_path": "simpleIdrisImpl.idr", "max_forks_repo_name": "karljakoblarsson/IdrisToAgda", "max_forks_repo_head_hexsha": "bb87c56b790a99936021f05db35d13127b13502e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-27T16:25:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-27T16:25:18.000Z", "avg_line_length": 16.75, "max_line_length": 50, "alphanum_fraction": 0.5956580733, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.729017549585124}} {"text": "module Main\n\nimport Data.Vect\n\ndata EqNat : (num1: Nat)-> (num2: Nat) -> Type where\n Same : (num: Nat) -> EqNat num num\n\n-- checkEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\n-- checkEqNat Z Z = ?checkEqNat_rhs_3\n-- checkEqNat Z (S k) = ?checkEqNat_rhs_4\n-- checkEqNat (S k) num2 = ?checkEqNat_rhs_2\n\n\nsameAs : (k: Nat) -> (j: Nat) -> (eq: EqNat k j) -> EqNat (S k) (S j)\nsameAs j j (Same j) = Same (S j)\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat Z Z = Just (Same Z)\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just eq => Just (sameAs _ _ eq)\n\nexactLength : (len: Nat) -> (input: Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case checkEqNat m len of\n Nothing => Nothing\n Just (Same len) => Just input\n\nsame_cons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys\nsame_cons {xs = []} {ys = []} prf = Refl\nsame_cons {xs = []} {ys = (x :: xs)} prf = cong prf\nsame_cons {xs = (x :: xs)} {ys = []} prf = cong prf\nsame_cons {xs = (x :: xs)} {ys = (y :: ys)} prf = cong prf\n\nsame_lists : {xs : List a} -> {ys : List a} -> (x = y) -> (xs = ys) -> (x :: xs) = (y :: ys)\nsame_lists {x = x} {y = x} Refl prf1 = cong prf1\n\ndata ThreeEq : (x: Nat) -> (y: Nat) -> (z: Nat) -> Type where\n SameThree : (x: Nat) -> ThreeEq x x x\n\nallSameS : (x, y, z: Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS k k k (SameThree k) = SameThree (S k)\n\n\nmyReverse : Vect n elem -> Vect n elem\nmyReverse [] = []\nmyReverse {n = S k} (x :: xs) = let rev_xs = myReverse xs\n result = rev_xs ++ [x] in\n rewrite plusCommutative 1 k in result\n\nmyReverse1 : Vect n elem -> Vect n elem\nmyReverse1 [] = []\nmyReverse1 (x :: xs) = reverseProof (myReverse xs ++ [x]) where\n reverseProof: Vect (len + 1) elem -> Vect (S len) elem\n reverseProof {len} xs = rewrite plusCommutative 1 len in xs\n\nappendnil : (Vect m elem) -> (Vect (plus m 0) elem)\nappendnil {m} elem = rewrite plusZeroRightNeutral m in elem\n\n\nappend : Vect n elem -> Vect m elem -> Vect (m + n) elem\nappend [] ys = appendnil ys\nappend (x :: xs) ys = ?append_proof (x :: append xs ys)\n\n\n-- append [] ys = ?append_rhs_1append (x :: xs) ys = ?append_rhs_2\n\ndata VElem : (value : a ) -> (xs: Vect k a) -> Type where\n Here: VElem x (x::xs)\n There: (later: VElem x xs) -> VElem x (y::xs)\n\n\n-- maryInVector : VElem \"Mary\" [\"Peter\", \"Paul\", \"Mary\"]\n-- maryInVector = There (There Here)\n\nUninhabited (VElem x []) where\n uninhabited x impossible\n\nremoveElem : (value: a) -> (xs: Vect (S n) a) -> (prf: VElem value xs) -> Vect n a\nremoveElem value (value :: ys) Here = ys\nremoveElem {n = Z} value (y :: []) (There later) = absurd later\nremoveElem {n = (S k)} value (y :: ys) (There later) = y :: removeElem value ys later\n\nremoveElem_auto : (value: a) -> (xs: Vect (S n) a) -> {auto prf: VElem value xs} -> Vect n a\nremoveElem_auto value (value :: ys) {prf=Here} = ys\nremoveElem_auto {n = Z} value (y :: []) {prf=There later} = absurd later\nremoveElem_auto {n = (S k)} value (y :: ys) {prf=There later} = y :: removeElem_auto value ys\n", "meta": {"hexsha": "ac6f32baf0586e386946c78ecb26d224aa765f77", "size": 3243, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter8.idr", "max_stars_repo_name": "gdevanla/idris-learn", "max_stars_repo_head_hexsha": "3348f611f6807e3e88dcd63951c713a327325c2a", "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": "Chapter8.idr", "max_issues_repo_name": "gdevanla/idris-learn", "max_issues_repo_head_hexsha": "3348f611f6807e3e88dcd63951c713a327325c2a", "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": "Chapter8.idr", "max_forks_repo_name": "gdevanla/idris-learn", "max_forks_repo_head_hexsha": "3348f611f6807e3e88dcd63951c713a327325c2a", "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": 36.4382022472, "max_line_length": 93, "alphanum_fraction": 0.5861856306, "num_tokens": 1141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7288567235014366}} {"text": "data Vect : Nat -> Type -> Type where \n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case m == len of\n False => Nothing\n True => Just ?exactLength_rhs_2\n", "meta": {"hexsha": "004d076292c3630e4495c1efe24d42286419c6fc", "size": 326, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp8/ExactLength.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp8/ExactLength.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp8/ExactLength.idr", "max_forks_repo_name": "Ryxai/idris_book_notes", "max_forks_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": 36.2222222222, "max_line_length": 69, "alphanum_fraction": 0.4754601227, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.7287201028729873}} {"text": "{- using 'z' in file name to recover alphabetical sort -}\nmodule Part2.Sez10_1_views \n\n%default total \n\n{- ListLast view examples -}\ndata ListLast : List a -> Type where \n Empty : ListLast [] \n NonEmpty : (xs : List a) -> (x : a) -> ListLast (xs ++ [x])\n\ntotal\nlistLast : (xs : List a) -> ListLast xs\nlistLast [] = Empty\nlistLast (x :: xs) = case listLast xs of\n Empty => NonEmpty [] x\n NonEmpty ys y => NonEmpty (x :: ys) y\n\n\ndescribeHelper : (input : List Int) -> ListLast input -> String\ndescribeHelper [] Empty = \"Empty\"\ndescribeHelper (xs ++ [x]) (NonEmpty xs x)\n = \"Non-empty, initial portion = \" ++ show xs\n\ndescribeListEnd : List Int -> String\ndescribeListEnd xs = describeHelper xs (listLast xs)\n\n{- cool with syntax adds additional arguments to function implementation -}\ndescribeListEnd' : List Int -> String\ndescribeListEnd' input with (listLast input)\n describeListEnd' [] | Empty = \"Empty\"\n describeListEnd' (xs ++ [x]) | (NonEmpty xs x)\n = \"Non-empty, initial portion = \" ++ show xs\n\n|||slow reverse - ListLast view is rebuilt in each recursive step\ncovering\nmyReverse : List a -> List a\nmyReverse input with (listLast input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (NonEmpty xs x) = x :: myReverse xs\n\n{- \nidris repl:\n*Part2/Sez10_1_views> myReverse [5,2,7,1]\n[1, 7, 2, 5] : List Integer\n-}\n\n{- SplitList, merge sort example -}\ndata SplitList : List a -> Type where\n SplitNil : SplitList []\n SplitOne : SplitList [x]\n SplitPair : (lefts : List a) -> (rights : List a) ->\n SplitList (lefts ++ rights)\n\ntotal\nsplitList : (input : List a) -> SplitList input\nsplitList input = splitListHelp input input\nwhere\n {- the first list acts as a counter only, \n each step removes 2 elements from the counter and adds new elements to `lefts` \n when counter is excausted all elements are added to `rights` -}\n splitListHelp : List a -> (input : List a) -> SplitList input\n splitListHelp _ [] = SplitNil\n splitListHelp _ [x] = SplitOne\n splitListHelp (_ :: _ :: counter) (item :: items)\n = case splitListHelp counter items of\n SplitNil => SplitOne --cool how Idris figures this out!\n SplitOne {x} => SplitPair [item] [x]\n SplitPair lefts rights => SplitPair (item :: lefts) rights\n splitListHelp _ items = SplitPair [] items\n\ncovering\nmergeSort : Ord a => List a -> List a\nmergeSort input with (splitList input)\n mergeSort [] | SplitNil = []\n mergeSort [x] | SplitOne = [x]\n mergeSort (lefts ++ rights) | (SplitPair lefts rights)\n -- merge : Ord a => List a -> List a -> List a\n = merge (mergeSort lefts) (mergeSort rights)\n\n{-\nidris repl: \n*Part2/Sez10_1_views> mergeSort [5,2,7,1]\n[1, 2, 5, 7] : List Integer\n-}\n\n-- excercises\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n \ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z xs = Exact [] --kinda amazing how much Idris infers here!\ntakeN (S k) [] = Fewer \ntakeN (S k) (x :: xs) = case takeN k xs of \n Fewer => Fewer\n Exact rxs => Exact (x :: rxs)\n\ncovering\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\n{-\nidris repl:\n*Part2/Sez10_1_views> groupByN 3 [1..10]\n[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] : List (List Integer)\n-}\n\n-- excercise 2\n-- use of div forces `partial` here\npartial\nhalves : List a -> (List a, List a)\nhalves list with (takeN ((length list) `div` 2) list)\n halves list | Fewer = (list, [])\n halves (half1 ++ half2) | (Exact half1) = (half1, half2)\n\n{-\n*Part2/Sez10_1_views> halves [1..10]\n([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]) : (List Integer, List Integer)\n*Part2/Sez10_1_views> halves [1]\n([], [1]) : (List Integer, List Integer)\n*Part2/Sez10_1_views> the (List Integer, List Integer) (halves [])\n([], []) : (List Integer, List Integer)\n-} \n", "meta": {"hexsha": "b5261312888e17f6037f210707e165bf6173a1c0", "size": 4026, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Part2/Sez10_1_views.idr", "max_stars_repo_name": "rpeszek/IdrisTddNotes", "max_stars_repo_head_hexsha": "37bca29819315be6f4001d0fe42ae101116fc06d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2018-06-07T06:18:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T06:08:35.000Z", "max_issues_repo_path": "src/Part2/Sez10_1_views.idr", "max_issues_repo_name": "rpeszek/IdrisTddNotes", "max_issues_repo_head_hexsha": "37bca29819315be6f4001d0fe42ae101116fc06d", "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/Part2/Sez10_1_views.idr", "max_forks_repo_name": "rpeszek/IdrisTddNotes", "max_forks_repo_head_hexsha": "37bca29819315be6f4001d0fe42ae101116fc06d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-08T18:55:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-22T09:25:43.000Z", "avg_line_length": 31.9523809524, "max_line_length": 84, "alphanum_fraction": 0.6244411326, "num_tokens": 1280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8198933271118222, "lm_q1q2_score": 0.7286874017806412}} {"text": "module DecOrderNat\n\n%access public export\n%default total\n\n||| The type of proof that between two elements one is less than\n||| equal to another\n\ndata DecMin : (m , n : Nat) -> Type where\n Left : (LTE m n) -> DecMin m n\n Right : (LTE n m) -> DecMin m n\n\n||| Decides which of the two numbers is smaller and gives the\n||| proof along with the decision\n\ndecideSucc : (m , n : Nat) -> (DecMin m n) -> (DecMin (S m) (S n))\ndecideSucc m n (Left pf) = Left (LTESucc pf)\ndecideSucc m n (Right pf) = Right (LTESucc pf)\n\ndecMin : (m , n : Nat) -> (DecMin m n)\ndecMin Z n = Left LTEZero\ndecMin n Z = Right LTEZero\ndecMin (S m) (S n) = decideSucc m n (decMin m n)\n", "meta": {"hexsha": "ba8dc01ff55f35e5edde5c8fc5da3812d33d48cc", "size": 657, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/DecOrderNat.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/DecOrderNat.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/DecOrderNat.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": 27.375, "max_line_length": 66, "alphanum_fraction": 0.6484018265, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9579122672782974, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.7286365861153319}} {"text": "-- 3.3.3 examples\n\nimport Data.Vect\n\ncreateEmpties : {n: _} -> Vect n (Vect 0 a)\ncreateEmpties = replicate _ []\n\ntransposeHelper : (x : Vect n a)\n -> (xsTrans : Vect n (Vect k a))\n -> Vect n (Vect (S k) a)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntransposeMat : {n: _} -> Vect m (Vect n a) -> Vect n (Vect m a)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in transposeHelper x xsTrans\n\ntransposeMat2 : {n: _} -> Vect m (Vect n a) -> Vect n (Vect m a)\ntransposeMat2 [] = createEmpties\ntransposeMat2 (x :: xs) = let xsTrans = transposeMat2 xs in zipWith (::) x xsTrans\n\n{-\nAddition recursion\n\ninput: addMatrix [[1,2], [3,4]] [[5,6], [7,8]]\nexpected: [[6, 8], [10, 12]]\n\naddMatrix (x :: xs) (y :: ys) = ([1,2] :: [[3,4]]) ([5,6] :: [[7,8]])\n addMatrix xs ys = [[3,4]] [[7,8]]\n addMatrix (x :: xs) (y :: ys) = ([3,4] :: []) ([7,8] :: [])\n addMatrix [] ys = []\n sumMatrix: zipWith (+) [3,4] [7,8] :: [] ==> [[10,12]]\n sumMatrix: zipWith (+) [1,2] [3,4] :: [[10,12]] ==> [[6,8], [10,12]]\n -}\naddMatrix : Num a => Vect n (Vect m a) \n -> Vect n (Vect m a) \n -> Vect n (Vect m a)\naddMatrix [] ys = ys\naddMatrix (x :: xs) (y :: ys) = let sumMatrix = addMatrix xs ys in zipWith (+) x y :: sumMatrix\n\nmultVect : {p: _} -> Num a \n => Vect m a \n -> Vect p (Vect m a) \n -> Vect p a\nmultVect _ [] = []\nmultVect xs ys = map (\\y => sum (zipWith (*) xs y)) ys\n\ndotProduct : Num a => {n: _} -> {p: _} -> Vect n (Vect m a) \n -> Vect p (Vect m a) \n -> Vect n (Vect p a)\ndotProduct [] _ = []\ndotProduct _ [] = createEmpties\ndotProduct (x :: xs) ys = let productMat = \n dotProduct xs ys \n in multVect x ys :: productMat\n\n{- \nTransposes right matrix:\ninput: multMatrix [[1,2], [3,4], [5,6]] [[7,8,9,10], [11,12,13,14]]\n\ntransposeMat2 [[7,8,9,10], [11,12,13,14]] ==> [[7, 11], [8, 12], [9, 13], [10, 14]]\n\nthen performs matrix dot product\n -}\nmultMatrix : Num a => {n: _} -> {p: _} -> Vect n (Vect m a)\n -> Vect m (Vect p a)\n -> Vect n (Vect p a)\nmultMatrix xs ys = dotProduct xs (transposeMat2 ys)\n", "meta": {"hexsha": "21a63281c83bcf40f44d0bded65ed3794023d961", "size": 2318, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch3/Matrix.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "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/ch3/Matrix.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": "src/ch3/Matrix.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": 33.5942028986, "max_line_length": 95, "alphanum_fraction": 0.5034512511, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7282944799826134}} {"text": "module ZZUtils\nimport ZZ\nimport NatUtils\n%access public export\n%default total\n\ndata IsNonNegative : ZZ->Type where\n NonNegative :(IsNonNegative (Pos k))\n\n\ndata NotBothZeroZ :ZZ->ZZ->Type where\n LeftPositive :NotBothZeroZ (Pos (S k)) m\n LeftNegative :NotBothZeroZ (NegS k) m\n RightPositive :NotBothZeroZ m (Pos (S k))\n RightNegative :NotBothZeroZ m (NegS k)\n\ndata NotZero:ZZ->Type where\n PositiveZ:NotZero (Pos (S k))\n NegativeZ:NotZero (NegS k)\n\ndata IsNegative:ZZ->Type where\n Negative: IsNegative (NegS k)\n\n|||Zero is not positive\nzeroNotPos:IsPositive (Pos Z)->Void\nzeroNotPos Positive impossible\n\n|||Proof that NotBothZeroZ 0 0 is uninhabited\nzeroZeroBothZero:NotBothZeroZ (Pos Z) (Pos Z) ->Void\nzeroZeroBothZero LeftPositive impossible\nzeroZeroBothZero LeftNegative impossible\nzeroZeroBothZero RightPositive impossible\nzeroZeroBothZero RightNegative impossible\n\n|||Decides whther two numbers are not both zero or not.\ndecNotBothZero : (a:ZZ)->(b:ZZ)->Dec (NotBothZeroZ a b)\ndecNotBothZero (Pos Z) (Pos Z) = No ( zeroZeroBothZero)\ndecNotBothZero (Pos Z) (Pos (S k)) = Yes RightPositive\ndecNotBothZero (Pos Z) (NegS k) = Yes RightNegative\ndecNotBothZero (Pos (S k)) b = Yes LeftPositive\ndecNotBothZero (NegS k) b = Yes LeftNegative\n\n|||Checks 2 numbers and produces a proof of either (a=0,b=0) or (NotBothZeroZ a b)\ncheckNotBothZero : (a:ZZ)->(b:ZZ)->Either ((a=0),(b=0)) (NotBothZeroZ a b)\ncheckNotBothZero (Pos Z) (Pos Z) = Left (Refl, Refl)\ncheckNotBothZero (Pos Z) (Pos (S k)) = Right RightPositive\ncheckNotBothZero (Pos Z) (NegS k) = Right RightNegative\ncheckNotBothZero (Pos (S k)) b = Right LeftPositive\ncheckNotBothZero (NegS k) b = Right LeftNegative\n\n|||Proof that positive numbers are not zero\nposThenNotZero:{a:ZZ}->(IsPositive a)->(NotZero a)\nposThenNotZero {a = (Pos (S k))} Positive = PositiveZ\n\n|||Negative numbers are not zero\nNegSThenNotZero:{a:ZZ}->(IsNegative a)->(NotZero a)\nNegSThenNotZero {a = (NegS k)} ZZUtils.Negative = NegativeZ\n|||negative of a negative number is positive\nnegateNegativePos:(IsNegative c) ->IsPositive (-c)\nnegateNegativePos {c = (NegS k)} Negative = Positive\n|||negative of a positive number is negative\nnegatePosIsNeg: IsPositive q ->IsNegative (-q)\nnegatePosIsNeg {q = (Pos (S k))} Positive =Negative\n\n\n|||If c and d are negative and c = d*q, then q is positive\nnegDivByNegIsPos:{c:ZZ}->{d:ZZ}->{q:ZZ}->(IsNegative c)->\n (IsNegative d)->(c=(d*q))->(IsPositive q)\nnegDivByNegIsPos {c = (NegS k)}{d = (NegS j)}{q = q}\n Negative Negative prf = posDivByPosIsPos {c=(-(NegS k))}{d=(-(NegS j))}\n Positive Positive (rewrite multNegateLeftZ (NegS j) q in (numbersSameNegativesSame prf))\n|||If c is negative, d is positive and c = d*q, then q is negative\nnegDivByPosIsNeg:{c:ZZ}->{d:ZZ}->{q:ZZ}->(IsNegative c)->\n (IsPositive d)->(c=(d*q))->(IsNegative q)\nnegDivByPosIsNeg {c}{d}{q} cNeg dPos prf =\n (case (posDivByPosIsPos {c =(-c)} {d=d} {q=-q}\n (negateNegativePos cNeg) dPos\n (rewrite multNegateRightZ d q in\n numbersSameNegativesSame prf)) of\n negqpos => (rewrite sym $ doubleNegElim q in\n negatePosIsNeg negqpos))\n|||Rewrites a=b as a=1*b\nrewriteRightAsOneTimesRight: {a:ZZ}->{b:ZZ}->(a=b)->(a=(1*b))\nrewriteRightAsOneTimesRight {a}{b}prf = rewrite ( (multOneLeftNeutralZ b)) in prf\n|||Rewrites a=b as 1*a=b\nrewriteLeftAsOneTimesLeft: {a:ZZ}->{b:ZZ}->(a=b)->(1*a=b)\nrewriteLeftAsOneTimesLeft {a}{b}prf = rewrite ( (multOneLeftNeutralZ a)) in prf\n|||Rewrites 1*a = b as a=b\nrewriteOneTimesLeftAsLeft:{a:ZZ}->{b:ZZ}->((1*a) = b)->(a=b)\nrewriteOneTimesLeftAsLeft {a}{b}prf =\n rewrite ( sym $(multOneLeftNeutralZ a)) in prf\n|||Rewrites (a*1)=b as a=b\nrewriteLeftTimesOneAsLeft : {a:ZZ}->{b:ZZ}->((a*1)=b)->(a=b)\nrewriteLeftTimesOneAsLeft {a}{b}prf =\n rewrite ( sym $(multOneRightNeutralZ a)) in prf\n\n|||Proof that negative integers are not non negative\nnegsAreNotNonNegs:(IsNonNegative (NegS k))->Void\nnegsAreNotNonNegs NonNegative impossible\n|||A function that checks whether an integer is non negative and returns a\n|||proof or a contradiction\ndecideIsNonNeg:(a: ZZ) -> Dec (IsNonNegative a)\ndecideIsNonNeg (Pos k) = Yes NonNegative\ndecideIsNonNeg (NegS k) = No (negsAreNotNonNegs)\n|||Proof that natural numbers are non negative\nnaturalsNonNegative: (x:Nat)->IsNonNegative (Pos x)\nnaturalsNonNegative x = NonNegative\n\n|||The less than type for ZZ\nLTZ :ZZ->ZZ->Type\nLTZ a b = LTEZ (1+a) b\n\n|||Theorem that if a and b are natural numbers and a{b:Nat}->(LT a b)->(LTZ (Pos a) (Pos b))\nltNatToZZ (LTESucc x) = PositiveLTE (LTESucc x)\n|||Proves that a<= a for any integer a\nlteReflZ:{a:ZZ}->LTEZ a a\nlteReflZ {a =(Pos k)} = PositiveLTE (lteRefl {n=k})\nlteReflZ {a= (NegS k)} = NegativeLte (lteRefl {n=k})\n|||Proof that a number is less than its successor\nnumLtSucc:(a:ZZ)->LTZ a (1+a)\nnumLtSucc a = lteReflZ\n|||Proof that one is not less than zero\noneNotLTEZero:(LTEZ (Pos (S Z)) (Pos Z))->Void\noneNotLTEZero (PositiveLTE LTEZero) impossible\noneNotLTEZero (PositiveLTE (LTESucc _)) impossible\n|||Proof that a number greater than or equal to 1 is positive\ngteOnePositive:(a:ZZ)->(LTEZ 1 a)->(IsPositive a)\ngteOnePositive (Pos Z) (PositiveLTE LTEZero) impossible\ngteOnePositive (Pos Z) (PositiveLTE (LTESucc _)) impossible\ngteOnePositive (Pos (S k)) x = Positive\ngteOnePositive (NegS _) (PositiveLTE _) impossible\ngteOnePositive (NegS _) NegLessPositive impossible\ngteOnePositive (NegS _) (NegativeLte _) impossible\n\n|||Proof that it is impossible that (1+a)<=a\nsuccNotLteNumZ:(a:ZZ)->(LTEZ (1+a) a) ->Void\nsuccNotLteNumZ (Pos k) y =\n impliesContrapositive (LTEZ (Pos (S k)) (Pos k)) (LTE (S k) k)\n LTEZZtoNat (succNotLTEnum k) y\nsuccNotLteNumZ (NegS Z) (PositiveLTE _) impossible\nsuccNotLteNumZ (NegS Z) NegLessPositive impossible\nsuccNotLteNumZ (NegS Z) (NegativeLte _) impossible\nsuccNotLteNumZ (NegS (S k)) y =\n impliesContrapositive (LTEZ (NegS k) (NegS (S k))) (LTE (S k) k)\n LTEZZtoNatNeg (succNotLTEnum k) y\n\n|||Multiplying positive numbers gives a positive number.\nposMultPosIsPos: (IsPositive m)->(IsPositive d)->(IsPositive (m*d))\nposMultPosIsPos{m = (Pos (S k))}{d = (Pos (S j))} Positive Positive = Positive\n|||The theorem that (-a)*(-b)=a*b\nnegateMultNegateNeutralZ: {a:ZZ}->{b:ZZ}->((-a)*(-b)=a*b)\nnegateMultNegateNeutralZ{a}{b} =\n rewrite (multNegateRightZ (-a) b) in\n rewrite (multNegateLeftZ a b ) in\n rewrite (doubleNegElim (a*b)) in Refl\n|||Proof that zero times an integer is not positive\nposIsNotZeroTimesInteger:((Pos (S k))=(Pos Z)*a)->Void\nposIsNotZeroTimesInteger{a = (Pos _)} Refl impossible\nposIsNotZeroTimesInteger{a = (NegS _)} Refl impossible\n|||Proof that Zero times an integer is not negative\nnegSIsNotZeroTimesInteger :((NegS k)=(Pos Z)*a)->Void\nnegSIsNotZeroTimesInteger {a = (Pos _)} Refl impossible\nnegSIsNotZeroTimesInteger {a = (NegS _)} Refl impossible\n|||Converts a nonNegative integer into the corresponding Natural number\nnonNegIntegerToNat:(a:ZZ)->(IsNonNegative a)->Nat\nnonNegIntegerToNat (Pos k) NonNegative = k\n|||Proof that a positive number is not zero times a negative number\nzeroTimesNegIsNotPos:(Pos (S k)) = (Pos Z)*(NegS j)->Void\nzeroTimesNegIsNotPos Refl impossible\n|||Proof that a positive number is not a negative number times zero\nnegTimesZeroIsNotPos :(Pos (S k)) = (NegS j)*(Pos Z)->Void\nnegTimesZeroIsNotPos {k}{j}prf =\n zeroTimesNegIsNotPos{k=k}{j=j}\n (rewrite (sym(multCommutativeZ (NegS j) (Pos Z))) in prf)\n|||Proof that a positive number is not a positive number times a negative number\nPosTimesNegIsNotPos:(Pos (S k)) = (Pos (S l))*(NegS j)->Void\nPosTimesNegIsNotPos Refl impossible\n|||Proof that a Positiv number is not a positive number times zero\nposIsNotZeroTimesPos: ((Pos (S k)) = (Pos Z)*(Pos (S j))) -> Void\nposIsNotZeroTimesPos Refl impossible\n|||proof that a positive number is not zero times a positive number\nposIsNotPosTimesZero: ((Pos(S k)) = (Pos (S j))*(Pos Z)) -> Void\nposIsNotPosTimesZero {k}{j}prf =\n posIsNotZeroTimesPos{k=k}{j=j}\n (rewrite (sym(multCommutativeZ ((Pos(S j))) (Pos Z))) in prf)\n\n\n|||Lemma that (c*d)*n = (c*n)*d\nmultCommuAndAssocZ1: {c:ZZ}->{d:ZZ}->{n:ZZ}->(c*d)*n = (c*n)*d\nmultCommuAndAssocZ1 {c}{d}{n}= rewrite (sym(multAssociativeZ c n d)) in\n rewrite (multCommutativeZ n d ) in\n rewrite( (multAssociativeZ c d n))in\n Refl\n\n\n\n|||Proof that if (a*b=1) then either (a=1,b=1) or (a=-1,b=-1)\nproductOneThenNumbersOne: (a:ZZ)->(b:ZZ)->(a*b=1) ->Either (a=1,b=1) (a=(-1),b=(-1))\nproductOneThenNumbersOne (Pos Z) (Pos _) Refl impossible\nproductOneThenNumbersOne (Pos Z) (NegS _) Refl impossible\nproductOneThenNumbersOne (Pos (S Z)) (Pos Z) prf = void (posIsNotPosMultZero {k=Z} (sym prf))\nproductOneThenNumbersOne (Pos (S Z)) (Pos (S Z)) prf = Left (Refl, Refl)\nproductOneThenNumbersOne (Pos (S Z)) (Pos (S (S _))) Refl impossible\nproductOneThenNumbersOne (Pos (S Z)) (NegS _) Refl impossible\nproductOneThenNumbersOne (Pos (S (S k))) (Pos Z) prf = void (posIsNotPosMultZero (sym prf))\nproductOneThenNumbersOne (Pos (S (S _))) (Pos (S Z)) Refl impossible\nproductOneThenNumbersOne (Pos (S (S _))) (Pos (S (S _))) Refl impossible\nproductOneThenNumbersOne (Pos (S (S _))) (NegS _) Refl impossible\nproductOneThenNumbersOne (NegS Z) (Pos Z) Refl impossible\nproductOneThenNumbersOne (NegS Z) (Pos (S _)) Refl impossible\nproductOneThenNumbersOne (NegS Z) (NegS Z) prf = Right (Refl,Refl)\nproductOneThenNumbersOne (NegS Z) (NegS (S _)) Refl impossible\nproductOneThenNumbersOne (NegS (S k)) (Pos Z) prf = void (negTimesZeroIsNotPos{k=Z} (sym prf))\nproductOneThenNumbersOne (NegS (S _)) (Pos (S _)) Refl impossible\nproductOneThenNumbersOne (NegS (S _)) (NegS Z) Refl impossible\nproductOneThenNumbersOne (NegS (S _)) (NegS (S _)) Refl impossible\n\n|||Right cancellation law for addition\n|||Proves that a+r=b+r implies a = b\nplusRightCancelZ:(left1:ZZ)->(left2:ZZ)->(right:ZZ)->\n (left1+right=left2+right)->(left1 = left2)\nplusRightCancelZ left1 left2 right prf =\n rewrite sym $plusZeroRightNeutralZ left1 in\n rewrite sym $plusZeroRightNeutralZ left2 in\n rewrite sym $plusNegateInverseRZ right in\n rewrite plusAssociativeZ left1 (-right) right in\n rewrite plusAssociativeZ left2 (-right) right in\n rewrite plusCommutativeZ left1 (-right) in\n rewrite plusCommutativeZ left2 (-right) in\n rewrite sym $ plusAssociativeZ (-right) left1 right in\n rewrite sym $ plusAssociativeZ (-right) left2 right in\n cong prf\n\n|||Left cancellation law for addition\n|||Proves that l+a=l+b implies a =b\nplusLeftCancelZ:(left : ZZ) -> (right1 : ZZ) -> (right2 : ZZ) ->\n (left+right1 = left+right2) -> (right1 = right2)\nplusLeftCancelZ left right1 right2 prf =\n plusRightCancelZ right1 right2 left (rewrite plusCommutativeZ right1 left in\n rewrite plusCommutativeZ right2 left in\n prf)\n\n|||Right cancellation law for multiplication when right is positive\nmultRightCancelPosZ:(left1:ZZ)->(left2:ZZ)->(right:ZZ)->\n IsPositive right->(left1*right=left2*right)->(left1 = left2)\nmultRightCancelPosZ (Pos j) (Pos i) (Pos (S k)) Positive prf =\n cong (multRightCancel j i (S k) SIsNotZ expression) where\n expression = posInjective prf\nmultRightCancelPosZ (Pos _) (NegS _) (Pos (S _)) Positive Refl impossible\nmultRightCancelPosZ (NegS _) (Pos _) (Pos (S _)) Positive Refl impossible\nmultRightCancelPosZ (NegS j) (NegS i) (Pos (S k)) Positive prf =\n cong (succInjective j i (multRightCancel (S j) (S i) (S k) SIsNotZ expression)) where\n expression = posInjective (negativesSameNumbersSame prf)\n\n\n|||Right cancellation law for multiplication given a proof that right is not zero\nmultRightCancelZ:(left1:ZZ)->(left2:ZZ)->(right:ZZ)->\n NotZero right->(left1*right=left2*right)->(left1 = left2)\nmultRightCancelZ left1 left2 (Pos (S k)) PositiveZ prf =\n multRightCancelPosZ left1 left2 (Pos (S k)) Positive prf\nmultRightCancelZ left1 left2 (NegS k) NegativeZ prf =\n multRightCancelPosZ left1 left2 (-(NegS k)) Positive expression where\n expression = rewrite (multNegateRightZ left1 (NegS k)) in\n rewrite (multNegateRightZ left2 (NegS k)) in\n (numbersSameNegativesSame prf)\n|||Left Cancellation law for multiplication given a proof that left is not zero\nmultLeftCancelZ :(left : ZZ) -> (right1 : ZZ) -> (right2 : ZZ) ->\n NotZero left -> (left*right1 = left*right2) -> (right1 = right2)\nmultLeftCancelZ left right1 right2 x prf =\n multRightCancelZ right1 right2 left x expression where\n expression = rewrite (multCommutativeZ right1 left) in\n rewrite (multCommutativeZ right2 left) in\n prf\n\n|||Proof that (-a)*(-b) = a*b\nmultNegNegNeutralZ: (a:ZZ)->(b:ZZ)->(-a)*(-b)=a*b\nmultNegNegNeutralZ a b =\n rewrite multNegateRightZ (-a) b in\n rewrite multNegateLeftZ a b in\n rewrite doubleNegElim (a*b) in\n Refl\n\n|||The theorem that if a =r+q*b and g = (m1*b)+(n1*rem)\n|||Then g = (n1*a) + ((m1+n1*(-quot))*b)\nbezoutReplace:{a:ZZ}->{b:ZZ}->{m1:ZZ}->{rem:ZZ}->\n {quot:ZZ}->{n1:ZZ}->{g:ZZ}-> (a = rem + (quot *b))->\n (g=(m1*b)+(n1*rem))->(g = (n1*a) + ((m1+n1*(-quot))*b))\nbezoutReplace {a}{b}{m1}{rem}{quot}{n1}{g}prf prf1 =\n rewrite multDistributesOverPlusLeftZ m1 (n1*(-quot)) b in\n rewrite prf in\n rewrite multDistributesOverPlusRightZ n1 rem (quot*b) in\n rewrite (sym (plusAssociativeZ (n1*rem) (n1*((quot)*b)) ((m1*b)+((n1*(-quot))*b)))) in\n rewrite (plusCommutativeZ (m1*b) ((n1*(-quot))*b)) in\n rewrite (plusAssociativeZ (n1*((quot)*b)) ((n1*(-quot))*b) (m1*b)) in\n rewrite (multAssociativeZ n1 quot b) in\n rewrite (sym (multDistributesOverPlusLeftZ (n1*quot) (n1*(-quot)) b)) in\n rewrite (sym(multDistributesOverPlusRightZ n1 quot (-quot))) in\n rewrite (plusNegateInverseLZ quot) in\n rewrite (multZeroRightZeroZ n1) in\n rewrite (multZeroLeftZeroZ b) in\n rewrite (plusZeroLeftNeutralZ (m1*b)) in\n rewrite (plusCommutativeZ (n1*rem) (m1*b)) in\n prf1\n\n\nzeroNotNonZero: (NotZero (Pos Z)) -> Void\nzeroNotNonZero PositiveZ impossible\nzeroNotNonZero NegativeZ impossible\n\ndecZero: (a: ZZ) -> Dec (NotZero a)\ndecZero (Pos Z) = No zeroNotNonZero\ndecZero (Pos (S k)) = Yes (posThenNotZero Positive)\ndecZero (NegS k) = Yes (NegSThenNotZero Negative)\n\nnonZeroNotZero: (a: ZZ) -> ( (a = (Pos Z) ) -> Void) -> (NotZero a)\nnonZeroNotZero (Pos Z) f = void (f Refl)\nnonZeroNotZero (Pos (S k)) f = PositiveZ\nnonZeroNotZero (NegS k) f = NegativeZ\n\nnotNotZeroThenZero: ((NotZero c)->Void)->c= 0\nnotNotZeroThenZero {c = (Pos Z)} f = Refl\nnotNotZeroThenZero {c = (Pos (S k))} f = void ( f (PositiveZ))\nnotNotZeroThenZero {c = (NegS k)} f = void ( f (NegativeZ))\n\nnotZeroNonZero:(NotZero a)->(a=0->Void)\nnotZeroNonZero {a = (Pos (S _))} PositiveZ Refl impossible\nnotZeroNonZero {a = (NegS _)} NegativeZ Refl impossible\n\n\nZZSisNotZ: (k: Nat) -> ((Pos (S k))= (Pos Z)) -> Void\nZZSisNotZ _ Refl impossible\n\nZZNegisNotZ: (k: Nat) -> ((NegS k) = Pos Z) -> Void\nZZNegisNotZ _ Refl impossible\n\nnegZeroZero: (a: ZZ) -> (a = (Pos Z)) -> (negate a = (Pos Z))\nnegZeroZero (Pos Z) Refl = Refl\nnegZeroZero (Pos (S k)) prf = void ((ZZSisNotZ k) prf)\nnegZeroZero (NegS k) prf = void ((ZZNegisNotZ k) prf)\n\nnegNegSIsPos: (a: ZZ) -> (a = (NegS k)) -> (-a = (Pos (S k)))\nnegNegSIsPos (Pos k) Refl impossible\nnegNegSIsPos (NegS k) Refl = Refl\n\nnegPosIsNeg: (a: ZZ) -> (a = (Pos (S k))) -> (-a = (NegS k))\nnegPosIsNeg (Pos Z) Refl impossible\nnegPosIsNeg (Pos (S k)) Refl = Refl\nnegPosIsNeg (NegS k) Refl impossible\n\n|||The theorem (a=(b*c)) => ((-a)=((-b)*c)))\nmultNegateLeftIsNegateZ:(a:ZZ)->(b:ZZ)->(c:ZZ)->(a=(b*c))->((-a)=(-b)*c)\nmultNegateLeftIsNegateZ a b c prf = (rewrite (multNegateLeftZ b c) in ( numbersSameNegativesSame prf))\n\nquotproof1: {a: ZZ} -> {b: ZZ} -> {quot: ZZ} -> (a=quot*b) -> (-a = (-quot)*b)\nquotproof1 {a} {b} {quot} prf = (multNegateLeftIsNegateZ a quot b prf)\n\nquotproof2: {a: ZZ} -> {b: ZZ} -> {quot: ZZ} -> (a=quot*b) -> (a = (-quot)*(-b))\nquotproof2 {a} {b} {quot} prf = trans (prf) (sym (multNegNegNeutralZ (quot) (b)))\n\nquotproof3: {a: ZZ} -> {b: ZZ} -> {quot: ZZ} -> (a=quot*b) -> (-a = (quot)*(-b))\nquotproof3 {a} {b} {quot} prf = (multNegateRightIsNegateZ a quot b prf)\n\nQRproof1: (a:ZZ) -> (b: ZZ) -> (a = (Pos (S k))) -> (b= (Pos (S j))) -> (quot: ZZ ** a = (quot)*b) -> (nquot: ZZ ** -a=(nquot)*b)\nQRproof1 (Pos Z) b Refl Refl x impossible\nQRproof1 (Pos (S k)) (Pos Z) Refl Refl x impossible\nQRproof1 (Pos (S k)) (Pos (S j)) Refl Refl (quot ** pf) = ((-quot) ** quotproof1(pf))\nQRproof1 (Pos (S k)) (NegS j) Refl Refl x impossible\nQRproof1 (NegS k) b Refl Refl x impossible\n\nQRproof3: (a:ZZ) -> (b: ZZ) -> (a = (Pos (S k))) -> (b= (Pos (S j))) -> (quot: ZZ ** a = (quot)*b) -> (nquot: ZZ ** a=(nquot)*(-b))\nQRproof3 (Pos Z) b Refl Refl x impossible\nQRproof3 (Pos (S k)) (Pos Z) Refl Refl x impossible\nQRproof3 (Pos (S k)) (Pos (S j)) Refl Refl (quot ** pf) = ((-quot) ** quotproof2(pf))\nQRproof3 (Pos (S k)) (NegS j) Refl Refl x impossible\nQRproof3 (NegS k) b Refl Refl x impossible\n\nQRproof4: (a:ZZ) -> (b: ZZ) -> (a = (Pos (S k))) -> (b= (Pos (S j))) -> (quot: ZZ ** a = (quot)*b) -> (quot: ZZ ** (-a)=(quot)*(-b))\nQRproof4 (Pos Z) b Refl Refl x impossible\nQRproof4 (Pos (S k)) (Pos Z) Refl Refl x impossible\nQRproof4 (Pos (S k)) (Pos (S j)) Refl Refl (quot ** pf) = (quot ** quotproof3(pf))\nQRproof4 (Pos (S k)) (NegS j) Refl Refl x impossible\nQRproof4 (NegS k) b Refl Refl x impossible\n\n\nsuccIsPlusOneRight:{n:Nat}->(Pos (S n)) = (Pos n) +1\nsuccIsPlusOneRight {n} = rewrite plusCommutativeZ (Pos n) 1 in\n Refl\nsuccIsPlusOneLeft :{n:Nat}->(Pos (S n)) =1+ (Pos n)\nsuccIsPlusOneLeft = Refl\n\nsubSuccSuccNeutrtalZ: ((Pos k)=(Pos n)+(-(Pos m)))->((Pos k)=(Pos (S n))+(-(Pos (S m))))\nsubSuccSuccNeutrtalZ {n = n}{m = Z}{k = k} prf = rewrite sym $ plusZeroRightNeutralZ (Pos n) in prf\nsubSuccSuccNeutrtalZ {n = n}{m = (S j)}{k = k} prf = prf\n", "meta": {"hexsha": "e343e4009df6904314b6c206b93932048d0cb597", "size": 17922, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/ZZUtils.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/ZZUtils.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/ZZUtils.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": 45.2575757576, "max_line_length": 132, "alphanum_fraction": 0.6831826805, "num_tokens": 6315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7279121621723113}} {"text": "import Data.Vect\n\ntryIndex : Integer -> Vect n a -> Maybe a\ntryIndex {n} i xs = case integerToFin i n of\n Nothing => Nothing\n Just idx => Just $ index idx xs\n\nvecTake : (n : Nat) -> (vec : Vect (n + m) a) -> Vect n a\nvecTake Z vec = []\nvecTake (S k) (x :: xs) = x :: vecTake k xs\n\nsumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos xs ys = case integerToFin pos n of\n Nothing => Nothing\n Just idx => Just $ index idx xs + index idx ys\n", "meta": {"hexsha": "aa391bf6ba2d41c52f647ae64edb777e0bed19b4", "size": 586, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/TryIndex.idr", "max_stars_repo_name": "DimaSamoz/idris-book", "max_stars_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "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": "Chapter4/TryIndex.idr", "max_issues_repo_name": "DimaSamoz/idris-book", "max_issues_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "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": "Chapter4/TryIndex.idr", "max_forks_repo_name": "DimaSamoz/idris-book", "max_forks_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "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": 36.625, "max_line_length": 78, "alphanum_fraction": 0.5051194539, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7278818383609044}} {"text": "> module LocalEffect.Exception\n\n\n> import Effects\n> import Effect.Exception\n\n> import Nat.LTProperties\n> import BoundedNat.BoundedNat\n> import Sigma.Sigma\n> import Pairs.Operations\n\n\n> %default total\n\n> %access public export\n\n\n> ||| Parses a string for a Nat\n> parseNat : String -> { [EXCEPTION String] } Eff Nat\n> parseNat str\n> = if all (\\x => isDigit x) (unpack str)\n> then pure (cast {to = Nat} (cast {to = Int} str))\n> else raise \"Not a Nat!\"\n\n\n> ||| Parses a string for a bounded Nat\n> parseLTB : (b : Nat) -> String -> { [EXCEPTION String] } Eff (LTB b)\n> {-\n> parseLTB b str\n> = if all (\\x => isDigit x) (unpack str)\n> then let n = cast {to = Nat} (cast {to = Int} str) in\n> case (decLT n b) of\n> (Yes p) => pure (MkSigma n p)\n> (No _) => raise \"Out of bound!\"\n> else raise \"Not a Nat!\"\n> -}\n> parseLTB b str\n> = if all (\\x => isDigit x) (unpack str)\n> then let m = cast {to = Nat} (cast {to = Int} str) in\n> case (decLT m b) of\n> (Yes p) => pure (MkSigma m p)\n> (No _) => raise \"Out of bound!\"\n> else raise \"Not a Nat!\"\n\n\n> ||| Parses a string for an Int\n> parseInt : String -> { [EXCEPTION String] } Eff Int\n> parseInt str\n> = if all (\\x => isDigit x || x == '-') (unpack str)\n> then pure (cast {to = Int} str)\n> else raise \"Not an Int!\"\n", "meta": {"hexsha": "c49b60be6368f1635139eb05e69d27888f463bc3", "size": 1352, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "LocalEffect/Exception.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "LocalEffect/Exception.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "LocalEffect/Exception.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0, "max_line_length": 70, "alphanum_fraction": 0.5643491124, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7278818268630649}} {"text": "import Data.Vect\n\nallLengths : Vect len String -> Vect len Nat\nallLengths [] = []\nallLengths (x :: xs) = length x :: allLengths xs\n\ninsert : Ord elem =>\n (x : elem) -> (xsSorted : Vect k elem) -> Vect (S k) elem\ninsert x [] = [x]\ninsert x (y :: xs) = if x < y\n then x :: y :: xs\n else y :: insert x xs\n\ninsSort : Ord elem => Vect n elem -> Vect n elem\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insert x xsSorted\n", "meta": {"hexsha": "9b0ca2c1057c6b218d4632b17566cc3918d5669d", "size": 462, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/WordLength_vec.idr", "max_stars_repo_name": "raventid/coursera_learning", "max_stars_repo_head_hexsha": "115a03f08d30d8ba49f02c9692c289cbfb242358", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-28T09:26:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-28T09:26:00.000Z", "max_issues_repo_path": "idris/WordLength_vec.idr", "max_issues_repo_name": "raventid/coursera_learning", "max_issues_repo_head_hexsha": "115a03f08d30d8ba49f02c9692c289cbfb242358", "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": "idris/WordLength_vec.idr", "max_forks_repo_name": "raventid/coursera_learning", "max_forks_repo_head_hexsha": "115a03f08d30d8ba49f02c9692c289cbfb242358", "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": 25.6666666667, "max_line_length": 59, "alphanum_fraction": 0.5714285714, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7275281716640211}} {"text": "import Data.Vect\n\nremoveElem : (value : a) ->\n (xs : Vect (S n) a) ->\n (prf : Elem value xs) ->\n Vect n a\nremoveElem value (value :: ys) Here = ys\nremoveElem {n = Z} value (y :: []) (There later) = absurd later\nremoveElem {n = (S k)} value (y :: ys) (There later)\n = y :: removeElem value ys later\n", "meta": {"hexsha": "ea5ed443a141c3039b679227124eb325baf2ca4d", "size": 375, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp9/RemoveElem.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp9/RemoveElem.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp9/RemoveElem.idr", "max_forks_repo_name": "Ryxai/idris_book_notes", "max_forks_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": 34.0909090909, "max_line_length": 74, "alphanum_fraction": 0.48, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.7272915898526412}} {"text": "module Problem1\n\nimport Common.Lte\n\n%default total\n\nDecr : (Nat -> Nat) -> Type\nDecr f = (x : Nat) -> LTE (f (S x)) (f x)\n\nValley : (Nat -> Nat) -> Nat -> Nat -> Type\nValley f n x = (y : Nat) -> LTE x y -> LTE y (n+x) -> f y = f x\n\ndecrN : (n : Nat) -> (f : Nat -> Nat) -> Decr f -> (x : Nat) ->\n LTE (f (n + x)) (f x)\ndecrN Z f decr x = lteRefl\ndecrN (S n') f decr x =\n let ind = decrN n' f decr x\n decrLte = decr (n' + x)\n in lteTransitive decrLte ind\n\nboundedAbove : (decr : Decr f) -> (a : Nat) -> (x : Nat) -> LTE a x ->\n LTE (f x) (f a)\nboundedAbove decr a x lte =\n case splitLte lte of\n (Left eq) => rewrite eq in lteRefl\n (Right lt) =>\n let S x' = x\n lte' = fromLteSucc lt\n ind = boundedAbove decr a x' lte'\n in decr x' `lteTransitive` ind\n\nboundedBelow : (n : Nat) -> (decr : Decr f) ->\n (a : Nat) -> (x : Nat) -> LTE x (n + a) ->\n LTE (f (n + a)) (f x)\nboundedBelow Z decr a x lte = boundedAbove decr x a lte\nboundedBelow n@(S n') decr a x lte =\n case splitLte lte of\n (Left eq) => boundedAbove decr x (S (n' + a)) lte\n (Right lt) =>\n let ind = boundedBelow n' decr a x (fromLteSucc lt)\n in decr (n' + a) `lteTransitive` ind\n\nmkValley : (n : Nat) -> (f : Nat -> Nat) -> (decr : Decr f) ->\n (x : Nat) -> f x = f (n + x) ->\n (y : Nat) -> LTE x y -> LTE y (n + x) -> f y = f x\nmkValley n f decr x prf y lteL lteU =\n let u = boundedAbove decr x y lteL\n l = boundedBelow n decr x y lteU\n in tightBound u (rewrite prf in l)\n\ndecrValley_rec : (n : Nat) -> (f : Nat -> Nat) -> (decr : Decr f) ->\n (x : Nat) -> (bound : Nat) -> (boundLte : LTE (f x) bound) ->\n (a : Nat ** Valley f n a)\ndecrValley_rec n f decr x Z boundLte =\n let boundLteN = decrN n f decr x\n boundLteN' = lteTransitive boundLteN boundLte\n xEqZ = lteZeqZ boundLte\n xNEqZ = lteZeqZ boundLteN'\n xEqNx = xEqZ `trans` sym xNEqZ\n in (x ** mkValley n f decr x xEqNx)\n\ndecrValley_rec n f decr x bound@(S bound') boundLte =\n case splitLte boundLte of\n (Right (LTESucc boundLte')) => decrValley_rec n f decr x bound' boundLte'\n (Left boundEq) =>\n let boundLteN = decrN n f decr x\n in case splitLte boundLteN of\n (Right boundLtN) =>\n let boundLteN' = fromLteSucc (boundLtN `lteTransitive` boundLte)\n in decrValley_rec n f decr (n + x) bound' boundLteN'\n (Left boundEqN) => (x ** mkValley n f decr x (sym boundEqN))\n\ndecrValley : (n : Nat) -> (f : Nat -> Nat) -> Decr f -> (x : Nat ** Valley f n x)\ndecrValley n f decr = decrValley_rec n f decr Z (f Z) lteRefl\n", "meta": {"hexsha": "06eddf15141f3f4329c732281785d234baee529f", "size": 2681, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Problem1.idr", "max_stars_repo_name": "farrellm/dailyprover", "max_stars_repo_head_hexsha": "f7416a9323b9219b6a2e8463b9d150e13d51b4f0", "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/Problem1.idr", "max_issues_repo_name": "farrellm/dailyprover", "max_issues_repo_head_hexsha": "f7416a9323b9219b6a2e8463b9d150e13d51b4f0", "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/Problem1.idr", "max_forks_repo_name": "farrellm/dailyprover", "max_forks_repo_head_hexsha": "f7416a9323b9219b6a2e8463b9d150e13d51b4f0", "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": 35.7466666667, "max_line_length": 81, "alphanum_fraction": 0.5475568818, "num_tokens": 1019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7269741203942603}} {"text": "> module SequentialDecisionProblems.applications.GoodBad\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Sigma.Sigma\n\n> %default total\n> %auto_implicits off\n> %access public export\n\n\n* Good / Bad options:\n\n> data GoodBad = Good | Bad \n\n\n* |GoodBad| is finite and non-empty:\n\n> to : GoodBad -> Fin 2\n> to Good = FZ\n> to Bad = FS FZ\n\n> from : Fin 2 -> GoodBad\n> from FZ = Good\n> from (FS FZ) = Bad\n> from (FS (FS k)) = absurd k\n\n> toFrom : (k : Fin 2) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS FZ) = Refl\n> toFrom (FS (FS k)) = absurd k\n\n> fromTo : (a : GoodBad) -> from (to a) = a\n> fromTo Good = Refl\n> fromTo Bad = Refl\n\n> ||| \n> finiteGoodBad : Finite GoodBad\n> finiteGoodBad = MkSigma 2 (MkIso to from toFrom fromTo)\n\n> |||\n> cardNotZGoodBad : CardNotZ finiteGoodBad\n> cardNotZGoodBad = cardNotZLemma finiteGoodBad Good\n\n\n* |GoodBad| is in |DecEq|:\n\n> goodNotBad : Good = Bad -> Void\n> goodNotBad Refl impossible\n\n> implementation [DecEqGoodBad] DecEq GoodBad where\n> decEq Good Good = Yes Refl\n> decEq Good Bad = No goodNotBad\n> decEq Bad Good = No (negEqSym goodNotBad)\n> decEq Bad Bad = Yes Refl\n\n\n* |GoodBad| is in |Eq|:\n\n> implementation Eq GoodBad where\n> (==) Good Good = True\n> (==) Good Bad = False\n> (==) Bad Good = False\n> (==) Bad Bad = True\n\n\n> {-\n\n> ---}\n\n\n \n", "meta": {"hexsha": "d951db6632f0a02c8823a87f80d82b440dbcc9c5", "size": 1462, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/GoodBad.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/applications/GoodBad.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/applications/GoodBad.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.987012987, "max_line_length": 57, "alphanum_fraction": 0.6190150479, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7268010096671873}} {"text": "module Pred\n\nimport Data.Vect\n\n\nmaryInVector : Elem \"Prat\" [\"Peter\", \"Paul\", \"Prat\"]\nmaryInVector = There $ There Here\n\nexport\nremoveElem : (value : a) ->\n (xs : Vect (S n) a) ->\n (prf : Elem value xs) ->\n Vect n a\nremoveElem value (value :: ys) Here = ys\nremoveElem {n = Z} value (y :: []) (There later) = absurd later\nremoveElem {n = (S k)} value (y :: ys) (There later) = y :: removeElem value ys later\n\n-- absurd : Uninhabited t => t -> a\n\nremoveElem_auto : (value : a) ->\n (xs : Vect (S n) a) ->\n {auto prf : Elem value xs} ->\n Vect n a\nremoveElem_auto value xs {prf} = removeElem value xs prf\n\n\n-- data Elem : a -> Vect k a -> Type where\n-- Here : Elem x (x :: xs)\n-- There : (later : Elem x xs) -> Elem x (y :: xs)\n\n\nnot_in_nil : Elem value [] -> Void\nnot_in_nil Here impossible\nnot_in_nil (There _) impossible\n\n\nnot_in_tail : (notThere : Elem value xs -> Void) ->\n (notHere : (value = x) -> Void) ->\n Elem value (x :: xs) -> Void\nnot_in_tail notThere notHere Here = notHere Refl\nnot_in_tail notThere notHere (There later) = notThere later\n\n\nisElem : DecEq a => (value : a) -> (xs : Vect n a) -> Dec (Elem value xs)\nisElem value [] = No not_in_nil\nisElem value (x :: xs) = case decEq value x of\n Yes Refl => Yes Here\n No notHere => case Pred.isElem value xs of\n Yes prf => Yes (There prf)\n No notThere => No (not_in_tail notThere notHere)\n", "meta": {"hexsha": "95380d0855fb1d3093d0bedc11cf7a83fc8bce11", "size": 1608, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "9-pred/pred.idr", "max_stars_repo_name": "prt2121/tdd-playground", "max_stars_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "9-pred/pred.idr", "max_issues_repo_name": "prt2121/tdd-playground", "max_issues_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": "9-pred/pred.idr", "max_forks_repo_name": "prt2121/tdd-playground", "max_forks_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": 31.5294117647, "max_line_length": 97, "alphanum_fraction": 0.5348258706, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7266163309856708}} {"text": "||| Rational number\n||| \n||| Copyright 2021, HATTORI, Hiroki\n||| This file is released under the MIT license, see LICENSE for more detail.\n||| \nmodule Data.Rational\n\nimport Data.Maybe\nimport Data.Integral.Gcd\n\nimport Generics.Derive\n\n%default total\n%language ElabReflection\n\n-- --------------------------------------------------------------------------\n\npublic export\nrecord Rational where\n constructor MkRational\n num : Integer\n den : Nat\n%runElab derive \"Rational\" [Generic, Eq, DecEq]\n\nexport infinity : Rational\ninfinity = MkRational 0 0\n\nexport isInfinity : Rational -> Bool\nisInfinity x = x.den == 0\n\n\n-- --------------------------------------------------------------------------\n\nexport reduce : (num:Integer) -> (den:Nat) -> Rational\nreduce x y =\n let d = gcd x $ natToInteger y\n in MkRational (x `div` d) (fromInteger $ (natToInteger y) `div` d)\n\ninfixr 9 %:\n\npublic export\n(%:) : (num:Integer) -> (den:Integer) -> Rational\n(%:) num den =\n if den >= 0\n then reduce num $ fromInteger den\n else reduce (negate num) (fromInteger $ negate den)\n\n-- --------------------------------------------------------------------------\n\npublic export Show Rational where show x = show x.num ++ \" %: \" ++ show x.den\n\npublic export\nOrd Rational where\n compare x y = let x' = x.num * natToInteger y.den\n y' = y.num * natToInteger x.den\n in compare x' y'\n\npublic export Cast Integer Rational where cast x = MkRational x 1\nCast ty Integer => Cast ty Rational where cast x = MkRational (cast x) 1\n\n\npublic export\nNum Rational where\n x + y = reduce (x.num * natToInteger y.den + y.num * natToInteger x.den) (x.den * y.den)\n x * y = reduce (x.num * y.num) (x.den * y.den)\n fromInteger x = MkRational x 1\n\npublic export\nNeg Rational where\n negate x = MkRational (negate x.num) x.den\n x - y = reduce (x.num * natToInteger y.den - x.num * natToInteger x.den) (x.den * y.den)\n\npublic export\nAbs Rational where\n abs x = MkRational (abs x.num) x.den\n -- signum x = MkRational (signum x.num) 1\n\n\npublic export\nFractional Rational where\n x / y = (x.num * natToInteger y.den) %: (y.num * natToInteger x.den)\n recip x = (natToInteger x.den) %: (fromInteger x.num)\n\n-- --------------------------------------------------------------------------\n\nexport floor : Rational -> Maybe Integer\nfloor x = toMaybe (x.den /= 0) $ x.num `div` (natToInteger x.den)\n\nexport ceil : Rational -> Maybe Integer\nceil x = floor $ MkRational (x.num + (natToInteger x.den) - 1) x.den\n\n-- --------------------------------------------------------------------------\n-- vim: tw=80 sw=2 expandtab :", "meta": {"hexsha": "43f897267e65da77ed5a1e0bec5a0d07a027808c", "size": 2605, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2-missing-numeric/src/Data/Rational.idr", "max_stars_repo_name": "seagull-kamome/idris2-missing", "max_stars_repo_head_hexsha": "ef0355d0ce0a7381e30b752e25c0aa6319f7a81a", "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": "idris2-missing-numeric/src/Data/Rational.idr", "max_issues_repo_name": "seagull-kamome/idris2-missing", "max_issues_repo_head_hexsha": "ef0355d0ce0a7381e30b752e25c0aa6319f7a81a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-02-03T11:05:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-01T12:42:01.000Z", "max_forks_repo_path": "idris2-missing-numeric/src/Data/Rational.idr", "max_forks_repo_name": "seagull-kamome/idris2-missing", "max_forks_repo_head_hexsha": "ef0355d0ce0a7381e30b752e25c0aa6319f7a81a", "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.0107526882, "max_line_length": 90, "alphanum_fraction": 0.5712092131, "num_tokens": 688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7265580495009235}} {"text": "module Main\n\n{-\nTo write these functions in vim:\n\n\\d to make a template definition\n\\c over a variable to do case analysis on that variable\n\\o to fill in a hole with the 'obvious' value\n\n-}\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n%name Vect xs,ys,zs\n\nappend : Vect n a -> Vect m a -> Vect (n + m) a\n\n{-\nTry to write this using the interactive tools alone:\n\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n-}\n\nvZipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\n\n\n{-\nTry to write this using the interactive tools alone:\n\nvZipWith f [] [] = []\nvZipWith f (x :: xs) (y :: ys) = f x y :: vZipWith f xs ys\n-}\n\n\n", "meta": {"hexsha": "e6268372f2ae5c3cb4d97a4849b5a6592940e5d3", "size": 687, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Intro/Vect.idr", "max_stars_repo_name": "idris-hackers/idris-demos", "max_stars_repo_head_hexsha": "356a5aa1dbd43f869b0eebd8b8fec15f790cc0dc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 132, "max_stars_repo_stars_event_min_datetime": "2016-01-25T22:35:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T17:23:06.000Z", "max_issues_repo_path": "Intro/Vect.idr", "max_issues_repo_name": "idris-hackers/idris-demos", "max_issues_repo_head_hexsha": "356a5aa1dbd43f869b0eebd8b8fec15f790cc0dc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-05-18T03:40:01.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-07T12:21:55.000Z", "max_forks_repo_path": "Intro/Vect.idr", "max_forks_repo_name": "idris-hackers/idris-demos", "max_forks_repo_head_hexsha": "356a5aa1dbd43f869b0eebd8b8fec15f790cc0dc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-10-25T07:58:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-08T19:22:51.000Z", "avg_line_length": 18.0789473684, "max_line_length": 60, "alphanum_fraction": 0.5997088792, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7263928220940951}} {"text": "module Algebraic\n\n-- Example functions\n\nor : Bool -> Bool -> Bool\nor p q = p || q\n\nxor : Bool -> Bool -> Bool\nxor p q = (p || q) && not (p && q)\n\n-- Idempotency\n\nIdempotent : (a -> a) -> a -> Type\nIdempotent f a = f (f a) = f a\n\n-- Involution\n\nnotNotTrue : not (not True) = True\nnotNotTrue = ?notNotTrue\n\nnotNotFalse : not (not False) = False\nnotNotFalse = ?notNotFalse\n\nnotNot : (b : Bool) -> not (not b) = b\nnotNot b = ?notNot\n\nInvolution : (a -> a) -> a -> Type\nInvolution f a = f (f a) = a\n\nxorInvolution : (a : Bool) -> (b : Bool) -> Involution (xor a) b\nxorInvolution a b = ?xorInvolution\n\n-- Uninhabited\n\nnotNotIdempotent : (b : Bool) -> Idempotent not b -> Void\nnotNotIdempotent b prf = ?notNotIdempotent\n\nsuccNotIdempotent : (n : Nat) -> Idempotent S n -> Void\nsuccNotIdempotent n prf = ?succNotIdempotent\n\n-- Both\n\nidempotentInvolution : Idempotent f a -> Involution f a -> f a = a\nidempotentInvolution idem invo = ?idempotentInvolution\n", "meta": {"hexsha": "633d1770aabe6ff9c482f46189cff495d3afac3c", "size": 947, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "speakers/puffnfresh/Algebraic.idr", "max_stars_repo_name": "jamondouglas/lamdaconf2015", "max_stars_repo_head_hexsha": "8363906b10285f78448387ee067fc81542dc9ea1", "max_stars_repo_licenses": ["Artistic-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "speakers/puffnfresh/Algebraic.idr", "max_issues_repo_name": "jamondouglas/lamdaconf2015", "max_issues_repo_head_hexsha": "8363906b10285f78448387ee067fc81542dc9ea1", "max_issues_repo_licenses": ["Artistic-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": "speakers/puffnfresh/Algebraic.idr", "max_forks_repo_name": "jamondouglas/lamdaconf2015", "max_forks_repo_head_hexsha": "8363906b10285f78448387ee067fc81542dc9ea1", "max_forks_repo_licenses": ["Artistic-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.0444444444, "max_line_length": 66, "alphanum_fraction": 0.651531151, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075744568837, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7263094322414025}} {"text": "square_root_approx : (number : Double) -> (approx : Double) -> Stream Double\nsquare_root_approx number approx =\n let next = (approx + (number / approx)) / 2\n in approx :: Delay (square_root_approx number next)\n\nsquare_root_bound : (max : Nat) -> (number : Double) -> (bound : Double) ->\n (approxs : Stream Double) -> Double\nsquare_root_bound Z number bound (approx :: approxs) = approx\nsquare_root_bound (S k) number bound (approx :: approxs)\n = if (within_bound number bound approx)\n then approx\n else square_root_bound k number bound approxs\n where\n within_bound : (number : Double) -> (bound : Double) -> (approx : Double) -> Bool\n within_bound number bound approx = abs((approx * approx) - number) < bound\n\nsquare_root : (number : Double) -> Double\nsquare_root number = square_root_bound 100 number 0.0000000001\n (square_root_approx number number)\n", "meta": {"hexsha": "8a837de9e1a49c6a724baa8140651e692ba7ccd0", "size": 925, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-11/square_root.idr", "max_stars_repo_name": "tekerson/type-driven-development", "max_stars_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-23T04:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-23T04:46:42.000Z", "max_issues_repo_path": "Chapter-11/square_root.idr", "max_issues_repo_name": "tekerson/type-driven-development", "max_issues_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": "Chapter-11/square_root.idr", "max_forks_repo_name": "tekerson/type-driven-development", "max_forks_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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.25, "max_line_length": 85, "alphanum_fraction": 0.6681081081, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.7261477612448238}} {"text": "import Data.List\n\ndata SplitList : List a -> Type where\n SplitNil : SplitList []\n SplitOne : SplitList [x]\n SplitPair : (lefts : List a) -> (rights : List a) ->\n SplitList (lefts ++ rights)\n\ntotal\nsplitList : (xs : List a) -> SplitList xs\nsplitList xs = splitListHelp xs xs\n where\n splitListHelp : (counter : List a) -> (xs : List a) -> SplitList xs\n splitListHelp _ [] = SplitNil\n splitListHelp _ [x] = SplitOne\n splitListHelp (_ :: _ :: ys) (x :: xs)\n = case splitListHelp ys xs of\n SplitNil => SplitOne\n SplitOne {x=y} => SplitPair [x] [y]\n SplitPair lefts rights => SplitPair (x :: lefts) rights\n splitListHelp _ xs = SplitPair [] xs\n\nmergeSort : Ord a => List a -> List a\nmergeSort input with (splitList input)\n mergeSort [] | SplitNil = []\n mergeSort [x] | SplitOne = [x]\n mergeSort (lefts ++ rights) | (SplitPair lefts rights)\n = merge (mergeSort lefts) (mergeSort rights)\n", "meta": {"hexsha": "19c3ca2377dd1fd2be57357d497813b6c836a951", "size": 981, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter10/MergeSort.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/typedd-book/chapter10/MergeSort.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/typedd-book/chapter10/MergeSort.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": 33.8275862069, "max_line_length": 71, "alphanum_fraction": 0.6034658512, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7259479113576555}} {"text": "\n------------- Example 1 ----------------\nnatInjective : (x, y : Nat) -> S x === S y -> x === y\nnatInjective x x Refl = Refl\n\nsuccNotZero : (x : Nat) -> Not (S x === Z)\nsuccNotZero x Refl impossible\n\npeanoNat : (a : Type\n ** n0 : a\n ** ns : a -> a\n ** inj : ((x, y : a) -> ns x === ns y -> x === y)\n ** (x : a) -> Not (ns x === n0))\npeanoNat = MkDPair\n Nat\n $ MkDPair\n Z\n $ MkDPair -- {a = Nat -> Nat}\n S\n $ MkDPair\n natInjective\n succNotZero\n\n------------- Example 2 ----------------\nac : forall r. ((x : a) -> (y : b ** r x y)) -> (f : a -> b ** (x : a) -> r x (f x))\nac g = (\\x => fst (g x) ** \\x => snd (g x))\n\n------------- Example 3 ----------------\nidid1 : forall A. (f : A -> A ** (x : A) -> f x = x)\nidid1 = MkDPair id (\\x => Refl)\n\n", "meta": {"hexsha": "f93b0ffffd4ee60b7295c8d393d4f3cb4117bfc9", "size": 863, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/reg046/Postpone.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "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": "tests/idris2/reg046/Postpone.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "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": "tests/idris2/reg046/Postpone.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "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": 26.96875, "max_line_length": 84, "alphanum_fraction": 0.359212051, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7257508270056064}} {"text": "import Data.Vect\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\n\n-- This is just zipWith (::)\ntransposeHelper : (x : Vect n elem) ->\n (xsTrans : Vect n (Vect len elem)) ->\n Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\n\ntransposeMat : Vect m (Vect n elem) ->\n Vect n (Vect m elem)\ntransposeMat [] = replicate _ []\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n zipWith (::) x xsTrans\n\n\n-- Exercise 3.3.2\naddMatrix : Num numType =>\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (+) x y :: addMatrix xs ys\n\n\n-- Exercise 3.3.3\n-- check: multMatrix [[1,2], [3,4], [5,6]] [[7,8,9.10], [11,12,13,14]]\n-- equals: [[29, 32,,,], [65,,,],,,]\nmultMatrix : Num numType =>\n Vect n (Vect m numType) ->\n Vect m (Vect p numType) ->\n Vect n (Vect p numType)\nmultMatrix xs ys = ?multMatrix_rhs1 xs (transposeMat ys)\n", "meta": {"hexsha": "a6435f46f36800a3281930befa1ac3422712c561", "size": 1169, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Matrix.idr", "max_stars_repo_name": "defndaines/idris-bits", "max_stars_repo_head_hexsha": "a940e4de7306a4cc1c5a53ce90945aa6048d7245", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matrix.idr", "max_issues_repo_name": "defndaines/idris-bits", "max_issues_repo_head_hexsha": "a940e4de7306a4cc1c5a53ce90945aa6048d7245", "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": "Matrix.idr", "max_forks_repo_name": "defndaines/idris-bits", "max_forks_repo_head_hexsha": "a940e4de7306a4cc1c5a53ce90945aa6048d7245", "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": 29.9743589744, "max_line_length": 71, "alphanum_fraction": 0.5466210436, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.725418794787645}} {"text": "module Sort\n\nSmaller : Nat -> Nat -> Nat\nSmaller Z n = Z\nSmaller m Z = Z\nSmaller (S m) (S n) = (S (Smaller m n))\n\nMin : (m: Nat) -> (n: Nat) -> Either (LTE m n) (LTE n m)\nMin Z n = Left LTEZero\nMin m Z = Right LTEZero\nMin (S a) (S b) = case (Min a b) of\n (Left l) => Left (LTESucc l)\n (Right r) => Right (LTESucc r)\n\nInsert: (n: Nat) -> List Nat -> List Nat\nInsert n [] = [n]\nInsert n (x :: xs) = case (Min n x) of\n (Left l) => ([n] ++ [x]) ++ xs\n (Right r) => [x] ++ (Insert n xs)\n\n\nSort: List Nat -> List Nat\nSort [] = []\nSort (x :: xs) = Insert x (Sort xs)\n", "meta": {"hexsha": "4b4bddd54327195b7b18d0a85cc27cf340b9e54c", "size": 652, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Assignments/InsertionSort.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": "_local-site/Assignments/InsertionSort.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": "_local-site/Assignments/InsertionSort.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": 26.08, "max_line_length": 57, "alphanum_fraction": 0.4616564417, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067276593032, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.7248632925605035}} {"text": "data SnocList : List a -> Type where\n Empty : SnocList []\n Snoc : (rec : SnocList xs) -> SnocList (xs ++ [x])\n\nsnocListHelper : (snoc : SnocList input) -> (rest : List a) -> SnocList (input ++ rest)\nsnocListHelper {input} snoc [] = rewrite appendNilRightNeutral input in snoc\nsnocListHelper {input} snoc (x :: xs) =\n rewrite appendAssociative input [x] xs in\n snocListHelper (Snoc snoc {x}) xs\n\nsnocList : (xs : List a) -> SnocList xs\nsnocList xs = snocListHelper Empty xs\n\nmyReverseHelper : (input : List a) -> SnocList input -> List a\nmyReverseHelper [] Empty = []\nmyReverseHelper (xs ++ [x]) (Snoc rec) = x :: myReverseHelper xs rec\n\nmyReverse : List a -> List a\nmyReverse input with (snocList input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (Snoc rec) = x :: myReverse xs | rec\n\nisSuffix : Eq a => List a -> List a -> Bool\nisSuffix input1 input2 with (snocList input1)\n isSuffix [] input2 | Empty = True\n isSuffix (xs ++ [x]) input2 | (Snoc xsrec) with (snocList input2)\n isSuffix (xs ++ [x]) [] | (Snoc xsrec) | Empty = False\n isSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec) =\n if x == y then isSuffix xs ys | xsrec | ysrec\n else False\n", "meta": {"hexsha": "468464bd8c7ce8499ad9883d656e370f88818922", "size": 1211, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/SnocList.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/SnocList.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/SnocList.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": 39.064516129, "max_line_length": 87, "alphanum_fraction": 0.6317093311, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7245450448328069}} {"text": "import Data.Nat.Views\n\ntoBinary : Nat -> String\ntoBinary k with (halfRec k)\n toBinary Z | HalfRecZ = \"\"\n toBinary (n + n) | (HalfRecEven rec) = (toBinary n | rec) ++ \"0\"\n toBinary (S (n + n)) | (HalfRecOdd rec) = (toBinary n | rec) ++ \"1\"\n", "meta": {"hexsha": "9b1804f57bc0273a161c6f2fc6f2d62fb5be9ac4", "size": 242, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/to_binary.idr", "max_stars_repo_name": "tekerson/type-driven-development", "max_stars_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-23T04:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-23T04:46:42.000Z", "max_issues_repo_path": "Chapter-10/to_binary.idr", "max_issues_repo_name": "tekerson/type-driven-development", "max_issues_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": "Chapter-10/to_binary.idr", "max_forks_repo_name": "tekerson/type-driven-development", "max_forks_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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.25, "max_line_length": 69, "alphanum_fraction": 0.6074380165, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172615983309, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7244829221867267}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 10\n\nimport Data.Vect\nimport Data.List.Views\nimport Data.Vect.Views\nimport Data.Nat.Views\n\n-- check that all functions are total\n%default total\n\n--\n-- section 10.1\n--\n\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ xs)\n\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z xs = Exact []\ntakeN (S k) [] = Fewer\ntakeN (S k) (x :: xs) = case takeN k xs of\n Fewer => Fewer\n (Exact n_xs) => Exact (x :: n_xs)\n\n-- more explicit using `with`\ntakeN' : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN' Z xs = Exact []\ntakeN' (S k) [] = Fewer\ntakeN' (S k) (x :: xs) with (takeN' k xs)\n takeN' (S k) (x :: xs) | Fewer = Fewer\n takeN' (S k) (x :: (n_xs ++ ys)) | (Exact n_xs) = Exact (x :: n_xs)\n\npartial\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\npartial\ngroupByN' : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN' n xs with (takeN' n xs)\n groupByN' n xs | Fewer = [xs]\n groupByN' n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN' n rest\n\npartial\nhalves : List a -> (List a, List a)\nhalves xs with (takeN (length xs `div` 2) xs)\n halves xs | Fewer = (xs, [])\n halves (n_xs ++ ys) | (Exact n_xs) = (n_xs, ys)\n\n--\n-- section 10.2\n--\n\nequalSuffix : Eq a => List a -> List a -> List a\nequalSuffix input1 input2 with (snocList input1)\n equalSuffix [] input2 | Empty = []\n equalSuffix (xs ++ [x]) input2 | (Snoc xsrec) with (snocList input2)\n equalSuffix (xs ++ [x]) [] | (Snoc xsrec) | Empty = []\n equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec)\n = if x == y then (equalSuffix xs ys | xsrec | ysrec) ++ [x]\n else []\n\nmergeSortVect : Ord a => Vect n a -> Vect n a\nmergeSortVect xs with (splitRec xs)\n mergeSortVect [] | SplitRecNil = []\n mergeSortVect [x] | SplitRecOne = [x]\n mergeSortVect (lefts ++ rights) | (SplitRecPair lrec rrec)\n = merge (mergeSortVect lefts | lrec)\n (mergeSortVect rights | rrec)\n\ntoBinary : Nat -> String\ntoBinary k with (halfRec k)\n toBinary Z | HalfRecZ = \"\"\n toBinary (n + n) | (HalfRecEven rec) = (toBinary n | rec) ++ \"0\"\n toBinary (S (n + n)) | (HalfRecOdd rec) = (toBinary n | rec) ++ \"1\"\n\n-- needed due to lazy argument of HalfRec\n-- use :exec toBinaryMain $ toBinary 42\ntoBinaryMain : Nat -> IO ()\ntoBinaryMain k = do putStrLn $ toBinary k\n\npalindrome : Eq a => List a -> Bool\npalindrome xs with (vList xs)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (x :: (ys ++ [y])) | (VCons rec)\n = (x == y) && palindrome ys | rec\n\n--\n-- section 10.3 (exercises)\n-- see DataStore.idr and TestStore.idr\n-- see Shape.idr and TestShape.idr\n--\n", "meta": {"hexsha": "7e820f157b068d79cb1b47cdeb78f7c2be11c912", "size": 2874, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter10/exercises.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": "chapter10/exercises.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": "chapter10/exercises.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": 29.6288659794, "max_line_length": 70, "alphanum_fraction": 0.5922059847, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7243940934937178}} {"text": "{-\n(+) : Nat -> Nat -> Nat\n Z + y = y\n(S k) + y = S(k+y)\n -}\n \n total\nascLaw : (a:Nat) -> (b:Nat) -> (c:Nat) -> (a + (b+c)) = ((a+b)+c)\n{- normal form of LHS: Z+(Z+c) = Z+c = c; \n Normal form of RHS: (Z+Z)+c = Z+c=c;\n so {c=c}=Refl proves it. -}\nascLaw Z Z c = Refl\n \n{-LHS: Z + ((S k)+ c) = Z+( S( k+c))=Z+(S (k+c)) = S (k+c), \n RHS: (Z+(S k)) + c = (S k)+c = S(k+c). Again Refl. -}\nascLaw Z (S k) c = Refl\n \n{- So now we have covered Z+(b + c) = (Z+b)+c, now change Z to S j -}\n{- normal form of LHS: (S j)+(b+c) = S(j +(b+c)); \n normal form of RHS: ((S j)+b)+c = S(j+b) +c= S ( (j+b)+c);\n NOT THE SAME, but we can induct on j+(b+c)=(j+b)+c and then\n Apply S to both sides. Applying S to both side of and equation is \n Done by “cong” -}\nascLaw (S j) b c = cong (ascLaw j b c)\n\n\ntotal cmLaw : (a:Nat) -> (b:Nat) -> (a+b) = (b+a)\ncmLaw Z Z = Refl\ncmLaw Z (S k) = cong {f=S} (left_id k) where\n left_id : (j:Nat) -> j = j+0\n left_id Z = Refl\n left_id (S d) = cong {f=S} (left_id d)\ncmLaw (S j) b = rewrite sucMove b j in cong {f=S} (cmLaw j b) where\n sucMove : (j:Nat) -> (k:Nat) -> j + (S k) = S(j+k)\n sucMove Z k = Refl\n sucMove (S j) k = cong {f=S} (sucMove j k)\n \n", "meta": {"hexsha": "7afab5380fd652a093a6c8fd2114f80ebc924750", "size": 1218, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/test-asc.idr", "max_stars_repo_name": "algeboy/BlackBoxType", "max_stars_repo_head_hexsha": "f8a7163086185953ef1dcc9216ee7a189f44b7ab", "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/test-asc.idr", "max_issues_repo_name": "algeboy/BlackBoxType", "max_issues_repo_head_hexsha": "f8a7163086185953ef1dcc9216ee7a189f44b7ab", "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/test-asc.idr", "max_forks_repo_name": "algeboy/BlackBoxType", "max_forks_repo_head_hexsha": "f8a7163086185953ef1dcc9216ee7a189f44b7ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-30T23:33:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-30T23:33:41.000Z", "avg_line_length": 32.0526315789, "max_line_length": 71, "alphanum_fraction": 0.4885057471, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7241427622879167}} {"text": "{- 1 -}\n\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN Z xs = Exact []\ntakeN (S k) [] = Fewer\ntakeN (S k) (x :: xs) with (takeN k xs)\n takeN (S k) (x :: xs) | Fewer = Fewer\n takeN (S k) (x :: (n_xs ++ rest)) | Exact _ = Exact (x :: n_xs)\n\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\n{- 2 -}\n\nhalves : List a -> (List a, List a)\nhalves input with (takeN (length input `div` 2) input)\n halves input | Fewer = (input, [])\n halves (n_xs ++ rest) | (Exact n_xs) = (n_xs, rest)\n", "meta": {"hexsha": "2e73e78179ff1659766c0595895c0965c6bdd9c6", "size": 737, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter10/Exercises/ex_10_1.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 161, "max_stars_repo_stars_event_min_datetime": "2017-02-27T02:28:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T22:17:47.000Z", "max_issues_repo_path": "Chapter10/Exercises/ex_10_1.idr", "max_issues_repo_name": "gdevanla/TypeDD-Samples", "max_issues_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2017-03-26T23:27:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:32:25.000Z", "max_forks_repo_path": "Chapter10/Exercises/ex_10_1.idr", "max_forks_repo_name": "gdevanla/TypeDD-Samples", "max_forks_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-03-19T11:01:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-10T05:30:22.000Z", "avg_line_length": 29.48, "max_line_length": 68, "alphanum_fraction": 0.5576662144, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7232911279493193}} {"text": "-- Find the sum of all the multiples of 3 or 5 below 1000.\n\nisMultiple : Int -> Int -> Bool\nisMultiple n m = (mod n m) == 0\n\nmain : IO ()\nmain = print (sum [x | x <- [1..999], isMultiple x 3 || isMultiple x 5])\n\n", "meta": {"hexsha": "bdf1ee677dce0932096b10855d49160ad77c7e51", "size": 212, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "quint/euler001.idr", "max_stars_repo_name": "edu-di-wu/project-euler", "max_stars_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "quint/euler001.idr", "max_issues_repo_name": "edu-di-wu/project-euler", "max_issues_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "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": "quint/euler001.idr", "max_forks_repo_name": "edu-di-wu/project-euler", "max_forks_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "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": 23.5555555556, "max_line_length": 72, "alphanum_fraction": 0.6037735849, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9579122744874229, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.7231423215512012}} {"text": "module AutoDiff\n\nrecord Diff a where\n constructor MkDiff\n getGradient : a\n getValue : a\n\n-- dC/dx = 0\nexport\nconstant : Num a => a -> Diff a\nconstant = MkDiff 0\n\n-- dx/dx = 1\nexport\nindependent : Num a => a -> Diff a\nindependent = MkDiff 1\n\n-- du/dx = du/dv * dv/dx\nexport\nelementary : Num a => (a -> a) -> (a -> a) -> Diff a -> Diff a\nelementary f f' (MkDiff dy y) = MkDiff (f' y * dy) (f y)\n\narithmetic : Num a => (a -> a -> a) -> (a -> a -> (a, a)) -> Diff a -> Diff a -> Diff a\narithmetic f f' (MkDiff du u) (MkDiff dv v) =\n let (dx, dy) = f' u v in MkDiff (dx * du + dy * dv) (f u v)\n\nsquared : Num a => a -> a\nsquared x = x * x\n\ndiff' : Num a => (Diff a -> Diff a) -> a -> Diff a\ndiff' f = f . independent\nexport\ndiff : Num a => (Diff a -> Diff a) -> a -> a\ndiff f = getGradient . diff' f\n\nexport\nsin' : Diff Double -> Diff Double\nsin' = elementary sin cos\nexport\ncos' : Diff Double -> Diff Double\ncos' = elementary cos (negate . sin)\n\nEq a => Eq (Diff a) where\n u == v = getValue u == getValue v\n\nOrd a => Ord (Diff a) where\n compare u v = compare (getValue u) (getValue v)\n\nNum a => Num (Diff a) where\n -- d(u+v) = du + dv\n (+) = arithmetic (+) (\\_, _ => (1, 1))\n -- d(uv) = v(du) + u(dv)\n (*) = arithmetic (*) (\\u, v => (v, u))\n fromInteger = constant . fromInteger\n\nNeg a => Neg (Diff a) where\n -- d(u-v) = du - dv\n (-) = arithmetic (-) (\\_, _ => (1, -1))\n -- d(-x) = -1\n negate = elementary negate (const (-1))\n", "meta": {"hexsha": "119b6e4acbaca545bb8617551db1a64875602a36", "size": 1443, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/AutoDiff.idr", "max_stars_repo_name": "dannypsnl/auto-diff", "max_stars_repo_head_hexsha": "24c4ea1c891a5ff23134412b6e99e1d2f6fcb66b", "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/AutoDiff.idr", "max_issues_repo_name": "dannypsnl/auto-diff", "max_issues_repo_head_hexsha": "24c4ea1c891a5ff23134412b6e99e1d2f6fcb66b", "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/AutoDiff.idr", "max_forks_repo_name": "dannypsnl/auto-diff", "max_forks_repo_head_hexsha": "24c4ea1c891a5ff23134412b6e99e1d2f6fcb66b", "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": 23.6557377049, "max_line_length": 87, "alphanum_fraction": 0.5509355509, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7228812547419194}} {"text": "data Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\n-- Exercise 1\n\nEq Shape where\n (==) (Triangle base height) (Triangle base' height')\n = base == base' && height == height'\n (==) (Rectangle length height) (Rectangle length' height')\n = length == length' && height == height'\n (==) (Circle radius) (Circle radius') = radius == radius'\n (==) _ _ = False\n\n-- Exercise 2\n\nOrd Shape where\n compare x y = compare (area x) (area y)\n\ntestShapes : List Shape\ntestShapes = [Circle 3, Triangle 3 9, Rectangle 2 6, Circle 4,\n Rectangle 2 7]\n", "meta": {"hexsha": "f8460f20a8273725d09f8c4bb04561eea65b06de", "size": 790, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter07/Exercises/ex_7_1.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter07/Exercises/ex_7_1.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter07/Exercises/ex_7_1.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "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.2142857143, "max_line_length": 62, "alphanum_fraction": 0.6164556962, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7228812472660695}} {"text": "import Data.Vect\nimport Decidable.Equality\n\ndata Elem : a -> Vect k a -> Type where\n Here : Elem x (x :: xs)\n There : (later : Elem x xs) -> Elem x (y :: xs)\n\nnotInNil : Elem value [] -> Void\nnotInNil Here impossible\nnotInNil (There _) impossible\n\nnotInTail : (notThere : Elem value xs -> Void) ->\n (notHere : (value = x) -> Void) ->\n Elem value (x :: xs) -> Void\nnotInTail notThere notHere Here = notHere Refl\nnotInTail notThere notHere (There later) = notThere later\n\n\nisElem : DecEq a => (value : a) -> (xs : Vect n a) -> Dec (Elem value xs)\nisElem value [] = No notInNil\nisElem value (x :: xs) \n = case decEq value x of\n Yes Refl => Yes Here\n No notHere => case isElem value xs of\n Yes prf => Yes (There prf)\n No notThere => No (notInTail notThere notHere)\n\n-- similar example for checking if an element is in a Vect using Booleans\nelem : Eq ty => (value : ty) -> (xs : Vect n ty) -> Bool\nelem value [] = False\nelem value (x :: xs) = case value == x of\n False => Main.elem value xs\n True => True\n\n\n", "meta": {"hexsha": "7a462bd6eca8e92be94863253d7a9f47011f8b75", "size": 1167, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch9/ElemType.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "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/ch9/ElemType.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": "src/ch9/ElemType.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": 32.4166666667, "max_line_length": 76, "alphanum_fraction": 0.5612682091, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.7226654894721246}} {"text": "module Graph\n\nimport Data.Vect\nimport Lemmas\n\n%default total\n\n||| 'Graph n' is the type of undirected graphs with no parallel edges and no self-loops with 'n' vertices.\n||| Vertex '0' corresponds to the innermost AddVertex call in the graph expression.\n||| Vertex '1' corresponds to the penultimate AddVertex call in the graph expression.\n||| ...\n||| Vertex 'n-1' corresponds to the outermost AddVertex call in the graph expression.\n||| The second argument of AddVertex is a Vect of Bools, where the 'i'-th entry indicates whether\n||| the current vertex should be connected to the 'i'-th vertex of the graph.\npublic export\ndata Graph : Nat -> Type where\n Empty : Graph 0\n AddVertex : Graph n -> Vect n Bool -> Graph (S n)\n\n||| The complete graph on 'n' vertices.\nexport\ncompleteGraph : (n : Nat) -> Graph n\ncompleteGraph 0 = Empty\ncompleteGraph (S k) = AddVertex (completeGraph k) (replicate k True)\n\n||| The graph with one vertex. Same as 'completeGraph 1'.\nexport\nsingletonGraph : Graph 1\nsingletonGraph = AddVertex Empty []\n\n||| A convenient representation of a graph cut.\n||| The 'i'-th entry indicates the color of the 'i'-th vertex in the cut.\npublic export\nCut : Nat -> Type\nCut n = Vect n Bool\n\n||| Helper function fot sizeCut\n|||\n||| color -- Color of the current vertex\n||| cut -- Colors of the other vertices\n||| edges -- Vect of edges between the current vertex and the others\n||| output -- Number of edges between the current vertex and the other vertices of a different color\nsizeCut' : (color : Bool) -> (cut : Vect n Bool) -> (edges : Vect n Bool) -> Nat\nsizeCut' _ [] [] = 0\nsizeCut' True (False :: cut) (True :: edges) = S (sizeCut' True cut edges)\nsizeCut' False (True :: cut) (True :: edges) = S (sizeCut' False cut edges)\nsizeCut' color (_::cut) (_::edges) = sizeCut' color cut edges\n\n||| Compute the size of a cut of a graph.\n|||\n||| graph -- The input graph of the problem\n||| cut -- The given cut\n||| output -- The size of the cut\nexport\nsizeCut : (graph : Graph n) -> (cut : Cut n) -> Nat\nsizeCut Empty [] = 0\nsizeCut (AddVertex graph edges) cut = \n let x = last cut\n smaller_cut = init cut\n in sizeCut' x smaller_cut edges + sizeCut graph smaller_cut\n\n\n||| Find the best cut of a graph among a vector of cuts (or the trivial cut if the vector is []).\n||| \n||| n -- The size of the input graph of the problem\n||| graph -- The input graph of the problem\n||| cuts -- Vector of cuts\n||| output -- The best cut from the vector and its size\nexport\nbestCut : {n : Nat} -> (graph : Graph n) -> (cuts : Vect k (Cut n)) -> (Cut n, Nat)\nbestCut graph [] = (replicate n True, 0)\nbestCut graph (cut::cuts) = \n let (best, size) = bestCut graph cuts\n s = sizeCut graph cut\n in if s >= size then (cut, s) else (best,size)\n\n\n", "meta": {"hexsha": "af535b3511d1fd417df807fd52621192a95951fe", "size": 2773, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Graph.idr", "max_stars_repo_name": "zamdzhiev/Qimaera", "max_stars_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-08-24T14:36:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T00:36:11.000Z", "max_issues_repo_path": "Graph.idr", "max_issues_repo_name": "zamdzhiev/Qimaera", "max_issues_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "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": "Graph.idr", "max_forks_repo_name": "zamdzhiev/Qimaera", "max_forks_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "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": 35.5512820513, "max_line_length": 106, "alphanum_fraction": 0.6768842409, "num_tokens": 781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.722442978304751}} {"text": "import Data.Vect\n\ninputs : Vect 4 Double\ninputs = [1.0, 2.0, 3.0, 2.5]\n\nweights1 : Vect 4 Double\nweights1 = [0.2, 0.8, -0.5, 1.0]\nweights2 : Vect 4 Double\nweights2 = [0.5, -0.91, 0.26, -0.5]\nweights3 : Vect 4 Double\nweights3 = [-0.26, -0.27, 0.17, 0.87]\n\nweights : Vect 3 (Vect 4 Double)\nweights = [weights1, weights2, weights3]\n\nbias1 : Double\nbias1 = 2.0\nbias2 : Double\nbias2 = 3.0\nbias3 : Double\nbias3 = 0.5\n\n-- NOTE: this is not the idiomatic way to implement this. This follows\n-- the spirit of the Python lesson, which aims for simplicity and clarity.\noutput : Vect 3 Double\noutput = [\n (index 0 inputs)*(index 0 weights1) + (index 1 inputs)*(index 1 weights1) + (index 2 inputs)*(index 2 weights1) + (index 3 inputs)*(index 3 weights1) + bias1,\n (index 0 inputs)*(index 0 weights2) + (index 1 inputs)*(index 1 weights2) + (index 2 inputs)*(index 2 weights2) + (index 3 inputs)*(index 3 weights2) + bias2,\n (index 0 inputs)*(index 0 weights3) + (index 1 inputs)*(index 1 weights3) + (index 2 inputs)*(index 2 weights3) + (index 3 inputs)*(index 3 weights3) + bias3]\n\nmain : IO ()\nmain = printLn output\n", "meta": {"hexsha": "cc3da9836681e35c38083327c61d4234d91010cd", "size": 1112, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/p002-Basic-Neuron-Layer.idr", "max_stars_repo_name": "witt3rd/NNfSiX", "max_stars_repo_head_hexsha": "b7dcfd6d74bf3dcc1847edb95ffc02dd2a6169cb", "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": "Idris/p002-Basic-Neuron-Layer.idr", "max_issues_repo_name": "witt3rd/NNfSiX", "max_issues_repo_head_hexsha": "b7dcfd6d74bf3dcc1847edb95ffc02dd2a6169cb", "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": "Idris/p002-Basic-Neuron-Layer.idr", "max_forks_repo_name": "witt3rd/NNfSiX", "max_forks_repo_head_hexsha": "b7dcfd6d74bf3dcc1847edb95ffc02dd2a6169cb", "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.696969697, "max_line_length": 160, "alphanum_fraction": 0.6735611511, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7853085859124003, "lm_q1q2_score": 0.722203172245012}} {"text": "module Tree\n\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n%name Tree tree, tree1, tree2\n\ndata BSTree : Type -> Type where\n BSEmpty : Ord elem => BSTree elem\n BSNode : Ord elem => (left : BSTree elem) -> (val: elem) -> (right : BSTree elem) -> BSTree elem\n\ninsert : elem -> BSTree elem -> BSTree elem\ninsert x BSEmpty = BSNode BSEmpty x BSEmpty\ninsert x orig@(BSNode left val right) = case compare x val of\n LT => BSNode (insert x left) val right\n EQ => orig\n GT => BSNode left val (insert x right)\n\nlistToTree : Ord a => List a -> BSTree a\nlistToTree [] = BSEmpty\nlistToTree (x :: xs) = insert x (listToTree xs)\n\ntreeToList : BSTree a -> List a\ntreeToList BSEmpty = []\ntreeToList (BSNode left val right) = (treeToList left) ++ (val :: treeToList right)\n", "meta": {"hexsha": "f5fe1a23648f0ece9c0aaa8ce4f13c086bac4d74", "size": 922, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Tree.idr", "max_stars_repo_name": "balajisivaraman/idris-book", "max_stars_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-06T12:38:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-06T12:38:55.000Z", "max_issues_repo_path": "Tree.idr", "max_issues_repo_name": "balajisivaraman/idris-book", "max_issues_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "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": "Tree.idr", "max_forks_repo_name": "balajisivaraman/idris-book", "max_forks_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-04T17:48:35.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-04T17:48:35.000Z", "avg_line_length": 36.88, "max_line_length": 101, "alphanum_fraction": 0.568329718, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.7218313536279197}} {"text": "module BiNat.Views\n\nimport BiNat\nimport BiNat.Properties.Plus\nimport BiNat.Properties.Induction\n\n%default total\n\n||| View for BiNat which represents whether the number is J or succ of something\npublic export\ndata SuccView : BiNat -> Type where\n IsJ : SuccView J\n IsSucc : SuccView (succ n)\n\n||| Determines whether the BiNat is J or succ of something.\nexport\nsuccView : (n : BiNat) -> SuccView n\nsuccView J = IsJ\nsuccView (x -: I) = IsSucc {n = x -: O}\nsuccView (x -: O) with (succView x)\n succView (J -: O) | IsJ = IsSucc {n = J}\n succView (succ n -: O) | IsSucc =\n rewrite sym $ plusJIsSucc n in\n rewrite sym $ plusDashAppendsAcc n J O [O] in\n rewrite plusAssociative (n -: O) J J in\n IsSucc {n = n -: I}\n\n||| Recursive view for BiNat like Nat.\npublic export\ndata NatView : BiNat -> Type where\n NJ : NatView J\n NS : Lazy (NatView n) -> NatView (succ n)\n\n||| Reconstruct the BiNat with NJ and NS, like Nat.\nexport\nnatView : (n : BiNat) -> NatView n\nnatView n = induction NatView (\\k, nv => NS nv) NJ n\n", "meta": {"hexsha": "91b1bb74682310228766b0acaca98c599c2730a7", "size": 1031, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "BiNat/Views.idr", "max_stars_repo_name": "SekiT/BiNat", "max_stars_repo_head_hexsha": "1ac44fa9d5f60e1fb6ceee6394d49c0ecd8aebfd", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "BiNat/Views.idr", "max_issues_repo_name": "SekiT/BiNat", "max_issues_repo_head_hexsha": "1ac44fa9d5f60e1fb6ceee6394d49c0ecd8aebfd", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BiNat/Views.idr", "max_forks_repo_name": "SekiT/BiNat", "max_forks_repo_head_hexsha": "1ac44fa9d5f60e1fb6ceee6394d49c0ecd8aebfd", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1315789474, "max_line_length": 80, "alphanum_fraction": 0.6682832202, "num_tokens": 332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7218313490658425}} {"text": "module ZZsubs\n\nimport congruence\nimport Quotient_Type\nimport ZZ_alt\nimport Product_Type_Eq\nimport ZZplus\n\n%access public export\n%default total\n\nnegate : ZZ1 -> ZZ1\nnegate (a, b) = (b, a)\n\nnegatePassesThrough : (a, b : ZZ1) -> (ZZ_Rel a b) -> (ZZ_Rel (negate a) (negate b))\nnegatePassesThrough (a1, a2) (b1, b2) pfRel = sym pfRel\n\nsubs : ZZ1 -> ZZ1 -> ZZ1\nsubs a b = plus a (negate b)\n\nsubsPassesThrough : (a, b, c, d : ZZ1) -> (ZZ_Rel a c) -> (ZZ_Rel b d) ->\n (ZZ_Rel (subs a b) (subs c d))\n\nsubsPassesThrough a b c d pfac pfbd = let\n \n pf1 : (ZZ_Rel (negate b) (negate d))\n = negatePassesThrough b d pfbd\n \n pf2 : (ZZ_Rel (plus a (negate b)) (plus c (negate d)))\n = plusPassesThrough a (negate b) c (negate d) pfac pf1\n \n in\n pf2\n\n", "meta": {"hexsha": "42d3633f02c46347f581437f7b110fa89e9fd36d", "size": 786, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/ZZsubs.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/ZZsubs.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/ZZsubs.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": 22.4571428571, "max_line_length": 84, "alphanum_fraction": 0.6145038168, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.721495379396315}} {"text": "module TypGleichheit\n\nimport Data.Vect\n\ncongruent : { ty, ty' : Type } -> { a,b : ty } -> {f : ty -> ty' } -> (a = b) -> (f a = f b)\ncongruent Refl = Refl\n\ngleicheZahl : (a : Nat) -> (b : Nat) -> Maybe (a = b)\ngleicheZahl Z Z = Just Refl\ngleicheZahl Z (S k) = Nothing\ngleicheZahl (S k) Z = Nothing\ngleicheZahl (S k) (S j) =\n case gleicheZahl k j of\n Just prf => Just (congruent prf)\n\n\nplus1IstSucc : (n:Nat) -> S n = n+1\nplus1IstSucc Z = Refl\nplus1IstSucc (S k) = cong (plus1IstSucc k)\n\n\nvecReverse : Vect n a -> Vect n a\nvecReverse [] = []\nvecReverse (x :: xs) = \n let ind = vecReverse xs\n v' = ind ++ [x]\n in isSame v'\n where\n isSame : Vect (k + 1) a -> Vect (S k) a\n isSame {k} v = rewrite (plus1IstSucc k) in v\n", "meta": {"hexsha": "c44bc036c021febc5956d040d32edf05f0602526", "size": 733, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Beispiele/TypGleicheit.idr", "max_stars_repo_name": "CarstenKoenig/DOS2016_IdrisWorkshop", "max_stars_repo_head_hexsha": "f329b584e5ae434f0c52564bf75710070cc247da", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-14T07:30:59.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-15T09:50:24.000Z", "max_issues_repo_path": "Beispiele/TypGleicheit.idr", "max_issues_repo_name": "CarstenKoenig/DOS2016_IdrisWorkshop", "max_issues_repo_head_hexsha": "f329b584e5ae434f0c52564bf75710070cc247da", "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": "Beispiele/TypGleicheit.idr", "max_forks_repo_name": "CarstenKoenig/DOS2016_IdrisWorkshop", "max_forks_repo_head_hexsha": "f329b584e5ae434f0c52564bf75710070cc247da", "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": 23.6451612903, "max_line_length": 92, "alphanum_fraction": 0.58526603, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.7214881229354694}} {"text": "module Relations\n\nimport congruence\n\n%access public export\n\n%default total\n\n||| Composing two relations and then extend them to the smallest equivalence relation containing them\n\ndata AddRel : (ty : Type) -> (ty -> ty -> Type) -> (ty -> ty -> Type) -> (ty -> ty -> Type) where\n\n Inc_l : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) ->\n (a, b : ty) -> (r1 a b) -> (AddRel ty r1 r2 a b)\n\n Inc_r : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) ->\n (a, b : ty) -> (r2 a b) -> (AddRel ty r1 r2 a b)\n\n Inc_refl : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) ->\n (a : ty) -> (AddRel ty r1 r2 a a)\n\n Inc_sym : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) ->\n (a, b : ty) -> (AddRel ty r1 r2 a b) -> (AddRel ty r1 r2 b a)\n\n Inc_trans : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) ->\n (a, b, c : ty) -> (AddRel ty r1 r2 a b) -> (AddRel ty r1 r2 b c) ->\n (AddRel ty r1 r2 a c)\n\n||| A proof that the composition operation is commutative\n\nf : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) -> (a, b : ty) ->\n (AddRel ty r1 r2 a b) -> (AddRel ty r2 r1 a b)\n\nf ty r1 r2 a b (Inc_l ty r1 r2 a b pf) = (Inc_r ty r2 r1 a b pf)\nf ty r1 r2 a b (Inc_r ty r1 r2 a b pf) = (Inc_l ty r2 r1 a b pf)\nf ty r1 r2 a a (Inc_refl ty r1 r2 a) = (Inc_refl ty r2 r1 a)\nf ty r1 r2 b a (Inc_sym ty r1 r2 a b pf) = (Inc_sym ty r2 r1 a b (f ty r1 r2 a b pf))\nf ty r1 r2 a c (Inc_trans ty r1 r2 a b c pfab pfbc) =\n (Inc_trans ty r2 r1 a b c (f ty r1 r2 a b pfab) (f ty r1 r2 b c pfbc))\n\n||| Proof that f is the inverse of itself\n\nrel_property_1 : (ty : Type) -> (r1, r2 : (ty -> ty -> Type)) ->\n (a, b : ty) -> (pf : (AddRel ty r1 r2 a b)) ->\n ( (f ty r2 r1 a b (f ty r1 r2 a b pf)) = pf)\n\nrel_property_1 ty r1 r2 a b (Inc_l ty r1 r2 a b pf) = Refl\nrel_property_1 ty r1 r2 a b (Inc_r ty r1 r2 a b pf) = Refl\nrel_property_1 ty r1 r2 b b (Inc_refl ty r1 r2 b) = Refl\nrel_property_1 ty r1 r2 a b (Inc_sym ty r1 r2 b a pf) = let\n pf1 = rel_property_1 ty r1 r2 b a pf\n pf2 = congruence (AddRel ty r1 r2 b a) (AddRel ty r1 r2 a b)\n (f ty r2 r1 b a (f ty r1 r2 b a pf)) pf\n (Inc_sym ty r1 r2 b a) pf1\n in\n pf2\n\nrel_property_1 ty r1 r2 a c (Inc_trans ty r1 r2 a b c pfab pfbc) = let\n \n pf1 = rel_property_1 ty r1 r2 a b pfab\n pf2 = rel_property_1 ty r1 r2 b c pfbc\n \n pf3 = congruence (AddRel ty r1 r2 b c) (AddRel ty r1 r2 a c) \n (f ty r2 r1 b c (f ty r1 r2 b c pfbc)) pfbc (\\k => Inc_trans ty r1 r2 a b c pfab k) pf2\n\n pf4 = congruence (AddRel ty r1 r2 a b) (AddRel ty r1 r2 a c) \n (f ty r2 r1 a b (f ty r1 r2 a b pfab)) pfab (\\k => Inc_trans ty r1 r2 a b c k (f ty r2 r1 b c (f ty r1 r2 b c pfbc))) pf1\n\n\n in\n (trans pf4 pf3)\n \n \n \n \n \n \n \n \n \n", "meta": {"hexsha": "19204c29643b1dc226358b657d24cb33b62fad93", "size": 2821, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Relations.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/Relations.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/Relations.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": 34.8271604938, "max_line_length": 129, "alphanum_fraction": 0.5349166962, "num_tokens": 1140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7208581325779451}} {"text": "import Data.Vect\n\ntotal insert : Ord type => (x : type) -> (xsSorted : Vect len type) -> Vect (S len) type\ninsert x [] = [x]\ninsert x (y :: xs) = case x < y of\n False => y :: insert x xs\n True => x :: y :: xs\n\ntotal insSort : Ord type => Vect length type -> Vect length type\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insert x xsSorted\n\ntotal len : List a -> Nat\nlen [] = 0\nlen (x :: xs) = 1 + len xs\n\ntotal rev : List a -> List a\nrev [] = []\nrev (x :: xs) = rev xs ++ [x]\n\ntotal map' : (a -> b) -> List a -> List b\nmap' f [] = []\nmap' f (x :: xs) = f x :: map' f xs\n\ntotal map'' : (a -> b) -> Vect n a -> Vect n b\nmap'' f [] = []\nmap'' f (x :: xs) = f x :: map'' f xs\n", "meta": {"hexsha": "6e9727f78779089536b2a474fa65676d675e3f50", "size": 771, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/3.3-SortingVectors.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/3.3-SortingVectors.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/3.3-SortingVectors.idr", "max_forks_repo_name": "ostera/asdf", "max_forks_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "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.5862068966, "max_line_length": 88, "alphanum_fraction": 0.4708171206, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7208240631375822}} {"text": "||| Indexing Vectors.\n|||\n||| `Elem` proofs give existential quantification that a given element\n||| *is* in the list, but not where in the list it is! Here we give a\n||| predicate that presents proof that a given index of a vector,\n||| given by a `Fin` instance, will return a certain element.\n|||\n||| Two decidable decision procedures are presented:\n|||\n||| 1. Check that a given index points to the provided element in the\n||| presented vector.\n|||\n||| 2. Find the element at the given index in the presented vector.\nmodule Data.Vect.AtIndex\n\nimport Data.Vect\nimport Decidable.Equality\n\n%default total\n\npublic export\ndata AtIndex : (idx : Fin n)\n -> (xs : Vect n type)\n -> (x : type)\n -> Type\n where\n Here : AtIndex FZ (x::xs) x\n\n There : (later : AtIndex rest xs x)\n -> AtIndex (FS rest) (y::xs) x\n\nnamespace Check\n public export\n elemDiffers : (y = x -> Void)\n -> AtIndex FZ (y :: xs) x\n -> Void\n elemDiffers f Here\n = f Refl\n\n public export\n elemNotInRest : (AtIndex z xs x -> Void)\n -> AtIndex (FS z) (y :: xs) x\n -> Void\n elemNotInRest f (There later)\n = f later\n\n ||| Is the element at the given index?\n |||\n public export\n index : DecEq type\n => (idx : Fin n)\n -> (x : type)\n -> (xs : Vect n type)\n -> Dec (AtIndex idx xs x)\n\n index FZ _ [] impossible\n index (FS y) _ [] impossible\n\n index FZ x (y :: xs) with (decEq y x)\n index FZ x (x :: xs) | (Yes Refl)\n = Yes Here\n index FZ x (y :: xs) | (No contra)\n = No (elemDiffers contra)\n\n index (FS z) x (y :: xs) with (Check.index z x xs)\n index (FS z) x (y :: xs) | (Yes prf)\n = Yes (There prf)\n index (FS z) x (y :: xs) | (No contra)\n = No (elemNotInRest contra)\n\nnamespace Find\n public export\n elemNotInRest : (DPair type (AtIndex x xs) -> Void)\n -> DPair type (AtIndex (FS x) (y :: xs)) -> Void\n\n elemNotInRest f (MkDPair i (There later))\n = f (MkDPair i later)\n\n ||| What is the element at the given index?\n |||\n public export\n index : DecEq type\n => (idx : Fin n)\n -> (xs : Vect n type)\n -> Dec (DPair type (AtIndex idx xs))\n index FZ (x :: xs)\n = Yes (MkDPair x Here)\n\n index (FS x) (y :: xs) with (Find.index x xs)\n index (FS x) (y :: xs) | (Yes (MkDPair i idx))\n = Yes (MkDPair i (There idx))\n index (FS x) (y :: xs) | (No contra) = No (elemNotInRest contra)\n\n-- [ EOF ]\n", "meta": {"hexsha": "d9b56abdcfac1b98054defc43a7e6532de727bad", "size": 2538, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Data/Vect/AtIndex.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "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": "libs/base/Data/Vect/AtIndex.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "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": "libs/base/Data/Vect/AtIndex.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "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": 26.7157894737, "max_line_length": 70, "alphanum_fraction": 0.5543735225, "num_tokens": 788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7206307533417838}} {"text": "module Data.Bool.BoolTheorems\n\n%default total\n%access export\n\npublic export\nifWithProofs : (x : Bool) -> ((x = True) -> a) -> (not x = True -> a) -> a\nifWithProofs True f _ = f Refl\nifWithProofs False _ f = f Refl\n\nAOrFalseIsA : (a : Bool) -> a || False = a\nAOrFalseIsA True = Refl\nAOrFalseIsA False = Refl\n\nNotAEqNotBImpliesAEqB : (a : Bool) -> (b : Bool) -> (not a = not b) -> (a = b)\nNotAEqNotBImpliesAEqB True True _ = Refl\nNotAEqNotBImpliesAEqB False False _ = Refl\nNotAEqNotBImpliesAEqB True False prf = absurd prf\nNotAEqNotBImpliesAEqB False True prf = absurd prf\n\nNotNotCancels : (a : Bool) -> a = True -> not (not a) = True\nNotNotCancels True prf = prf\nNotNotCancels False prf = prf\n", "meta": {"hexsha": "5a2642a64a54ec0a272cee0222350ceef606fbc3", "size": 692, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Bool/BoolTheorems.idr", "max_stars_repo_name": "andrevidela/http4idris", "max_stars_repo_head_hexsha": "792584d6f05d0529baeed6274d0d5e9d1e32c09c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2017-12-01T23:13:08.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-13T00:34:32.000Z", "max_issues_repo_path": "Data/Bool/BoolTheorems.idr", "max_issues_repo_name": "andrevidela/http4idris", "max_issues_repo_head_hexsha": "792584d6f05d0529baeed6274d0d5e9d1e32c09c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-01-16T08:07:27.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-10T22:28:37.000Z", "max_forks_repo_path": "Data/Bool/BoolTheorems.idr", "max_forks_repo_name": "andrevidela/http4idris", "max_forks_repo_head_hexsha": "792584d6f05d0529baeed6274d0d5e9d1e32c09c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-01-16T05:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-11T20:02:28.000Z", "avg_line_length": 28.8333333333, "max_line_length": 78, "alphanum_fraction": 0.6936416185, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7931059560743423, "lm_q1q2_score": 0.7206302658531694}} {"text": "module Main\n\nimport Data.Nat\nimport Data.DPair\n\nfib : (n : Nat) -> Int\nfib Z = 0\nfib (S Z) = 1\nfib (S (S k)) = fib k + fib (S k)\n\nfibc : (n : Nat) -> Int\nfibc n = loop n 0 1\n where\n loop : (n : Nat) -> (f0 : Int) -> (f1 : Int) -> Int\n loop Z f0 _ = f0\n loop (S n) f0 f1 = loop n f1 (f0 + f1)\n\ndata Fib : (0 _ : Nat) -> Int -> Type where\n Fib0 : Fib 0 0\n Fib1 : Fib 1 1\n FibN : {0 n : Nat}\n -> {r0, r1 : Int}\n -> (0 _ : Fib n r0) -> (0 _ : Fib (S n) r1)\n -> Fib (S (S n)) (r0 + r1)\n\nfibCert : (n : Nat) -> (r : Int ** Fib n r)\nfibCert 0 = (_ ** Fib0)\nfibCert (S 0) = (_ ** Fib1)\nfibCert (S (S k)) =\n case (fibCert k , fibCert (S k)) of\n ((r0 ** p0) , (r1 ** p1)) => (r0 + r1 ** FibN p0 p1)\n\nfibcCert : (n : Nat) -> Int\nfibcCert n = fst calc\n where\n loop : {r0, r1 : Int} -> (i : Nat) -> (ni : Nat) -> Fib i r0 -> Fib (S i) r1 -> Subset Int (Fib (ni + i))\n loop i Z pf0 pf1 = (Element _ pf0)\n loop i (S k) pf0 pf1 = rewrite (plusSuccRightSucc k i) in loop (S i) k pf1 (FibN pf0 pf1)\n\n calc : Subset Int (Fib n)\n calc = rewrite (sym (plusZeroRightNeutral n)) in loop 0 n Fib0 Fib1\n\nmain : IO ()\nmain = printLn $ fibcCert 40\n", "meta": {"hexsha": "ad23811de7298ee89fc9fbad550d2a357d09344a", "size": 1194, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/FibTest.idr", "max_stars_repo_name": "andorp/IdrisExtSTGCodegen", "max_stars_repo_head_hexsha": "3565a6fdd5f58fc6556214685d6da4dd5db25865", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2020-10-30T22:06:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T07:14:52.000Z", "max_issues_repo_path": "test/FibTest.idr", "max_issues_repo_name": "andorp/IdrisExtSTGCodegen", "max_issues_repo_head_hexsha": "3565a6fdd5f58fc6556214685d6da4dd5db25865", "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": "test/FibTest.idr", "max_forks_repo_name": "andorp/IdrisExtSTGCodegen", "max_forks_repo_head_hexsha": "3565a6fdd5f58fc6556214685d6da4dd5db25865", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-11T10:59:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:20:02.000Z", "avg_line_length": 26.5333333333, "max_line_length": 109, "alphanum_fraction": 0.5041876047, "num_tokens": 509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.7202305542336452}} {"text": "module Teleportation\n\nimport Data.Nat\nimport Data.List\nimport Data.Vect\nimport Unitary\nimport Control.Linear.LIO\nimport QStateT\nimport Injection\nimport LinearTypes\nimport QuantumOp\nimport Examples\n\n%default total\n\n||| Example : Teleportation protocol\n\n||| The unitary circuit that we have to apply to the initial state.\nexport\ntelep1 : Unitary 3\ntelep1 = H 0 (CNOT 0 1 (apply toBellBasis IdGate [1,2]))\n\n||| The unitary correction that has to be applied after performing the measurement in the Bell basis.\n||| The two Bool arguments indicate the measurement results.\nexport\nunitary_correction : Bool -> Bool -> Unitary 1\nunitary_correction b1 b2 = (if b2 then XGate else IdGate) . (if b1 then ZGate else IdGate)\n\n||| The Quantum Teleportation Protocol as a state transformer.\nexport\nteleportation : QuantumOp t =>\n (1 _ : Qubit) -> QStateT (t 1) (t 1) (LFstPair Qubit (Vect 2 Bool))\nteleportation q0 = do\n [q1, q2] <- newQubits 2\n [q0,q1,q2] <- applyUnitary [q0,q1,q2] telep1\n [b1, b2] <- measure [q0,q1]\n [q] <- applyUnitary [q2] (unitary_correction b1 b2) \n pure (q # [b1, b2])\n \n||| Run the teleportation protocol where the qubit to be teleported is in state |+>.\nexport\nrunTeleportation : QuantumOp t => IO (Vect 3 Bool)\nrunTeleportation = \n run (do\n q <- newQubit {t = t}\n q <- applyH q\n (q # [b1, b2]) <- teleportation q\n [b3] <- measure [q]\n pure [b1,b2,b3]\n )\n\n||| Print some useful information on the screen obtained by executing runTeleportation.\nexport\ndrawTeleportation : QuantumOp t => IO ()\ndrawTeleportation = do\n [b1, b2, b3] <- runTeleportation {t = t}\n putStrLn \"Teleportation Protocol\\n\\n\"\n putStrLn \"First circuit:\"\n draw telep1\n putStrLn \"Measurement results on first two qubits:\"\n putStrLn (show (b1, b2))\n putStrLn \"\\nUnitary corrections:\"\n draw (unitary_correction b1 b2)\n putStrLn \"Result of measurement on the last qubit:\"\n putStrLn (show b3)\n\n", "meta": {"hexsha": "e27a53c12040bfa2aa778b7bbcd82970d8474209", "size": 1946, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Teleportation.idr", "max_stars_repo_name": "zamdzhiev/Qimaera", "max_stars_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-08-24T14:36:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T00:36:11.000Z", "max_issues_repo_path": "Teleportation.idr", "max_issues_repo_name": "zamdzhiev/Qimaera", "max_issues_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "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": "Teleportation.idr", "max_forks_repo_name": "zamdzhiev/Qimaera", "max_forks_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "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": 29.0447761194, "max_line_length": 101, "alphanum_fraction": 0.6978417266, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.7200783032439783}} {"text": "> module Rel.Preorder\n\n\n> %default total\n> %access public export\n\n\n> ||| Preorder\n> data Preorder : Type -> Type where\n> MkPreorder : {A : Type} ->\n> (R : A -> A -> Type) ->\n> (reflexive : (x : A) -> R x x) ->\n> (transitive : (x : A) -> (y : A) -> (z : A) -> R x y -> R y z -> R x z) ->\n> Preorder A\n\n\n", "meta": {"hexsha": "65b4464a8502d656bb805e0a4f3afa73067765b7", "size": 364, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Rel/Preorder.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Rel/Preorder.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Rel/Preorder.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4117647059, "max_line_length": 91, "alphanum_fraction": 0.4120879121, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.929440397949314, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7199290839867333}} {"text": "module Addition.Scaling\n\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.Ring\nimport Proofs.SemigroupTheory\nimport Proofs.RingTheory\nimport Addition.Carry\n\n%default total\n%access export\n\nscalingLemmaM : Ringops s => UnitalRingSpec {s} (+) Zero Ng (*) One ->\n (radix : s) ->\n scale Zero Ng radix M = radix * value M\nscalingLemmaM spec radix = o2 @== o1 where\n o1 : Ng (radix * One) = radix * Ng One\n o1 = negatedMultiplication (ring spec) radix One\n o2 : Ng (radix * One) = Ng radix\n o2 = cong $ neutralR (multiplicativeMonoid spec) radix\n\nscalingLemma : Ringops s => UnitalRingSpec {s} (+) Zero Ng (*) One ->\n (radix : s) -> (c : Carry) ->\n scale Zero Ng radix c = radix * value c\nscalingLemma spec radix P = sym $ neutralR (multiplicativeMonoid spec) radix\nscalingLemma spec radix O = sym $ zeroAbsorbsR (ring spec) radix\nscalingLemma spec radix M = scalingLemmaM spec radix\n\n\nrewriteInvariant : Ringops s => UnitalRingSpec {s} (+) Zero Ng (*) One ->\n (radix, i, o : s) ->\n (c : Carry) ->\n scale Zero Ng radix c + o = i ->\n o + radix * value c = i\nrewriteInvariant spec radix i o c invariant = o2 @== invariant where\n o1 : scale Zero Ng radix c = radix * value c\n o1 = scalingLemma spec radix c\n o2 : scale Zero Ng radix c + o = o + radix * value c\n o2 = abelianCongruence (plusAbelian (ring spec)) o1\n", "meta": {"hexsha": "3c6e6440199719b5210dd112ebd74fc09b7c0098", "size": 1341, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Addition/Scaling.idr", "max_stars_repo_name": "jeroennoels/verified-exact-real", "max_stars_repo_head_hexsha": "77ad54fe7d0b0058926b92d1c38937ed48d5dd6c", "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/Addition/Scaling.idr", "max_issues_repo_name": "jeroennoels/verified-exact-real", "max_issues_repo_head_hexsha": "77ad54fe7d0b0058926b92d1c38937ed48d5dd6c", "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/Addition/Scaling.idr", "max_forks_repo_name": "jeroennoels/verified-exact-real", "max_forks_repo_head_hexsha": "77ad54fe7d0b0058926b92d1c38937ed48d5dd6c", "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.525, "max_line_length": 76, "alphanum_fraction": 0.6868008949, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440397949314, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7199290839867333}} {"text": "import Control.Monad.State\n\ndata Tree a = Empty | Node (Tree a) a (Tree a)\n\ntestTree : Tree String\ntestTree =\n Node (Node (Node Empty \"Jim\" Empty) \"Fred\"\n (Node Empty \"Sheila\" Empty)) \"Alice\"\n (Node Empty \"Bob\" (Node Empty \"Eve\" Empty))\n\nflatten : Tree a -> List a\nflatten Empty = []\nflatten (Node left val right) = flatten left ++ val :: flatten right\n\ntreeLabelWith : Tree a -> State (Stream labelType) (Tree (labelType, a))\ntreeLabelWith Empty = pure Empty\ntreeLabelWith (Node left val right) =\n do\n leftLabelled <- treeLabelWith left\n (this :: rest) <- get\n put rest\n rightLabelled <- treeLabelWith right\n pure (Node leftLabelled (this, val) rightLabelled)\n\ntreeLabel : Tree a -> Tree (Integer, a)\ntreeLabel tree = evalState (treeLabelWith tree) [1..]\n\ncountEmpty : Tree a -> State Nat ()\ncountEmpty Empty =\n do\n count <- get\n put (S count)\ncountEmpty (Node left val right) =\n do\n countEmpty left\n countEmpty right\n\ncountEmptyNode : Tree a -> State (Nat, Nat) ()\ncountEmptyNode Empty =\n do\n (empties, nodes) <- get\n put ((S empties), nodes)\ncountEmptyNode (Node left val right) =\n do\n countEmptyNode left\n (empties, nodes) <- get\n put (empties, (S nodes))\n countEmptyNode right\n", "meta": {"hexsha": "5dec9fe83edb6b7e8dc3598a81e2fce539722a4c", "size": 1311, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/TreeLabelState.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/TreeLabelState.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/TreeLabelState.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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.7551020408, "max_line_length": 72, "alphanum_fraction": 0.6323417239, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7194854675511073}} {"text": "data Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\n%builtin Natural Fin\n\nfinToInteger : Fin k -> Integer\nfinToInteger FZ = 0\nfinToInteger (FS k) = 1 + finToInteger k\n\n%builtin NaturalToInteger finToInteger\n", "meta": {"hexsha": "7aee8bb809e528072bb44d3687f6dcc8afb556f9", "size": 232, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/builtin007/Test.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/idris2/builtin007/Test.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/idris2/builtin007/Test.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": 19.3333333333, "max_line_length": 40, "alphanum_fraction": 0.6724137931, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7194287431770732}} {"text": "module PLFI.Part1.Relations\n\nimport PLFI.Part1.Induction\nimport PLFI.Part1.Naturals\nimport Syntax.PreorderReasoning\n\n%default total\n\n%hide Prelude.(+)\n%hide Prelude.(*)\n\n-- z≤n --------\n-- zero ≤ n\n\n-- m ≤ n\n-- s≤s -------------\n-- suc m ≤ suc n\n\n-- z≤n -----\n-- 0 ≤ 2\n-- s≤s -------\n-- 1 ≤ 3\n-- s≤s ---------\n-- 2 ≤ 4\n\ninfix 4 <=\n\ndata (<=) : N -> N -> Type where\n\n Zero\n : {n : N} ->\n -------------\n Zero <= n\n \n Suc\n : {m, n : N} ->\n (m <= n) ->\n -------------------\n (Suc m) <= (Suc n)\n\n\ninvSucLTE : {m,n : N} -> (Suc m) <= (Suc n) -> m <= n\ninvSucLTE (Suc lte) = lte\n\ninvZeroLTE : {m : N} -> m <= Zero -> m = Zero\ninvZeroLTE Zero = Refl\n\n-- Exercise orderings (practice)\n-- Give an example of a preorder that is not a partial order\n-- Give an example of a partial order that is not a total order\n\n-- Reflexivity\n\n-- lteRefl0 : n <= n\n-- lteRefl0 {n} = ?h1\n\nlteRefl\n : {n : N} ->\n ------------\n n <= n\nlteRefl {n = Zero} = Zero\nlteRefl {n = (Suc m)} = Suc lteRefl\n\n-- Transitivity\n\nlteTrans\n : {m,n,p : N} ->\n m <= n ->\n n <= p ->\n ----------------\n m <= p\nlteTrans Zero y = Zero\nlteTrans (Suc x) (Suc y) = Suc (lteTrans x y)\n\n-- lteTrans {n = n} {m = Zero} {p = p} Zero np = Zero\n-- lteTrans {n = (Suc n)} {m = (Suc m)} {p = (Suc p)} (Suc mn) (Suc np) = Suc (lteTrans mn np)\n\n\nlteAntisym\n : {m,n : N} ->\n m <= n ->\n n <= m ->\n --------------\n n = m\nlteAntisym Zero Zero = Refl\n-- lteAntisym (Suc x) (Suc y) = rewrite (lteAntisym x y) in Refl\nlteAntisym (Suc x) (Suc y) = cong Suc (lteAntisym x y)\n-- lteAntisym (Suc x) (Suc y) = let Refl = lteAntisym x y in Refl\n\n-- Total\n\n-- data Total0 : N -> N -> Type where\n\n-- Forward0\n-- : m <= n ->\n-- -----------\n-- Total0 m n\n \n-- Flipped0\n-- : n <= m ->\n-- -----------\n-- Total0 m n\n\ndata Total : (m, n : N) -> Type where\n\n Forward\n : m <= n ->\n -----------\n Total m n\n \n Flipped\n : n <= m ->\n -----------\n Total m n\n\n-- lteTotal : (m, n : N) -> Total m n\n-- lteTotal Zero n = Forward Zero\n-- lteTotal (Suc m) Zero = Flipped Zero\n-- lteTotal (Suc m) (Suc n) with (lteTotal m n)\n-- _ | Forward mn = Forward (Suc mn)\n-- _ | Flipped nm = Flipped (Suc nm)\n\nlteTotal : (m, n : N) -> Total m n\nlteTotal Zero n = Forward Zero\nlteTotal (Suc m) Zero = Flipped Zero\nlteTotal (Suc m) (Suc n) = case lteTotal m n of\n Forward mn => Forward (Suc mn)\n Flipped nm => Flipped (Suc nm)\n\n%hint\naddMonoR_LTE\n : (n,p,q : N) ->\n p <= q ->\n -------------------\n (n + p) <= (n + q)\naddMonoR_LTE Zero p q pq = pq\naddMonoR_LTE (Suc m) p q pq = Suc (addMonoR_LTE m p q pq)\n\n%hint\naddMonoL_LTE\n : (m,n,p : N) ->\n m <= n ->\n -------------------\n (m + p) <= (n + p)\naddMonoL_LTE m n p mn =\n rewrite (addComm m p) in\n rewrite (addComm n p) in\n addMonoR_LTE p m n mn\n\naddMono_LTE\n : (m,n,p,q : N) ->\n m <= n ->\n p <= q ->\n -------------------\n (m + p) <= (n + q)\naddMono_LTE m n p q mn pq\n = lteTrans\n {n=(n + p)}\n (addMonoL_LTE m n p mn)\n (addMonoR_LTE n p q pq)\n\n-- Exercise (strech) *-mono-≤\n\nmultMonoLTE\n : (m,n,p,q : N) ->\n m <= n ->\n p <= q ->\n -------------------\n (m * p) <= (n * q)\n\n-- Strict inequality\n\ninfix 4 <\n\npublic export\ndata (<) : N -> N -> Type where\n\n ZeroLT\n : {n : N} -> \n ---------------\n Zero < (Suc n)\n \n SucLT\n : {m, n : N} ->\n m < n ->\n ------------------\n (Suc m) < (Suc n)\n\n-- Exercise lteTrans (recommended)\n\nltTrans\n : {m,n,p : N} -> \n m < n ->\n n < p ->\n ----------------\n m < p\nltTrans ZeroLT (SucLT x) = ZeroLT\nltTrans (SucLT x) (SucLT y) = SucLT (ltTrans x y)\n\nnamespace LTTrans\n\n ltTrans1\n : (m,n,p : N) -> \n m < n ->\n n < p ->\n ----------------\n m < p\n ltTrans1 Zero (Suc n) (Suc p) ZeroLT (SucLT x) = ZeroLT\n ltTrans1 (Suc m) (Suc n) (Suc p) (SucLT x) (SucLT y) = SucLT (ltTrans1 m n p x y)\n\n public export\n ltTrans2\n : {m,n,p : N} -> \n m < n ->\n n < p ->\n ----------------\n m < p\n ltTrans2 {m,n,p} mn np = ltTrans1 m n p mn np\n\n-- Exercise trichotomy (practice)\n\ndata Trichotomy : N -> N -> Type where\n LT : m < n -> Trichotomy m n\n EQ : m = n -> Trichotomy m n\n GT : n < m -> Trichotomy m n\n\n-- 0 m : N\n-- 0 n : N\n-- ------------------------------\n-- trichotomy_rhs : Trichotomy m n\n0\ntrich : forall m , n . Trichotomy m n\ntrich {m = Zero} {n = Zero} = EQ Refl\ntrich {m = Zero} {n = (Suc m)} = LT ZeroLT\ntrich {m = (Suc m)} {n = n} = ?trichotomy_rhs0_2\n\ntrichotomy : (m, n : N) -> Trichotomy m n\ntrichotomy Zero Zero = EQ Refl\ntrichotomy Zero (Suc _) = LT ZeroLT\ntrichotomy (Suc _) Zero = GT ZeroLT\ntrichotomy (Suc m) (Suc n) = case (trichotomy m n) of\n (LT mn) => LT (SucLT mn)\n (EQ mm) => EQ (cong Suc mm)\n (GT nm) => GT (SucLT nm)\n\n-- trichotomy (Suc m) (Suc n) with (trichotomy m n)\n-- _ | (LT x) = ?trichotomy_rhs_4_rhs4_1\n-- _ | (EQ prf) = ?trichotomy_rhs_4_rhs4_2\n-- _ | (GT x) = ?trichotomy_rhs_4_rhs4_3\n\n-- Exercise addMonoLT (practice)\n\naddMonoR_LT\n : (n,p,q : N) ->\n p < q ->\n -------------------\n (n + p) < (n + q)\naddMonoR_LT Zero p q pq = pq\naddMonoR_LT (Suc m) p q pq = SucLT (addMonoR_LT m p q pq)\n\naddMonoL_LT\n : (m,n,p : N) ->\n m < n ->\n -------------------\n (m + p) < (n + p)\naddMonoL_LT m n p mn = \n rewrite (addComm m p) in\n rewrite (addComm n p) in\n addMonoR_LT p m n mn\n\naddMonoLT\n : (m,n,p,q : N) ->\n m < n ->\n p < q -> \n ------------------\n (m + p) < (n + q)\naddMonoLT m n p q mn pq\n = ltTrans\n {n=(n + p)}\n (addMonoL_LT m n p mn)\n (addMonoR_LT n p q pq)\n\n{-\nMemo:\ninterface Transitive rel => Proof (rel : N -> N -> Type) where\n {-# MINIMAL (monoL | monoR) #-}\n monoL : ({n,m,p: _} -> rel n m -> rel (n + p) (m + p))\n monoL = monoLFromMonoRAndPlusComm\n monoR : ({n,m,p: _} -> rel n m -> rel (n + p) (m + p))\n monoR = monoRFromMonoLAndPlusComm\n \nproofIsMonoProof : Proof rel => rel n m -> rel p q -> rel (n + p) (m + p)\nproofIsMonoProof\n = trans\n {n=(n + p)}\n (monoL m n p mn)\n (monoR n p q pq)\n \nTransitive : (rel : N -> N -> Type) -> Type\nTransitive rel = forall n,m,p : rel n m -> rel m p -> rel n p\n-- Transitive rel = {n,m,p : N} -> rel n m -> rel m p -> rel n p\n-}\n\n\n-- Exercise lte iff lt (recommended)\n\nlteIffLtL\n : (m,n : N) ->\n (Suc m) <= n ->\n ------------------\n m < n\nlteIffLtL Zero (Suc _) (Suc x) = ZeroLT\nlteIffLtL (Suc m) (Suc _) (Suc x) = SucLT (lteIffLtL m _ x)\n\nlteIffLtR\n : (m,n : N) ->\n m < n ->\n ---------------\n (Suc m) <= n\nlteIffLtR Zero (Suc _) ZeroLT = Suc Zero\nlteIffLtR (Suc m) (Suc _) (SucLT x) = Suc (lteIffLtR m _ x)\n\n-- Exercise ltTransRevisited (practice)\n\n-- Give an alternative proof that strict inequality is transitive,\n-- using the relation between strict inequality and inequality\n-- and the fact that inequality is transitive.\n\n{-\nlteIffLtR\n : (m,n : N) ->\n m < n ->\n ---------------\n (Suc m) <= n\nlteIffLtL\n : (m,n : N) ->\n (Suc m) <= n ->\n ------------------\n m < n\nlteTrans\n : {m,n,p : N} ->\n m <= n ->\n n <= p ->\n ----------------\n m <= p\n-}\n\nlteSucc : (n : N) -> n <= Suc n\nlteSucc Zero = Zero\nlteSucc (Suc m) = Suc (lteSucc m)\n\ninfixr 4 `lteTrans`\n\nltTransRevisited\n : (m,n,p : N) ->\n m < n ->\n n < p ->\n ----------------\n m < p\nltTransRevisited m n p mn np with (lteIffLtR m n mn, lteIffLtR n p np)\n _ | (lr1, lr2) = lteIffLtL m p $ lr1 `lteTrans` lteSucc n `lteTrans` lr2\n\nltTransRevisited2\n : (m,n,p : N) ->\n m < n ->\n n < p ->\n ----------------\n m < p\nltTransRevisited2 m n p mn np\n = lteIffLtL m p\n $ lteIffLtR m n mn `lteTrans` lteSucc n `lteTrans` lteIffLtR n p np\n\n{-\n lr1 : Suc m <= n\n lr4 : n <= Suc n\n lr2 : Suc n <= p\n------------------------------\n h1 : Suc m <= p\n-}\n\nnamespace Even0\n\n public export\n data Prop = Even | Odd\n\n public export\n flip : Prop -> Prop\n flip Even = Odd\n flip Odd = Even\n\n public export\n data EvenOrOdd : Prop -> N -> Type where\n Zero : EvenOrOdd Even Zero\n Suc : EvenOrOdd p n -> EvenOrOdd (flip p) (Suc n)\n\n public export\n isEven : N -> Type \n isEven n = EvenOrOdd Even n\n\nmutual\n\n namespace Even\n\n public export\n data Even : N -> Type where\n\n Zero :\n ---------\n Even Zero\n \n Suc\n : {n : N} ->\n Odd n ->\n ------------\n Even (Suc n)\n\n namespace Odd\n\n public export\n data Odd : N -> Type where\n\n Suc\n : {n : N} ->\n Even n ->\n -------------\n Odd (Suc n)\n\ntotal\nevenAddEven\n : {m, n : N} ->\n Even m ->\n Even n ->\n ---------------\n Even (m + n)\n\ntotal\noddAddEven\n : {m, n : N} ->\n Odd m ->\n Even n ->\n ---------------\n Odd (m + n)\n\nevenAddEven Zero en = en\nevenAddEven (Suc om) en = Suc (oddAddEven om en)\n\noddAddEven (Suc em) on = Suc (evenAddEven em on)\n\n-- Exercise - Bin-predicates\n\n-- Can : Bin -> Type\n\n-- Can b\n-- -----------\n-- Can (inc b)\n\n-- ----------\n-- Can (to n)\n\n-- Can b\n-- ---------------\n-- to (from b) = b\n", "meta": {"hexsha": "556e4dca56ea6d8328ec57eef3786652ec963872", "size": 9327, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "PLFI/Part1/Relations.idr", "max_stars_repo_name": "andorp/PLFI", "max_stars_repo_head_hexsha": "820c304515711e2b6ca5a28571725a0136fdfa2d", "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": "PLFI/Part1/Relations.idr", "max_issues_repo_name": "andorp/PLFI", "max_issues_repo_head_hexsha": "820c304515711e2b6ca5a28571725a0136fdfa2d", "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": "PLFI/Part1/Relations.idr", "max_forks_repo_name": "andorp/PLFI", "max_forks_repo_head_hexsha": "820c304515711e2b6ca5a28571725a0136fdfa2d", "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": 20.1447084233, "max_line_length": 94, "alphanum_fraction": 0.4687466495, "num_tokens": 3369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7194175789542177}} {"text": "import Control.Isomorphism\n\n%default total\n\n-- probably useless\ndata Morphism : (a : Type) -> (b : Type) -> (f : a -> b) -> Type where\n MkMorphism : (f : a -> b) ->\n Morphism a b f\n\n-- retraction for f\ndata Retraction : (a : Type) -> (b : Type) -> (f : a -> b) -> (r : b -> a) -> Type where\n MkRetraction : (f : a -> b) ->\n (r : b -> a) ->\n (v : (x : a) -> r (f x) = x) ->\n Retraction a b f r\n\n-- section for f\ndata Section : (a : Type) -> (b : Type) -> (f : a -> b) -> (s : b -> a) -> Type where\n MkSection : (f : a -> b) ->\n (s : b -> a) ->\n (v : (y : b) -> f (s y) = y) ->\n Section a b f s\n\n-- retraction + section\ndata Isomorphism : (a : Type) -> (b : Type) -> Type where\n MkIsomorphism : {f : a -> b} ->\n (r : Retraction a b f r') ->\n (s : Section a b f s') ->\n Isomorphism a b\n\nuniquenessOfInverses : Retraction a b f r -> Section a b f s -> (x : b) -> r x = s x\nuniquenessOfInverses (MkRetraction f r rv) (MkSection f s sv) x =\n -- s x = r x\n rewrite (sym $ sv x) in\n -- r (f (s x)) = s (f (s x))\n rewrite (rv (s x)) in\n -- s x = s (f (s x))\n rewrite (sv x) in\n -- s x = s x\n Refl\n\ntoIso : Isomorphism a b -> Iso a b\ntoIso (MkIsomorphism (MkRetraction f r rv) (MkSection f s sv)) =\n MkIso f s sv (\\x => rewrite (sym $ uniquenessOfInverses (MkRetraction f r rv) (MkSection f s sv) (f x)) in (rv x))\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\nappIso : Iso a b -> a -> b\nappIso (MkIso to _ _ _) x = to x\n\nunappIso : Iso a b -> b -> a\nunappIso (MkIso _ from _ _) x = from x\n\n", "meta": {"hexsha": "ea59336b95251ac589f183a7788e00cb3712652c", "size": 1868, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Common.idr", "max_stars_repo_name": "defanor/morphisms", "max_stars_repo_head_hexsha": "57ec23fc955dc69300d6fbd394cb9ac3209ff76b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-10T20:58:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-10T20:58:11.000Z", "max_issues_repo_path": "src/Common.idr", "max_issues_repo_name": "defanor/morphisms", "max_issues_repo_head_hexsha": "57ec23fc955dc69300d6fbd394cb9ac3209ff76b", "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/Common.idr", "max_forks_repo_name": "defanor/morphisms", "max_forks_repo_head_hexsha": "57ec23fc955dc69300d6fbd394cb9ac3209ff76b", "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.1290322581, "max_line_length": 116, "alphanum_fraction": 0.4801927195, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7194175721924155}} {"text": "module Graphiti.BTree\n\n-- shows a basic Binary Tree with insert, toList and fromList ops\n-- shows how to reverse/invert it without using a stack or a queue\n\n%hide toList -- we do not want the standard library to pollute our definitions here\n\npublic export\ndata BTree a = Leaf | Node (BTree a) a (BTree a)\n\ndata LR = L | R\n\ninserter : Ord a => a -> BTree a -> LR -> BTree a\ninserter x Leaf _ = Node Leaf x Leaf\ninserter x (Node l y r) L = if (x < y) then (Node (inserter x l L) y r)\n else (Node l y (inserter x r L))\ninserter x (Node l y r) R = if (x > y) then (Node (inserter x l R) y r)\n else (Node l y (inserter x r R))\n\nexport\ninsert : Ord a => a -> BTree a -> BTree a\ninsert x t = inserter x t L\n\ninvInsert : Ord a => a -> BTree a -> BTree a\ninvInsert x t = inserter x t R\n\nexport\ntoList : BTree a -> List a\ntoList Leaf = []\ntoList (Node l y r) = BTree.toList l ++ (y :: BTree.toList r)\n\nexport\nfromList : Ord a => List a -> BTree a\nfromList [] = Leaf\nfromList (x :: xs) = BTree.insert x (BTree.fromList xs)\n\nfromListInv : Ord a => List a -> BTree a\nfromListInv [] = Leaf\nfromListInv (x :: xs) = invInsert x (fromListInv xs)\n\nexport\nreverseList : List a -> List a\nreverseList xs = revAcc [] xs where\n revAcc : List a -> List a -> List a\n revAcc acc [] = acc\n revAcc acc (y :: ys) = revAcc (y :: acc) ys\n\nexport\nrevBTree : Ord a => BTree a -> BTree a\nrevBTree Leaf = Leaf\nrevBTree node = fromList ( BTree.reverseList (BTree.toList node) )\n\n\nexport\nreinvBTree : Ord a => BTree a -> BTree a\nreinvBTree Leaf = Leaf\nreinvBTree node = fromListInv (toList node)\n\n\n\n-- shows a proof that inversion of inversion is the original\n-- i.e. inv . inv = id\n\ninvOfInv : Ord a => (bt: BTree a) -> reinvBTree (reinvBTree bt) = bt\ninvOfInv Leaf = Refl\ninvOfInv (Node x y z) = ?hole", "meta": {"hexsha": "63c0dc59b1d08f752f9ca1af8db711814e8dfe2a", "size": 1846, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Graphiti/BTree.idr", "max_stars_repo_name": "umbrela-academy/idrusti", "max_stars_repo_head_hexsha": "b595db27d2ff7b0816ee248cf4f669402ef55e04", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Graphiti/BTree.idr", "max_issues_repo_name": "umbrela-academy/idrusti", "max_issues_repo_head_hexsha": "b595db27d2ff7b0816ee248cf4f669402ef55e04", "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": "Graphiti/BTree.idr", "max_forks_repo_name": "umbrela-academy/idrusti", "max_forks_repo_head_hexsha": "b595db27d2ff7b0816ee248cf4f669402ef55e04", "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": 27.9696969697, "max_line_length": 83, "alphanum_fraction": 0.6343445287, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7192171932341972}} {"text": "module CH08\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\ndata ThreeEq : a -> b -> c -> Type where\n ThreeSame : ThreeEq x x x\n\ncong2 : { f : x -> y -> z} -> a = b -> c = d -> f a c = f b d\ncong2 Refl Refl = Refl\n\nsame_cons : {xs : List a} -> {ys : List a}\n -> xs = ys -> x :: xs = x :: ys\nsame_cons Refl = Refl\n\nsame_lists : {xs : List a} -> {ys : List a}\n -> x = y -> xs = ys -> x :: xs = y :: ys\nsame_lists Refl Refl = Refl\n\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS x x x ThreeSame = ThreeSame\n\nmyPlusCommutes : (n : Nat) -> (m: Nat) -> n + m = m + n\nmyPlusCommutes Z m = rewrite (plusZeroRightNeutral m) in Refl\nmyPlusCommutes (S k) m = rewrite myPlusCommutes k m\n in plusSuccRightSucc m k\n\nmyReverse : Vect n a -> Vect n a\nmyReverse xs = reverse' [] xs\n where\n reverse' : Vect k a -> Vect m a -> Vect (k + m) a\n reverse' {k} acc [] = rewrite (plusZeroRightNeutral k) in acc\n reverse' {k} {m = S m} acc (x :: xs) = rewrite sym (plusSuccRightSucc k m)\n in (reverse' (x :: acc) xs)\n\nheadUnequal : DecEq a => {xs : Vect n a}\n -> {ys : Vect n a}\n -> (contra: (x = y) -> Void)\n -> ((x :: xs) = (y :: ys))\n -> Void\nheadUnequal contra Refl = contra Refl\n\ntailUnequal : DecEq a => {xs : Vect n a}\n -> {ys : Vect n a}\n -> (contra: (xs = ys) -> Void)\n -> ((x :: xs) = (y :: ys))\n -> Void\ntailUnequal contra Refl = contra Refl\n\nDecEq a => DecEq (Vect n a) where\n decEq [] [] = Yes Refl\n decEq (x :: xs) (y :: ys) = case decEq x y of\n Yes Refl => case decEq xs ys of\n Yes Refl => Yes Refl\n No contra => No (tailUnequal contra)\n No contra => No (headUnequal contra)\n", "meta": {"hexsha": "376ab1995895aa614f88158217a2dc9e116b09d8", "size": 2105, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch08/exercises.idr", "max_stars_repo_name": "dgvncsz0f/idris-study-group", "max_stars_repo_head_hexsha": "6c21f7198c946dd9ce8cee55fcf92bbdca78cc44", "max_stars_repo_licenses": ["Unlicense"], "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/ch08/exercises.idr", "max_issues_repo_name": "dgvncsz0f/idris-study-group", "max_issues_repo_head_hexsha": "6c21f7198c946dd9ce8cee55fcf92bbdca78cc44", "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": "src/ch08/exercises.idr", "max_forks_repo_name": "dgvncsz0f/idris-study-group", "max_forks_repo_head_hexsha": "6c21f7198c946dd9ce8cee55fcf92bbdca78cc44", "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": 36.2931034483, "max_line_length": 83, "alphanum_fraction": 0.4489311164, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7190924796929252}} {"text": "||| Matrix operations with vector space dimensionalities enforced\n||| at the type level. Uses operations from the Num type class.\nmodule Data.Matrix.Numeric\n\nimport public Data.Matrix\n\n%default total\n\ninfixr 2 <:> -- vector inner product\ninfixr 2 >< -- vector outer product\ninfixr 2 <<>> -- matrix commutator\ninfixr 2 >><< -- matrix anticommutator\ninfixl 3 <\\> -- row times a matrix\ninfixr 4 -- matrix times a column\ninfixr 5 <> -- matrix multiplication\ninfixl 5 <#> -- matrix rescale\ninfixl 5 <# -- vector rescale\ninfixr 7 \\&\\ -- vector tensor product\ninfixr 7 <&> -- matrix tensor product\n\n-----------------------------------------------------------------------\n-- Vectors as members of Num\n-----------------------------------------------------------------------\n\ninstance Num a => Num (Vect n a) where\n (+) = zipWith (+)\n (*) = zipWith (*)\n fromInteger n = replicate _ (fromInteger n)\n\ninstance Neg a => Neg (Vect n a) where\n (-) = zipWith (-)\n abs = map abs\n negate = map negate\n\n-----------------------------------------------------------------------\n-- Vector functions\n-----------------------------------------------------------------------\n\n||| Inner product of ring vectors\n(<:>) : Num a => Vect n a -> Vect n a -> a\n(<:>) w v = sum $ zipWith (*) w v\n\n||| Scale a numeric vector by a scalar\n(<#) : Num a => a -> Vect n a -> Vect n a\n(<#) r = map (r *)\n\n||| Tensor multiply (⊗) numeric vectors\n(\\&\\) : Num a => Vect n a -> Vect m a -> Vect (n * m) a\n(\\&\\) {n} {m} v w = zipWith (*) (oextend m v) (orep n w) where\n orep : (n : Nat) -> Vect m a -> Vect (n * m) a\n orep n v = concat $ replicate n v\n oextend : (n : Nat) -> Vect k a -> Vect (k * n) a\n oextend n w = concat $ map (replicate n) w\n\n||| Standard basis vector with one nonzero entry, numeric data type and vector-length unfixed\nbasis : Num a => (Fin d) -> Vect d a\nbasis i = replaceAt i 1 0\n\n-----------------------------------------------------------------------\n-- Matrix functions\n-----------------------------------------------------------------------\n\n||| Matrix times a column vector\n() : Num a => Matrix n m a -> Vect m a -> Vect n a\n() m v = map (v <:>) m\n\n||| Matrix times a row vector\n(<\\>) : Num a => Vect n a -> Matrix n m a -> Vect m a\n(<\\>) r m = map (r <:>) $ transpose m\n\n||| Matrix multiplication\n(<>) : Num a => Matrix n k a ->\n Matrix k m a ->\n Matrix n m a\n(<>) m1 m2 = map (<\\> m2) m1\n\n||| Scale matrix by a scalar\n(<#>) : Num a => a -> Matrix n m a -> Matrix n m a\n(<#>) r = map (r <#)\n\n||| Tensor multiply (⊗) for numeric matrices\n(<&>) : Num a => Matrix h1 w1 a -> Matrix h2 w2 a -> Matrix (h1 * h2) (w1 * w2) a\n(<&>) m1 m2 = zipWith (\\&\\) (stepOne m1 m2) (stepTwo m1 m2) where\n stepOne : Matrix h1 w1 a -> Matrix h2 w2 a -> Matrix (h1 * h2) w1 a\n stepOne {h2} m1 m2 = concat $ map (replicate h2) m1\n stepTwo : Matrix h1 w1 a -> Matrix h2 w2 a -> Matrix (h1 * h2) w2 a\n stepTwo {h1} m1 m2 = concat $ replicate h1 m2\n\n||| Outer product between numeric vectors\n(><) : Num a => Vect n a -> Vect m a -> Matrix n m a\n(><) x y = col x <> row y\n\n||| Matrix commutator\n(<<>>) : Neg a => Matrix n n a -> Matrix n n a -> Matrix n n a\n(<<>>) m1 m2 = (m1 <> m2) - (m2 <> m1)\n\n||| Matrix anti-commutator\n(>><<) : Num a => Matrix n n a -> Matrix n n a -> Matrix n n a\n(>><<) m1 m2 = (m1 <> m2) + (m2 <> m1)\n\n||| Identity matrix\nId : Num a => Matrix d d a\nId = map (\\n => basis n) (fins _)\n\n||| Square matrix from diagonal elements\ndiag_ : Num a => Vect n a -> Matrix n n a\ndiag_ = zipWith (\\f => \\x => replaceAt f x 0) (fins _)\n\n||| Combine two matrices to make a new matrix in block diagonal form\nblockDiag : Num a => Matrix n n a -> Matrix m m a -> Matrix (n+m) (n+m) a\nblockDiag {n} {m} g h = map (++ replicate m 0) g ++ map ((replicate n 0) ++) h\n\n-----------------------------------------------------------------------\n-- Determinants\n-----------------------------------------------------------------------\n\n||| Alternating sum\naltSum : Neg a => Vect n a -> a\naltSum (x::y::zs) = (x - y) + altSum zs\naltSum [x] = x\naltSum [] = 0\n\n||| Determinant of a 2-by-2 matrix\ndet2 : Neg a => Matrix 2 2 a -> a\ndet2 [[x1,x2],[y1,y2]] = x1*y2 - x2*y1\n\n||| Determinant of a square matrix\ndet : Neg a => Matrix (S (S n)) (S (S n)) a -> a\ndet {n} m = case n of\n Z => det2 m\n (S k) => altSum . map (\\c => indices FZ c m * det (subMatrix FZ c m))\n $ fins (S (S (S k)))\n", "meta": {"hexsha": "b2ecd38bbd273347f2db10bda4480bbf4a1104d7", "size": 4519, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Matrix/Numeric.idr", "max_stars_repo_name": "BlackBrane/xquant", "max_stars_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-10-31T21:21:40.000Z", "max_stars_repo_stars_event_max_datetime": "2017-01-23T17:42:39.000Z", "max_issues_repo_path": "src/Data/Matrix/Numeric.idr", "max_issues_repo_name": "fieldstrength/xquant", "max_issues_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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/Matrix/Numeric.idr", "max_forks_repo_name": "fieldstrength/xquant", "max_forks_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "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.977443609, "max_line_length": 93, "alphanum_fraction": 0.4883823855, "num_tokens": 1402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7190606125273441}} {"text": "\n\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n%name Tree tree, tree1, tree2\n\n\ninsert : Ord elem => elem -> Tree elem -> Tree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node tleft val tright) = case compare x val of\n LT => Node (insert x tleft) val tright\n EQ => orig\n GT => Node tleft val (insert x tright)\n", "meta": {"hexsha": "6de95c655382774d667903b7dbd797bf6bc2517b", "size": 467, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/tree.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter4/tree.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter4/tree.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 33.3571428571, "max_line_length": 78, "alphanum_fraction": 0.4903640257, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.71894327459562}} {"text": "module Ch05.LambdaCalculus\n\nimport Ch03.Relations\n\n%access public export\n\n||| The type of variables\nVariable : Type\nVariable = Nat\n\n||| The type of terms in the untyped lambda calculus\ndata Term = Var Variable\n | Abs Variable Term\n | App Term Term\n\n||| Convenient infix notation for construction of function application terms\n(.) : Term -> Term -> Term\n(.) = App\n\n-- TODO: Can we get rid of the argument `n`?\n||| Convenience function for constructing lambda terms\nlambda : Nat -> (Term -> Term) -> Term\nlambda n f = Abs n (f (Var n))\n\nMultiAppArgType : (numArgs : Nat) -> Type\nMultiAppArgType Z = Term\nMultiAppArgType (S k) = Term -> MultiAppArgType k\n\n-- K_0 = id : a -> a\n-- K : a -> b -> a\n-- K_2 : a -> b -> b -> a\n-- K_n : a -> b ... -> b -> a\n--\n-- K f t\n-- K_2 f t1 t2 := K (K f t1) t2\n--\n-- K_{n+1} : a -> b -> .. -> b -> (b -> a)\n-- K_{n+1} f x1 ... x{n+1} = K (K_n f x1 ... x_n) x_{n+1}\n\n||| Convenience version of the `App` constructor that allows for a variable number of arguments.\nmulti_app : {numArgs : Nat} -> (MultiAppArgType numArgs -> Term)\nmulti_app {numArgs = Z} = \\f => f\nmulti_app {numArgs = (S k)} = ?hole--(\\f : Term => App f t) . (multi_app {numArgs=k})\n\ndata DirectSubterm : Term -> Term -> Type where\n IsAbsBody : {x : Variable} ->\n {t : Term} ->\n DirectSubterm t (Abs x t)\n IsAppFun : {f, x : Term} ->\n DirectSubterm f (App f x)\n\n IsAppArg : {f, x : Term} ->\n DirectSubterm x (App f x)\n\n\nSubterm : Term -> Term -> Type\nSubterm = ReflSymmClos DirectSubterm\n\n-- vars (x) = {x}\n-- vars (lambda x . t) = {x} \\cup vars (t)\n-- vars (f t) = vars(f) \\cup vars(t)\n-- \n-- bound_vars (x) = {}\n-- bound_vars (lambda x . t) = \\{x\\} \\cup bound_vars(t)\n-- bound_vars (f t) = bound_vars(f) \\cup bound_vars(t)\n--\n-- free_vars (x) = {}\n-- free_vars (lambda x . t) = free_vars(t) - \\{x\\}\n-- free_vars (f t) = free_vars(f) \\cup free_vars(t)\n-- \n\n\n\nnamespace Occurs\n ||| Propositional type describing that a variable occurs in a term.\n data Occurs : Variable -> Term -> Type where\n IsVar : (x : Variable) ->\n Occurs x (Var x)\n\nnamespace OccursFree\n ||| Propositional type describing that a variable occurs freely in a term.\n data OccursFree : Variable -> Term -> Type where\n IsVar : (x : Variable) ->\n OccursFree x (Var x)\n InBody : {x,y : Variable} ->\n {t : Term} ->\n Not (x = y) ->\n OccursFree x t ->\n OccursFree x (Abs y t)\n InAppFun : {x : Variable} ->\n {f, t : Term} ->\n OccursFree x f ->\n OccursFree x (App f t)\n InAppArg : {x : Variable} ->\n {f, t : Term} ->\n OccursFree x t ->\n OccursFree x (App f t)\n\nClosed : Term -> Type\nClosed t = (x : Variable) -> Not (OccursFree x t)\n\nnamespace OccursBound\n ||| Propositional type describing that a variable occurs bound in a term.\n data OccursBound : Variable -> Term -> Type where\n\n\n||| The identity combinator.\nid : Term\nid = Abs 0 (Var 0)\n\n||| Proof that the identity combinator is closed.\nid_is_closed : Closed Ch05.LambdaCalculus.id\nid_is_closed x pf_occurs_free = case pf_occurs_free of\n (InBody pf_ne pf_in_t) => case pf_in_t of\n (IsVar Z) => pf_ne Refl\n\n--------------------------------------------------------------------------------\n-- Booleans\n--------------------------------------------------------------------------------\n\n||| The Church boolean true\ntru : Term\ntru = Abs 1 (Abs 0 (Var 1))\n\n||| The Church boolean false\nfls : Term\nfls = Abs 1 (Abs 0 (Var 0))\n\n||| Church encoding of the if-then-else operator\ntest : Term\ntest = Abs 2 (Abs 1 (Abs 0 (App (App (Var 2) (Var 1)) (Var 0))))\n\n||| Logical AND operator for Church booleans.\nand : Term\nand = Abs 0 (Abs 1 (App (App (Var 0) (Var 1)) fls))\n\n--------------------------------------------------------------------------------\n-- Pairs\n--------------------------------------------------------------------------------\n\n||| Church pair constructor\npair : Term\npair = Abs 0 (Abs 1 (Abs 2 (App (App (Var 2) (Var 0)) (Var 1))))\n\n||| Projection onto the first component of a pair\nfst : Term\nfst = Abs 0 (Abs 1 (Var 0))\n\n||| Projection onto the second component of a pair\nsnd : Term\nsnd = Abs 0 (Abs 1 (Var 1))\n\n--------------------------------------------------------------------------------\n-- Numerals\n--------------------------------------------------------------------------------\n\n||| The Church numeral zero.\nchurch_zero : Term\nchurch_zero = Abs 1 (Abs 0 (Var 0))\n\n||| The Church numeral one.\nchurch_one : Term\nchurch_one = Abs 1 (Abs 0 (App (Var 1) (Var 0)))\n\n||| The Church numeral two.\nchurch_two : Term\nchurch_two = Abs 1 (Abs 0 (App (Var 1) (App (Var 1) (Var 0))))\n\n||| The successors function for Church numerals\nscc : Term\nscc = Abs 0 (Abs 1 (Abs 2 (App (Var 1) (App (App (Var 0) (Var 1)) (Var 2)))))\n\n||| Addition of Church numerals\nplus : Term\nplus = Abs 0 (Abs 1 (Abs 2 (Abs 3 ((Var 0) . (Var 2)) . (((Var 1) . (Var 2)) . (Var 3)))))\n\n||| Multiplication of Church numerals\ntimes : Term\ntimes = Abs 0 (Abs 1 ((Var 0) . (plus . (Var 1))) . church_zero)\n\n||| Tests whether a Church numeral is zero or not\niszro : Term\niszro = Abs 0 ((Var 0) . (Abs 0 fls)) . tru\n\n||| The predecessor function on Church numerals\nprd : Term\nprd = let zz = pair . church_zero . church_zero\n ss = Abs 0 (pair . (snd . (Var 0)) . (scc . (snd . (Var 0)))) in\n Abs 0 (fst . ((Var 0) . ss) . zz)\n\n--------------------------------------------------------------------------------\n-- Lists\n--------------------------------------------------------------------------------\n\n-- See Ch05.Exercise_5_2_8\n\n--------------------------------------------------------------------------------\n-- Self-replicating terms\n--------------------------------------------------------------------------------\n\n||| The (?) simplest self-replicating term in the lambda calculus\nomega : Term\nomega = let x = Var 0\n f = Abs 0 (x . x) in\n f . f\n\n||| The call-by-value version of the fix-point combinator (i.e. Y combinator)\nfix : Term\nfix = let f = Var 0\n x = Var 1\n y = Var 2\n t = Abs 1 f . (Abs 2 (x . x . y)) in\n Abs 0 (t . t)\n", "meta": {"hexsha": "dba81c4682db5aa24d1b18ffebbb8a83982742bf", "size": 6330, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Ch05/LambdaCalculus.idr", "max_stars_repo_name": "mr-infty/tapl", "max_stars_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-02-27T13:52:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:38:28.000Z", "max_issues_repo_path": "Ch05/LambdaCalculus.idr", "max_issues_repo_name": "mr-infty/tapl", "max_issues_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "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": "Ch05/LambdaCalculus.idr", "max_forks_repo_name": "mr-infty/tapl", "max_forks_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T04:56:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T07:08:45.000Z", "avg_line_length": 29.5794392523, "max_line_length": 96, "alphanum_fraction": 0.5045813586, "num_tokens": 1797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.718719593166512}} {"text": "module Logic\n\n%access public export\n\n%default total\n\nnotInvolutive : (b : Bool) -> not (not b) = b\nnotInvolutive False = Refl\nnotInvolutive True = Refl\n\nneqSym : Not (a = b) -> Not (b = a)\nneqSym contra prf = contra $ sym prf\n\nband : b1 && b2 = True -> (b1 = True, b2 = True)\nband {b1 = False} prf = absurd prf\nband {b1 = True} prf = (Refl, prf)\n\nn_eq_succ__n_neq_0 : n = S k -> Not (n = 0)\nn_eq_succ__n_neq_0 n_eq_succ n_eq_0 = SIsNotZ $ trans (sym n_eq_succ) n_eq_0\n\niff : {p, q : Type} -> Type\niff {p} {q} = (p -> q, q -> p)\n\nsyntax [p] \"↔\" [q] = iff {p} {q}\n\niff_sym : (p ↔ q) -> (q ↔ p)\niff_sym (p_imp_q, q_imp_p) = (q_imp_p, p_imp_q)\n\nnot_true_iff_false : (Not (b = True)) ↔ (b = False)\nnot_true_iff_false {b} = (not_true_is_false b, not_true_and_false b)\n where not_true_and_false : (b : Bool) -> (b = False) -> Not (b = True)\n not_true_and_false False _ Refl impossible\n not_true_and_false True Refl _ impossible\n not_true_is_false : (b : Bool) -> Not (b = True) -> b = False\n not_true_is_false False _ = Refl\n not_true_is_false True h = absurd $ h Refl\n\niff_refl : p ↔ p\niff_refl = (id, id)\n\niff_trans : (p ↔ q) -> (q ↔ r) -> (p ↔ r)\niff_trans (p_imp_q, q_imp_p) (q_imp_r, r_imp_q) =\n (q_imp_r . p_imp_q, q_imp_p . r_imp_q)\n\nnat_beq_iff : (n, m : Nat) -> (n == m = True) ↔ (n = m)\nnat_beq_iff = \\n, m => (forward n m, backward n m)\nwhere forward : (n, m : Nat) -> n == m = True -> n = m\n forward Z Z _ = Refl\n forward Z (S _) prf = absurd prf\n forward (S _) Z prf = absurd prf\n forward (S k) (S j) prf = cong {f=S} (forward k j prf)\n backward : (n, m : Nat) -> n = m -> n == m = True\n backward Z Z _ = Refl\n backward Z (S _) prf = absurd prf\n backward (S _) Z prf = absurd prf\n backward (S k) (S j) prf = backward k j (succInjective k j prf)\n\nnat_nbeq_iff : (n, m : Nat) -> (n == m = False) ↔ (Not (n = m))\nnat_nbeq_iff = \\n, m => (forward n m, backward n m)\nwhere forward : (n, m : Nat) -> n == m = False -> Not (n = m)\n forward Z Z bprf _ = absurd bprf\n forward Z (S _) _ prf = SIsNotZ $ sym prf\n forward (S _) Z _ prf = SIsNotZ prf\n forward (S k) (S j) bprf prf = forward k j bprf (succInjective k j prf)\n backward : (n, m : Nat) -> Not (n = m) -> n == m = False\n backward Z Z contra = absurd $ contra Refl\n backward Z (S _) _ = Refl\n backward (S _) Z _ = Refl\n backward (S k) (S j) contra =\n backward k j (\\prf => contra (cong {f=S} prf))\n\nlte_plus_minus : LTE n m -> n + (minus m n) = m\nlte_plus_minus {n = Z} {m} _ = minusZeroRight m\nlte_plus_minus {n = S _} {m = Z} succ_lte_m = absurd $ succNotLTEzero succ_lte_m\nlte_plus_minus {n = S k} {m = S j} succ_lte_m =\n cong $ lte_plus_minus (fromLteSucc succ_lte_m)\n\nlte_beq_iff : (n, m : Nat) -> ((lte n m = True) ↔ (LTE n m))\nlte_beq_iff = \\n, m => (forward, backward)\nwhere forward : lte n m = True -> LTE n m\n forward {n = Z} _ = LTEZero\n forward {n = S _} {m = Z} prf = absurd prf\n forward {n = S k} {m = S j} prf = LTESucc (forward prf)\n backward : LTE n m -> lte n m = True\n backward LTEZero = Refl\n backward (LTESucc lte_prf) = backward lte_prf\n\nlte_nbeq_iff : (n, m : Nat) -> ((lte n m = False) ↔ (LT m n))\nlte_nbeq_iff = \\n, m => (forward, backward)\nwhere forward : lte n m = False -> LT m n\n forward {n = Z} prf = absurd prf\n forward {n = S _} {m = Z} _ = LTESucc LTEZero\n forward {n = S k} {m = S j} prf = LTESucc $ forward {n=k} {m=j} prf\n backward : LT m n -> lte n m = False\n backward {n = Z} lt_prf = absurd $ succNotLTEzero lt_prf\n backward {n = S _} {m = Z} _ = Refl\n backward {n = S k} {m = S j} lt_prf = backward (fromLteSucc lt_prf)\n\nlte_z__eq_z : LTE n 0 -> n = 0\nlte_z__eq_z {n = Z} _ = Refl\nlte_z__eq_z {n = S _} lte_prf = absurd $ succNotLTEzero lte_prf\n\nlte_succ_minus : LTE n m -> minus (S m) n = S (minus m n)\nlte_succ_minus {n = Z} {m} lte_prf = rewrite minusZeroRight m in Refl\nlte_succ_minus {n = S _} {m = Z} lte_prf = absurd $ succNotLTEzero lte_prf\nlte_succ_minus {n = S k} {m = S j} lte_prf = lte_succ_minus (fromLteSucc lte_prf)\n\nlte_minus_plus_sum : LTE k n -> minus n k + plus m k = n + m\nlte_minus_plus_sum {k = Z} {n} {m} lte_prf =\n rewrite minusZeroRight n\n in rewrite plusZeroRightNeutral m\n in Refl\nlte_minus_plus_sum {k = S _} {n = Z} lte_prf = absurd $ succNotLTEzero lte_prf\nlte_minus_plus_sum {k = S i} {n = S k} {m} lte_prf =\n rewrite sym (plusSuccRightSucc m i)\n in rewrite sym (plusSuccRightSucc (minus k i) (m + i))\n in cong (lte_minus_plus_sum (fromLteSucc lte_prf))\n\nbounded__eq : LTE n m -> LTE m n -> n = m\nbounded__eq {n = Z} _ above = sym $ lte_z__eq_z above\nbounded__eq {n = S _} {m = Z} below _ = absurd $ succNotLTEzero below\nbounded__eq {n = S _} {m = S _} below above =\n cong $ bounded__eq (fromLteSucc below) (fromLteSucc above)\n\nnotZeroImpliesGTZero : Not (n = 0) -> LT 0 n\nnotZeroImpliesGTZero {n = Z} contra = absurd $ contra Refl\nnotZeroImpliesGTZero {n = (S _)} _ = LTESucc LTEZero\n\nplusCong : {a, b, n, m : Nat} -> a = n -> b = m -> a + b = n + m\nplusCong prf1 prf2 = rewrite prf1 in rewrite prf2 in Refl\n\nfromNotLteSucc : Not (LTE (S n) (S m)) -> Not (LTE n m)\nfromNotLteSucc contra lte_prf = contra (LTESucc lte_prf)\n\nlteImpliesNotGT : LTE n m -> Not (GT n m)\nlteImpliesNotGT {n = Z} _ = succNotLTEzero\nlteImpliesNotGT {n = S _} {m = Z} lte_prf = absurd $ succNotLTEzero lte_prf\nlteImpliesNotGT {n = S k} {m = S j} lte_prf = \\succ_prf =>\n lteImpliesNotGT (fromLteSucc lte_prf) (fromLteSucc succ_prf)\n\nRelation : (p : Type) -> Type\nRelation p = p -> p -> Type\n\nDeterministic : (r : Relation p) -> Type\nDeterministic {p} r = {x, y1, y2 : p} -> r x y1 -> r x y2 -> y1 = y2\n\nNormalForm : (r : Relation t) -> (x : t) -> Type\nNormalForm r x = Not (x' ** r x x')\n\ndata Multi : {t : Type} -> (r : Relation t) -> Relation t where\n MultiRefl : Multi r x x\n MultiStep : r x y -> Multi r y z -> Multi r x z\n\nmulti_R : {r : Relation t} -> r x y -> Multi r x y\nmulti_R rxy = MultiStep rxy MultiRefl\n\nmulti_trans : {r : Relation t} -> Multi r x y -> Multi r y z -> Multi r x z\nmulti_trans MultiRefl ryz = ryz\nmulti_trans (MultiStep once next) ryz = MultiStep once (multi_trans next ryz)\n", "meta": {"hexsha": "bee85d1380937d9682c0aa44588a5025257c8f75", "size": 6213, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Logic.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": "Logic.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": "Logic.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": 38.83125, "max_line_length": 81, "alphanum_fraction": 0.6151617576, "num_tokens": 2346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7186568100801387}} {"text": "module Ray\n\nimport Vec3\n-- import Hittable\n\n%access export\n\npublic export\n\nrecord Ray where\n constructor MkRay\n orig, dir : Vec3\n\nat : Ray -> Double -> Vec3\nat ray t = orig ray + t * dir ray\n\nhitSphere : Vec3 -> Double -> Ray -> Double\nhitSphere center radius ray = if discriminant < 0 \n then -1.0\n else (-half_b - sqrt discriminant) / a\n where \n oc : Vec3\n oc = orig ray - center\n\n a : Double\n a = lengthSquared (dir ray)\n\n half_b : Double\n half_b = dot oc (dir ray)\n\n c : Double\n c = lengthSquared oc - radius * radius\n\n discriminant : Double\n discriminant = half_b*half_b - a*c\n", "meta": {"hexsha": "5ae4f598fb9ea015c58f15788ed0f495bfccd2b9", "size": 754, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Ray.idr", "max_stars_repo_name": "MarkMarkyMarkus/YART", "max_stars_repo_head_hexsha": "51cc720e6b9764a2c598d97301afa21fe974656b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Ray.idr", "max_issues_repo_name": "MarkMarkyMarkus/YART", "max_issues_repo_head_hexsha": "51cc720e6b9764a2c598d97301afa21fe974656b", "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": "Ray.idr", "max_forks_repo_name": "MarkMarkyMarkus/YART", "max_forks_repo_head_hexsha": "51cc720e6b9764a2c598d97301afa21fe974656b", "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": 20.9444444444, "max_line_length": 54, "alphanum_fraction": 0.5225464191, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9669140187510509, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.718579571314854}} {"text": "module Chapter3\n\n%default total\n\ndescribeList : List Int -> String\ndescribeList [] = \"Empty\"\ndescribeList (_ :: xs) = \"Non-Empty with tail \" ++ show xs\n\nmutual\n isEven : Nat -> Bool\n isEven Z = True\n isEven (S k) = isOdd k\n\n isOdd : Nat -> Bool\n isOdd Z = False\n isOdd (S k) = isEven k", "meta": {"hexsha": "4e67252304f404c9298b421ee5625d0efbacce86", "size": 291, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter3/Chapter3.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter3/Chapter3.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": "chapter3/Chapter3.idr", "max_forks_repo_name": "timmyjose-study/tdd-with-idris", "max_forks_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": 18.1875, "max_line_length": 58, "alphanum_fraction": 0.6391752577, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7184716758988823}} {"text": "module AssRecRule\n\nimport Data.Fin\nimport Data.Vect\n\n%default total\n%access public export\n\nrecList : (a: Type) -> (x: Type) -> x -> (a -> List a -> x -> x) -> (List a -> x)\nrecList a x base fn [] = base\nrecList a x base fn (y :: xs) = fn y xs (recList a x base fn xs)\n\nmapList : (a: Type) -> (b: Type) -> (f: a -> b) -> List a -> List b\nmapList a b f lst = recList a (List b) []\n (\\q => \\lsta => \\lstb => (f q) :: lstb) lst\n\nfoldList : (a: Type) -> (init: a) -> (op : a -> a -> a) -> List a -> a\nfoldList a init op xs = recList a a init (\\q => \\lst => op q) xs\n\ninducFin : (xs : (n: Nat) -> Fin n -> Type) ->\n (base : (m: Nat) -> xs (S m) FZ) ->\n (step : (p: Nat) -> (k: Fin p) -> (prev: xs p k) -> (xs (S p) (FS k))) ->\n (q: Nat) -> (j: Fin q) -> xs q j\ninducFin xs base step (S k) FZ = base k\ninducFin xs base step (S k) (FS x) = step k x (inducFin xs base step k x)\n\nfetchElem : (a: Type) -> (q: Nat) -> (j: Fin q) -> (Vect q a -> a)\nfetchElem a q j vect = inducFin (\\n => \\q => Vect n a -> a)\n (\\m => \\(x :: xs) => x)\n (\\p => \\k => \\prev => \\(x :: xs) => prev xs)\n q j vect\n", "meta": {"hexsha": "afd982be487c3de5999b84649398a5d80fd73c39", "size": 1155, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/SriramAssRecRule.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/SriramAssRecRule.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/SriramAssRecRule.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": 36.09375, "max_line_length": 82, "alphanum_fraction": 0.4744588745, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564154, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.7182899992378208}} {"text": "-- Exercise_4_2.idr\n--\n\nimport Data.Vect\n\n\n||| Take the first n elements of given Vect xs\nvectTake : (n : Nat) -> (xs : Vect (n + m) a) -> Vect n a\nvectTake Z [] = []\nvectTake Z (x :: xs) = []\nvectTake (S k) (x :: xs) = x :: vectTake k xs\n\n\n||| Calculate sum of selected entries, return Nothing if index\n||| is out of bounds\nsumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a ->\n Maybe a\nsumEntries {n} pos xs ys = case integerToFin pos n of\n Nothing => Nothing\n (Just x) => Just ((index x xs) + (index x ys))\n\n\n\n", "meta": {"hexsha": "c918c7e743a8772574b58fb16f5dde134270744f", "size": 598, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_4/Exercises_4_2.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/Exercises_4_2.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": "Idris/TDD/Chapter_4/Exercises_4_2.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "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": 24.9166666667, "max_line_length": 78, "alphanum_fraction": 0.5334448161, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.718054398447844}} {"text": "\n||| Represents shapes.\ndata Shape = ||| A triangle, with its base length and height.\n Triangle Double Double\n | ||| A rectangle, with its length and height.\n Rectangle Double Double\n | ||| A circle, with its raduis\n Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\ndata Picture = Primitive Shape\n | Combine Picture Picture\n | Rotate Double Picture\n | Translate Double Double Picture\n\nrectangle : Picture\nrectangle = Primitive (Rectangle 20 10)\n\ncircle : Picture\ncircle = Primitive (Circle 5)\n\ntriangle : Picture\ntriangle = Primitive (Triangle 10 10)\n\ntestPicture : Picture\ntestPicture = Combine (Translate 5 5 rectangle)\n (Combine (Translate 35 5 circle)\n (Translate 15 25 triangle))\n\n%name Shape shape, shape1, shape2\n%name Picture pic, pic1, pic2\n\npictureArea : Picture -> Double\npictureArea (Primitive shape) = area shape\npictureArea (Combine pic pic1) = pictureArea pic + pictureArea pic1\npictureArea (Rotate x pic) = pictureArea pic\npictureArea (Translate x y pic) = pictureArea pic\n\nmaxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe Nothing y = y\nmaxMaybe x Nothing = x\nmaxMaybe (Just x) (Just y) = case x < y of\n False => Just x\n True => Just y\n\nbiggestTriangle : Picture -> Maybe Double\nbiggestTriangle (Primitive t@(Triangle x y)) = Just $ area t\nbiggestTriangle (Primitive _) = Nothing\nbiggestTriangle (Combine pic pic1) = maxMaybe (biggestTriangle pic) (biggestTriangle pic1)\nbiggestTriangle (Rotate x pic) = biggestTriangle pic\nbiggestTriangle (Translate x y pic) = biggestTriangle pic\n\ntestPic1 : Picture\ntestPic1 = Combine (Primitive (Triangle 2 3))\n (Primitive (Triangle 2 4))\n\ntestPic2 : Picture\ntestPic2 = Combine (Primitive (Rectangle 1 3))\n (Primitive (Circle 4))\n", "meta": {"hexsha": "3612ac05215944d3024d63f0bb0b87f7bbecd29e", "size": 2069, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/Shapes.idr", "max_stars_repo_name": "DimaSamoz/idris-book", "max_stars_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "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": "Chapter4/Shapes.idr", "max_issues_repo_name": "DimaSamoz/idris-book", "max_issues_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "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": "Chapter4/Shapes.idr", "max_forks_repo_name": "DimaSamoz/idris-book", "max_forks_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "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.328125, "max_line_length": 90, "alphanum_fraction": 0.6534557757, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.7178831986487819}} {"text": "-- Minimal implicational modal logic, PHOAS approach, final encoding\n\nmodule Pf.BoxMp\n\n%default total\n\n\n-- Types\n\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n BOX : Ty -> Ty\n\n\n-- Context and truth judgement with modal depth\n\nCx : Type\nCx = Nat -> Ty -> Type\n\nisTrue : Ty -> Nat -> Cx -> Type\nisTrue a d tc = tc d a\n\n\n-- Terms\n\nTmRepr : Type\nTmRepr = Nat -> Cx -> Ty -> Type\n\ninfixl 1 :$\nclass ArrMpTm (tr : TmRepr) where\n var : isTrue a d tc -> tr d tc a\n lam' : (isTrue a d tc -> tr d tc b) -> tr d tc (a :=> b)\n (:$) : tr d tc (a :=> b) -> tr d tc a -> tr d tc b\n\nlam'' : {tr : TmRepr} -> ArrMpTm tr => (tr d tc a -> tr d tc b) -> tr d tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\n\nclass ArrMpTm tr => BoxMpTm (tr : TmRepr) where\n box : tr (succ d) tc a -> tr d tc (BOX a)\n unbox' : tr d tc (BOX a) -> (isTrue a gd tc -> tr d tc b) -> tr d tc b\n\nunbox'' : {tr : TmRepr} -> BoxMpTm tr => tr d tc (BOX a) -> (tr gd tc a -> tr d tc b) -> tr d tc b\nunbox'' x' f = unbox' x' $ \\x => f (var x)\n\nsyntax \"unbox\" [a'] as {a} \":=>\" [b] = unbox'' a' (\\a => b)\n\nThm : Ty -> Type\nThm a = {tr : TmRepr} -> {d : Nat} -> {tc : Cx} -> BoxMpTm tr => tr d tc a\n\n\n-- Example theorems\n\nrNec : Thm a -> Thm (BOX a)\nrNec x =\n box x\n\naK : Thm (BOX (a :=> b) :=> BOX a :=> BOX b)\naK =\n lam f' :=>\n lam x' :=>\n unbox f' as f :=>\n unbox x' as x :=> box (f :$ x)\n\naT : Thm (BOX a :=> a)\naT =\n lam x' :=>\n unbox x' as x :=> x\n\na4 : Thm (BOX a :=> BOX (BOX a))\na4 =\n lam x' :=>\n unbox x' as x :=> box (box x)\n\nt1 : Thm (a :=> BOX (a :=> a))\nt1 =\n lam x :=> box (lam y :=> y)\n", "meta": {"hexsha": "141d94655ebc6a3d23957d628c829780995fe89e", "size": 1698, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pf/BoxMp.idr", "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": ["X11"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_issues_repo_path": "src/Pf/BoxMp.idr", "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_licenses": ["X11"], "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/Pf/BoxMp.idr", "max_forks_repo_name": "mietek/formal-logic", "max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_forks_repo_licenses": ["X11"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.962962963, "max_line_length": 98, "alphanum_fraction": 0.4817432273, "num_tokens": 700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7176204938177535}} {"text": "module Data.RandomAccessList\n\nimport Data.Fin\n\n%default total\n\n-- TODO: Use idris-quickcheck to verify that the chosen implementation matches the\n-- behavior of an implementation that uses induction (see comments)\nselect : (size1 : Nat) -> {size2 : Nat} -> Fin (size1 + size2) -> Either (Fin size1) (Fin size2)\n-- select Z {size2} idx = Right idx\n-- select (S size1) FZ = Left FZ\n-- select (S size1) {size2} (FS idx)\n-- = case select size1 idx of\n-- Left n => Left $ FS n\n-- Right n => Right n\nselect size1 {size2 = Z} idx = Left $ rewrite sym $ plusZeroRightNeutral size1 in idx\nselect size1 {size2 = S _} idx\n = let idxInt = finToInteger idx in\n case integerToFin idxInt size1 of\n Just idx' => Left idx'\n Nothing => Right $ restrict _ (idxInt - cast size1)\n\ndata Tree : (size : Nat) -> (ty : Type) -> Type where\n Singleton : (value : ty) -> Tree (S Z) ty\n Merged : .{halfSize : Nat} -> (left : Tree halfSize ty) -> (right : Tree halfSize ty) -> Tree (halfSize + halfSize) ty\n\ntreeLookup : {size : Nat} -> Fin size -> Tree size ty -> ty\ntreeLookup FZ (Singleton x) = x\ntreeLookup {size = halfSize + halfSize} idx (Merged left right) with (select halfSize idx)\n | (Left idx') = treeLookup idx' left\n | (Right idx') = treeLookup idx' right\n\ntreeUpdate : {size : Nat} -> Fin size -> Tree size ty -> (ty -> ty) -> Tree size ty\ntreeUpdate FZ (Singleton x) f = Singleton $ f x\ntreeUpdate {size = halfSize + halfSize} idx (Merged left right) f with (select halfSize idx)\n | (Left idx') = Merged (treeUpdate idx' left f) right\n | (Right idx') = Merged left (treeUpdate idx' right f)\n\npow2 : Nat -> Nat\npow2 n = power 2 n\n\ndata TreeList : (pos : Nat) -> (size : Nat) -> (ty : Type) -> Type where\n Nil : TreeList _ Z _\n (::) : {nextPos : Nat} -> .{auto posPrf : LT pos nextPos}\n -> .{size : Nat} -> .{auto smaller : LTE (pow2 pos) size}\n -> Tree (pow2 pos) ty -> TreeList nextPos (size - (pow2 pos)) ty\n -> TreeList pos size ty\n\nminusLeftPlusRight : {x, y, z : Nat} -> {auto smaller : LTE y x}\n -> x - y = z -> x = y + z\nminusLeftPlusRight {x} {y = Z} {z} prf = rewrite sym $ minusZeroRight x in prf\nminusLeftPlusRight {x = Z} {y = S _} _ impossible\nminusLeftPlusRight {x = S x'} {y = S y'} {z} {smaller} prf\n = let smaller' = fromLteSucc smaller\n prf' = replace {P = \\var => var = z} (minusSuccSucc x' y') prf\n ind = minusLeftPlusRight prf' in\n cong {f = S} ind\n\ntreeSizeComponents : (pos, size : Nat) -> {auto smaller : LTE (pow2 pos) size}\n -> size = pow2 pos + (size - pow2 pos)\ntreeSizeComponents pos size {smaller} = minusLeftPlusRight Refl\n\ntreeListLookup : {pos, size : Nat} -> Fin size -> TreeList pos size ty -> ty\ntreeListLookup {pos} {size} idx (t :: ts)\n with (let eqPrf = treeSizeComponents pos size\n idx' = (replace {P = \\x => Fin x} eqPrf idx) in\n select (pow2 pos) idx')\n | (Left idx') = treeLookup idx' t\n | (Right idx') = treeListLookup idx' ts\n\ntreeListUpdate : {pos, size : Nat} -> Fin size -> TreeList pos size ty -> (ty -> ty) -> TreeList pos size ty\ntreeListUpdate {pos} {size} idx (t :: ts) f\n with (let eqPrf = treeSizeComponents pos size\n idx' = (replace {P = \\x => Fin x} eqPrf idx) in\n select (pow2 pos) idx')\n | (Left idx') = treeUpdate idx' t f :: ts\n | (Right idx') = t :: treeListUpdate idx' ts f\n\npow2Lemma : (x : Nat) -> (pow2 x + pow2 x) = pow2 (S x)\npow2Lemma Z = Refl\npow2Lemma (S x)\n = let hyp = pow2Lemma x in\n rewrite sym hyp in\n rewrite plusZeroRightNeutral (pow2 x + pow2 x) in\n Refl\n\nlteAddLeft : (m, n : Nat) -> LTE n (m + n)\nlteAddLeft m n = rewrite plusCommutative m n in lteAddRight {m} n\n\nltAddRight : (n : Nat) -> {m : Nat} -> LT n (n + (S m))\nltAddRight n {m} = rewrite sym $ plusSuccRightSucc n m in lteAddRight {m} (S n)\n\nlteAddBoth : {x, y, x', y' : Nat} -> LTE x y -> LTE x' y' -> LTE (x + x') (y + y')\nlteAddBoth {x' = S _} {y' = Z} _ _ impossible\nlteAddBoth {x} {y} {x' = Z} {y'} smaller _\n = rewrite plusZeroRightNeutral x in\n lteTransitive smaller (lteAddRight y)\nlteAddBoth {x} {y} {x' = S x''} {y' = S y''} smaller smaller'\n = let ind = lteAddBoth smaller (fromLteSucc smaller') in\n rewrite sym $ plusSuccRightSucc x x'' in\n rewrite sym $ plusSuccRightSucc y y'' in\n LTESucc ind\n\npow2Monotone : {n, m : Nat} -> LTE n m -> LTE (pow2 n) (pow2 m)\npow2Monotone {n = Z} {m = Z} _ = LTESucc LTEZero\npow2Monotone {n = Z} {m = S m'} _\n = let prf = pow2Monotone {n = Z} {m = m'} LTEZero in\n lteTransitive prf (lteAddRight (pow2 m') {m = (pow2 m' + 0)})\npow2Monotone {n = S _} {m = Z} _ impossible\npow2Monotone {n = S n'} {m = S m'} smaller\n = let prf = pow2Monotone {n = n'} {m = m'} (fromLteSucc smaller)\n prf' = lteAddBoth prf (lteRefl {n = Z}) in\n lteAddBoth prf prf'\n\nminusPlusNeutral : (x, y : Nat) -> LTE y x -> (x - y) + y = x\nminusPlusNeutral x Z _\n = replace {P = \\var => var = x}\n (sym $ plusZeroRightNeutral (x `minus` Z))\n (minusZeroRight x)\nminusPlusNeutral Z (S _) _ impossible\nminusPlusNeutral (S x) (S y) prf\n = let ind = minusPlusNeutral x y (fromLteSucc prf)\n succPrf = plusSuccRightSucc (x `minus` y) y in\n rewrite sym succPrf in\n cong {f = S} ind\n\nplusMinusAssociative : (a, b, c : Nat) -> {auto smaller : LTE c b} -> a + (b `minus` c) = (a + b) `minus` c\nplusMinusAssociative a b Z\n = rewrite minusZeroRight b in\n rewrite minusZeroRight (a + b) in\n Refl\nplusMinusAssociative a Z (S _) impossible\nplusMinusAssociative a (S b) (S c) {smaller}\n = let ind = plusMinusAssociative {smaller = fromLteSucc smaller} a b c\n succPrf = sym $ minusSuccSucc (a + b) c\n p = \\x => (a + b) `minus` c = x `minus` (S c)\n succPrf' = replace {P = p} (plusSuccRightSucc a b) succPrf in\n replace {P = \\x => a + (b `minus` c) = x} succPrf' ind\n\nlteReflAddLeftContra : LTE (x + S y) x -> Void\nlteReflAddLeftContra {x = S _} LTEZero impossible\nlteReflAddLeftContra (LTESucc {left = Z + S y} {right = Z} prf) impossible\nlteReflAddLeftContra (LTESucc {left = S x + S y} {right = S x} prf) = absurd $ lteReflAddLeftContra prf\n\ntreeListCons : {tPos, pos : Nat} -> Tree (pow2 tPos) ty -> TreeList pos size ty -> .{auto fits : LTE tPos pos}\n -> (newPos : Nat ** TreeList newPos (size + (pow2 tPos)) ty)\ntreeListCons {ty} {tPos} t Nil = rewrite plusCommutative Z (pow2 tPos) in\n rewrite plusZeroRightNeutral (pow2 tPos) in\n let nil = replace {P = \\x => TreeList (S tPos) x ty}\n (minusZeroN (pow2 tPos))\n RandomAccessList.Nil\n ts' = (::) {nextPos = S tPos} {posPrf = lteRefl} {smaller = lteRefl} t nil in\n (tPos ** ts')\ntreeListCons {tPos} {pos} {size} t' ((::) {smaller} t ts) {fits} {ty}\n = case cmp tPos pos of\n CmpEQ => let merged = Merged t' t\n merged' = replace {P = \\x => Tree x ty} (pow2Lemma tPos) merged\n (newPos ** ts') = treeListCons {tPos = S tPos} merged' ts in\n rewrite sym $ plusZeroRightNeutral (pow2 tPos) in\n rewrite sym $ minusPlusNeutral size (pow2 tPos) $\n lteTransitive (pow2Monotone fits) smaller in\n rewrite sym $ plusAssociative (size `minus` pow2 tPos) (pow2 tPos) (pow2 tPos + Z) in\n (newPos ** ts')\n CmpLT diff => let p = plusZeroRightNeutral size\n p' = minusZeroN $ pow2 tPos\n p'' = replace {P = \\x => size + x = size} p' p\n p''' = replace {P = \\x => x = size} (plusMinusAssociative {smaller = lteRefl} size (pow2 tPos) (pow2 tPos)) p''\n ts' = (::) {smaller} t ts\n ts'' = replace {P = \\s => TreeList (tPos + (S diff)) s ty} (sym p''') ts'\n ts''' = RandomAccessList.(::) {posPrf = ltAddRight tPos} {smaller = lteAddLeft size (pow2 tPos)} t' ts'' in\n (tPos ** ts''')\n CmpGT diff => absurd $ lteReflAddLeftContra fits\n\npow2StrictlyPositive : (n : Nat) -> LTE 1 (pow2 n)\npow2StrictlyPositive Z = lteRefl\npow2StrictlyPositive (S n)\n = let ind = pow2StrictlyPositive n in\n lteTransitive ind (lteAddRight {m = pow2 n + Z} (pow2 n))\n\nequalsNotLT : {n, m : Nat} -> n = m -> LT n m -> Void\nequalsNotLT {n = Z} {m = Z} _ lt impossible\nequalsNotLT {n = Z} {m = S _} Refl _ impossible\nequalsNotLT {n = S _} {m = Z} Refl _ impossible\nequalsNotLT {n = S n'} {m = S m'} eq (LTESucc lt')\n = equalsNotLT (cong {f = Nat.pred} eq) lt'\n\ntreeListTailHelper : {tPos, tsPos, size : Nat}\n -> Tree (pow2 tPos) ty\n -> TreeList tsPos size ty\n -> {posPrf : LTE tPos tsPos}\n -> let smaller = lteTransitive (pow2StrictlyPositive tPos)\n (lteAddRight {m = size} (pow2 tPos)) in\n (pos' ** TreeList pos' ((-) {smaller} (pow2 tPos + size) (S Z)) ty)\ntreeListTailHelper {size} {tPos = Z} _ ts = rewrite minusZeroRight size in (_ ** ts)\ntreeListTailHelper {ty} {size} {tPos = S pos'} t {tsPos} {posPrf} ts\n = let (_ ** (t', eqPrf)) = eraseSize t in\n case t' of\n Singleton _ => void $ notSingleton eqPrf\n Merged {halfSize} l r =>\n let eqPrf' = replace {P = \\y => halfSize + halfSize = pow2 pos' + y} (plusZeroRightNeutral $ pow2 pos') eqPrf\n l' = replace {P = \\x => Tree x ty} (halve eqPrf') l\n r' = replace {P = \\x => Tree x ty} (halve eqPrf') r\n p = plusZeroRightNeutral size\n p' = minusZeroN $ pow2 pos'\n p'' = replace {P = \\x => size + x = size} p' p\n p''' = replace {P = \\x => x = size} (plusMinusAssociative {smaller = lteRefl} size (pow2 pos') (pow2 pos')) p''\n ts' = replace {P = \\x => TreeList tsPos x ty} (sym p''') ts\n ts'' = RandomAccessList.(::) {posPrf} {smaller = lteAddLeft size (pow2 pos')} r' ts' in\n rewrite plusZeroRightNeutral (pow2 pos') in\n rewrite sym $ plusAssociative (pow2 pos') (pow2 pos') size in\n rewrite plusCommutative (pow2 pos') size in\n treeListTailHelper {posPrf = lteRefl} l' ts''\n where eraseSize : {n : Nat} -> Tree n ty -> (n' : Nat ** (Tree n' ty, n' = n))\n eraseSize t = (_ ** (t, Refl))\n halve : {x, y : Nat} -> x + x = y + y -> x = y\n halve {x = Z} {y = S _} Refl impossible\n halve {x = S _} {y = Z} Refl impossible\n halve {x = Z} {y = Z} _ = Refl\n halve {x = S x'} {y = S y'} prf = cong {f = S} $ halve prev\n where prev : x' + x' = y' + y'\n prev = let prf' = replace {P = \\var => var = S (S y' + y')}\n (sym $ plusSuccRightSucc (S x') x') $\n replace {P = \\var => S x' + S x' = var}\n (sym $ plusSuccRightSucc (S y') y')\n prf in\n cong {f = Nat.pred . Nat.pred} prf'\n notSingleton : {n : Nat} -> 1 = (pow2 n) + (pow2 n + Z) -> Void\n notSingleton {n} eq\n = let eq' = replace {P = \\var => 1 = pow2 n + var}\n (plusZeroRightNeutral $ pow2 n)\n eq\n lte = pow2StrictlyPositive n\n lte' = lteAddBoth lte lte in\n void $ equalsNotLT eq' lte'\n\ntreeListTail : {pos, size : Nat} -> TreeList pos (S size) ty -> (newPos : Nat ** TreeList newPos size ty)\ntreeListTail {ty} {pos} {size} ((::) {posPrf} t ts)\n = let (newPos ** newList) = treeListTailHelper {posPrf = lteSuccLeft posPrf} t ts\n p = plusMinusAssociative (pow2 pos) (S size) (pow2 pos)\n newList' = replace {P = \\x => TreeList newPos (x `minus` 1) ty} p newList\n p' = plusCommutative (pow2 pos) (S size)\n newList'' = replace {P = \\x => TreeList newPos ((x `minus` pow2 pos) `minus` 1) ty} p' newList'\n p'' = sym $ plusMinusAssociative {smaller = lteRefl} (S size) (pow2 pos) (pow2 pos)\n newList''' = replace {P = \\x => TreeList newPos (x `minus` 1) ty} p'' newList'' in\n rewrite sym $ plusZeroRightNeutral size in\n rewrite minusZeroN $ pow2 pos in\n rewrite sym $ minusZeroRight (size + (pow2 pos `minus` pow2 pos)) in\n (newPos ** newList''')\n\nnamespace RandomAccessList\n export\n RandomAccessList : Nat -> Type -> Type\n RandomAccessList size ty = (pos : Nat ** TreeList pos size ty)\n\n export\n empty : RandomAccessList Z ty\n empty = (Z ** Nil)\n\n export\n cons : ty -> RandomAccessList size ty -> RandomAccessList (S size) ty\n cons {size} x (pos ** l)\n = let (pos' ** l') = treeListCons (Singleton x) l in\n rewrite plusCommutative (S Z) size in\n (pos' ** l')\n\n export\n tail : {size : Nat} -> RandomAccessList (S size) ty -> RandomAccessList size ty\n tail (pos ** l) = treeListTail l\n\n export\n index : {size : Nat} -> Fin size -> RandomAccessList size ty -> ty\n index idx (pos ** l) = treeListLookup idx l\n\n export\n update : {size : Nat} -> Fin size -> RandomAccessList size ty -> (ty -> ty) -> RandomAccessList size ty\n update idx (pos ** l) f = (pos ** treeListUpdate idx l f)\n\nnamespace CountedRandomAccessList\n export\n CountedRandomAccessList : Type -> Type\n CountedRandomAccessList ty = (len : Nat ** RandomAccessList len ty)\n\n export\n empty : CountedRandomAccessList ty\n empty = (Z ** RandomAccessList.empty)\n\n export\n cons : ty -> CountedRandomAccessList ty -> CountedRandomAccessList ty\n cons x (size ** arr) = (S size ** cons x arr)\n\n export\n tail : CountedRandomAccessList ty -> CountedRandomAccessList ty\n tail (Z ** arr) = (Z ** arr)\n tail (S size ** arr) = (size ** tail arr)\n\n export\n size : CountedRandomAccessList ty -> Nat\n size (size ** _) = size\n\n export\n index : (idx : Nat) -> (carr : CountedRandomAccessList ty) -> Maybe ty\n index idx (size ** arr)\n = do finIdx <- natToFin idx size\n pure $ index finIdx arr\n\n export\n update : (idx : Nat) -> (carr : CountedRandomAccessList ty) -> (ty -> ty) -> CountedRandomAccessList ty\n update idx (size ** arr) f\n = maybe (size ** arr) \n (\\finIdx => (size ** update finIdx arr f))\n (natToFin idx size)\n", "meta": {"hexsha": "492887e5786eae9971c0ef36317bc0edbc93aa6d", "size": 14350, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/RandomAccessList.idr", "max_stars_repo_name": "jdevuyst/idris-data", "max_stars_repo_head_hexsha": "dab40425d208a09a9cf2ce4dadcf73b053522c1a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-08-02T11:18:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-07T12:32:38.000Z", "max_issues_repo_path": "src/Data/RandomAccessList.idr", "max_issues_repo_name": "jdevuyst/idris-data", "max_issues_repo_head_hexsha": "dab40425d208a09a9cf2ce4dadcf73b053522c1a", "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/Data/RandomAccessList.idr", "max_forks_repo_name": "jdevuyst/idris-data", "max_forks_repo_head_hexsha": "dab40425d208a09a9cf2ce4dadcf73b053522c1a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-16T09:13:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-16T20:00:26.000Z", "avg_line_length": 45.9935897436, "max_line_length": 133, "alphanum_fraction": 0.5717770035, "num_tokens": 4678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7174837358828132}} {"text": "module permutation_with_constructors\n\nimport Data.Vect\nimport congruence\n\n%access public export\n%default total\n\n--- Goal - To define permutations with constructors\n\ndata PermC : Nat -> Type where\n Idt : (n : Nat) -> PermC n -- Identity permutation\n Swap : (n : Nat) -> (pos : Fin n) -> (PermC n)\n{-\n Flip : (n : Nat) -> PermC n -- [1 2 3 ... n]-> [2 1 3 ... n]\n Shift : (n : Nat) -> PermC n -- [1 2 3 .. n] -> [n 1 2 .. (n-1)]\n-}\n CPerm : (n : Nat) -> PermC n -> PermC n -> PermC n\n\n-----------------------------------------------------------------------------------------------------\n\n||| Method to apply the permutation on a vector\n\napplyPerm : (n : Nat) -> (typ : Type) -> (PermC n) -> (Vect n typ) -> (Vect n typ)\n\napplyPerm Z typ perm v = v\napplyPerm (S Z) typ perm v = v\napplyPerm (S (S k)) typ (Idt (S (S k))) v = v\n\napplyPerm (S (S k)) typ (Swap (S (S k)) FZ) v =\n (index (FS FZ) v) :: ( (index FZ v) :: (tail(tail v)))\n\napplyPerm (S (S k)) typ (Swap (S (S k)) (FS pos)) (a :: v) =\n a :: (applyPerm (S k) typ (Swap (S k) pos) v)\n--applyPerm (S (S k)) t (Flip (S (S k))) v = (index (FS FZ) v) :: ( (index FZ v) :: (tail(tail v)))\n--applyPerm (S (S k)) t (Shift (S (S k))) v = reverse( (index FZ v) :: (reverse (tail v)))\n\napplyPerm n typ (CPerm n f g) v = applyPerm n typ f (applyPerm n typ g v)\n\n-----------------------------------------------------------------------------------------------------\n\n||| Proof that applyperm respects composition\n\napplyPerm_Comp : (n : Nat) -> (typ : Type) -> (f, g : PermC n) -> (v : Vect n typ) ->\n ( ((applyPerm n typ (CPerm n f g) ) v) = applyPerm n typ f (applyPerm n typ g v))\n\napplyPerm_Comp Z typ p q v = Refl\napplyPerm_Comp (S Z) typ p q v = Refl\napplyPerm_Comp (S (S k)) typ p q v = Refl\n\n{-\n||| The permutation which shifts k times\n\nmany_shifts : (n : Nat) -> (k : Nat) -> (PermC n)\nmany_shifts n Z = Idt n\nmany_shifts n (S k) = CPerm n (Shift n) (many_shifts n k)\n-}\n\n-----------------------------------------------------------------------------------------------------\n\n||| viewing a permutation of n elements as a permutation of (n + 1) elements with the first element\n||| not moved\n\nincludePerm : (n : Nat) -> (PermC n) -> (PermC (S n))\nincludePerm Z perm = (Idt (S Z))\nincludePerm (S Z) perm = (Idt (S (S Z)))\nincludePerm n (Idt n) = Idt (S n)\nincludePerm n (Swap n pos) = Swap (S n) (FS pos)\n--includePerm (S (S k)) (Flip (S (S k))) = Flip (S (S (S k)))\n--includePerm (S (S k)) (Shift (S (S k))) = ?rhs\nincludePerm n (CPerm n f g) = CPerm (S n) (includePerm n f) (includePerm n g)\n\n-----------------------------------------------------------------------------------------\n\nappSwap : (n : Nat) -> (typ : Type) -> (k : Fin n) -> (Vect n typ) -> (Vect n typ)\nappSwap n typ k v = applyPerm n typ (Swap n k) v\n\n-----------------------------------------------------------------------------------------\n\n||| auxilliary proof - a map from Fin Z to Void\naux_pf_1 : Fin Z -> Void\naux_pf_1 k impossible\n\n-----------------------------------------------------------------------------------------\n\n||| swap is the inverse of itself\nSelf_inv_swap : (n : Nat) -> (typ : Type) -> (k : (Fin n)) -> (v : (Vect n typ))->\n ((((appSwap n typ k) . (appSwap n typ k)) v) = v)\n\nSelf_inv_swap Z typ k v = Refl\nSelf_inv_swap (S Z) typ k v = Refl\nSelf_inv_swap (S (S n)) typ FZ (a :: b :: v) = Refl\nSelf_inv_swap (S (S n)) typ (FS k) (a :: v) =\n (rewrite (Self_inv_swap (S n) typ k v) in Refl)\n\n------------------------------------------------------------------------------------------\n\n\nIs_Left_Inv : (n : Nat) -> (typ : Type) -> (f : ((Vect n typ) -> (Vect n typ)) ) ->\n (g : ((Vect n typ) -> (Vect n typ)) ) -> Type\nIs_Left_Inv n typ f g = ( (v : (Vect n typ)) -> ( ((g . f) v) = v))\n\n------------------------------------------------------------------------------------------\n\nIs_Right_Inv : (n : Nat) -> (typ : Type) -> (f : ((Vect n typ) -> (Vect n typ)) ) ->\n (g : ((Vect n typ) -> (Vect n typ)) ) -> Type\nIs_Right_Inv n typ f g = ( (v : (Vect n typ)) -> ( ((f . g) v) = v))\n\n------------------------------------------------------------------------------------------\n\nIs_Inv : (n : Nat) -> (typ : Type) -> (f : ((Vect n typ) -> (Vect n typ)) ) ->\n (g : ((Vect n typ) -> (Vect n typ)) ) -> Type\nIs_Inv n typ f g = ( (Is_Left_Inv n typ f g) , (Is_Right_Inv n typ f g))\n------------------------------------------------------------------------------------------\n\n||| (left) Inv(f.h) = (Inv h).(Inv f)\n\nLeft_Inv_comp : (n : Nat) -> (typ : Type) ->\n (f, g, h, k : ((Vect n typ) -> (Vect n typ)) ) ->\n (Is_Left_Inv n typ f g) -> (Is_Left_Inv n typ h k) ->\n (Is_Left_Inv n typ (f . h) (k . g))\n\nLeft_Inv_comp n typ f g h k pf_fg pf_hk = pf_3 where\n\n pf_1 : (v : (Vect n typ)) -> ((g (f (h v))) = (h v) )\n pf_1 v = pf_fg (h v)\n\n pf_2 : (v : (Vect n typ)) -> ( (k (g (f (h v)))) = (k (h v)) )\n pf_2 v = congruence (Vect n typ) (Vect n typ)\n ((g . f . h) v) (h v) k (pf_1 v)\n\n pf_3 : (v : (Vect n typ)) -> ( (k (g (f (h v)))) = v )\n pf_3 v = trans (pf_2 v) (pf_hk v)\n\n------------------------------------------------------------------------------------------\n\n||| (right) Inv(f.h) = (Inv h).(Inv f)\n\nRight_Inv_comp : (n : Nat) -> (typ : Type) ->\n (f, g, h, k : ((Vect n typ) -> (Vect n typ)) ) ->\n (Is_Right_Inv n typ f g) -> (Is_Right_Inv n typ h k) ->\n (Is_Right_Inv n typ (f . h) (k . g))\n\nRight_Inv_comp n typ f g h k pf_fg pf_hk = pf_3 where\n\n pf_1 : (v : (Vect n typ)) -> ((h (k (g v))) = (g v))\n pf_1 v = pf_hk (g v)\n\n pf_2 : (v : (Vect n typ)) -> ((f (h (k (g v)))) = (f (g v)) )\n pf_2 v = congruence (Vect n typ) (Vect n typ)\n ((h . k . g) v) (g v) f (pf_1 v)\n\n pf_3 : (v : (Vect n typ)) -> ( (f (h (k (g v)))) = v)\n pf_3 v = trans (pf_2 v) (pf_fg v)\n\n------------------------------------------------------------------------------------------\n\n\n||| Inverse of f.g is (inv g).(inv f)\n\nInv_comp : (n : Nat) -> (typ : Type) ->\n (f, g, h, k : ((Vect n typ) -> (Vect n typ)) ) ->\n (Is_Inv n typ f g) -> (Is_Inv n typ h k) ->\n (Is_Inv n typ (f . h) (k . g))\n\nInv_comp n typ f g h k pf_fg pf_hk = let\n pf_left_fg = fst pf_fg\n pf_right_fg = snd pf_fg\n pf_left_hk = fst pf_hk\n pf_right_hk = snd pf_hk\n pf_left = Left_Inv_comp n typ f g h k pf_left_fg pf_left_hk\n pf_right = Right_Inv_comp n typ f g h k pf_right_fg pf_right_hk\n in\n (pf_left, pf_right)\n\n------------------------------------------------------------------------------------------\n\n||| The type of bijections\n\nIsBijection : (n : Nat) -> (typ : Type) -> (f : (Vect n typ) -> (Vect n typ) ) -> Type\nIsBijection n typ f =\n (g : ((Vect n typ) -> (Vect n typ)) ** ( Is_Inv n typ f g))\n\n\n||| Proof that permutations are bijections\n\n\nPermC_are_bij : (n : Nat) -> (typ : Type) -> (perm : PermC n) ->\n (IsBijection n typ (applyPerm n typ perm) )\n\nPermC_are_bij Z typ perm = (idZ ** (fun, fun)) where\n idZ : (Vect Z typ) -> (Vect Z typ)\n idZ = applyPerm Z typ perm\n fun : (v : (Vect Z typ)) -> (v = v)\n fun v = Refl\n\n\nPermC_are_bij (S Z) typ perm = (idSZ ** (fun, fun)) where\n idSZ : (Vect (S Z) typ) -> (Vect (S Z) typ)\n idSZ = applyPerm (S Z) typ (Idt (S Z))\n fun : (v : (Vect (S Z) typ)) -> (v = v)\n fun v = Refl\n\nPermC_are_bij (S (S k)) typ (Idt (S (S k))) = (idn ** (fun, fun)) where\n idn : (Vect (S (S k)) typ) -> (Vect (S (S k)) typ)\n idn = applyPerm (S (S k)) typ (Idt (S (S k)))\n fun : (v : (Vect (S (S k)) typ)) -> (v = v)\n fun v = Refl\n\n\nPermC_are_bij (S (S k)) typ (Swap (S (S k)) pos) =\n ( (appSwap (S (S k)) typ pos) ** (fun, fun)) where\n fun : (v : Vect (S (S k)) typ ) ->\n ((((appSwap (S (S k)) typ pos) . (appSwap (S (S k)) typ pos)) v) = v)\n fun v = (Self_inv_swap (S (S k)) typ pos v)\n\nPermC_are_bij n typ (CPerm n f h) = let\n inv_f = PermC_are_bij n typ f\n g = fst inv_f\n pf_fg = snd inv_f\n pf_fg_left = fst pf_fg\n pf_fg_right = snd pf_fg\n f1 = (applyPerm n typ f)\n\n inv_h = PermC_are_bij n typ h\n k = fst inv_h\n pf_hk = snd inv_h\n pf_hk_left = fst pf_hk\n pf_hk_right = snd pf_hk\n h1 = (applyPerm n typ h)\n\n pf_com = applyPerm_Comp n typ f h\n pf_com_1 = \\v => (congruence (Vect n typ) (Vect n typ)\n (applyPerm n typ (CPerm n f h) v)\n (applyPerm n typ f (applyPerm n typ h v))\n (k . g) (pf_com v) )\n\n pf_left_1 =\n Left_Inv_comp n typ f1 g h1 k pf_fg_left pf_hk_left\n\n pf_left = \\v => (trans (pf_com_1 v) (pf_left_1 v))\n\n pf_right_1 =\n Right_Inv_comp n typ f1 g h1 k pf_fg_right pf_hk_right\n\n pf_right = \\v => (trans (pf_com ((k . g) v) ) (pf_right_1 v) )\n\n in\n ( (k . g) ** (pf_left , pf_right))\n", "meta": {"hexsha": "2a316833e77c115b9394e0be45a97fcafbcd74b7", "size": 8886, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/PermCons.idr", "max_stars_repo_name": "rathivrunda/LTS2019", "max_stars_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": "Code/PermCons.idr", "max_issues_repo_name": "rathivrunda/LTS2019", "max_issues_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": "Code/PermCons.idr", "max_forks_repo_name": "rathivrunda/LTS2019", "max_forks_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "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": 35.544, "max_line_length": 101, "alphanum_fraction": 0.4549853702, "num_tokens": 2946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7174837316320114}} {"text": "> module Nat.examples.InductiveProofs\n \n> import Syntax.PreorderReasoning\n\n> succPlusLeftRightEqPlusLeftSuccRight : (m : Nat) -> (n : Nat) -> S (plus m n) = plus m (S n)\n> succPlusLeftRightEqPlusLeftSuccRight Z n = Refl\n> succPlusLeftRightEqPlusLeftSuccRight (S m) n = ( S (plus (S m) n) )\n> ={ Refl }=\n> ( S (S (plus m n)) )\n> ={ cong (succPlusLeftRightEqPlusLeftSuccRight m n) }=\n> ( S (plus m (S n)) )\n> ={ Refl }=\n> ( plus (S m) (S n) )\n> QED\n\n", "meta": {"hexsha": "28130988c4892fb33dd6ed264f1f3ef26de4e8df", "size": 773, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/examples/InductiveProofs.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Nat/examples/InductiveProofs.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Nat/examples/InductiveProofs.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.3125, "max_line_length": 100, "alphanum_fraction": 0.3686934023, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.7173825338203024}} {"text": "module TypeSynonym\n\nimport Data.Vect\n\ntri : Vect 3 (Double, Double)\ntri = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)]\n\n-- Type Synonym, similar to type alias in Scala and Haskell\nPosition : Type\nPosition = (Double, Double)\n\ntriBetter : Vect 3 Position\ntriBetter = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)]\n\n-- Type Synonym, which is actually a function which computes a type\nPolygon : Nat -> Type\nPolygon n = Vect n Position\n\ntriPoly : Polygon 3\ntriPoly = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)]\n\ntriEval : Polygon 3\ntriEval = [(?triEval_rhs1, ?triEval_rhs2),\n (?triEval_rhs3, ?triEval_rhs4),\n (?triEval_rhs5, ?triEval_rhs6)]\n", "meta": {"hexsha": "16298903cd4b2b5a154d15c9b755cd7a9a51106d", "size": 631, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeSynonym.idr", "max_stars_repo_name": "balajisivaraman/idris-book", "max_stars_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-06T12:38:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-06T12:38:55.000Z", "max_issues_repo_path": "TypeSynonym.idr", "max_issues_repo_name": "balajisivaraman/idris-book", "max_issues_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "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": "TypeSynonym.idr", "max_forks_repo_name": "balajisivaraman/idris-book", "max_forks_repo_head_hexsha": "2452de85e54de0242ec074a95762bde6fc4fe672", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-04T17:48:35.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-04T17:48:35.000Z", "avg_line_length": 24.2692307692, "max_line_length": 67, "alphanum_fraction": 0.6386687797, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7172345371012881}} {"text": "> module List.DecIn\n> import Data.List\n> %access public export\n\nA type can have decidable list membership:\n\n> ||| Decision procedures for determining list membership.\n> interface DecIn (t: Type) where\n> decIn: (x:t) -> (xs : List t) -> Dec (Elem x xs)\n\nDecidable equality and decidable list membership are equivalent. The first half\nof the proof is quite easy - if we have decidable list membership, then \ndeciding $x=y$ can be solved by determining $`DecIn` x [y]$.\n\n> ||| Given an implementation of DecIn t, t has decidable equality.\n> ||| Note: the implementation must be named due to a bug in Idris 1,\n> ||| see (#4296)[https://github.com/idris-lang/Idris-dev/issues/4296]\n> [decInToDecEqImpl] DecIn t => DecEq t where\n> decEq x y = case (decIn x [y]) of\n> Yes Here => Yes Refl\n> No contra => No (\\eq => contra (rewrite eq in Here))\n\nFor the second half of the equivalence, we will need a trivial helper lemmas:\n\n> matchingSingleton : Data.List.Elem x [y] -> (x = y)\n> matchingSingleton Here = Refl\n> matchingSingleton (There later) impossible\n\nUsing this, proving decidable equality gives decidable list memership is a bit\nintricate, but mostly straightforward. The small difficulty arises from the fact\nthat, when deciding list membership, we traverse the list head-to-tail, but the\nIdris prelude `Elem` goes from tail-to-head (building up `There` and `Here` \ncalls). So we will need to make a recursive call on the tail of the list.\n\nNote: perhaps this can be cleaned up a bit, it seems rather circuitous. \n\n> DecEq t => DecIn t where\n> decIn x [] = No absurd\n> decIn x (y::ys) with (decIn x ys) \n> decIn x (y::ys) | No notLater = case decEq x y of\n> Yes Refl => Yes Here\n> No contra => No (\\later => \n> case later of\n> Here => contra (matchingSingleton Here)\n> (There t) => notLater t)\n> decIn x (y::ys) | Yes later = Yes (There later)\n\n> ElementPreservingCorrespondence : DecIn t => List t -> List t -> Type\n> ElementPreservingCorrespondence xs ys = (x : t) -> (Elem x xs -> Elem x ys, Elem x ys -> Elem x xs)\n\n> ||| ElementPreservingCorrespondence is a reflexive relation on lists.\n> elementPreservingCorrespondenceReflexive : DecIn t => {xs : List t} -> ElementPreservingCorrespondence xs xs\n> elementPreservingCorrespondenceReflexive {xs=[]} _ = (\\a => absurd a, \\b => absurd b)\n> elementPreservingCorrespondenceReflexive {xs = (y::ys)} x = \n> case decIn x (y::ys) of\n> Yes pf => (\\a => pf,\\b => pf)\n> No contra => (\\a => absurd (contra a), \\b => absurd (contra b))\n\n> ||| ElementPreservingCorrespondence is a symmetric relation on lists.\n> elementPreservingCorrespondenceSymmetric : DecIn t => {xs,ys : List t} -> ElementPreservingCorrespondence xs ys -> ElementPreservingCorrespondence ys xs\n> elementPreservingCorrespondenceSymmetric pf x = (snd (pf x),fst (pf x))\n\n> ||| ElementPreservingCorrespondence is a transitive relation on lists.\n> elementPreservingCorrespondenceTransitive : \n> DecIn t => {xs,ys,zs : List t} -> \n> ElementPreservingCorrespondence xs ys -> \n> ElementPreservingCorrespondence ys zs ->\n> ElementPreservingCorrespondence xs zs\n> elementPreservingCorrespondenceTransitive pf1 pf2 x = \n> ((fst (pf2 x)) . (fst (pf1 x)), (snd (pf1 x)) . (snd (pf2 x)))\n\n", "meta": {"hexsha": "c2df163eec2b782a9522a964415078a428b53e69", "size": 3410, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Data/List/DecIn.lidr", "max_stars_repo_name": "nicklecompte/idris-finite-sets", "max_stars_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_stars_repo_licenses": ["CC0-1.0"], "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/Data/List/DecIn.lidr", "max_issues_repo_name": "nicklecompte/idris-finite-sets", "max_issues_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_issues_repo_licenses": ["CC0-1.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": "src/Data/List/DecIn.lidr", "max_forks_repo_name": "nicklecompte/idris-finite-sets", "max_forks_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.3611111111, "max_line_length": 154, "alphanum_fraction": 0.6668621701, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7172178131281922}} {"text": "module NatProps\n\nimport Basic\nimport Unit\nimport Void\nimport Coproduct\nimport Nat\nimport Sigma\nimport Path\nimport CoproductProps\nimport PreorderReasoning\nimport General\nimport Dec\n\n%default total\n\nNegN : (n : Nat) -> Type -> Type\nNegN Z p = p\nNegN (S k) p = Neg (NegN k p)\n\ndni : p -> NegN N.two p\ndni a u = u a\n\ncontrapositive : (a -> b) -> (Neg b -> Neg a)\ncontrapositive f v a = v (f a)\n\ntno : NegN N.three p -> Neg p\ntno = contrapositive dni\n\nabsurdityX3IsAbsurdity : {p : _} -> NegN N.three p <=> Neg p\nabsurdityX3IsAbsurdity = firstly # secondly\n where\n firstly : NegN N.three p -> Neg p\n firstly = tno\n\n secondly : Neg p -> NegN N.three p\n secondly = dni\n\nPositiveNotZero : (x : Nat) -> S x /= Z\n-- p : S x == Z\nPositiveNotZero x p = UnitNotVoid (g p)\n where\n f : Nat -> Type\n f Z = Void\n f (S _) = Unit\n\n g : S x == Z -> Unit == Void\n g = ap f\n\npred : Nat -> Nat\npred Z = Z\npred (S k) = k\n\nSuccLeftCancel : {x, y : _} -> S x == S y -> x == y\nSuccLeftCancel = ap pred\n\nNatNotSuccNat : (x : Nat) -> x /= S x\nNatNotSuccNat Z = negSym (PositiveNotZero Z)\nNatNotSuccNat (S k) = let r = NatNotSuccNat k in \\l =>\n r (SuccLeftCancel l)\n\n-- Proof that Nat has decidable equality.\n-- Doesn't use pattern matching.\n-- OMG\n-- You'll never know the true value of pattern matching\n-- until you are left without it (as an exercise).\nnamespace NatDec\n Lemma0 : {x, y : _} -> x == y -> (S x /= y)\n Lemma0 p = J (\\x, y, _ => (S x /= y))\n (\\x => negSym (NatNotSuccNat x)) x y p\n\n Lemma1 : {x, y : _} -> Dec (x == y) -> Dec (S x == S y)\n Lemma1 = SumInduction (const $ Dec (S x == S y))\n (\\p => Inl (ap S p))\n (\\p => Inr (\\l => p (SuccLeftCancel l)))\n\n export\n NatDecEq : DecEq Nat\n NatDecEq x y = NatInduction (\\x => (y : Nat) -> (x == y) + (x /= y))\n -- p0 : (y : Nat) -> (Z == y) + (Z /= y)\n (\\y => (NatInduction (\\y => (Z == y) + (Z /= y))\n -- p0\n (Inl $ Refl Z)\n -- pn\n (\\y, _ => Inr (negSym $ PositiveNotZero y))\n --n\n y))\n -- pn : (x : Nat) -> (y : Nat) -> (S x == y) + (S x /= y)\n -- hyp : Dec (x == y)\n (\\x, hyp, y =>\n NatInduction (\\y => (S x == y) + (S x /= y))\n --p0\n (Inr (PositiveNotZero x))\n --pn\n (\\y, _ => Lemma1 $ hyp y)\n --n\n y)\n x y\n\nplusAssoc : (x, y, z : Nat) -> (x + y) + z == x + (y + z)\nplusAssoc Z y z = Chain $ || (Z + y) + z\n |=> Z + (y + z) ...(Refl _)\nplusAssoc (S x) y z = Chain $ || (S x + y) + z\n |=> S ((x + y) + z) ...(Refl _)\n |=> S (x + (y + z)) ...(ap S $ plusAssoc x y z)\n |=> (S x + (y + z)) ...(Refl _)\n\nBaseOnRight : (x : Nat) -> x + Z == x\nBaseOnRight Z = Refl _\nBaseOnRight (S x) = ap S (BaseOnRight x)\n\nStepOnRight : (x, y : Nat) -> x + S y == S (x + y)\n-- goal : S y == S (Z + y)\nStepOnRight Z y = Refl _\n-- goal : S (x + S y) == S (S (x + y))\nStepOnRight (S x) y = Chain $ || S (x + S y)\n |=> S (S (x + y)) ...(ap S $ StepOnRight x y)\n\nPlusComm : (x, y : Nat) -> x + y == y + x\nPlusComm x Z = BaseOnRight x\n-- goal : x + S y == S (y + x)\nPlusComm x (S y) = Chain $ || x + S y\n |=> S (x + y) ...(StepOnRight x y)\n |=> S (y + x) ...(ap S $ PlusComm x y)\n\nOnLhs : {x, y, z : _} -> x == z -> x == y -> z == y\nOnLhs p q = sym p . q\n\nOnRhs : {x, y, z : _} -> y == z -> x == y -> x == z\nOnRhs p q = q . p\n\nPlusRightCancel : (x, y, z : Nat) -> x + y == z + y -> x == z\n-- goal : x == z\n-- prf : x + Z == z + Z\nPlusRightCancel x Z z prf = Chain $ || x\n |=> x + Z ...(sym $ BaseOnRight x)\n |=> z + Z ...prf\n |=> z ...(BaseOnRight z)\n-- goal : x == z\n-- prf : x + S y == z + S y\n-- prf' : TypeOf prf -> x + y == z + y\n-- hyp : x + y == z + y -> x == z\nPlusRightCancel x (S y) z prf =\n let prf' =\n Chain $ || x + S y == z + S y\n |=> S (x + y) == z + S y ...(OnLhs $ StepOnRight x y)\n |=> S (x + y) == S (z + y) ...(OnRhs $ StepOnRight z y)\n |=> x + y == z + y ...SuccLeftCancel\n $\n prf\n in PlusRightCancel x y z prf'\n\n||| Alternative definition of non-strict inequality.\nLte' : Nat -> Nat -> Type\nLte' x y = Sigma Nat (\\z => z + x == y)\n\nLteImpliesLte' : (x, y : Nat) -> x <= y -> Lte' x y\nLteImpliesLte' Z y _ = y # (Chain $ || y + Z\n |=> Z + y ...(PlusComm y Z))\nLteImpliesLte' (S _) Z l = VoidRecursion _ l\n-- prf : z + x == y\n-- goal : z + S x == S y\nLteImpliesLte' (S x) (S y) l = let z # prf = LteImpliesLte' x y l in\n let prf' = Chain $ || z + x == y\n |=> x + z == y ...(OnLhs $ PlusComm z x)\n |=> S x + z == S y ...(ap S)\n |=> z + S x == S y ...(OnLhs $ PlusComm (S x) z)\n $ prf\n in z # prf'\n\nLte'ImpliesLte : (x, y : Nat) -> Lte' x y -> x <= y\nLte'ImpliesLte Z _ _ = ()\nLte'ImpliesLte (S x) Z (z # contra) =\n let contra' = OnLhs (PlusComm z (S x)) contra in\n let p = PositiveNotZero (x + z) in\n p contra'\nLte'ImpliesLte (S x) (S y) (z # prf) =\n let prf' = Chain $ || z + S x == S y\n |=> S x + z == S y ...(OnLhs $ PlusComm z (S x))\n |=> x + z == y ...(ap pred)\n |=> z + x == y ...(OnLhs $ PlusComm x z)\n $ prf in\n Lte'ImpliesLte x y (z # prf')\n\nLogicallyEqualivalentLte : (x, y : Nat) -> x <= y <=> Lte' x y\nLogicallyEqualivalentLte x y = LteImpliesLte' x y\n # Lte'ImpliesLte x y\n\nLteRefl : (n : Nat) -> n <= n\nLteRefl Z = ()\nLteRefl (S n) = LteRefl n\n\nLteTrans : (l, m, n : Nat) -> l <= m -> m <= n -> l <= n\nLteTrans Z m n q p = ()\nLteTrans (S l) Z n q p = VoidRecursion _ q\nLteTrans (S l) (S m) Z q p = VoidRecursion _ p\nLteTrans (S l) (S m) (S n) q p = LteTrans l m n q p\n\nLteAnti : (m, n : Nat) -> m <= n -> n <= m -> m == n\nLteAnti Z Z q p = Refl Z\nLteAnti (S m) Z q p = VoidRecursion _ q\nLteAnti Z (S n) q p = VoidRecursion _ p\nLteAnti (S m) (S n) q p = ap S $ LteAnti m n q p\n\nLteSucc : (n : Nat) -> n <= S n\nLteSucc Z = ()\nLteSucc (S n) = LteSucc n\n\nZeroMinimal : (n : Nat) -> Z <= n\nZeroMinimal _ = ()\n\nUniqueMinimal : (n : Nat) -> n <= Z -> n == Z\nUniqueMinimal Z p = Refl Z\nUniqueMinimal (S n) p = VoidRecursion _ p\n\nLteSplit : (m, n : Nat) -> m <= S n -> (m <= n) + (m == S n)\nLteSplit Z n p = Inl ()\nLteSplit (S m) Z p with (UniqueMinimal _ p)\n LteSplit (S Z) Z p | Refl _ = Inr (Refl (S Z))\nLteSplit (S m) (S n) p = let H = LteSplit m n p in\n case H of\n Inl p => Inl p\n Inr p => Inr (ap S p)\n\nLteSplit' : (m, n : Nat) -> m <= n -> (S m <= n) + (m == n)\nLteSplit' Z Z p = Inr (Refl Z)\nLteSplit' Z (S n) p = Inl ()\nLteSplit' (S m) Z p = VoidRecursion _ p\nLteSplit' (S m) (S n) p =\n case LteSplit' m n p of\n Inl x => Inl x\n Inr x => Inr (ap S x)\n\n\ninfixl 1 <\n\n(<) : Nat -> Nat -> Type\nx < y = S x <= y\n\nNotLtGivesLte : (m, n : Nat) -> Neg (n < m) -> m <= n\nNotLtGivesLte Z n _ = ()\nNotLtGivesLte (S m) Z p = p ()\nNotLtGivesLte (S m) (S n) p = NotLtGivesLte m n p\n\nBoundedForallNext : (p : Nat -> Type)\n -> (k : Nat)\n -> p k\n -> ((n : Nat) -> n < k -> p n)\n -> (n : Nat) -> n < S k -> p n\nBoundedForallNext p k pk f n l with (LteSplit' n k l)\n BoundedForallNext p k pk f n l | Inl prf = f n prf\n BoundedForallNext p k pk f k l | Inr (Refl _) = pk\n\n||| The type of roots of a function.\nRoot : (Nat -> Nat) -> Type\nRoot f = Sigma Nat (\\n => f n == Z)\n\nHasNoRootLt : (Nat -> Nat) -> Nat -> Type\nHasNoRootLt f k = (n : Nat) -> n < k -> f n /= Z\n\nIsMinimalRoot : (Nat -> Nat) -> Nat -> Type\nIsMinimalRoot f m = Pair (f m == Z) (f `HasNoRootLt` m)\n\nAtMostOneMinimalRoot : (f : Nat -> Nat)\n -> (m, n : Nat)\n -> IsMinimalRoot f m\n -> IsMinimalRoot f n\n -> m == n\n-- prfm : forall n. n < m -> f n == Z -> Void\n-- prfn : forall m. m < n -> f m == Z -> Void\nAtMostOneMinimalRoot f m n (rm # prfm) (rn # prfn) = c _ _ a b\n where\n a : Neg (m < n)\n a contra = prfn m contra rm\n\n b : Neg (n < m)\n b contra = prfm n contra rn\n\n c : (m, n : Nat) -> Neg (m < n) -> Neg (n < m) -> m == n\n c m n q q' = LteAnti m n (NotLtGivesLte _ _ q') (NotLtGivesLte _ _ q)\n\nMinimalRoot : (Nat -> Nat) -> Type\nMinimalRoot f = Sigma Nat (IsMinimalRoot f)\n\nMinimalRootIsRoot : MinimalRoot f -> Root f\nMinimalRootIsRoot (r # prf # _) = r # prf\n\nBoundedNatSearch : (k, f : _) -> MinimalRoot f + (f `HasNoRootLt` k)\nBoundedNatSearch Z f = Inr (\\_, v, _ => v)\nBoundedNatSearch (S k) f = SumRecursion _ Inl y\n (BoundedNatSearch k f)\n where\n A : Nat -> (Nat -> Nat) -> Type\n A k f = MinimalRoot f + (f `HasNoRootLt` k)\n\n y : f `HasNoRootLt` k -> A (S k) f\n y u = SumRecursion _ y0 y1 (NatDecEq (f k) Z)\n where\n y0 : f k == Z -> A (S k) f\n y0 p = Inl (k # p # u)\n\n y1 : f k /= Z -> A (S k) f\n y1 v = Inr (BoundedForallNext (\\n => f n /= Z) k v u)\n\nRightFailsGivesLeftHolds : {P, Q : Type} -> P + Q -> Neg Q -> P\nRightFailsGivesLeftHolds (Inl p) u = p\nRightFailsGivesLeftHolds (Inr q) u = VoidRecursion _ (u q)\n\nRootGivesMinimalRoot : (f : _) -> Root f -> MinimalRoot f\nRootGivesMinimalRoot f (n # p) = y\n where\n g : Neg (f `HasNoRootLt` S n)\n g phi = phi n (LteRefl n) p\n\n y : MinimalRoot f\n y = RightFailsGivesLeftHolds (BoundedNatSearch (S n) f) g\n\n", "meta": {"hexsha": "41cda7dd3cf3a910d1fad95401ea44e56f8d91b3", "size": 9491, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/NatProps.idr", "max_stars_repo_name": "Russoul/Idris2-HoTT", "max_stars_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-17T05:44:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T09:36:13.000Z", "max_issues_repo_path": "src/NatProps.idr", "max_issues_repo_name": "Russoul/Idris2-HoTT", "max_issues_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "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/NatProps.idr", "max_forks_repo_name": "Russoul/Idris2-HoTT", "max_forks_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "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": 29.8459119497, "max_line_length": 76, "alphanum_fraction": 0.4846696871, "num_tokens": 3644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7170046183129609}} {"text": "import DataStore\n\nimport Data.Vect\n\n{- 1 -}\n\ntestStore : DataStore (SString .+. SInt)\ntestStore = addToStore (\"First\", 1) $\n addToStore (\"Second\", 2) $\n empty\n\ngetValues : DataStore (SString .+. val_schema) ->\n List (SchemaType val_schema)\ngetValues input with (storeView input)\n getValues empty | SNil = []\n getValues (addToStore (key, value) store) | (SAdd rec)\n = value :: getValues store | rec\n\n{- 2 -}\n\nexport\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\nexport\ntriangle : Double -> Double -> Shape\ntriangle = Triangle\n\nexport\nrectangle : Double -> Double -> Shape\nrectangle = Rectangle\n\nexport\ncircle : Double -> Shape\ncircle = Circle\n\ndata ShapeView : Shape -> Type where\n STriangle : ShapeView (triangle base height)\n SRectangle : ShapeView (rectangle width height)\n SCircle : ShapeView (circle radius)\n\nshapeView : (s : Shape) -> ShapeView s\nshapeView (Triangle x y) = STriangle\nshapeView (Rectangle x y) = SRectangle\nshapeView (Circle x) = SCircle\n\narea : Shape -> Double\narea s with (shapeView s)\n area (triangle base height) | STriangle = 0.5 * base * height\n area (rectangle width height) | SRectangle = width * height\n area (circle radius) | SCircle = pi * radius * radius\n", "meta": {"hexsha": "d0027547dcdcdc7a81b7e6f0445b906e0aa5cece", "size": 1299, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter10/Exercises/ex_10_3.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 161, "max_stars_repo_stars_event_min_datetime": "2017-02-27T02:28:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T22:17:47.000Z", "max_issues_repo_path": "Chapter10/Exercises/ex_10_3.idr", "max_issues_repo_name": "gdevanla/TypeDD-Samples", "max_issues_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2017-03-26T23:27:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:32:25.000Z", "max_forks_repo_path": "Chapter10/Exercises/ex_10_3.idr", "max_forks_repo_name": "gdevanla/TypeDD-Samples", "max_forks_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-03-19T11:01:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-10T05:30:22.000Z", "avg_line_length": 24.5094339623, "max_line_length": 63, "alphanum_fraction": 0.6712856043, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7169209401549426}} {"text": "module BasicProofs\n\n%default total\n\n{-\n data Equal : a -> b -> Type where\n Refl : Equal x x\n-}\n\nproofNotTrue : (not True) = False\nproofNotTrue = Refl\n\nproofNotFalse : (not False) = True\nproofNotFalse = Refl\n\nproofOnePlusOne : 1 + 1 = 2\nproofOnePlusOne = Refl\n\nproofNotInvolutive : (x : Bool) -> not (not x) = x\nproofNotInvolutive False = Refl\nproofNotInvolutive True = Refl\n\nplusZeroRightNeutral : (left : Nat) -> left + 0 = left\nplusZeroRightNeutral Z = Refl\nplusZeroRightNeutral (S k) =\n let inductiveHypothesis = plusZeroRightNeutral k in\n rewrite inductiveHypothesis in Refl\n\nvarEquality : m = m\nvarEquality = Refl\n", "meta": {"hexsha": "76e234ddea07af32bb2278a98676c606b1b218a5", "size": 629, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "theorem_proving/BasicProofs.idr", "max_stars_repo_name": "timmyjose-study/idris-from-the-docs", "max_stars_repo_head_hexsha": "ea1b7af57245ddb29b5d9d24ae623e37ecc01d12", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "theorem_proving/BasicProofs.idr", "max_issues_repo_name": "timmyjose-study/idris-from-the-docs", "max_issues_repo_head_hexsha": "ea1b7af57245ddb29b5d9d24ae623e37ecc01d12", "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": "theorem_proving/BasicProofs.idr", "max_forks_repo_name": "timmyjose-study/idris-from-the-docs", "max_forks_repo_head_hexsha": "ea1b7af57245ddb29b5d9d24ae623e37ecc01d12", "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": 20.2903225806, "max_line_length": 54, "alphanum_fraction": 0.7170111288, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.7167500909474119}} {"text": "everyOther : Stream a -> Stream a\neveryOther (val1 :: val2 :: xs) = val2 :: everyOther xs\n\nsquareRootApprox : (number : Double) -> (approx : Double) -> Stream Double\nsquareRootApprox number approx =\n let next = (approx + (number / approx)) / 2 in\n next :: squareRootApprox number next\n\nsquareRootBound : (max : Nat) -> (number : Double) -> (bound : Double)->\n (approxs : Stream Double) -> Double\nsquareRootBound Z number bound (value :: xs) = value\nsquareRootBound (S k) number bound (value :: xs) =\n if value * value - number < bound\n then value\n else squareRootBound k number bound xs\n\nsquareRoot : (num : Double) -> Double\nsquareRoot num = squareRootBound 100 num 0.00000000001 (squareRootApprox num num)\n", "meta": {"hexsha": "ad57de4ccd7b8005064aa8c3ab648232be7e578f", "size": 738, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/11_1.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/11_1.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/11_1.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": 38.8421052632, "max_line_length": 81, "alphanum_fraction": 0.6761517615, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438126, "lm_q2_score": 0.8152324871074607, "lm_q1q2_score": 0.7167089954837743}} {"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 definitions for probability distributions.\nmodule Distribution\n\nimport Data.Nat\nimport Tensor\n\n||| A joint, or multivariate distribution over a tensor of floating point values, where the first\n||| two central moments (mean and covariance) are known. Every sub-event is assumed to have the\n||| same shape.\n|||\n||| @event The shape of each sub-event.\n||| @dist Constructs the distribution from the number of events in the distribution.\npublic export\ninterface Distribution (0 event : Shape) (0 dist : (0 dim : Nat) -> Type) | dist where\n ||| The mean of the distribution.\n mean : dist dim -> Tensor (dim :: event) Double\n\n ||| The covariance, or correlation, between sub-events.\n cov : dist dim -> Tensor (dim :: dim :: event) Double\n\n||| The variance of a single random variable.\nexport\nvariance : Distribution event dist => dist 1 -> Tensor (1 :: event) Double\nvariance dist = squeeze {from=(1 :: 1 :: event)} $ cov dist\n\n||| A joint, or multivariate distribution over a tensor of floating point values, where the density\n||| function and corresponding cumulative density function are known (either analytically or via\n||| approximation). Every sub-event is assumed to have the same shape.\n|||\n||| @event The shape of each sub-event.\n||| @dist Constructs the distribution from the number of events in the distribution.\npublic export\ninterface Distribution event dist =>\n ClosedFormDistribution (0 event : Shape) (0 dist : (0 dim : Nat) -> Type) where\n ||| The probability density function of the distribution at the specified point.\n pdf : dist (S d) -> Tensor (S d :: event) Double -> Tensor [] Double\n\n ||| The cumulative distribution function of the distribution at the specified point (that is,\n ||| the probability the random variable takes a value less than or equal to the given point).\n cdf : dist (S d) -> Tensor (S d :: event) Double -> Tensor [] Double\n\n||| A joint Gaussian distribution.\n|||\n||| @event The shape of each sub-event.\n||| @dim The number of sub-events.\npublic export\ndata Gaussian : (0 event : Shape) -> (0 dim : Nat) -> Type where\n ||| @mean The mean of the events.\n ||| @cov The covariance between events.\n MkGaussian : {d : Nat} -> (mean : Tensor (S d :: event) Double) ->\n (cov : Tensor (S d :: S d :: event) Double) ->\n Gaussian event (S d)\n\nexport\nDistribution event (Gaussian event) where\n mean (MkGaussian mean' _) = mean'\n cov (MkGaussian _ cov') = cov'\n\nexport\nClosedFormDistribution [1] (Gaussian [1]) where\n pdf (MkGaussian {d} mean cov) x =\n let diff : Tensor [S d, 1] Double\n diff = x - mean\n\n exponent : Tensor [] Double\n exponent = - (squeeze $ diff.T @@ cov.T @@ diff) / (const 2.0)\n\n denominator : Tensor [] Double\n denominator = (const $ 2 * pi) ^ (const $ cast (S d) / 2.0)\n * (det $ squeeze {to=[S d, S d]} cov) ^ const 0.5\n\n in (exp exponent) / denominator\n\n cdf (MkGaussian mean cov) x = ?cdf_rhs\n", "meta": {"hexsha": "03e65112be16b452e01cfd1a67ecb2d5ee2c031a", "size": 3551, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Distribution.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/Distribution.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/Distribution.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": 39.4555555556, "max_line_length": 99, "alphanum_fraction": 0.6862855534, "num_tokens": 885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.7166677416896907}} {"text": "module Diff\n\nsub: (n: Nat) -> (m: Nat) -> (LTE m n) -> Nat\nsub n Z LTEZero = n\nsub (S right) (S left) (LTESucc x) = sub right left x\n\nrl: (n: Nat) -> LTE n n\nrl Z = LTEZero\nrl (S k) = LTESucc (rl k)\n\nrs: (n: Nat) -> LTE n (S n)\nrs Z = LTEZero\nrs (S k) = LTESucc (rs k)\n\nzm : (n: Nat) -> LTE n 0 -> n = 0\nzm Z LTEZero = ?zm_rhs_1\n\nes: (n: Nat) -> (m: Nat) -> (n = m) -> S n = S m\nes m m Refl = Refl\n\nans : (n: Nat) -> (m: Nat) -> (LTE n m) -> (LTE m n) -> n = m\nans Z Z LTEZero LTEZero = Refl\nans (S a) (S b) (LTESucc x) (LTESucc y) = es a b (ans a b x y)\n\ncontra: (1 = 2) -> Void\ncontra Refl impossible\n\ndata IsEven : Nat -> Type where\n ZeroEven : IsEven 0\n PlusTwo : (n: Nat) -> IsEven n -> IsEven (S (S n))\n\ntwoEven : IsEven 2\ntwoEven = PlusTwo 0 ZeroEven\n\noneOdd : (IsEven 1) -> Void\noneOdd ZeroEven impossible\noneOdd (PlusTwo _ _) impossible\n\none: Nat\none = 1\n\nthreeOdd : (IsEven 3) -> Void\nthreeOdd (PlusTwo (S Z) ZeroEven) impossible\nthreeOdd (PlusTwo (S Z) (PlusTwo _ _)) impossible\n\nthmEven : (n: Nat) -> Either (IsEven n) (IsEven (S n))\nthmEven Z = Left ZeroEven\nthmEven (S k) = case thmEven k of\n (Left l) => Right (PlusTwo k l)\n (Right r) => Left r\n\ndivTwo: (n: Nat) -> IsEven n -> Nat\ndivTwo Z ZeroEven = 0\ndivTwo (S (S k)) (PlusTwo k x) = S (divTwo k x)\n", "meta": {"hexsha": "da600713149070bd5782230ef2677a5fd5a928aa", "size": 1309, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/code/diff.idr", "max_stars_repo_name": "rohit3499/LTS2019", "max_stars_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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": "_local-site/code/diff.idr", "max_issues_repo_name": "rohit3499/LTS2019", "max_issues_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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": "_local-site/code/diff.idr", "max_forks_repo_name": "rohit3499/LTS2019", "max_forks_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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.8, "max_line_length": 62, "alphanum_fraction": 0.5760122231, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.7165863012035961}} {"text": "module Data.Vect.Elem\n\nimport Data.Vect\nimport Decidable.Equality\n\n--------------------------------------------------------------------------------\n-- Vector membership proof\n--------------------------------------------------------------------------------\n\n||| A proof that some element is found in a vector\npublic export\ndata Elem : a -> Vect k a -> Type where\n Here : Elem x (x::xs)\n There : (later : Elem x xs) -> Elem x (y::xs)\n\nexport\nUninhabited (Elem x []) where\n uninhabited Here impossible\n\n||| An item not in the head and not in the tail is not in the Vect at all\nexport\nneitherHereNorThere : Not (x = y) -> Not (Elem x xs) -> Not (Elem x (y :: xs))\nneitherHereNorThere xneqy xninxs Here = xneqy Refl\nneitherHereNorThere xneqy xninxs (There xinxs) = xninxs xinxs\n\n||| A decision procedure for Elem\npublic export\nisElem : DecEq a => (x : a) -> (xs : Vect n a) -> Dec (Elem x xs)\nisElem x [] = No uninhabited\nisElem x (y::xs) with (decEq x y)\n isElem x (x::xs) | (Yes Refl) = Yes Here\n isElem x (y::xs) | (No xneqy) with (isElem x xs)\n isElem x (y::xs) | (No xneqy) | (Yes xinxs) = Yes (There xinxs)\n isElem x (y::xs) | (No xneqy) | (No xninxs) = No (neitherHereNorThere xneqy xninxs)\n\npublic export\nreplaceElem : (xs : Vect k t) -> (1 _ : Elem x xs) -> (y : t) -> (ys : Vect k t ** Elem y ys)\nreplaceElem (x::xs) Here y = (y :: xs ** Here)\nreplaceElem (x::xs) (There xinxs) y with (replaceElem xs xinxs y)\n replaceElem (x::xs) (There xinxs) y | (ys ** yinys) = (x :: ys ** There yinys)\n\npublic export\nreplaceByElem : (xs : Vect k t) -> (1 _ : Elem x xs) -> t -> Vect k t\nreplaceByElem (x::xs) Here y = y :: xs\nreplaceByElem (x::xs) (There xinxs) y = x :: replaceByElem xs xinxs y\n\npublic export\nmapElem : {0 xs : Vect k t} -> {0 f : t -> u} ->\n (1 _ : Elem x xs) -> Elem (f x) (map f xs)\nmapElem Here = Here\nmapElem (There e) = There (mapElem e)\n\n||| Remove the element at the given position.\n|||\n||| @xs The vector to be removed from\n||| @p A proof that the element to be removed is in the vector\npublic export\ndropElem : {k : _} -> (xs : Vect (S k) t) -> (1 _ : Elem x xs) -> Vect k t\ndropElem (x::ys) Here = ys\ndropElem {k = S k} (x::ys) (There later) = x :: dropElem ys later\n\n||| Erase the indices, returning the bounded numeric position of the element\npublic export\nelemToFin : {0 xs : Vect n a} -> (1 _ : Elem x xs) -> Fin n\nelemToFin Here = FZ\nelemToFin (There p) = FS (elemToFin p)\n\n||| Find the element with a proof at a given bounded position\npublic export\nindexElem : (1 _ : Fin n) -> (xs : Vect n a) -> (x ** Elem x xs)\nindexElem FZ (y::_) = (y ** Here)\nindexElem (FS n) (_::ys) = let (x ** p) = indexElem n ys in\n (x ** There p)\n", "meta": {"hexsha": "871a6df28c36f85ac0884fb2f197837583d40efb", "size": 2751, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/Vect/Elem.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/base/Data/Vect/Elem.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/base/Data/Vect/Elem.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": 37.1756756757, "max_line_length": 93, "alphanum_fraction": 0.5776081425, "num_tokens": 910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7163789463435218}} {"text": "\nmodule Term\n\n-- Simply-typed lambda calculus with \n-- (1) natural numbers as the only base type, and\n-- (2) general recursion.\n-- This calculus is also referred to as PCF.\n--\n-- Note that variables in the lambda calculus are not\n-- named but identified by their de Bruijn index.\n\n\nimport Data.Fin\nimport public Data.Vect\n\n\n%default total\n%access public export\n\n\n---------------------------------------------------\n-- Begin: TYPES IN THE SIMPLY-TYPED LAMBDA CALCULUS\n\n-- Data type 'Ty' represents the types in the\n-- simply-typed lambda calculus:\n-- (1) Base type 'TyNat' of natural numbers.\n-- (2) Type constructor 'TyFun' for forming\n-- function types.\ndata Ty = TyNat | TyFun Ty Ty\n\n\n-- Simplified syntax for function types:\ninfixr 10 :->:\n(:->:) : Ty -> Ty -> Ty\n(:->:) t1 t2 = TyFun t1 t2\n\n-- End: TYPES IN THE SIMPLY-TYPED LAMBDA CALCULUS\n-------------------------------------------------\n\n\n\n---------------------------------------------------------\n-- Begin: CONTEXT FOR TYPING TERMS IN THE LAMBDA CALCULUS\n\nContext : Nat -> Type\nContext n = Vect n Ty\n\n-- End: CONTEXT FOR TYPING TERMS IN THE LAMBDA CALCULUS\n-------------------------------------------------------\n\n\n\n-------------------------------------------------\n-- Begin: WELL-TYPED TERMS OF THE LAMBDA CALCULUS\n\n-- Data type of well-typed terms in the \n-- simply-typed lambda calculus:\ndata Term : Context n -> Ty -> Type where\n -- Variable:\n -- The data constructor for variables ('Var') takes\n -- as arguments a de Bruijn index ('i') and a proof\n -- ('prf') that the variable at index 'i' in the \n -- context 'ctx' has type 't'.\n TVar : (i : Fin n) -> {auto prf : index i ctx = t} -> \n Term ctx t\n -- Abstraction:\n -- The data constructor for abstractions ('Abs')\n -- takes as its first (implicit) argument the\n -- type of the variable that is bound by this\n -- abstraction.\n TAbs : {s : Ty} -> Term (s::ctx) t ->\n Term ctx (s :->: t)\n -- Application:\n TApp : Term ctx (s :->: t) -> Term ctx s -> \n Term ctx t \n -- Fix-point operator:\n TFix : Term ctx (t :->: t) -> \n Term ctx t\n -- Constant 'Zero' (natural number):\n TZero : Term ctx TyNat\n -- Successor:\n TSucc : Term ctx TyNat ->\n Term ctx TyNat\n -- Predecessor:\n TPred : Term ctx TyNat ->\n Term ctx TyNat\n -- Test for equality with 'Zero' \n -- (with terms for the \"then\" and\n -- \"else\" branches):\n TIfz : Term ctx TyNat -> Term ctx t -> Term ctx t ->\n Term ctx t\n\n-- End: WELL-TYPED TERMS OF THE LAMBDA CALCULUS\n-----------------------------------------------\n\n\n\n---------------------------------------\n-- Begin: VALUES IN THE LAMBDA CALCULUS \n\n-- The following lambda calculus terms\n-- are values (i.e. normal forms for \n-- reduction under the \"Step\" relation):\n-- (1) lambda abstractions (that are\n-- not applied),\n-- (2) the constant 'Zero',\n-- (3) the natural number constants\n-- (formed by applying 'Succ' to\n-- another value). \ndata Value : Term [] t -> Type where\n VZero : Value TZero\n VSucc : Value e -> Value (TSucc e)\n VAbs : Value (TAbs e)\n\n\nvalueTerm : {e : Term [] t} -> Value e -> Term [] t\nvalueTerm {e = e} _ = e\n\n-- End: VALUES IN THE LAMBDA CALCULUS \n-------------------------------------\n", "meta": {"hexsha": "271fe72edbc62aab62d6ae8ea708f239ff1d7880", "size": 3266, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "typed/src/Term.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "typed/src/Term.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "typed/src/Term.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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.9917355372, "max_line_length": 57, "alphanum_fraction": 0.5526638089, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.7163694199311994}} {"text": "module Intro\n\nsm : List Nat -> Nat\nsm [] = 0\nsm (x :: xs) = x + (sm xs)\n\nfct : Nat -> Nat\nfct Z = 1\nfct (S k) = (S k) * (fct k)\n\nfbp : Nat -> (Nat, Nat)\nfbp Z = (1, 1)\nfbp (S k) = (snd (fbp k), fst (fbp k) + snd (fbp k))\n\nfib : Nat -> Nat\nfib n = fst (fbp n)\n\nadd : Nat -> Nat -> Nat\nadd Z j = j\nadd (S k) j = S (add k j)\n\nmul : Nat -> Nat -> Nat\nmul Z j = Z\nmul (S k) j = add j (mul k j)\n\nsub : (n: Nat) -> (m : Nat) -> (LTE m n) -> Nat\nsub n Z LTEZero = n\nsub (S right) (S left) (LTESucc x) = sub right left x\n", "meta": {"hexsha": "b13e6e637140988e2db1c54717fac60044cfce4c", "size": 512, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/code/intro.idr", "max_stars_repo_name": "rohit3499/LTS2019", "max_stars_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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": "_local-site/code/intro.idr", "max_issues_repo_name": "rohit3499/LTS2019", "max_issues_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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": "_local-site/code/intro.idr", "max_forks_repo_name": "rohit3499/LTS2019", "max_forks_repo_head_hexsha": "c8ad0d45487523d6ad5fa570750350a7fcec07d3", "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.6551724138, "max_line_length": 53, "alphanum_fraction": 0.498046875, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.716369407684988}} {"text": "-- By considering the terms in the Fibonacci sequence whose values do not exceed \n-- four million, find the sum of the even-valued terms.\n\nimport Data.List\nimport Data.Stream\n\nstreamWhile : (a -> Bool) -> Stream a -> List a\nstreamWhile f (x::xs) = \n if f x \n then x :: (streamWhile f xs) \n else []\n\neven : Nat -> Bool\neven Z = True\neven (S n) = not (even n)\n\nfib : Stream Nat -- Why is this SOOOO slow?!\nfib = 0 :: zipWith (+) fib (1::fib)\n\nmain : IO ()\nmain = print (sum (filter even (streamWhile (\\x => x <= 4000000) fib)))\n\n", "meta": {"hexsha": "0877f8b219cfbfd1709ad2577c967e4a88743da0", "size": 536, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "quint/euler002.idr", "max_stars_repo_name": "edu-di-wu/project-euler", "max_stars_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "quint/euler002.idr", "max_issues_repo_name": "edu-di-wu/project-euler", "max_issues_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "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": "quint/euler002.idr", "max_forks_repo_name": "edu-di-wu/project-euler", "max_forks_repo_head_hexsha": "65ab70df3a35e56e85080f6db0245c2612736a61", "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": 23.3043478261, "max_line_length": 81, "alphanum_fraction": 0.6324626866, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947070591977, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.7161116647246859}} {"text": "module Ex8\n\nimport Decidable.Equality\nimport Data.Nat\nimport Data.Vect\n\n%default total\n\nsame_cons : { xs : List a } -> { ys : List a } -> xs = ys -> x :: xs = x :: ys\nsame_cons Refl = Refl\n\nsame_lists : { xs : List a } -> { ys : List a } -> x = y -> xs = ys -> x :: xs = y :: ys\nsame_lists Refl Refl = Refl\n\ndata ThreeEq : a -> b -> c -> Type where\n AllSame : ThreeEq x x x\n\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS _ _ _ AllSame = AllSame \n\nmyPlusCommutes : (n : Nat) -> (m : Nat) -> n + m = m + n\nmyPlusCommutes Z m = rewrite plusZeroRightNeutral m in Refl\nmyPlusCommutes (S k) m = rewrite myPlusCommutes k m in\n rewrite plusSuccRightSucc m k in Refl\n\nreverseProof_nil : Vect n a -> Vect (plus n 0) a\nreverseProof_nil {n} xs = rewrite plusZeroRightNeutral n in xs\n\nreverseProof_xs : Vect (S n + k) a -> Vect (plus n (S k)) a\nreverseProof_xs {n} {k} xs = rewrite sym (plusSuccRightSucc n k) in xs\n\nmyReverse : Vect n a -> Vect n a\nmyReverse xs = reverse' [] xs where\n reverse' : forall n, m. Vect n a -> Vect m a -> Vect (n + m) a\n reverse' acc [] = reverseProof_nil acc\n reverse' acc (x :: xs) = reverseProof_xs (reverse' (x :: acc) xs)\n\nheadUnequal : DecEq a => { xs : Vect n a } -> { ys : Vect n a } -> \n (contra : (x = y) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\nheadUnequal contra Refl = contra Refl\n\ntailUnequal : DecEq a => { xs : Vect n a } -> { ys : Vect n a } -> \n (contra : (xs = ys) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\ntailUnequal contra Refl = contra Refl\n", "meta": {"hexsha": "84d61da9d5662df5a50d35f01cd3a3494e96ff51", "size": 1608, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter8/Ex8.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter8/Ex8.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": "chapter8/Ex8.idr", "max_forks_repo_name": "timmyjose-study/tdd-with-idris", "max_forks_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": 35.7333333333, "max_line_length": 88, "alphanum_fraction": 0.5758706468, "num_tokens": 539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7160210904157698}} {"text": "module Examples\n\nimport Linear.Equality\nimport Linear.Types\nimport Data.Fin\nimport Data.Nat\nimport QPF\nimport QCont\n\n\n-- Example 12\nnamespace ListAsQCont\n\n ListCont : Type -> Type\n ListCont = F Nat Fin\n\n MaybeCont : Type -> Type\n MaybeCont = F Bool (\\b => if b then I else Fin 0)\n\n Just : x -<> MaybeCont x\n Just x = True # (\\Star => x)\n\n Nothing : (Fin 0 -<> x) -<> MaybeCont x\n Nothing f = False # f\n\n head : ListCont x -<> MaybeCont x\n head (0 # f) = Nothing f\n head (S n # f) = Just (f 0)\n\n-- Example 21\nnamespace NatAsQPF\n\n NatF : Desc\n NatF = Sum' (Const' I) Id'\n\n N : Type\n N = W NatF\n\n Zero : N\n Zero = Con (Inl Star)\n\n Suc : N -> N\n Suc n = Con (Inr n)\n\n elim : (0 p : N -> Type) -> p Zero -> ((0 n : N) -> p n -<> p (Suc n)) ->\n (1 n : N) -> p n\n elim p p0 ps = induction {p = p} f where\n f : (1 w : Sigma0 (qpf NatF N) (lift NatF p)) -> p (Con (fst w))\n f (_ # (Inl (Star # (Refl # (Star # Refl))))) = p0\n f (_ # (Inr (b # (Refl # ih)))) = ps b ih\n\n-- Example 22\nnamespace BinTreeAsQPF\n parameters (a : Type)\n\n BtF : Desc\n BtF = Sum' (Const' a) (Prod' Id' Id')\n\n Tree : Type\n Tree = W BtF\n\n Leaf : a -<> Tree\n Leaf x = Con (Inl x)\n\n Node : Tree -<> Tree -<> Tree\n Node l r = Con (Inr (l # r))\n\n\n elim : (0 p : Tree -> Type) ->\n (pl : (1 x : a) -> p (Leaf x)) ->\n (pn : (0 l : Tree) -> (0 r : Tree) -> p l -<> p r -<> p (Node l r)) ->\n (1 t : Tree) -> p t\n elim p pl pn = induction {p = p} f where\n f : (1 w : Sigma0 (qpf BtF Tree) (lift BtF p)) -> p (Con (fst w))\n f (_ # Inl (x # (Refl # (x # Refl)))) = pl x\n f (x # Inr (w # (q # (ihl # ihr)))) = replace1 (\\ y => p (Con y)) (eq x w q) (pn _ _ ihl ihr)\n where\n eq : (0 x : Sum a (LPair (W (Sum' (Const' a) (Prod' Id' Id'))) (W (Sum' (Const' a) (Prod' Id' Id'))))) ->\n (0 w : LPair (W (Sum' (Const' a) (Prod' Id' Id'))) (W (Sum' (Const' a) (Prod' Id' Id')))) ->\n (1 q : x = Inr w) -> Inr (fst w # snd w) = x\n eq (Inr (w1 # w2)) (w1 # w2) Refl = Refl\n", "meta": {"hexsha": "1c6eaf7523a1edf614144e1f0b0a5027236c63df", "size": 2071, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Examples.idr", "max_stars_repo_name": "g-nakov/quantitative-poly", "max_stars_repo_head_hexsha": "7602304f9e85b2a4abf1db08328d3ea302c854da", "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": "Examples.idr", "max_issues_repo_name": "g-nakov/quantitative-poly", "max_issues_repo_head_hexsha": "7602304f9e85b2a4abf1db08328d3ea302c854da", "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": "Examples.idr", "max_forks_repo_name": "g-nakov/quantitative-poly", "max_forks_repo_head_hexsha": "7602304f9e85b2a4abf1db08328d3ea302c854da", "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": 25.256097561, "max_line_length": 113, "alphanum_fraction": 0.483341381, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7159711554361364}} {"text": "\nimport Data.Fin\nimport Data.Vect\n\ntail : {0 A : Type} -> {n : Nat} -> (Fin (S n) -> A) -> (Fin n -> A)\ntail f = f . FS\n\ntoVect : {0 A : Type} -> {n : Nat} -> (Fin n -> A) -> Vect n A\ntoVect {n = Z} _ = Nil\ntoVect {n = S m} f = (f FZ) :: (toVect (tail f))\n\nrecord Iso a b where\n constructor MkIso\n to : a -> b\n from : b -> a\n toFrom : (y : b) -> to (from y) = y\n fromTo : (x : a) -> from (to x) = x\n\ninterface Finite t where\n card : Nat\n iso : Iso t (Fin card)\n\n -- default methods\n\n foo : Vect card t\n foo = toVect (from iso)\n", "meta": {"hexsha": "1311404cfcd4bc2524b00fdaab0c30762fa7c71b", "size": 540, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interface012/Defmeth.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/interface012/Defmeth.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/interface012/Defmeth.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": 20.0, "max_line_length": 68, "alphanum_fraction": 0.5203703704, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.754914975839675, "lm_q1q2_score": 0.7157760544244467}} {"text": "module Order\n\n%default total\n%access public export\n\ndata InclusiveEither : (typeLeft : Type) -> (typRight : Type) -> Type where\n\tLeftInc : typLeft -> Not typRight -> InclusiveEither typLeft typRight\n\tRightInc : Not typLeft -> typRight -> InclusiveEither typLeft typRight\n\tBoth : typLeft -> typRight -> InclusiveEither typLeft typRight\n\ndata ExclusiveEither : (typLeft : Type) -> (typRight : Type) -> Type where\n\tLeftExc : typLeft -> Not typRight -> ExclusiveEither typLeft typRight\n\tRightExc : Not typLeft -> typRight -> ExclusiveEither typLeft typRight\n\n|||Type of subset of a set\nsubset : Type -> Type\nsubset typ = (typ -> Bool)\n\n|||Type of proof that an element x belongs to a subset\nisIn : {typ : Type} -> (subset typ) -> (x : typ) -> Type\nisIn {typ} subSet x = ((subSet x) = True)\n\n|||Type of proof that two relations are equal\nrelEqual : {typ : Type} -> (typ -> typ -> Type) -> (typ -> typ -> Type) -> Type\nrelEqual {typ} r1 r2 = (a : typ) -> (b : typ) -> ((r1 a b) -> (r2 a b), (r2 a b) -> (r1 a b))\n\n|||Induces a strict relation from a relation\ntoStrictRelation : {typ : Type} -> (r : (typ -> typ -> Type)) -> (typ -> typ -> Type)\ntoStrictRelation r = (\\a => (\\b => (r a b, Not (a = b))))\n\n|||Induces a reverse relation from a relation\ntoReverseRelation : {typ : Type} -> (r : (typ -> typ -> Type)) -> (typ -> typ -> Type)\ntoReverseRelation r = (\\a => (\\b => (r b a)))\n\n|||Induces a strict reverse relation from a relation\ntoStrictReverseRelation : {typ : Type} -> (r : (typ -> typ -> Type)) -> (typ -> typ -> Type)\ntoStrictReverseRelation r = (\\a => (\\b => (r b a, Not (b = a))))\n\n|||Type of proof that a relation is reflexive\nisReflexive : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisReflexive {typ} r = {a : typ} -> (r a a)\n\n|||Type of proof that a relation is symmetric\nisSymmetric : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisSymmetric {typ} r = {a : typ} -> {b : typ} -> (r a b) -> (r b a)\n\n|||Type of proof that a relation is anti-symmetric\nisAntiSymmetric : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisAntiSymmetric {typ} r = {a : typ} -> {b : typ} -> (r a b) -> (r b a) -> (a = b)\n\n|||Type of proof that a relation is transitive\nisTransitive : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisTransitive {typ} r = {a : typ} -> {b : typ} -> {c : typ} -> (r a b) -> (r b c) -> (r a c)\n\n|||Type of proof that a relation is an equivalence\nisEquivalence : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisEquivalence {typ} r = (isReflexive r, isSymmetric r, isTransitive r)\n\n|||Type of proof that a relation is a partial order\nisPartialOrder : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisPartialOrder {typ} r = (isReflexive r, isAntiSymmetric r, isTransitive r)\n\n|||Type of proof that a relation is a total order\nisTotalOrder : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisTotalOrder {typ} r = (isPartialOrder r, (a : typ) -> (b : typ) -> (InclusiveEither (r a b) ((toReverseRelation r) a b)))\n\n|||Type of proof that a relation is a well-order\nisWellOrder : {typ : Type} -> (r : (typ -> typ -> Type)) -> Type\nisWellOrder {typ} r = (isPartialOrder r, (subSet : (subset typ)) -> (a : typ ** (isIn subSet a, ((x : typ) -> (isIn subSet x) -> (r a x)))))\n\n|||Proof that the reverse of the reverse of the relation is the relation\nreverseIdempotent : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t(relEqual r (toReverseRelation (toReverseRelation r)))\nreverseIdempotent {typ} {r} a b = (id, id)\n\n|||Proof that the reverse of a reflexive relation is reflexive\nreversePreservesRefl : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t\t(isReflexive r) -> (isReflexive (toReverseRelation r))\nreversePreservesRefl {typ} {r} rIsRefl = rIsRefl\n\n|||Proof that the reverse of a symmetric relation is symmetric\nreversePreservesSymm : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t\t(isSymmetric r) -> (isSymmetric (toReverseRelation r))\nreversePreservesSymm {typ} {r} rIsSymm = rIsSymm\n\n|||Proof that the reverse of an anti-symmetric relation is anti-symmetric\nreversePreservesAntiSymm : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t\t\t(isAntiSymmetric r) -> (isAntiSymmetric (toReverseRelation r))\nreversePreservesAntiSymm {typ} {r} rIsAntiSymm relLeft relRight = rIsAntiSymm relRight relLeft\n\n|||Proof that the reverse of a transitive relation is transitive\nreversePreservesTrans : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t\t(isTransitive r) -> (isTransitive (toReverseRelation r))\nreversePreservesTrans {typ} {r} rIsTrans relLeft relRight = rIsTrans relRight relLeft\n\n|||Proof that a reverse order of a symmetric relation is the relation itself\nreverseSymmEq : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t(isSymmetric r) -> (relEqual r (toReverseRelation r))\nreverseSymmEq {typ} {r} rIsSymmetric a b = (rIsSymmetric, rIsSymmetric)\n\n|||Proof that a reverse order of a partial order is a partial order\nreversePOrderIsPOrder : {typ : Type} -> {r : (typ -> typ -> Type)} ->\n\t\t\t\t\t(isPartialOrder r) -> (isPartialOrder (toReverseRelation r))\nreversePOrderIsPOrder {typ} {r} (rIsRefl, rIsAntiSym, rIsTrans) = (rIsRefl, reversePreservesAntiSymm rIsAntiSym, reversePreservesTrans {typ} {r} rIsTrans)\n\n|||Proof that !(b <= a) implies a != b\nnotSymmImpliesNotEq : {typ : Type} -> {r : (typ -> typ -> Type)} -> (isReflexive r) -> (Not ((toReverseRelation r) a b)) -> (Not (a = b))\nnotSymmImpliesNotEq {typ} {r} rIsRefl notLTE Refl = void(notLTE rIsRefl)\n\n|||Proof that a total order leads to a strict order\ntoStrictOrder : {typ : Type} -> {r : (typ -> typ -> Type)} -> (isTotalOrder r) -> ((a : typ) -> (b : typ) -> (Either (a = b) (ExclusiveEither ((toStrictRelation r) a b) ((toStrictReverseRelation r) a b))))\ntoStrictOrder {typ} {r} rIsTotalOrder a b =\n\tcase rIsTotalOrder of\n\t(rIsPartialOrder, rIsTotal) =>\n\t\tcase (rIsPartialOrder) of\n\t\t(rIsRefl, rIsAntiSymm, rIsTrans) =>\n\t\t\t\tcase (rIsTotal a b) of\n\t\t\t\t(Both leftOrder rightOrder) => Left (rIsAntiSymm leftOrder rightOrder)\n\t\t\t\t(LeftInc leftOrder notRightOrder) => Right (LeftExc (leftOrder, notSymmImpliesNotEq rIsRefl notRightOrder) (\\rightOrder => notRightOrder (fst rightOrder)))\n\t\t\t\t(RightInc notLeftOrder rightOrder) => Right (RightExc (\\leftOrder => notLeftOrder (fst leftOrder)) (rightOrder, notSymmImpliesNotEq rIsRefl notLeftOrder))\n", "meta": {"hexsha": "04931a7c330fd7e61666fb9834c6b8700c8f9193", "size": 6263, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/Order.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": "_local-site/Code/Order.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": "_local-site/Code/Order.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": 51.7603305785, "max_line_length": 205, "alphanum_fraction": 0.6554366917, "num_tokens": 2026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.715597055719874}} {"text": "\nmodule BigStep\n\n-- Relation 'BigStep' for fully reducing terms\n-- in the simply-typed lambda calculus to values.\n \n\nimport Term\nimport Subst\n\n\n%default total\n%access public export\n\n\n-----------------------------------------------------------------------\n-- Begin: BIG-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n\n-- The relation 'BigStep' defines evaluation of terms in the lambda\n-- calculus following big-step semantics.\n--\n-- Big-step semantics fully evaluates terms to values.\n-- (A proof of this statement appears below.)\ndata BigStep : Term [] t -> (y: Term [] t) -> Type where\n BStValue : (v : Value e) -> BigStep e e\n --\n BStApp : BigStep e1 (TAbs e1') ->\n BigStep e2 e2' ->\n BigStep (subst e2' FZ e1') e ->\n BigStep (TApp e1 e2) e\n -- \n BStFix : BigStep e (TAbs e') ->\n BigStep (subst (TFix (TAbs e')) FZ e') e'' ->\n BigStep (TFix e) e''\n -- \n BStSucc : BigStep e e' ->\n BigStep (TSucc e) (TSucc e')\n -- \n BStPredZero : BigStep e TZero ->\n BigStep (TPred e) TZero\n -- \n BStPredSucc : BigStep e (TSucc e') ->\n BigStep (TPred e) e'\n -- \n BStIfzZero : BigStep e1 TZero ->\n BigStep e2 e ->\n BigStep (TIfz e1 e2 _) e\n -- \n BStIfzSucc : BigStep e1 (TSucc _) ->\n BigStep e3 e ->\n BigStep (TIfz e1 _ e3) e\n\n\nbigStepFst : {e : Term [] t} -> BigStep e _ -> Term [] t\nbigStepFst {e = e} _ = e\n\n\nbigStepSnd : {e : Term [] t} -> BigStep _ e -> Term [] t\nbigStepSnd {e = e} _ = e\n\n\nbigStepValue : BigStep _ e -> Value e\nbigStepValue (BStValue v) = v\nbigStepValue (BStApp _ _ z) = bigStepValue z\nbigStepValue (BStFix _ z) = bigStepValue z\nbigStepValue (BStSucc z) = VSucc (bigStepValue z)\nbigStepValue (BStPredZero _) = VZero\nbigStepValue (BStPredSucc z) = case bigStepValue z of\n VZero impossible\n VSucc v => v\nbigStepValue (BStIfzZero _ z) = bigStepValue z\nbigStepValue (BStIfzSucc _ z) = bigStepValue z\n \n-- End: BIG-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n---------------------------------------------------------------------\n\n\n\n---------------------------------------------------------\n-- Begin: DIVERGENCE OF TERM 'Subst.omega' UNDER BIG-STEP\n\n-- The following straightforward approach to proving\n-- that 'omega' diverges does not pass Idris' totality\n-- checker because of the rewriting of 'bst' in the\n-- induction step:\n--\n-- divergenceOmega : BigStep Subst.omega e -> Void\n-- divergenceOmega {e = _} (BStValue v) = case v of\n-- VZero impossible\n-- (VSucc _) impossible\n-- VAbs impossible\n-- divergenceOmega {e = e} (BStFix (BStValue v) bst) =\n-- let bst' = replace {P = \\x => BigStep x e} substOmega bst\n-- in divergenceOmega bst'\n\n\n-- To prove that 'omega' diverges under big-step semantics,\n-- an indexed version of the 'BigStep' relation is introduced:\ndata BigStepN : Nat -> Term [] t -> (y: Term [] t) -> Type where\n BStValueN : (v : Value e) -> BigStepN Z e e\n --\n BStAppN : BigStepN k e1 (TAbs e1') ->\n BigStepN m e2 e2' ->\n BigStepN n (subst e2' FZ e1') e ->\n BigStepN (S $ k+m+n) (TApp e1 e2) e\n -- \n BStFixN : BigStepN m e (TAbs e') ->\n BigStepN n (subst (TFix (TAbs e')) FZ e') e'' ->\n BigStepN (S $ m+n) (TFix e) e''\n -- \n BStSuccN : BigStepN n e e' ->\n BigStepN (S n) (TSucc e) (TSucc e')\n -- \n BStPredZeroN : BigStepN n e TZero ->\n BigStepN (S n) (TPred e) TZero\n -- \n BStPredSuccN : BigStepN n e (TSucc e') ->\n BigStepN (S n) (TPred e) e'\n -- \n BStIfzZeroN : BigStepN m e1 TZero ->\n BigStepN n e2 e ->\n BigStepN (S $ m+n) (TIfz e1 e2 _) e\n -- \n BStIfzSuccN : BigStepN m e1 (TSucc _) ->\n BigStepN n e3 e ->\n BigStepN (S $ m+n) (TIfz e1 _ e3) e\n\n\nbigStepToN : BigStep e1 e2 -> (n : Nat ** BigStepN n e1 e2)\nbigStepToN (BStValue v) = (Z ** BStValueN v)\n--\nbigStepToN (BStApp bst1 bst2 bst3) = let (n1 ** bstn1) = bigStepToN bst1\n (n2 ** bstn2) = bigStepToN bst2\n (n3 ** bstn3) = bigStepToN bst3\n in ((S $ n1+n2+n3) ** BStAppN bstn1 bstn2 bstn3)\n-- \nbigStepToN (BStFix bst1 bst2) = let (n1 ** bstn1) = bigStepToN bst1\n (n2 ** bstn2) = bigStepToN bst2\n in ((S $ n1+n2) ** BStFixN bstn1 bstn2) \n-- \nbigStepToN (BStSucc bst) = let (n ** bstn) = bigStepToN bst\n in ((S n) ** BStSuccN bstn)\n-- \nbigStepToN (BStPredZero bst) = let (n ** bstn) = bigStepToN bst\n in ((S n) ** BStPredZeroN bstn)\n-- \nbigStepToN (BStPredSucc bst) = let (n ** bstn) = bigStepToN bst\n in ((S n) ** BStPredSuccN bstn)\n--\nbigStepToN (BStIfzZero bst1 bst2) = let (n1 ** bstn1) = bigStepToN bst1\n (n2 ** bstn2) = bigStepToN bst2\n in ((S $ n1+n2) ** BStIfzZeroN bstn1 bstn2) \n-- \nbigStepToN (BStIfzSucc bst1 bst2) = let (n1 ** bstn1) = bigStepToN bst1\n (n2 ** bstn2) = bigStepToN bst2\n in ((S $ n1+n2) ** BStIfzSuccN bstn1 bstn2) \n\n\nbigStepFromN : BigStepN n e1 e2 -> BigStep e1 e2\nbigStepFromN (BStValueN v) = BStValue v\n--\nbigStepFromN (BStAppN bstn1 bstn2 bstn3) = let bst1 = bigStepFromN bstn1\n bst2 = bigStepFromN bstn2\n bst3 = bigStepFromN bstn3\n in BStApp bst1 bst2 bst3\n-- \nbigStepFromN (BStFixN bstn1 bstn2) = let bst1 = bigStepFromN bstn1\n bst2 = bigStepFromN bstn2\n in BStFix bst1 bst2\n-- \nbigStepFromN (BStSuccN bstn) = let bst = bigStepFromN bstn\n in BStSucc bst\n--\nbigStepFromN (BStPredZeroN bstn) = let bst = bigStepFromN bstn\n in BStPredZero bst\n--\nbigStepFromN (BStPredSuccN bstn) = let bst = bigStepFromN bstn\n in BStPredSucc bst\n--\nbigStepFromN (BStIfzZeroN bstn1 bstn2) = let bst1 = bigStepFromN bstn1\n bst2 = bigStepFromN bstn2\n in BStIfzZero bst1 bst2\n--\nbigStepFromN (BStIfzSuccN bstn1 bstn2) = let bst1 = bigStepFromN bstn1\n bst2 = bigStepFromN bstn2\n in BStIfzSucc bst1 bst2\n\n\n-- Divergence of 'omega' under the indexed version of big-step semantics:\ndivergenceOmega' : {e : Term [] TyNat} -> (n : Nat) -> BigStepN n Subst.omega e -> Void\ndivergenceOmega' Z (BStValueN v) = case v of\n VZero impossible\n (VSucc _) impossible\n VAbs impossible\ndivergenceOmega' {e} (S n) bstn = case bstn of\n (BStFixN (BStValueN v) bstn2) => let bstn2' = replace {P = \\x => BigStepN n x e} substOmega bstn2\n in divergenceOmega' n bstn2'\n\n\ndivergenceOmega : BigStep Subst.omega e -> Void\ndivergenceOmega bst = let (n ** bstn) = bigStepToN bst\n in divergenceOmega' n bstn\n\n-- End: DIVERGENCE OF TERM 'Subst.omega' UNDER BIG-STEP\n-------------------------------------------------------\n\n", "meta": {"hexsha": "372a2d5531b395b97e0cabd6bb0155ed02cee74d", "size": 8236, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "typed/src/BigStep.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "typed/src/BigStep.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "typed/src/BigStep.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": 39.7874396135, "max_line_length": 99, "alphanum_fraction": 0.4791160758, "num_tokens": 2369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7155572533696872}} {"text": "\ndata EqNat : (num1 : Nat) -> (num2 : Nat) -> Type where\n Same : (num : Nat) -> EqNat num num\n\n-- Proves that k and j are the same\nsameS : (k : Nat) -> (j : Nat) -> (eq : EqNat k j) -> EqNat (S k) (S j)\nsameS k k (Same k) = Same (S k) -- proving k is the same as itself\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (EqNat num1 num2)\ncheckEqNat 0 0 = Just (Same 0)\ncheckEqNat 0 (S k) = Nothing\ncheckEqNat (S k) 0 = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just eq => Just (sameS _ _ eq)\n", "meta": {"hexsha": "ddc2d5f0475b9ff89c75c21e0a1e02cf8dfcd0da", "size": 591, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch8/EqNat.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "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/ch8/EqNat.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": "src/ch8/EqNat.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": 36.9375, "max_line_length": 71, "alphanum_fraction": 0.5414551607, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.71549190913596}} {"text": "> module Nat.DivisorProperties\n\n> import Syntax.PreorderReasoning\n\n> import Nat.Divisor\n> import Nat.DivisorOperations\n> import Basic.Operations\n> import Nat.Operations\n> import Nat.OperationsProperties\n> import Sigma.Sigma\n> import Pairs.Operations\n\n\n> %default total\n> %auto_implicits on\n> %access export\n> -- %access public export\n\n\n> ||| Fundamental quotient lemma\n> quotientLemma : (m : Nat) -> (d : Nat) -> (dDm : d `Divisor` m) -> d * (quotient m d dDm) = m\n> quotientLemma m d (Element q prf) = prf\n> %freeze quotientLemma\n\n> ||| Fundamental quotient lemma\n> quotientLemma' : (m : Nat) -> (d : Nat) -> (dDm : d `Divisor` m) -> (quotient m d dDm) * d = m\n> quotientLemma' m d dDm = replace {P = \\ ZUZ => ZUZ = m} (multCommutative d (quotient m d dDm)) (quotientLemma m d dDm)\n> %freeze quotientLemma'\n\n\nProperties of |Divisor|:\n\n> ||| Any natural number is a divisor of zero\n> anyDivisorZ : (m : Nat) -> m `Divisor` Z\n> anyDivisorZ m = Element Z (multZeroRightZero m)\n> %freeze anyDivisorZ\n\n> ||| One is a divisor of any natural number\n> oneDivisorAny : (m : Nat) -> (S Z) `Divisor` m\n> oneDivisorAny m = Element m (multOneLeftNeutral m)\n> %freeze oneDivisorAny\n\n> ||| Any natural number is a divisor of itself\n> anyDivisorAny : (m : Nat) -> m `Divisor` m\n> anyDivisorAny m = Element (S Z) (multOneRightNeutral m)\n> %freeze anyDivisorAny\n\n> ||| |Divisor| is reflexive\n> divisorReflexive : (m : Nat) -> m `Divisor` m\n> divisorReflexive = anyDivisorAny\n> %freeze divisorReflexive\n\n> ||| |Divisor| is transitive\n> divisorTransitive : l `Divisor` m -> m `Divisor` n -> l `Divisor` n\n> divisorTransitive {l} {m} {n} (Element q1 p1) (Element q2 p2) = Element (q1 * q2) p where\n> s1 : (l * q1) * q2 = m * q2\n> s1 = multPreservesEq (l * q1) m q2 q2 p1 Refl\n> s2 : (l * q1) * q2 = n\n> s2 = trans s1 p2\n> p : l * (q1 * q2) = n\n> p = replace {x = (l * q1) * q2}\n> {y = l * (q1 * q2)}\n> {P = \\ ZUZU => ZUZU = n}\n> (sym (multAssociative l q1 q2)) s2\n> %freeze divisorTransitive\n\n> ||| |Divisor| is antysymmetric\n> divisorAntisymmetric : (m : Nat) -> (n : Nat) -> m `Divisor` n -> n `Divisor` m -> m = n\n> divisorAntisymmetric Z Z _ _ = Refl\n> divisorAntisymmetric Z (S n) (Element q1 p1) _ = absurd p1\n> divisorAntisymmetric (S m) Z _ (Element q2 p2) = absurd p2\n> divisorAntisymmetric (S m) (S n) (Element q1 p1) (Element q2 p2) = s8 where\n> s1 : (S m) * q1 = S n\n> s1 = p1\n> s2 : (S n) * q2 = S m\n> s2 = p2\n> s3 : ((S n) * q2) * q1 = S n\n> s3 = replace {x = S m}\n> {y = (S n) * q2}\n> {P = \\ZUZU => ZUZU * q1 = S n}\n> (sym s2)\n> s1\n> s4 : (S n) * (q2 * q1) = S n\n> s4 = replace {x = ((S n) * q2) * q1}\n> {y = (S n) * (q2 * q1)}\n> {P = \\ ZUZU => ZUZU = S n}\n> (sym (multAssociative (S n) q2 q1) ) s3\n> s5 : q2 * q1 = S Z\n> s5 = multElim1 n (q2 * q1) s4\n> s6 : q1 = S Z\n> s6 = multOneRightOne q2 q1 s5\n> s7 : (S m) * (S Z) = S n\n> s7 = replace {x = q1}\n> {y = S Z}\n> {P = \\ ZUZU => (S m) * ZUZU = S n}\n> s6 s1\n> s8 : S m = S n\n> s8 = replace {x = (S m) * (S Z)}\n> {y = S m}\n> {P = \\ ZUZU => ZUZU = S n}\n> (multOneRightNeutral (S m)) s7\n> %freeze divisorAntisymmetric\n\n> ||| Any divisor of two numbers is a divisor of their sum\n> divisorPlusLemma1 : (m : Nat) -> (n : Nat) -> (d : Nat) ->\n> d `Divisor` m -> d `Divisor` n -> d `Divisor` (m + n)\n> divisorPlusLemma1 m n d (Element q1 p1) (Element q2 p2) =\n> Element (q1 + q2) p where\n> s1 : d * (q1 + q2) = d * q1 + d * q2\n> s1 = multDistributesOverPlusRight d q1 q2\n> s2 : d * (q1 + q2) = m + d * q2\n> s2 = replace {x = d * q1} {y = m} {P = \\ ZUZU => d * (q1 + q2) = ZUZU + d * q2} p1 s1\n> p : d * (q1 + q2) = m + n\n> p = replace {x = d * q2} {y = n} {P = \\ ZUZU => d * (q1 + q2) = m + ZUZU} p2 s2\n> --%freeze divisorPlusLemma1\n\n> ||| Any divisor of two numbers is a divisor of their sum\n> divisorPlusLemma2 : (m : Nat) -> (n : Nat) -> (d : Nat) ->\n> d `Divisor` m -> d `Divisor` n -> d `Divisor` (n + m)\n> divisorPlusLemma2 m n d (Element q1 p1) (Element q2 p2) =\n> Element (q1 + q2) p where\n> s1 : d * (q1 + q2) = d * q1 + d * q2\n> s1 = multDistributesOverPlusRight d q1 q2\n> s2 : d * (q1 + q2) = m + d * q2\n> s2 = replace {x = d * q1} {y = m} {P = \\ ZUZU => d * (q1 + q2) = ZUZU + d * q2} p1 s1\n> s3 : d * (q1 + q2) = m + n\n> s3 = replace {x = d * q2} {y = n} {P = \\ ZUZU => d * (q1 + q2) = m + ZUZU} p2 s2\n> p : d * (q1 + q2) = n + m\n> p = replace {x = m + n} {y = n + m} {P = \\ ZUZU => d * (q1 + q2) = ZUZU} (plusCommutative m n) s3\n> %freeze divisorPlusLemma2\n\n> ||| The product of (two) divisors (of two natural numbers) is a divisor of the\n> ||| product (of those numbers)\n> divisorMultLemma1 : (m1 : Nat) -> (d1 : Nat) -> d1 `Divisor` m1 -> \n> (m2 : Nat) -> (d2 : Nat) -> d2 `Divisor` m2 -> \n> (d1 * d2) `Divisor` (m1 * m2)\n> divisorMultLemma1 m1 d1 (Element q1 p1) m2 d2 (Element q2 p2) = \n> Element (q1 * q2) p where\n> s1 : (d1 * q1) * (d2 * q2) = m1 * m2\n> s1 = multPreservesEq (d1 * q1) m1 (d2 * q2) m2 p1 p2\n> p : (d1 * d2) * (q1 * q2) = m1 * m2\n> p = replace {x = (d1 * q1) * (d2 * q2)}\n> {y = (d1 * d2) * (q1 * q2)}\n> {P = \\ ZUZU => ZUZU = m1 * m2}\n> (multFlipCentre d1 q1 d2 q2) s1\n> -- %freeze divisorMultLemma1\n\n> ||| Any divisor of two numbers is a divisor of their difference\n> divisorMinusLemma : (m : Nat) -> (n : Nat) -> (d : Nat) ->\n> d `Divisor` m -> d `Divisor` n -> d `Divisor` (n - m)\n> divisorMinusLemma m n d (Element q1 p1) (Element q2 p2) =\n> Element q p where\n> q : Nat\n> q = q2 - q1\n> p : d * q = n - m\n> p = s2 where\n> s1 : d * q2 - d * q1 = n - m\n> s1 = cong2 p2 p1\n> s2 : d * (q2 - q1) = n - m\n> s2 = replace {x = d * q2 - d * q1}\n> {y = d * (q2 - q1)}\n> {P = \\ZUZU => ZUZU = n - m}\n> (sym (multDistributesOverMinusRight d q2 q1))\n> s1\n> %freeze divisorMinusLemma\n\n> ||| \n> divisorOneLemma : (d : Nat) -> (d' : Nat) -> (S d) * d' `Divisor` (S d) -> d' `Divisor` S Z\n> divisorOneLemma d d' (Element q p) =\n> Element q p' where\n> s1 : ((S d) * d') * q = S d\n> s1 = p\n> s2 : (S d) * (d' * q) = S d\n> s2 = replace {x = ((S d) * d') * q} {y = (S d) * (d' * q)} {P = \\ ZUZU => ZUZU = S d} (sym (multAssociative (S d) d' q)) s1\n> p' : d' * q = S Z\n> p' = multElim1 d (d' * q) s2\n> %freeze divisorOneLemma\n\n> |||\n> divisorOneLemma' : (d : Nat) -> (d' : Nat) -> Not (d = Z) -> d * d' `Divisor` d -> d' `Divisor` S Z\n> divisorOneLemma' Z _ dNotZ _ = void (dNotZ Refl)\n> divisorOneLemma' (S d) d' dNotZ (Element q p) =\n> Element q p' where\n> s1 : ((S d) * d') * q = S d\n> s1 = p\n> s2 : (S d) * (d' * q) = S d\n> s2 = replace {x = ((S d) * d') * q} {y = (S d) * (d' * q)} {P = \\ ZUZU => ZUZU = S d} (sym (multAssociative (S d) d' q)) s1\n> p' : d' * q = S Z\n> p' = multElim1 d (d' * q) s2\n> %freeze divisorOneLemma'\n\n> |||\n> divisorOneLemma'' : (d : Nat) -> (d' : Nat) -> Z `LT` d -> d * d' `Divisor` d -> d' `Divisor` S Z\n> divisorOneLemma'' Z _ p _ = \n> absurd p\n> divisorOneLemma'' (S d) d' _ (Element q p) =\n> Element q p' where\n> s1 : ((S d) * d') * q = S d\n> s1 = p\n> s2 : (S d) * (d' * q) = S d\n> s2 = replace {x = ((S d) * d') * q} {y = (S d) * (d' * q)} {P = \\ ZUZU => ZUZU = S d} (sym (multAssociative (S d) d' q)) s1\n> p' : d' * q = S Z\n> p' = multElim1 d (d' * q) s2\n> %freeze divisorOneLemma''\n\n> |||\n> divisorTowerLemma: (d : Nat) -> (d' : Nat) -> (m : Nat) ->\n> (dDm : d `Divisor` m) -> d' `Divisor` (quotient m d dDm) -> d * d' `Divisor` m\n> divisorTowerLemma d d' m dDm d'DmOd = Element q' p where\n> q' : Nat\n> q' = quotient (quotient m d dDm) d' d'DmOd\n> s1 : d' * q' = quotient m d dDm\n> s1 = quotientLemma (quotient m d dDm) d' d'DmOd\n> s2 : d * (quotient m d dDm) = m\n> s2 = quotientLemma m d dDm\n> s3 : d * (d' * q') = m\n> s3 = replace {x = quotient m d dDm} {y = d' * q'} {P = \\ ZUZU => d * ZUZU = m} (sym s1) s2\n> p : (d * d') * q' = m\n> p = replace {x = d * (d' * q')} {y = (d * d') * q'} {P = \\ ZUZU => ZUZU = m} (multAssociative d d' q') s3\n> %freeze divisorTowerLemma\n\n\nProperties of |quotient|:\n\n> |||\n> quotientIsJustGetWitness : (m : Nat) -> (d : Nat) -> (dDm : d `Divisor` m) -> \n> quotient m d dDm = getWitness dDm\n> quotientIsJustGetWitness m d (Element q prf) = \n> ( quotient m d (Element q prf) )\n> ={ Refl }=\n> ( q )\n> ={ Refl }=\n> ( getWitness (Element q prf) )\n> QED\n> %freeze quotientIsJustGetWitness\n\n> |||\n> quotientDivisorLemma2 : (m : Nat) -> \n> (d1 : Nat) -> (d1Dm : d1 `Divisor` m) ->\n> (d2 : Nat) -> (d2Dm : d2 `Divisor` m) -> \n> d1 = d2 -> Not (d1 = Z) -> quotient m d1 d1Dm = quotient m d2 d2Dm \n> quotientDivisorLemma2 m d (Element q1 dq1EQm) d (Element q2 dq2EQm) Refl NdEQZ =\n> ( quotient m d (Element q1 dq1EQm) )\n> ={ Refl }=\n> ( q1 )\n> ={ multMultElimLeft d d q1 q2 Refl NdEQZ (trans dq1EQm (sym dq2EQm)) }=\n> ( q2 )\n> ={ Refl }=\n> ( quotient m d (Element q2 dq2EQm) )\n> QED\n> %freeze quotientDivisorLemma2\n\n> ||| quotient preserves positivity\n> quotientPreservesPositivity : (m : Nat) -> (d : Nat) -> (dDm : d `Divisor` m) -> \n> Z `LT` m -> Z `LT` (quotient m d dDm)\n> quotientPreservesPositivity m d dDm zLTm = \n> multLTZeroRightLTZero d q zLTdq where\n> q : Nat\n> q = quotient m d dDm\n> zLTdq : Z `LT` (d * q)\n> zLTdq = replace {x = m} \n> {y = d * q} \n> {P = \\ ZUZU => Z `LT` ZUZU} \n> (sym (quotientLemma m d dDm)) zLTm\n> %freeze quotientPreservesPositivity\n\n> |||\n> quotientAnyOneAny : (m : Nat) -> (d : Nat) -> (dDm : d `Divisor` m) -> \n> (d = S Z) -> quotient m d dDm = m\n> quotientAnyOneAny m d (Element q p) dEQ1 = \n> ( quotient m d (Element q p) )\n> ={ Refl }=\n> ( q )\n> ={ sym (multOneLeftNeutral q) }=\n> ( (S Z) * q )\n> ={ replace {x = S Z}\n> {y = d}\n> {P = \\ ZUZU => (S Z) * q = ZUZU * q}\n> (sym dEQ1) Refl }=\n> ( d * q )\n> ={ p }=\n> ( m )\n> QED\n> %freeze quotientAnyOneAny\n\n> |||\n> quotientPlusLemma : (m : Nat) -> (n : Nat) -> (d : Nat) -> \n> (dDm : d `Divisor` m) -> (dDn : d `Divisor` n) ->\n> (quotient m d dDm) + (quotient n d dDn) \n> =\n> quotient (m + n) d (divisorPlusLemma1 m n d dDm dDn)\n> quotientPlusLemma m n d (Element q1 p1) (Element q2 p2) =\n> ( (quotient m d (Element q1 p1)) + (quotient n d (Element q2 p2)) )\n> ={ Refl }=\n> ( q1 + q2 )\n> ={ Refl }=\n> ( quotient (m + n) d (divisorPlusLemma1 m n d (Element q1 p1) (Element q2 p2)) )\n> QED\n> %freeze quotientPlusLemma\n\n> |||\n> quotientMultLemma : (m1 : Nat) -> (d1 : Nat) -> (d1Dm1 : d1 `Divisor` m1) ->\n> (m2 : Nat) -> (d2 : Nat) -> (d2Dm2 : d2 `Divisor` m2) ->\n> (quotient m1 d1 d1Dm1) * (quotient m2 d2 d2Dm2) \n> =\n> quotient (m1 * m2) (d1 * d2) (divisorMultLemma1 m1 d1 d1Dm1 m2 d2 d2Dm2)\n> quotientMultLemma m1 d1 (Element q1 p1) m2 d2 (Element q2 p2) =\n> ( (quotient m1 d1 (Element q1 p1)) * (quotient m2 d2 (Element q2 p2)) )\n> ={ Refl }=\n> ( q1 * q2 )\n> ={ Refl }=\n> ( quotient (m1 * m2) (d1 * d2) (divisorMultLemma1 m1 d1 (Element q1 p1) m2 d2 (Element q2 p2)) )\n> QED\n> %freeze quotientMultLemma\n\n> |||\n> quotientCancellationLemma : (m : Nat) -> (d : Nat) -> \n> (sdDsdm : (S d) `Divisor` (S d) * m) -> \n> quotient ((S d) * m) (S d) sdDsdm = m\n> quotientCancellationLemma m d (Element q prf) = \n> ( q )\n> ={ multMultElimLeft (S d) (S d) q m Refl SIsNotZ prf }=\n> ( m )\n> QED\n> %freeze quotientCancellationLemma\n\n> quotientScaleInvariant : (m : Nat) -> (n : Nat) -> (d : Nat) -> Not (d * n = Z) ->\n> (nDm : n `Divisor` m) -> (dnDdm : (d * n) `Divisor` (d * m)) ->\n> quotient m n nDm = quotient (d * m) (d * n) dnDdm \n> quotientScaleInvariant m n d ndnEQZ (Element p npEQm) (Element q dnqEQdm) =\n> let s1 : (d * (n * p) = d * m)\n> = multPreservesEq d d (n * p) m Refl npEQm in\n> let s2 : ((d * n) * p = d * m)\n> = replace {P = \\ ZUZU => ZUZU = d * m} (multAssociative d n p) s1 in\n> let s3 : ((d * n) * p = (d * n) * q)\n> = trans s2 (sym dnqEQdm) in\n> ( quotient m n (Element p npEQm) )\n> ={ Refl }=\n> ( p )\n> ={ multMultElimLeft (d * n) (d * n) p q Refl ndnEQZ s3 }=\n> ( q )\n> ={ Refl }=\n> ( quotient (d * m) (d * n) (Element q dnqEQdm) )\n> QED\n> %freeze quotientScaleInvariant\n \n> |||\n> quotientDivisorLemma : (d : Nat) -> (m : Nat) -> (n : Nat) ->\n> (sdDm : S d `Divisor` m) ->\n> (mDn: m `Divisor` n) -> \n> (sdDn : S d `Divisor` n) ->\n> (quotient m (S d) sdDm) `Divisor` (quotient n (S d) sdDn)\n> quotientDivisorLemma d m n (Element x sdxEQm) (Element y myEQn) (Element z sdzEQn) = \n> Element y xyEQz where\n> sdxyEQmy : ((S d) * x) * y = m * y\n> sdxyEQmy = multPreservesEq ((S d) * x) m y y sdxEQm Refl\n> sdxyEQsdz : ((S d) * x) * y = (S d) * z\n> sdxyEQsdz = trans sdxyEQmy (trans myEQn (sym sdzEQn))\n> sdxyEQsdz' : (S d) * (x * y) = (S d) * z\n> sdxyEQsdz' = replace {x = ((S d) * x) * y}\n> {y = (S d) * (x * y)}\n> {P = \\ ZUZU => ZUZU = (S d) * z}\n> (sym (multAssociative (S d) x y)) sdxyEQsdz\n> xyEQz : x * y = z\n> xyEQz = multMultElimLeft (S d) (S d) (x * y) z Refl SIsNotZ sdxyEQsdz'\n> %freeze quotientDivisorLemma\n\n> |||\n> quotientDivisorLemma1 : (a : Nat) -> (b : Nat) -> (c : Nat) ->\n> (saDb : S a `Divisor` b) ->\n> (bDc : b `Divisor` c) -> \n> (quotient b (S a) saDb) \n> `Divisor` \n> (quotient c (S a) (divisorTransitive {l = S a} {m = b} {n = c} saDb bDc))\n> quotientDivisorLemma1 a b c saDb bDc = prf where\n> x : Nat\n> x = getWitness saDb\n> saxEQb : (S a) * x = b\n> saxEQb = getProof saDb\n> y : Nat\n> y = getWitness bDc\n> byEQc : b * y = c\n> byEQc = getProof bDc\n> saDc : (S a) `Divisor` c\n> saDc = divisorTransitive {l = S a} {m = b} {n = c} saDb bDc\n> z : Nat\n> z = getWitness saDc\n> sazEQc : (S a) * z = c\n> sazEQc = getProof saDc \n> saxyEQby : ((S a) * x) * y = b * y\n> saxyEQby = multPreservesEq ((S a) * x) b y y saxEQb Refl\n> saxyEQsaz : ((S a) * x) * y = (S a) * z\n> saxyEQsaz = trans saxyEQby (trans byEQc (sym sazEQc))\n> saxyEQsaz' : (S a) * (x * y) = (S a) * z\n> saxyEQsaz' = replace {x = ((S a) * x) * y}\n> {y = (S a) * (x * y)}\n> {P = \\ ZUZU => ZUZU = (S a) * z}\n> (sym (multAssociative (S a) x y)) saxyEQsaz\n> xyEQz : x * y = z\n> xyEQz = multMultElimLeft (S a) (S a) (x * y) z Refl SIsNotZ saxyEQsaz'\n> prf1 : x `Divisor` z\n> prf1 = Element y xyEQz\n> prf2 : (quotient b (S a) saDb) `Divisor` z\n> prf2 = replace {x = x}\n> {y = quotient b (S a) saDb}\n> {P = \\ ZUZU => ZUZU `Divisor` z}\n> (sym (quotientIsJustGetWitness b (S a) saDb)) prf1\n> prf : (quotient b (S a) saDb) `Divisor` (quotient c (S a) saDc)\n> prf = replace {x = z}\n> {y = quotient c (S a) (divisorTransitive {l = S a} {m = b} {n = c} saDb bDc)}\n> {P = \\ ZUZU => (quotient b (S a) saDb) `Divisor` ZUZU}\n> (sym (quotientIsJustGetWitness c (S a) saDc)) prf2\n> %freeze quotientDivisorLemma1\n\n> |||\n> flipQuotientLemma : (m : Nat) -> (n : Nat) -> (d : Nat) ->\n> (dDm : d `Divisor` m) -> (dDn : d `Divisor` n) ->\n> (quotient m d dDm) * n = m * (quotient n d dDn)\n> flipQuotientLemma m n d dDm dDn = \n> let qmd = quotient m d dDm in\n> let qnd = quotient n d dDn in\n> ( qmd * n )\n> ={ cong {f = \\ ZUZU => qmd * ZUZU} (sym (quotientLemma n d dDn)) }=\n> ( qmd * (d * qnd) )\n> ={ multAssociative qmd d qnd }=\n> ( (qmd * d) * qnd )\n> ={ cong {f = \\ ZUZU => ZUZU * qnd} (multCommutative qmd d) }=\n> ( (d * qmd) * qnd )\n> ={ cong {f = \\ ZUZU => ZUZU * qnd} (quotientLemma m d dDm) }=\n> ( m * qnd )\n> QED\n> %freeze flipQuotientLemma\n\n> |||\n> quotientEqLemma : (m1 : Nat) -> (d1 : Nat) -> (d1Dm1 : d1 `Divisor` m1) ->\n> (m2 : Nat) -> (d2 : Nat) -> (d2Dm2 : d2 `Divisor` m2) ->\n> m1 = m2 -> d1 = d2 -> Not (d1 = Z) ->\n> quotient m1 d1 d1Dm1 = quotient m2 d2 d2Dm2\n> quotientEqLemma m d (Element p dpEQm) m d (Element q dqEQm) Refl Refl ndEQZ =\n> ( quotient m d (Element p dpEQm) )\n> ={ Refl }=\n> ( p )\n> ={ multMultElimLeft d d p q Refl ndEQZ (trans dpEQm (sym dqEQm)) }=\n> ( q )\n> ={ Refl }=\n> ( quotient m d (Element q dqEQm) )\n> QED\n> %freeze quotientEqLemma\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "e3e169e88b51c9164e1983997b7d7bf3861ffb0a", "size": 17906, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/DivisorProperties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Nat/DivisorProperties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Nat/DivisorProperties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4405286344, "max_line_length": 129, "alphanum_fraction": 0.4739752038, "num_tokens": 7248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.7154895694802285}} {"text": "module GenericArity\n\n-- Inspired by https://strathprints.strath.ac.uk/68800/\n\nimport Data.Vect\n\n%access public export\n\nTypes : Nat -> Type\nTypes n = Vect n Type\n\nArrows : (n : Nat) -> Types n -> Type -> Type\nArrows Z [] b = b\nArrows (S n) (a :: as) b = a -> Arrows n as b\n\nProduct : (n : Nat) -> Types n -> Type\nProduct Z [] = ()\nProduct (S n) (a :: as) = (a, Product n as)\n\n\ncurryn : (n : Nat) -> {as : Types n} -> (Product n as -> r) -> Arrows n as r\ncurryn Z {as = []} f = f ()\ncurryn (S n) {as = (a :: as)} f = curryn n . curry f\n\nuncurryn : (n : Nat) -> {as : Types n} -> Arrows n as r -> (Product n as -> r)\nuncurryn Z {as = []} f () = f\nuncurryn (S n) {as = (a :: as)} f (x, prod) = uncurryn n (f x) prod\n\nCong : (n : Nat) -> {as : Types n} -> Arrows n as r -> Arrows n as r -> Type\nCong Z {as = []} f g = f = g\nCong (S n) {as = (a :: as)} f g = {x, y : a} -> x = y -> Cong n (f x) (g y)\n\ncongn : (n : Nat) -> {as : Types n} -> {r : Type} -> (f : Arrows n as r) -> Cong n {as} f f\ncongn Z {as = []} f = Refl\ncongn (S n) {as = (a :: as)} f = \\(Refl {x}) => congn n {as} (f x)\n\ncong : {a, b : Type} -> {f : a -> b} -> {x, y : a} -> x = y -> f x = f y\ncong {a} {b} {f} = let r = congn 1 {as = (a :: [])} {r = b} f in r\n\ntestCong : (f : Int -> String -> Bool) -> f 1 \"1\" = f 1 \"1\"\ntestCong f = let r = congn 2 {as = (Int :: String :: [])} {r = Bool} f in r Refl Refl\n\nSubst : (n : Nat) -> {as : Types n} -> Arrows n as Type -> Arrows n as Type -> Type\nSubst Z {as = []} p q = p -> q\nSubst (S n) {as = (a :: as)} p q = {x, y : a} -> x = y -> Subst n (p x) (p y)\n\nsubstn : (n : Nat) -> {as : Types n} -> (p : Arrows n as Type) -> Subst n {as} p p\nsubstn Z {as = []} p = id\nsubstn (S n) {as = (a :: as)} p = \\(Refl {x}) => substn n {as} (p x)\n\nsubst : {a : Type} -> (p : a -> Type) -> {x, y : a} -> x = y -> p x -> p y\nsubst {a} p = let r = substn 1 {as = (a :: [])} p in r\n\ntestSubst : (p : Int -> String -> Type) -> p 1 \"1\" -> p 1 \"1\"\ntestSubst p = let r = substn 2 {as = (Int :: String :: [])} p in r Refl Refl\n", "meta": {"hexsha": "50c5e6876aa5eb941d51830521cde2eadc464704", "size": 2014, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/GenericArity.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/GenericArity.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/GenericArity.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": 35.9642857143, "max_line_length": 91, "alphanum_fraction": 0.4831181728, "num_tokens": 847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7153932045864464}} {"text": "module Data.List.Predicates.Unique\n\nimport Data.List\n\n%access public export\n%default total\n\n||| Proof that a list `xs` is unique.\ndata Unique : (xs : List type) -> Type where\n\n ||| Empty lists are 'unique'\n Empty : Unique Nil\n\n ||| Only add an element to the list is it doesn't appear in the\n ||| remaining lists.\n Cons : (x : type)\n -> (prfU : Not (Elem x xs))\n -> (rest : Unique xs)\n -> Unique (x::xs)\n\n-- ----------------------------------------------------------------- [ Helpers ]\nduplicateElement : (prf : Elem x xs) -> Unique (x :: xs) -> Void\nduplicateElement prf (Cons x f rest) = f prf\n\nrestNotUnique : (f : Unique xs -> Void) -> (contra : Elem x xs -> Void) -> Unique (x :: xs) -> Void\nrestNotUnique f contra (Cons x g rest) = f rest\n\n||| Is the list `xs` unique?\nunique : DecEq type\n => (xs : List type)\n -> Dec (Unique xs)\nunique [] = Yes Empty\nunique (x :: xs) with (isElem x xs)\n unique (x :: xs) | (Yes prf) = No (duplicateElement prf)\n unique (x :: xs) | (No contra) with (unique xs)\n unique (x :: xs) | (No contra) | (Yes prf) = Yes (Cons x contra prf)\n unique (x :: xs) | (No contra) | (No f) = No (restNotUnique f contra)\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "62607d3dc10e314a6cda13213fc13899a05fbeae", "size": 1262, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/List/Predicates/Unique.idr", "max_stars_repo_name": "MarcelineVQ/idris-containers", "max_stars_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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": "Data/List/Predicates/Unique.idr", "max_issues_repo_name": "MarcelineVQ/idris-containers", "max_issues_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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": "Data/List/Predicates/Unique.idr", "max_forks_repo_name": "MarcelineVQ/idris-containers", "max_forks_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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": 31.55, "max_line_length": 99, "alphanum_fraction": 0.5332805071, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7153759910818299}} {"text": "data Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : Vect k a -> Vect (S k) a\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (num1 = num2)\ncheckEqNat Z Z = Just Refl\ncheckEqNat Z (S k) = Nothing\ncheckEqNat (S k) Z = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just eq => Just (cong eq)\n\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case decEq m len of\n Yes Refl => Just input\n No contra => Nothing\n\nsameCons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys\nsameCons Refl = Refl\n\nsameLists : {xs : List a} -> {ys : List a} -> x = y -> xs = ys -> x :: xs = y :: ys\nsameLists Refl Refl = Refl\n\ndata ThreeEq : (x1 : a) -> (x2 : a) -> (x3 : a) -> Type where\n Same : (x : a) -> ThreeEq x x x \n\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS z z z (Same z) = Same (S z)\n", "meta": {"hexsha": "3ba0144e96730a70ebac7350dd7a57950b12a6eb", "size": 1039, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/ExactLength.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/ExactLength.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/ExactLength.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": 35.8275862069, "max_line_length": 83, "alphanum_fraction": 0.500481232, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.7148142302562053}} {"text": "\nmodule SnocList\n\n-- data SnocList ty = Empty | Snoc (SnocList ty) ty\n\ndata SnocList : List a -> Type where\n Empty : SnocList []\n Snoc : (rec : SnocList xs) -> SnocList (xs ++ [x])\n\n\nsnocListHelp : (snoc : SnocList input) -> (rest : List a) -> SnocList (input ++ rest)\nsnocListHelp {input} snoc [] = rewrite appendNilRightNeutral input in snoc\nsnocListHelp {input} snoc (x :: xs) = rewrite appendAssociative input [x] xs in\n snocListHelp (Snoc snoc {x}) xs\n\nsnocList : (xs : List a) -> SnocList xs\nsnocList xs = snocListHelp Empty xs\n\n\n-- myReverseHelper : (input : List a) -> SnocList input -> List a\n-- myReverseHelper [] Empty = []\n-- myReverseHelper (xs ++ [x]) (Snoc rec) = x :: myReverseHelper xs rec\n\n-- myReverse : List a -> List a\n-- myReverse xs = myReverseHelper xs $ snocList xs\n\n-- Alternate attempt to write a variation of myReverse that is also total before I was introduced to fun | sugaring.\n-- myReverse : List a -> List a\n-- myReverse xs = myRev xs $ snocList xs\n-- where\n-- myRev : (xs : List a) -> SnocList xs -> List a\n-- myRev xs slxs with (slxs)\n-- myRev [] slxs | Empty = []\n-- myRev (ys ++ [x]) slxs | (Snoc rec) = x :: myRev ys rec\n\n\nmyReverse : List a -> List a\nmyReverse xs with (snocList xs)\n myReverse [] | Empty = []\n myReverse (ys ++ [x]) | (Snoc rec) = x :: myReverse ys | rec\n\n\nisSuffix : Eq a => List a -> List a -> Bool\nisSuffix xs ys with (snocList xs)\n isSuffix [] ys | Empty = True\n isSuffix (zs ++ [z]) ys | (Snoc zsrec) with (snocList ys)\n isSuffix (zs ++ [z]) [] | (Snoc zsrec) | Empty = False\n isSuffix (zs ++ [z]) (ys ++ [y]) | (Snoc zsrec) | (Snoc ysrec) = case z == y of\n False => False\n True => isSuffix zs ys | zsrec | ysrec\n\n\n", "meta": {"hexsha": "b95fb62666903629db68dc7e948a7025a7d48317", "size": 1899, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter10/SnocList.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter10/SnocList.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter10/SnocList.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 35.8301886792, "max_line_length": 116, "alphanum_fraction": 0.5634544497, "num_tokens": 570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.8056321889812554, "lm_q1q2_score": 0.7147605692996809}} {"text": "--\n-- copyright (c) 2017 Simon Beaumont\n--\n\n||| This module defines an AST for the Dirac notation of linear algebra.\n\nmodule Language.Dirac.AST\n\nimport public Data.Complex -- for complex amplitides\n\nimport Data.Fin -- finite domain \nimport Data.Vect -- for finite lists\nimport Data.Matrix -- for matrices (in one intepretation)\n\n\n||| The types in Dirac notation - the attempt here is to keep these as\n||| abstract as possible and then provide concrete implmentations.\n\ndata Typ =\n ||| A real valued expression (R)\n Real |\n ||| A complex valued expression (C)\n Amplitude | \n ||| The primary type of state\n Ket Nat | \n ||| Adjoint dual of a Ket\n Bra Nat |\n ||| Unitary operator\n Operator Nat |\n ||| Self adjoint operator\n Measure Nat |\n ||| A typed functional language\n Function Typ Typ\n\n\n||| Transform AST type to a concrete Idris type \n\ninterpTyp : Typ -> Type\ninterpTyp Real = Double\ninterpTyp Amplitude = Complex Double\ninterpTyp (Ket n) = Vect n (Complex Double)\ninterpTyp (Bra n) = Vect n (Complex Double)\ninterpTyp (Operator n) = Matrix n n (Complex Double)\ninterpTyp (Measure n) = Matrix n n (Complex Double)\ninterpTyp (Function a t) = interpTyp a -> interpTyp t\n\n\n\n-- Context of language evaluation - taken from well typed interpreter\n-- example in Idris documentation \n\n\nusing (G : Vect n Typ)\n\n ||| Variables are deBruijn indexed \n data HasType : (i : Fin n) -> Vect n Typ -> Typ -> Type where\n Stop : HasType FZ (t :: G) t\n Pop : HasType k G t -> HasType (FS k) (u :: G) t\n \n ||| Type indexed expressions \n data Expr : Vect n Typ -> Typ -> Type where\n ||| Variable constructor\n Var : HasType i G t -> Expr G t\n ||| Real value\n RVal : (x : Double) -> Expr G Real\n ||| Complex value\n CVal : (z : (Complex Double)) -> Expr G Amplitude\n ||| Arbitrary binary op -- TODO might need more sophisitcated ops\n Op : (interpTyp a -> interpTyp b -> interpTyp c) -> Expr G a -> Expr G b -> Expr G c\n ||| Lambda\n Lam : Expr (a :: G) t -> Expr G (Function a t)\n ||| Function application\n App : Expr G (Function a t) -> Expr G a -> Expr G t\n\n ||| Get a value from the enviroment of in scope expressions\n\n data Env : Vect n Typ -> Type where\n Nil : Env Nil\n (::) : interpTyp a -> Env G -> Env (a :: G)\n\n lookup : HasType i G t -> Env G -> interpTyp t\n lookup Stop (x :: xs) = x\n lookup (Pop k) (x :: xs) = lookup k xs\n\n\n ||| An interpreter takes an expression in an environment\n ||| into an Idris value\n \n interp : Env G -> Expr G t -> interpTyp t\n interp env (Var i) = lookup i env\n interp env (RVal x) = x\n interp env (CVal z) = z\n interp env (Lam sc) = \\x => interp (x :: env) sc\n interp env (App f s) = interp env f (interp env s)\n interp env (Op op x y) = op (interp env x) (interp env y)\n\n -- Examples\n \n ||| Add two complex amplitudes\n add : Expr G (Function Amplitude (Function Amplitude Amplitude))\n add = Lam (Lam (Op (+) (Var Stop) (Var (Pop Stop))))\n\n -- ||| Add two Kets (Qubits)\n sum : Expr G (Function (Ket 2) (Function (Ket 2) (Ket 2)))\n sum = Lam (Lam (Op (Data.Vect.zipWith (+)) (Var Stop) (Var (Pop Stop))))\n \n \n-- Local Variables:\n-- idris-load-packages: (\"base\" \"contrib\")\n-- End:\n\n", "meta": {"hexsha": "f3d897f925fd0db04e294dabb84a88512abbd540", "size": 3254, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Language/Dirac/AST.idr", "max_stars_repo_name": "sebeaumont/hilbert", "max_stars_repo_head_hexsha": "1f9017ae3f805ba120bf02c7104a71a0f0b66c67", "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/Language/Dirac/AST.idr", "max_issues_repo_name": "sebeaumont/hilbert", "max_issues_repo_head_hexsha": "1f9017ae3f805ba120bf02c7104a71a0f0b66c67", "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/Language/Dirac/AST.idr", "max_forks_repo_name": "sebeaumont/hilbert", "max_forks_repo_head_hexsha": "1f9017ae3f805ba120bf02c7104a71a0f0b66c67", "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": 29.0535714286, "max_line_length": 88, "alphanum_fraction": 0.6259987707, "num_tokens": 953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7146296746417404}} {"text": "module Gadgil.Ass1\n\nimport Evens\n\n-- name your module as above\n\ndata IsOdd : Nat -> Type where\n OneOdd : IsOdd 1\n SSOdd : (n: Nat) -> IsOdd n -> IsOdd (S (S n))\n\nnotOddZ : IsOdd Z -> Void\nnotOddZ OneOdd impossible\nnotOddZ (SSOdd _ _) impossible\n\nnotOdd2: IsOdd 2 -> Void\nnotOdd2 (SSOdd Z OneOdd) impossible\nnotOdd2 (SSOdd Z (SSOdd _ _)) impossible\n\nevenS : (n: Nat) -> IsEven n -> IsOdd (S n)\nevenS Z ZEven = OneOdd\nevenS (S (S k)) (SSEven k x) = SSOdd (S k) (evenS k x)\n", "meta": {"hexsha": "8acf1da179e861d202fc2e780c4dc7381436f1dc", "size": 473, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Assignments/MyAss1.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": "_local-site/Assignments/MyAss1.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": "_local-site/Assignments/MyAss1.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": 21.5, "max_line_length": 54, "alphanum_fraction": 0.6638477801, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.953966096291997, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.7146038098209605}} {"text": "plus2 : Nat -> Nat\nplus2 = S . S\n\nokplus2Injective : (x, y : Nat) -> Equal (plus2 x) (plus2 y) -> Equal x y\nokplus2Injective Z Z Refl = Refl\nokplus2Injective (S n) (S n) Refl = Refl\nokplus2Injective Z (S _) _ impossible\nokplus2Injective (S _) Z _ impossible\n\nbadplus2Injective : (x, y : Nat) -> Equal (plus2 x) (plus2 y) -> Equal x y\nbadplus2Injective Z Z Refl = Refl\nbadplus2Injective Z (S _) _ impossible\nbadplus2Injective (S _) Z _ impossible\nbadplus2Injective (S n) (S n) Refl = Refl\n", "meta": {"hexsha": "0c29c1df9e1f8a421b72a179dc054e7bf58a9a25", "size": 488, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/coverage017/Issue1421.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/idris2/coverage017/Issue1421.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/idris2/coverage017/Issue1421.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": 32.5333333333, "max_line_length": 74, "alphanum_fraction": 0.6987704918, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7145589908813024}} {"text": "AdderType : (numargs : Nat) -> Type\nAdderType Z = Int \nAdderType (S k) = (next : Int) -> AdderType k\n\nadder : (numargs : Nat) -> (acc : Int) -> AdderType numargs\nadder Z acc = acc \nadder (S k) acc = \\next => adder k (next + acc)\n\nTupleVect : (length : Nat) -> (ty : Type) -> Type\nTupleVect Z _ = ()\nTupleVect (S k) x = (x, TupleVect k x)\n\ntest : TupleVect 4 Nat\ntest = (1,2,3,4,())\n\n", "meta": {"hexsha": "4822dd7952c8618ef976c630b2e8743ad9bea787", "size": 383, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp6/Adder.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp6/Adder.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp6/Adder.idr", "max_forks_repo_name": "Ryxai/idris_book_notes", "max_forks_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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.9375, "max_line_length": 59, "alphanum_fraction": 0.5953002611, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7142155498652581}} {"text": "> module NonNegRational.BasicProperties\n\n> import Syntax.PreorderReasoning\n\n> import NonNegRational.NonNegRational\n> import NonNegRational.BasicOperations\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.Predicates\n> import Fraction.BasicProperties\n> import Fraction.Normalize\n> import Fraction.NormalizeProperties\n> import Fraction.EqProperties\n> import Fraction.Normal\n> import Subset.Properties\n> import Unique.Predicates\n> import Unique.Properties\n> import Nat.Positive\n> import Nat.Coprime -- used by the implementation of |not1Eq0|!\n> import Nat.GCDAlgorithm -- used by the implementation of |not1Eq0|!\n> import Num.Refinements\n> import Pairs.Operations\n> import PNat.PNat\n> import PNat.Operations\n> import PNat.Properties \n> import Basic.Operations\n\n> %default total\n> -- %access export\n> %access public export\n\n\n* Properties of |toFraction|:\n\n> ||| toFraction is injective\n> toFractionInjective : {x, y : NonNegRational} -> (toFraction x) = (toFraction y) -> x = y\n> toFractionInjective {x} {y} p = subsetEqLemma1 x y p NormalUnique \n\n> ||| toFraction preserves equality\n> toFractionEqLemma2 : {x, y : NonNegRational} -> x = y -> (toFraction x) = (toFraction y)\n> toFractionEqLemma2 {x} {y} p = getWitnessPreservesEq p \n\n\n* Properties of |fromFraction| and |toFraction|:\n\n> ||| fromFraction is left inverse of toFraction\n> fromToId : (x : NonNegRational) -> fromFraction (toFraction x) = x\n> fromToId (Element x nx) = ( fromFraction (toFraction (Element x nx)) )\n> ={ Refl }=\n> ( fromFraction x )\n> ={ Refl }=\n> ( Element (normalize x) (normalNormalize x) )\n> ={ toFractionInjective (normalizePreservesNormal x nx) }=\n> ( Element x nx )\n> QED\n\n> ||| Equivalence of fractions implies equality of non-negative rationals \n> fromFractionEqLemma : (x, y : Fraction) -> x `Eq` y -> fromFraction x = fromFraction y\n> fromFractionEqLemma x y xEqy = s7 where\n> s1 : normalize x = normalize y\n> s1 = normalizeEqLemma2 x y xEqy\n> s2 : Normal (normalize x) = Normal (normalize y)\n> s2 = cong s1\n> s3 : Normal (normalize x)\n> s3 = normalNormalize x\n> s4 : Normal (normalize y)\n> s4 = normalNormalize y\n> s5 : s3 = s4\n> s5 = uniqueLemma (\\ f => NormalUnique {x = f}) (normalize x) (normalize y) s3 s4 s1\n> s6 : Element (normalize x) (normalNormalize x) = Element (normalize y) (normalNormalize y)\n> s6 = depCong2 {alpha = Fraction} \n> {P = Normal} \n> {gamma = Subset Fraction Normal}\n> {a1 = normalize x} \n> {a2 = normalize y}\n> {Pa1 = normalNormalize x} \n> {Pa2 = normalNormalize y} \n> {f = \\ ZUZU => \\ ZAZA => Element ZUZU ZAZA} s1 s5 \n> s7 : fromFraction x = fromFraction y\n> s7 = s6\n\n> ||| Denominators of non-negative rationals are greater than zero\n> denLTLemma : (x : NonNegRational) -> Z `LT` den x\n> denLTLemma x = s2 where\n> s1 : Z `LT` den (toFraction x)\n> s1 = Fraction.BasicProperties.denLTLemma (toFraction x)\n> s2 : Z `LT` den x\n> s2 = replace {P = \\ ZUZU => Z `LT` ZUZU} Refl s1\n\n> ||| \n> toFractionFromNatLemma : (n : Nat) -> toFraction (fromNat n) = fromNat n\n> toFractionFromNatLemma n =\n> ( toFraction (fromNat n) )\n> ={ Refl }=\n> ( toFraction (fromFraction (fromNat n)) )\n> ={ Refl }=\n> ( toFraction (fromFraction (n, Element (S Z) MkPositive)) )\n> ={ Refl }=\n> ( toFraction (Element (normalize (n, Element (S Z) MkPositive)) (normalNormalize (n, Element (S Z) MkPositive))) )\n> ={ cong (toFractionInjective (normalizePreservesNormal (n, Element (S Z) MkPositive) fromNatNormal)) }=\n> ( toFraction (Element (n, Element (S Z) MkPositive) fromNatNormal) )\n> ={ Refl }=\n> ( (n, Element (S Z) MkPositive) )\n> ={ Refl }=\n> ( fromNat n )\n> QED\n\n\n* Implementations:\n\n> ||| NonNegRational is an implementation of Show\n> implementation Show NonNegRational where\n> show q = if (den q == 1) \n> then show (num q)\n> else show (num q) ++ \"/\" ++ show (den q)\n\n> ||| NonNegRational is an implementation of Num\n> implementation Num NonNegRational where\n> (+) = plus\n> (*) = mult\n> fromInteger = fromNat . fromIntegerNat\n\n> ||| NonNegRational is an implementation of DecEq\n> implementation DecEq NonNegRational where\n> decEq x y with (Decidable.Equality.decEq (toFraction x) (toFraction y))\n> | (Yes p) = Yes (toFractionInjective p)\n> | (No contra) = No (\\ prf => contra (toFractionEqLemma2 prf))\n\n> ||| NonNegRational is an implementation of Eq\n> implementation Eq NonNegRational where\n> (==) x y with (decEq x y)\n> | (Yes _) = True\n> | (No _) = False\n\n\n* One is not zero\n\n> num0Eq0 : NonNegRational.BasicOperations.num (fromInteger 0) = 0\n> num0Eq0 = ( NonNegRational.BasicOperations.num (fromInteger 0) )\n> ={ Refl }=\n> ( Fraction.BasicOperations.num (toFraction (fromInteger 0)) )\n> ={ Refl }=\n> ( fst (toFraction (fromInteger 0)) )\n> ={ Refl }=\n> ( fst (toFraction (fromNat (fromIntegerNat 0))) )\n> ={ cong (toFractionFromNatLemma (fromIntegerNat 0)) }=\n> ( fst (fromNat (fromIntegerNat 0)) )\n> ={ Refl }=\n> ( fromIntegerNat 0 ) \n> ={ Refl }=\n> ( 0 )\n> QED\n\n> num1Eq1 : NonNegRational.BasicOperations.num (fromInteger 1) = 1\n> num1Eq1 = ( NonNegRational.BasicOperations.num (fromInteger 1) )\n> ={ Refl }=\n> ( Fraction.BasicOperations.num (toFraction (fromInteger 1)) )\n> ={ Refl }=\n> ( fst (toFraction (fromInteger 1)) )\n> ={ Refl }=\n> ( fst (toFraction (fromNat (fromIntegerNat 1))) )\n> ={ cong (toFractionFromNatLemma (fromIntegerNat 1)) }=\n> ( fst (fromNat (fromIntegerNat 1)) )\n> ={ Refl }=\n> ( fromIntegerNat 1 ) \n> ={ Refl }=\n> ( 1 )\n> QED\n\n> not1Eq0 : Not ((=) {A = NonNegRational} {B = NonNegRational} (fromInteger 1) (fromInteger 0))\n> not1Eq0 prf = SIsNotZ s3 where\n> s1 : (=) {A = Nat} {B = Nat} \n> (NonNegRational.BasicOperations.num (fromInteger 1)) \n> (NonNegRational.BasicOperations.num (fromInteger 0))\n> s1 = cong {f = NonNegRational.BasicOperations.num} prf\n> s2 : (=) {A = Nat} {B = Nat} 1 (NonNegRational.BasicOperations.num (fromInteger 0))\n> s2 = replace {P = \\ X => (=) {A = Nat} {B = Nat} X (NonNegRational.BasicOperations.num (fromInteger 0))} num1Eq1 s1\n> s3 : (=) {A = Nat} {B = Nat} 1 0\n> s3 = replace {P = \\ X => (=) {A = Nat} {B = Nat} 1 X} num0Eq0 s2\n\n\n* Further properties of toFraction, fromInteger, etc.:\n\n> |||\n> toFractionFromIntegerLemma : (n : Integer) -> toFraction (fromInteger n) = fromInteger n\n> toFractionFromIntegerLemma n =\n> ( toFraction (fromInteger n) )\n> ={ Refl }=\n> ( toFraction (fromNat (fromIntegerNat n)) )\n> ={ toFractionFromNatLemma (fromIntegerNat n) }=\n> ( fromNat (fromIntegerNat n) )\n> ={ Refl }=\n> ( fromInteger n )\n> QED\n\n> ||| fromFraction is linear\n> fromFractionLinear : (x, y : Fraction) -> fromFraction (x + y) = fromFraction x + fromFraction y\n> fromFractionLinear x y =\n> let s1 = Element (normalize (x + y)) (normalNormalize (x + y)) in\n> let s2 = Element (normalize (normalize x + normalize y)) (normalNormalize (normalize x + normalize y)) in\n> ( fromFraction (x + y) )\n> ={ Refl }=\n> ( Element (normalize (x + y)) (normalNormalize (x + y)) ) \n> ={ subsetEqLemma1 s1 s2 (sym (normalizePlusElim x y)) NormalUnique }=\n> ( Element (normalize (normalize x + normalize y)) (normalNormalize (normalize x + normalize y)) )\n> ={ Refl }=\n> ( fromFraction (normalize x + normalize y) )\n> ={ Refl }=\n> ( fromFraction (toFraction (Element (normalize x) (normalNormalize x)) \n> + \n> toFraction (Element (normalize y) (normalNormalize y))) )\n> ={ Refl }=\n> ( fromFraction (toFraction (fromFraction x) + toFraction (fromFraction y)) )\n> ={ Refl }=\n> ( fromFraction x + fromFraction y )\n> QED\n\n\n* Properties of addition:\n\n> ||| Addition is commutative\n> plusCommutative : (x : NonNegRational) -> (y : NonNegRational) -> x + y = y + x\n> plusCommutative x y =\n> ( x + y )\n> ={ Refl }=\n> ( fromFraction (toFraction x + toFraction y) )\n> ={ cong {f = fromFraction} (plusCommutative (toFraction x) (toFraction y)) }=\n> ( fromFraction (toFraction y + toFraction x) )\n> ={ Refl }=\n> ( y + x )\n> QED\n\n> ||| 0 is neutral element of addition\n> plusZeroRightNeutral : (x : NonNegRational) -> x + 0 = x\n> plusZeroRightNeutral x = \n> ( x + 0 )\n> ={ Refl }=\n> ( fromFraction (toFraction x + toFraction 0) )\n> ={ cong {f = fromFraction} (plusZeroRightNeutral (toFraction x)) }=\n> ( fromFraction (toFraction x) )\n> ={ fromToId x }=\n> ( x )\n> QED\n\n> ||| 0 is neutral element of addition\n> plusZeroLeftNeutral : (x : NonNegRational) -> 0 + x = x\n> plusZeroLeftNeutral x = \n> ( 0 + x )\n> ={ plusCommutative 0 x }=\n> ( x + 0 )\n> ={ plusZeroRightNeutral x }=\n> ( x )\n> QED\n\n> ||| Addition is associative\n> plusAssociative : (x, y, z : NonNegRational) -> x + (y + z) = (x + y) + z\n> plusAssociative x y z =\n> let x' = toFraction x in\n> let y' = toFraction y in\n> let z' = toFraction z in\n> ( x + (y + z) )\n> ={ Refl }=\n> ( fromFraction (x' + toFraction (fromFraction (y' + z'))) )\n> ={ Refl }=\n> ( fromFraction (x' + normalize (y' + z')) )\n> ={ Refl }=\n> ( Element (normalize (x' + normalize (y' + z'))) (normalNormalize (x' + normalize (y' + z'))) )\n> ={ toFractionInjective (normalizePlusElimRight x' (y' + z')) }=\n> ( Element (normalize (x' + (y' + z'))) (normalNormalize (x' + (y' + z'))) )\n> ={ toFractionInjective (cong (plusAssociative x' y' z')) }=\n> ( Element (normalize ((x' + y') + z')) (normalNormalize ((x' + y') + z')) )\n> ={ sym (toFractionInjective (normalizePlusElimLeft (x' + y') z')) }=\n> ( Element (normalize (normalize (x' + y') + z')) (normalNormalize (normalize (x' + y') + z')) )\n> ={ Refl }= \n> ( fromFraction (normalize (x' + y') + z') )\n> ={ Refl }=\n> ( fromFraction (toFraction (fromFraction (x' + y')) + z') )\n> ={ Refl }=\n> ( (x + y) + z )\n> QED\n\n\n* Properties of multiplication:\n\n> ||| Multiplication is commutative\n> multCommutative : (x : NonNegRational) -> (y : NonNegRational) -> x * y = y * x\n> multCommutative x y =\n> ( x * y )\n> ={ Refl }=\n> ( fromFraction ((toFraction x) * (toFraction y)) )\n> ={ cong {f = fromFraction} (multCommutative (toFraction x) (toFraction y)) }=\n> ( fromFraction ((toFraction y) * (toFraction x)) )\n> ={ Refl }=\n> ( y * x )\n> QED\n\n> ||| 1 is neutral element of multiplication\n> multOneRightNeutral : (x : NonNegRational) -> x * 1 = x\n> multOneRightNeutral x = \n> ( x * 1 )\n> ={ Refl }=\n> ( fromFraction ((toFraction x) * (toFraction 1)) )\n> ={ Refl }=\n> ( fromFraction ((toFraction x) * (toFraction (fromInteger 1))) )\n> ={ cong {f = \\ ZUZU => fromFraction ((toFraction x) * ZUZU)} (toFractionFromIntegerLemma 1) }=\n> ( fromFraction ((toFraction x) * (fromInteger 1)) )\n> ={ cong {f = fromFraction} (multOneRightNeutral (toFraction x)) }=\n> ( fromFraction (toFraction x) )\n> ={ fromToId x }=\n> ( x )\n> QED\n\n> ||| 1 is neutral element of multiplication\n> multOneLeftNeutral : (x : NonNegRational) -> 1 * x = x\n> multOneLeftNeutral x = \n> ( 1 * x )\n> ={ multCommutative 1 x }=\n> ( x * 1 )\n> ={ multOneRightNeutral x }=\n> ( x )\n> QED\n\n> |||\n> multZeroRightZero : (x : NonNegRational) -> x * 0 = 0\n> multZeroRightZero x = \n> let x' = toFraction x in \n> ( x * 0 )\n> ={ Refl }=\n> ( fromFraction (x' * 0) )\n> ={ Refl }=\n> ( Element (normalize (x' * 0)) (normalNormalize (x' * 0)) )\n> ={ toFractionInjective (normalizeEqLemma2 (x' * 0) 0 (multZeroRightEqZero x')) }=\n> ( Element (normalize 0) (normalNormalize 0) )\n> ={ Refl }=\n> ( fromFraction 0 )\n> ={ fromToId 0 }=\n> ( 0 )\n> QED\n\n> ||| \n> multZeroLeftZero : (x : NonNegRational) -> 0 * x = 0\n> multZeroLeftZero x = \n> ( 0 * x )\n> ={ multCommutative 0 x }=\n> ( x * 0 )\n> ={ multZeroRightZero x }=\n> ( 0 )\n> QED\n\n\n* Properties of addition and multiplication:\n\n> |||\n> multDistributesOverPlusRight : (x, y, z : NonNegRational) -> x * (y + z) = (x * y) + (x * z)\n> multDistributesOverPlusRight x y z =\n> let x' = toFraction x in\n> let y' = toFraction y in\n> let z' = toFraction z in\n> ( x * (y + z) )\n> ={ Refl }=\n> ( fromFraction (x' * toFraction (fromFraction (y' + z'))) )\n> ={ Refl }=\n> ( fromFraction (x' * (normalize (y' + z'))) )\n> ={ Refl }=\n> ( Element (normalize (x' * (normalize (y' + z')))) (normalNormalize (x' * (normalize (y' + z')))) )\n> ={ toFractionInjective (normalizeMultElimRight x' (y' + z')) }=\n> ( Element (normalize (x' * (y' + z'))) (normalNormalize (x' * (y' + z'))) )\n> ={ toFractionInjective (normalizeEqLemma2 (x' * (y' + z')) ((x' * y') + (x' * z')) multDistributesOverPlusRightEq) }=\n> ( Element (normalize ((x' * y') + (x' * z'))) (normalNormalize ((x' * y') + (x' * z'))) )\n> ={ toFractionInjective (sym (normalizePlusElim (x' * y') (x' * z'))) }=\n> ( Element (normalize (normalize (x' * y') + normalize (x' * z'))) \n> (normalNormalize (normalize (x' * y') + normalize (x' * z'))) )\n> ={ Refl }=\n> ( fromFraction ((normalize (x' * y')) + (normalize (x' * z'))) )\n> ={ Refl }=\n> ( fromFraction ((toFraction (fromFraction (x' * y'))) + (toFraction (fromFraction (x' * z')))) )\n> ={ Refl }=\n> ( (x * y) + (x * z) )\n> QED\n\n> |||\n> multDistributesOverPlusLeft : (x, y, z : NonNegRational) -> (x + y) * z = (x * z) + (y * z)\n> multDistributesOverPlusLeft x y z =\n> ( (x + y) * z )\n> ={ multCommutative (x + y) z }=\n> ( z * (x + y) )\n> ={ multDistributesOverPlusRight z x y }=\n> ( z * x + z * y )\n> ={ cong {f = \\ ZUZU => ZUZU + z * y} (multCommutative z x) }=\n> ( x * z + z * y )\n> ={ cong {f = \\ ZUZU => x * z + ZUZU} (multCommutative z y) }=\n> ( x * z + y * z ) \n> QED \n\n\n* Implementations of refinements of |Num|:\n\n> ||| NonNegRational is an implementation of NumPlusZeroNeutral\n> implementation NumPlusZeroNeutral NonNegRational where\n> plusZeroLeftNeutral = NonNegRational.BasicProperties.plusZeroLeftNeutral\n> plusZeroRightNeutral = NonNegRational.BasicProperties.plusZeroRightNeutral\n\n> ||| NonNegRational is an implementation of NumPlusAssociative\n> implementation NumPlusAssociative NonNegRational where\n> plusAssociative = NonNegRational.BasicProperties.plusAssociative\n\n> ||| NonNegRational is an implementation of NumMultZeroOne\n> implementation NumMultZeroOne NonNegRational where\n> multZeroRightZero = NonNegRational.BasicProperties.multZeroRightZero\n> multZeroLeftZero = NonNegRational.BasicProperties.multZeroLeftZero\n> multOneRightNeutral = NonNegRational.BasicProperties.multOneRightNeutral\n> multOneLeftNeutral = NonNegRational.BasicProperties.multOneLeftNeutral\n\n> ||| NonNegRational is an implementation NumMultDistributesOverPlus\n> implementation NumMultDistributesOverPlus NonNegRational where\n> multDistributesOverPlusRight = NonNegRational.BasicProperties.multDistributesOverPlusRight\n> multDistributesOverPlusLeft = NonNegRational.BasicProperties.multDistributesOverPlusLeft\n\n\n* Elementary arithmetic properties:\n\n> multElimRight : (m : Nat) -> (n, d : PNat) -> fromFraction (m * (toNat n), d * n) = fromFraction (m, d)\n> multElimRight m n d =\n> let s1 = Element (normalize (m * (toNat n), d * n)) (normalNormalize (m * (toNat n), d * n)) in\n> let s2 = Element (normalize (m, d)) (normalNormalize (m, d)) in\n> ( fromFraction (m * (toNat n), d * n) )\n> ={ Refl }=\n> ( Element (normalize (m * (toNat n), d * n)) (normalNormalize (m * (toNat n), d * n)) ) \n> ={ subsetEqLemma1 s1 s2 (normalizeUpscaleLemma (m, d) n) NormalUnique }=\n> ( Element (normalize (m, d)) (normalNormalize (m, d)) )\n> ={ Refl }=\n> ( fromFraction (m, d) )\n> QED\n\n\n> postulate sumOneLemma1 : {n: Nat} -> \n> fromFraction (n, Element (S n) MkPositive) \n> + \n> fromFraction (1, Element (S n) MkPositive) \n> = \n> 1\n\n\n> {-\n\n> ---}\n \n", "meta": {"hexsha": "e936f2336de4f10d77b91f7c64668f5dde11cc5b", "size": 16480, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegRational/BasicProperties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "NonNegRational/BasicProperties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "NonNegRational/BasicProperties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7857142857, "max_line_length": 121, "alphanum_fraction": 0.591868932, "num_tokens": 5313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7140659716446128}} {"text": "> module SequentialDecisionProblems.applications.GoodOrBad\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Sigma.Sigma\n\n> %default total\n> %auto_implicits off\n> %access public export\n\n\n* Good / Bad options:\n\n> data GoodOrBad = Good | Bad \n\n\n* |GoodOrBad| is finite and non-empty:\n\n> to : GoodOrBad -> Fin 2\n> to Good = FZ\n> to Bad = FS FZ\n\n> from : Fin 2 -> GoodOrBad\n> from FZ = Good\n> from (FS FZ) = Bad\n> from (FS (FS k)) = absurd k\n\n> toFrom : (k : Fin 2) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS FZ) = Refl\n> toFrom (FS (FS k)) = absurd k\n\n> fromTo : (a : GoodOrBad) -> from (to a) = a\n> fromTo Good = Refl\n> fromTo Bad = Refl\n\n> ||| \n> finiteGoodOrBad : Finite GoodOrBad\n> finiteGoodOrBad = MkSigma 2 (MkIso to from toFrom fromTo)\n\n> |||\n> cardNotZGoodOrBad : CardNotZ finiteGoodOrBad\n> cardNotZGoodOrBad = cardNotZLemma finiteGoodOrBad Good\n\n\n> {-\n\n> ---}\n\n\n \n", "meta": {"hexsha": "e7fe794997cc5e4a6fc5dd2af0e1eda0eefb4b4c", "size": 1030, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/GoodOrBad.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/applications/GoodOrBad.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/applications/GoodOrBad.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.3928571429, "max_line_length": 59, "alphanum_fraction": 0.627184466, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7138674554955261}} {"text": "> module Permutation\n> import Data.List\n> import Data.List.DecIn\n\n> ||| Proofs that two lists `xs` and `ys` have the same length and same elements;\n> ||| i.e., that `xs` and `ys` are related by a permutation of their elements.\n> Permutation : DecIn t => List t -> List t -> Type\n> Permutation xs ys = \n> ((length xs = length ys),ElementPreservingCorrespondence xs ys)", "meta": {"hexsha": "3c7b4473bdcaf49f91f322e66fd9a49a4a205410", "size": 369, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Permutation.lidr", "max_stars_repo_name": "nicklecompte/idris-finite-sets", "max_stars_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_stars_repo_licenses": ["CC0-1.0"], "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/Permutation.lidr", "max_issues_repo_name": "nicklecompte/idris-finite-sets", "max_issues_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_issues_repo_licenses": ["CC0-1.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": "src/Permutation.lidr", "max_forks_repo_name": "nicklecompte/idris-finite-sets", "max_forks_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0, "max_line_length": 81, "alphanum_fraction": 0.6937669377, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.7137737943490059}} {"text": "module Applications.Example\n\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.OrderedGroup\nimport Proofs.OrderTheory\nimport Proofs.GroupTheory\nimport Proofs.GroupCancelationLemmas\nimport Proofs.TranslationInvarianceTheory\n\n%default total\n%access public export\n\n\nabsoluteValue : (Ringops s, Decidable [s,s] leq) =>\n .OrderedGroupSpec (+) Zero Ng leq -> s -> (a ** leq Zero a)\nabsoluteValue spec x =\n case decision {rel = leq} x Zero of\n Yes prf => (Ng x ** invertNegative (partiallyOrderedGroup spec) x prf)\n No contra =>\n let (positive, _) = orderContra (totalOrder spec) x Zero contra\n in (x ** positive)\n", "meta": {"hexsha": "d70441d614f7f7a5161f73b3cdfd0dd35fcbeab5", "size": 645, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Applications/Example.idr", "max_stars_repo_name": "jeroennoels/verified-algebra", "max_stars_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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/Applications/Example.idr", "max_issues_repo_name": "jeroennoels/verified-algebra", "max_issues_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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/Applications/Example.idr", "max_forks_repo_name": "jeroennoels/verified-algebra", "max_forks_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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.0434782609, "max_line_length": 74, "alphanum_fraction": 0.7379844961, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947101574298, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.7133906744191528}} {"text": "zeroNotSucc : (0 = S k) -> Void\nzeroNotSucc Refl impossible\n\nsuccNotZero : (S k = 0) -> Void\nsuccNotZero Refl impossible\n\nnoRec : (contra : (k = j) -> Void) -> (S k = S j) -> Void\nnoRec contra Refl = contra Refl\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Dec (num1 = num2)\ncheckEqNat Z Z = Yes Refl\ncheckEqNat Z (S k) = No zeroNotSucc\ncheckEqNat (S k) Z = No succNotZero\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Yes prf => Yes (cong prf)\n No contra => No (noRec contra)\n", "meta": {"hexsha": "b402a4b088161a314d626e7f470db7e2ede121bd", "size": 539, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter08/CheckEqDec.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter08/CheckEqDec.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter08/CheckEqDec.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "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.7058823529, "max_line_length": 62, "alphanum_fraction": 0.5769944341, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947163538936, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7133906686755991}} {"text": "module Path\n\nimport Basic\nimport Unit\nimport Void\n\n||| Type of identities or paths between two points in space.\npublic export\ndata Id : (0 a : Type) -> a -> a -> Type where\n Refl : (x : a) -> Id a x x\n\ninfix 4 ==\n\npublic export\n(==) : a -> a -> Type\nx == y = Id _ x y\n\n||| Induction principle for paths\npublic export\nJ : (p : (x, y : a) -> (x == y) -> Type)\n -> ((x : a) -> p x x (Refl x))\n -> (x, y : a) -> (i : x == y) -> p x y i\nJ p f x x (Refl x) = f x\n\n-- Another one\npublic export\nH : (x : a) -> (p : (y : a) -> (x == y) -> Type)\n -> p x (Refl x)\n -> (y : a) -> (i : x == y) -> p y i\nH x p f x (Refl x) = f\n\n-- J and H agree (no proof here)\n-- TODO prove it ?\n\n-- No axiom-K\n\n-- Axiom-K is incompatible with the Univalence Axiom.\n-- But unfortunately the former is provable in Idris 2.\n-- And there is no option to remove it from the system.\n\n-- In practice this means that we must not pattern match\n-- on loops (paths from a point to itself)\n-- i.e\n\n-- veryBad : x === x -> ...\n-- veryBad Refl = ...\n\n-- but on the other hand, this is ok:\n-- noContradiction : x === y -> ...\n-- noContradiction Refl = ...\n\n||| Lift a point in the base space `a` to the point in the total\n||| space `Sigma a p` via the given path in the base space.\npublic export\ntransport : (p : a -> Type) -> {x, y : _} -> x == y -> p x -> p y\n-- transport p i = J (\\x, y, _ => p x -> p y) (\\_ => id) _ _ i\ntransport p (Refl x) = id\n\npublic export\nIdFun : {a, b: Type} -> a == b -> a -> b\nIdFun = transport id\n\npublic export\ntransportConst : (a, b : Type)\n -> (x, y : a)\n -> (x' : b)\n -> (path : Id a x y)\n -> transport (\\_ => b) path x' == x'\ntransportConst a b x x x' (Refl x) = Refl x'\n\nnamespace Id\n public export\n (.) : {x, y, z : a} -> x == y -> y == z -> x == z\n p . q = transport (x ==) q p\n\n --TODO Vertical composition\n\n||| p <=> p⁻¹\npublic export\nsym : {x, y : a} -> (p : x == y) -> y == x\nsym p = transport (== x) p (Refl x)\n\n||| Congruence or f(p)/(ap f p) in the HoTT book\n||| p => f(p)\npublic export\nap : {x, y : a} -> (f : a -> b) -> (p : x == y) -> f x == f y\n-- ap f p = transport (\\that => f x == f that) p (Refl (f x))\nap f (Refl x) = Refl (f x)\n\n||| Dependent map\npublic export\napd : (p : a -> Type)\n -> (f : (x : a) -> p x)\n -> (x, y : a)\n -> (path : x == y)\n -> transport p path (f x) == f y\napd p f x x (Refl x) = Refl (f x)\n", "meta": {"hexsha": "1870a92323a74f4fa1a9a7277339daf27d15b366", "size": 2388, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Path.idr", "max_stars_repo_name": "Russoul/Idris2-HoTT", "max_stars_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-17T05:44:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T09:36:13.000Z", "max_issues_repo_path": "src/Path.idr", "max_issues_repo_name": "Russoul/Idris2-HoTT", "max_issues_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "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/Path.idr", "max_forks_repo_name": "Russoul/Idris2-HoTT", "max_forks_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "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.3673469388, "max_line_length": 65, "alphanum_fraction": 0.5159128978, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.7132167783583491}} {"text": "module Toolkit.Data.Vect.Extra\n\nimport public Decidable.Equality\nimport Data.Vect\n\n%default total\n\nnamespace Equality\n public export\n vecEq : Eq type => Vect n type -> Vect m type -> Bool\n vecEq [] [] = True\n vecEq [] (x :: xs) = False\n vecEq (x :: xs) [] = False\n vecEq (x :: xs) (y :: ys) = x == y && vecEq xs ys\n\nnamespace Decidable\n namespace SameLength\n public export\n decEq : DecEq type\n => (n = m)\n -> (xs : Vect n type)\n -> (ys : Vect m type)\n -> Dec (xs = ys)\n decEq Refl xs ys with (decEq xs ys)\n decEq Refl ys ys | (Yes Refl) = Yes Refl\n decEq Refl xs ys | (No contra) = No contra\n\n namespace DiffLength\n\n public export\n vectorsDiffLength : DecEq type\n => (contra : (n = m) -> Void)\n -> {xs : Vect n type}\n -> {ys : Vect m type}\n -> (xs = ys) -> Void\n vectorsDiffLength contra Refl = contra Refl\n\n public export\n decEq : DecEq type\n => {n,m : Nat}\n -> (xs : Vect n type)\n -> (ys : Vect m type)\n -> Dec (xs = ys)\n decEq xs ys {n} {m} with (decEq n m)\n decEq xs ys {n = m} {m = m} | (Yes Refl) = decEq Refl xs ys\n decEq xs ys {n = n} {m = m} | (No contra) = No (vectorsDiffLength contra)\n\nnamespace Shape\n\n public export\n data Shape : (xs : Vect n a)\n -> (ys : Vect m a)\n -> Type\n where\n Empty : Shape Nil Nil\n LH : Shape (x::xs) Nil\n RH : Shape Nil (y::ys)\n Both : Shape (x::xs) (y::ys)\n\n export\n shape : (xs : Vect n a)\n -> (ys : Vect m a)\n -> Shape xs ys\n shape [] [] = Empty\n shape [] (y :: ys) = RH\n shape (x :: xs) [] = LH\n shape (x :: xs) (y :: ys) = Both\n\n-- [ EOF ]\n", "meta": {"hexsha": "0f9be7a4b1b81aee0594018f323cee844e3a0b70", "size": 1781, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/Vect/Extra.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/Toolkit/Data/Vect/Extra.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/Toolkit/Data/Vect/Extra.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": 25.4428571429, "max_line_length": 79, "alphanum_fraction": 0.4907355418, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.71302774525302}} {"text": "data Expr\n = Tr\n | Fl\n | IsZero Expr\n | Succ Expr\n | Pred Expr\n | If Expr Expr Expr\n | Zero\n\ndata TType\n = TBool\n | TNat\n | TArr TType TType\n\nEq TType where\n (==) TBool TBool = True\n (==) TNat TNat = True\n (==) (TArr x z) (TArr y w) = ((x == y) && (z ==w))\n (==) _ _ = False\n\nisNum : Expr -> Bool\nisNum Zero = True\nisNum (Succ t) = isNum t\nisNum _ = False\n\nisVal : Expr -> Bool\nisVal Tr = True\nisVal Fl = True\nisVal Zero = True\nisVal (Succ t) = isVal t\nisVal _ = False\n\npartial\neval1 : Expr -> Maybe Expr\neval1 t =\n case t of\n Succ t => Succ <$> (eval1 t)\n Pred Zero => Just Zero\n Pred (Succ t) => case isNum t of\n False => Nothing\n True => Just t\n Pred t => Pred <$> (eval1 t)\n IsZero Zero => Just Tr\n IsZero (Succ t) => case isNum t of\n False => Nothing -- might be wrong\n True => Just Fl\n IsZero t => IsZero <$> (eval1 t)\n If Tr c _ => Just c\n If Fl _ a => Just a\n If t c a => (\\t' => If t' c a) <$> eval1 t\n _ => Nothing\n\npartial\nnf : Expr -> Expr\nnf t = fromMaybe t (nf <$> eval1 t)\n\npartial\neval : Expr -> Maybe Expr\neval t = case (isVal t) of\n False => Just (nf t)\n True => Nothing\n\ndata TypeError\n = TypeMismatch TType TType\n\ncheck : Expr -> Either TypeError TType\n\ntypeof : Expr -> Either TypeError TType\ntypeof t =\n case t of\n (IsZero a) => do\n ta <- typeof a\n case ta of\n TNat => Right TNat\n _ => Left (TypeMismatch ta TNat)\n (Succ a) => do\n ta <- typeof a\n case ta of\n TNat => Right TNat\n _ => Left (TypeMismatch ta TNat)\n (Pred a) => do\n ta <- typeof a\n case ta of\n TNat => Right TNat\n _ => Left (TypeMismatch ta TNat)\n (If a b c) => do\n ta <- typeof a\n tb <- typeof b\n tc <- typeof c\n case ta of\n TBool => case tb == tc of\n True => Right tc\n False => Left (TypeMismatch tb tc)\n _ => Left (TypeMismatch ta TBool)\n Zero => Right TNat\n Tr => Right TBool\n Fl => Right TBool\n", "meta": {"hexsha": "883866cc2e4fb63c848ca058a67c763bd43f6661", "size": 2374, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "typed-lambda-calc/Typed.idr", "max_stars_repo_name": "alexhumphreys/pl-playground", "max_stars_repo_head_hexsha": "da90cc3527e0ff3a7effd1f5dde5437b47ac1170", "max_stars_repo_licenses": ["BSD-2-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": "typed-lambda-calc/Typed.idr", "max_issues_repo_name": "alexhumphreys/pl-playground", "max_issues_repo_head_hexsha": "da90cc3527e0ff3a7effd1f5dde5437b47ac1170", "max_issues_repo_licenses": ["BSD-2-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": "typed-lambda-calc/Typed.idr", "max_forks_repo_name": "alexhumphreys/pl-playground", "max_forks_repo_head_hexsha": "da90cc3527e0ff3a7effd1f5dde5437b47ac1170", "max_forks_repo_licenses": ["BSD-2-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.2244897959, "max_line_length": 65, "alphanum_fraction": 0.4582982308, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7130192264365797}} {"text": "\nmodule Eval\n\n-- Evaluators for terms in the simply-typed\n-- lambda calculus. \n\n\nimport PnP\nimport Step\nimport Term\nimport Typing\n\n\n%access export\n\n\n\n------------------------------------------------------------\n-- Begin: EVALUATOR (FORMALLY) BASED ON SMALL-STEP SEMANTICS\n\neval : (e : Term) -> \n Typing [] e t ->\n (e' : Term ** (Value e', Typing [] e' t, TransStep e e'))\neval e ty = case progress e ty of\n (Left v) => (e ** (v, ty, TStRefl e))\n (Right (e' ** st)) => let ty' = preservation e ty st\n (e'' ** (v'', ty'', tst)) = eval e' ty'\n in (e'' ** (v'', ty'', TStTrans st tst))\n\n-- End: EVALUATOR (FORMALLY) BASED ON SMALL-STEP SEMANTICS\n----------------------------------------------------------\n\n\n\n\n--------------------------------------------------\n-- Begin: ENVIRONMENT-BASED/DENOTATIONAL EVALUATOR\n\ntotal denoteType : Ty -> Type\ndenoteType TyNat = Nat\ndenoteType (TyFun t1 t2) = denoteType t1 -> denoteType t2\n\n\n\ndata Env : Context -> Type where\n ENil : Env []\n ECons : denoteType t -> Env ctx -> Env (t::ctx)\n\n\n\ntotal lookup : (i : Nat) ->\n (ctx : Context) ->\n index' i ctx = Just t ->\n Env ctx ->\n denoteType t\nlookup Z [] Refl ENil impossible\nlookup (S _) [] Refl ENil impossible\nlookup Z (s::ctx) Refl (ECons x env) = x\nlookup (S i) (s::ctx) prf (ECons x env) = lookup i ctx prf env\n\n\n\ntotal primRec : Nat -> t -> (Nat -> t -> t) -> t\nprimRec Z e0 e1 = e0\nprimRec (S n) e0 e1 = e1 n (primRec n e0 e1) \n\n\ntotal evalEnv : Env ctx -> \n (e : Term) ->\n Typing ctx e t ->\n denoteType t\nevalEnv env (TVar i) (TyVar prf) = lookup i _ prf env\nevalEnv env (TAbs e) (TyAbs s ty) = \\x => evalEnv (ECons x env) e ty\nevalEnv env (TApp e1 e2) (TyApp ty1 ty2) = \n (evalEnv env e1 ty1) (evalEnv env e2 ty2)\nevalEnv env (TRec e1 e2 e3) (TyRec ty1 ty2 ty3) = \n let n = evalEnv env e1 ty1\n e0 = evalEnv env e2 ty2\n erec = evalEnv env e3 ty3\n in primRec n e0 erec\nevalEnv env TZero TyZero = Z\nevalEnv env (TSucc e) (TySucc ty) = S $ evalEnv env e ty\nevalEnv env (TPred e) (TyPred ty) = \n case evalEnv env e ty of\n Z => Z\n (S k) => k\nevalEnv env (TIfz e1 e2 e3) (TyIfz ty1 ty2 ty3) = \n case evalEnv env e1 ty1 of\n Z => evalEnv env e2 ty2\n (S k) => evalEnv env e3 ty3\n\n-- End: ENVIRONMENT-BASED/DENOTATIONAL EVALUATOR\n------------------------------------------------\n", "meta": {"hexsha": "af95a4ab9d27ac4f2fb519ee42290ca032beb5ea", "size": 2510, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "totality/src/Eval.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "totality/src/Eval.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "totality/src/Eval.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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.7021276596, "max_line_length": 68, "alphanum_fraction": 0.5171314741, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7129956439998263}} {"text": "module Ratio\n\n%access public export\n\n-- TODO: This could probably all be better...\n\ngcd : (Integral a, Abs a, Eq a) => a -> a -> a\ngcd n m = gcd' (abs n) (abs m)\n where\n gcd' : a -> a -> a\n gcd' n m =\n if m == 0\n then n\n else gcd' m (n `mod` m)\n\nnonZero : (Integral a, Eq a) => a -> Bool\nnonZero n = n /= 0\n\ninfixl 7 .%\ndata Ratio : Type -> Type where\n (.%) : (Integral a, Eq a, Abs a, Ord a, Neg a) => a -> a -> Ratio a\n\ninfixl 7 :%\n(:%) : (Integral a, Eq a, Abs a, Ord a, Neg a) =>\n a -> a -> Maybe (Ratio a)\n(:%) n m =\n case m == 0 of\n False =>\n let cd = gcd n m\n num = (n `div` cd) -- TODO: Should be `quot`?\n den = (m `div` cd) -- TODO: Should be `quot`?\n in Just $ num .% den\n True => Nothing\n\nRational : Type\nRational = Ratio Integer\n\nnumerator : Ratio a -> a\nnumerator (n .% _) = n\n\ndenominator : Ratio a -> a\ndenominator (_ .% d) = d\n\nEq a => Eq (Ratio a) where\n (a .% b) == (c .% d) = (a * d) == (c * b)\n\nOrd a => Ord (Ratio a) where\n compare (a .% b) (c .% d) = compare (a * d) (c * b)\n\n\n\nrationalDiv : Ratio a -> Ratio a -> Maybe (Ratio a)\nrationalDiv (a .% b) (c .% d) = (a * d) :% (b * c)\n\n-- rationalMod : Ratio a -> Ratio a -> Maybe (Ratio a)\n-- rationalMod a b = (a - b) * a `div` b\n\nrationalAdd : Ratio a -> Ratio a -> Maybe (Ratio a)\nrationalAdd (a .% b) (c .% d) = ((a * d) + (b * c)) :% (b * d)\n\nrationalMul : Ratio a -> Ratio a -> Maybe (Ratio a)\nrationalMul (a .% b) (c .% d) = (a * c) :% (b * d)\n\nrationalFromInteger : Integer -> Maybe (Ratio Integer)\nrationalFromInteger i = (fromInteger i) :% 1\n\nrationalNegate : Ratio a -> Maybe (Ratio a)\nrationalNegate (a .% b) = (negate a) :% b\n\nrationalSub : Ratio a -> Ratio a -> Maybe (Ratio a)\nrationalSub (a .% b) (c .% d) = ((a * d) - (c * b)) :% (b * d)\n\nShow a => Show (Ratio a) where\n show (n .% d) = show n ++ \" % \" ++ show d\n\nrationalCast : Rational -> Maybe Double\nrationalCast (a .% b) =\n case b == 0 of\n False => Just $ (cast a) / (cast b)\n True => Nothing\n", "meta": {"hexsha": "7f83b2e398ab1456d79eabecd6abc602b1d34268", "size": 2051, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Ratio.idr", "max_stars_repo_name": "ebenpack/lidrisp", "max_stars_repo_head_hexsha": "f48bdeff82b3cb9b1f516d42180eaa6fcfef8ffa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-24T09:04:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-24T09:04:53.000Z", "max_issues_repo_path": "src/Ratio.idr", "max_issues_repo_name": "ebenpack/lidrisp", "max_issues_repo_head_hexsha": "f48bdeff82b3cb9b1f516d42180eaa6fcfef8ffa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-09T16:54:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-09T16:54:44.000Z", "max_forks_repo_path": "src/Ratio.idr", "max_forks_repo_name": "ebenpack/lidrisp", "max_forks_repo_head_hexsha": "f48bdeff82b3cb9b1f516d42180eaa6fcfef8ffa", "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": 25.3209876543, "max_line_length": 71, "alphanum_fraction": 0.5119453925, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7128514551419156}} {"text": "\nmodule Eval\n\n-- Evaluators for terms in the simply-typed\n-- lambda calculus. \n\n\nimport BigStep\nimport Equivalence\nimport Determinism\nimport Progress\nimport Step\nimport Subst\nimport Term\n\n\n%access export\n\n\n------------------------------------------------------------\n-- Begin: EVALUATOR (FORMALLY) BASED ON SMALL-STEP SEMANTICS\n\neval : (e : Term [] t) -> (e' : Term [] t ** (Value e', TransStep e e'))\neval e = case progress e of\n Left v => (e ** (v, TStRefl e))\n Right (e' ** s') => let (e'' ** (v'', s'')) = eval e'\n in (e'' ** (v'', TStTrans s' s''))\n\n-- End: EVALUATOR (FORMALLY) BASED ON SMALL-STEP SEMANTICS\n----------------------------------------------------------\n\n\n\n----------------------------------------------------------\n-- Begin: EVALUATOR INFORMALLY BASED ON BIG-STEP SEMANTICS\n\neval' : Term [] t -> Term [] t\neval' (TVar _) impossible\neval' (TAbs e) = TAbs e\neval' (TApp e1 e2) = let (TAbs e1v) = eval' e1\n e2v = eval' e2\n in eval' $ subst e2v First e1v\neval' (TFix e) = let (TAbs ev) = eval' e\n in eval' $ subst (TFix (TAbs ev)) First ev\neval' TZero = TZero\neval' (TSucc e) = TSucc (eval' e)\neval' (TPred e) = case eval' e of \n TZero => TZero\n TSucc ev' => ev'\neval' (TIfz e1 e2 e3) = case eval' e1 of\n TZero => eval' e2\n TSucc _ => eval' e3 \n\n-- End: EVALUATOR INFORMALLY BASED ON BIG-STEP SEMANTICS\n--------------------------------------------------------\n\n\n\n--------------------------------------------------------\n-- Begin: EVALUATOR FORMALLY BASED ON BIG-STEP SEMANTICS\n\nevalBigStep : (e : Term [] t) -> (e' : Term [] t ** (Value e', BigStep e e'))\nevalBigStep (TVar _) impossible\nevalBigStep (TAbs x) = (TAbs x ** (VAbs, BStValue VAbs))\nevalBigStep (TApp x y) = case evalBigStep x of\n (_ ** (VZero, _)) impossible\n (_ ** (VSucc _, _)) impossible\n (TAbs ex ** (VAbs, bStx)) => let (ey ** (_ , bSty)) = evalBigStep y\n (er ** (vr, bStr)) = evalBigStep (subst ey First ex)\n in (er ** (vr, BStApp bStx bSty bStr))\nevalBigStep (TFix x) = case evalBigStep x of\n (_ ** (VZero, _)) impossible\n (_ ** (VSucc _, _)) impossible\n (TAbs ex ** (VAbs, bStx)) => let (er ** (vr, bStr)) = evalBigStep (subst (TFix (TAbs ex)) First ex)\n in (er ** (vr, BStFix bStx bStr))\nevalBigStep TZero = (TZero ** (VZero, BStValue VZero))\nevalBigStep (TSucc x) = let (ex ** (vx, bStx)) = evalBigStep x\n in (TSucc ex ** (VSucc vx, BStSucc bStx))\nevalBigStep (TPred x) = case evalBigStep x of\n (TZero ** (_, bStx)) => (TZero ** (VZero, BStPredZero bStx))\n (TSucc ex ** (VSucc vx, bStx)) => (ex ** (vx, BStPredSucc bStx))\n (_ ** (VAbs, _)) impossible\nevalBigStep (TIfz x y z) = case evalBigStep x of\n (TZero ** (_, bStx)) => let (ey ** (vy, bSty)) = evalBigStep y\n in (ey ** (vy, BStIfzZero bStx bSty))\n (TSucc ex ** (VSucc vx, bStx)) => let (ez ** (vz, bStz)) = evalBigStep z\n in (ez ** (vz, BStIfzSucc bStx bStz))\n (_ ** (VAbs, _)) impossible\n\n-- End: EVALUATOR FORMALLY BASED ON BIG-STEP SEMANTICS\n------------------------------------------------------\n\n\n\n-----------------------------------\n-- Begin: EQUIVALENCE OF EVALUATORS\n\ntotal equivEval : (eval e1) = (e2 ** (v2, tst2)) ->\n (evalBigStep e1) = (e3 ** (v3, bSt3)) ->\n e2 = e3 \nequivEval {v2 = v2} {tst2 = tst2} {bSt3 = bSt3} _ _ = \n let (tst3, v3) = bigStepToTransStep bSt3\n in transStepDeterministic v2 tst2 v3 tst3\n\n-- End: EQUIVALENCE OF EVALUATORS\n---------------------------------\n\n", "meta": {"hexsha": "835a94b993fed030b785cae1c0d87ea01f37274d", "size": 3980, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "conventional/src/Eval.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "conventional/src/Eval.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "conventional/src/Eval.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": 36.8518518519, "max_line_length": 101, "alphanum_fraction": 0.4605527638, "num_tokens": 1206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7125200690424267}} {"text": "import Data.Vect\n\n-- Reimplement transpose_mat using zipWith instead of transpose_helper.\n\ncreate_empties : Vect n (Vect 0 elem)\ncreate_empties = replicate _ []\n\ntranspose_helper : (x : Vect n elem) ->\n (xs_trans : Vect n (Vect k elem)) ->\n Vect n (Vect (S k) elem)\ntranspose_helper [] [] = []\ntranspose_helper (x :: xs) (y :: ys) = (x :: y) :: transpose_helper xs ys\n\ntranspose_mat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntranspose_mat [] = create_empties\ntranspose_mat (x :: xs) = let xs_trans = transpose_mat xs in\n zipWith (::) x xs_trans\n\n-- *ex_3_3_3> transpose_mat [[1,2], [3,4], [5,6]]\n-- [[1, 3, 5], [2, 4, 6]] : Vect 2 (Vect 3 Integer)\n\n-- zipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\n", "meta": {"hexsha": "5943c2efec7442feb303242b3b3f2d429d47bb40", "size": 782, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "starting/ex_3_3_3.idr", "max_stars_repo_name": "prt2121/tdd-playground", "max_stars_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "starting/ex_3_3_3.idr", "max_issues_repo_name": "prt2121/tdd-playground", "max_issues_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": "starting/ex_3_3_3.idr", "max_forks_repo_name": "prt2121/tdd-playground", "max_forks_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": 34.0, "max_line_length": 73, "alphanum_fraction": 0.5831202046, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7123452698113114}} {"text": "||| More functions and properties for relative numbers\n||| Re-exports all of `Data.ZZ` from contrib for convenience\nmodule Data.ZZ.Extra\n\nimport Data.Nat\nimport Data.Sign\nimport public Data.ZZ\n\n%default total\n\n||| Proof that if the absolute value of a number is 0, then this number is 0\n||| @y: a relative number which we take absolute value of\npublic export\nabsZIsPosZ : {y : ZZ } -> (absZ y = 0) -> (y = Pos 0)\nabsZIsPosZ {y = (Pos Z)} Refl = Refl\nabsZIsPosZ {y = (Pos (S _))} Refl impossible\nabsZIsPosZ {y = (NegS _)} Refl impossible\n\npublic export\ncontrapositive : (a -> b) -> (Not b -> Not a)\ncontrapositive = flip (.)\n\n||| Proof that if a number is not 0, its absolute value is not 0\n||| This is the contrapositive proof to `absZIsPosZ`\n||| @y: a Relative number which is not 0\npublic export\nnotPosZIsNotAbsZ : {y : ZZ } -> ((y = Pos 0) -> Void) -> ((absZ y = 0) -> Void)\nnotPosZIsNotAbsZ = contrapositive absZIsPosZ\n\npublic export\ndivNatNZ' : Nat -> (y: Nat) -> { prf : Not (y = Z) } -> Nat\ndivNatNZ' left Z {prf} = void (prf Refl)\ndivNatNZ' left (S right) = div' left left right\n where\n div' : Nat -> Nat -> Nat -> Nat\n div' Z centre right = Z\n div' (S left) centre right =\n if lte centre right then\n Z\n else\n S (div' left (minus centre (S right)) right)\n\n\n||| Euclidean division of 2 `ZZ` numbers ensuring divisor is not 0\n||| We compute using `Nat`'s division and checking the `multiply` of the signs\n||| of both numbers, observing that if the sign is `Zero` then this implis `x`\n||| is 0 and thus the result is 0.\n|||\n||| @x: dividend of euclidean division\n||| @y: divisor of euclidean division\n||| @divisorNotZ: a proof the divisor is not null\npublic export\ndivZZNZ : (x : ZZ) -> (y : ZZ) -> {z : Not (y = Pos Z) } -> ZZ\ndivZZNZ x (Pos Z) {z} = absurd (z Refl)\ndivZZNZ x y {z} with (sign x `multiply` sign y)\n divZZNZ x y {z} | Zero = Pos Z\n divZZNZ x y {z} | Plus = Pos $ divNatNZ' (absZ x) (absZ y) { prf = notPosZIsNotAbsZ z }\n divZZNZ x y {z} | Minus = NegS $ divNatNZ' (absZ x) (absZ y) { prf = notPosZIsNotAbsZ z }\n\n||| A strictly Positive `ZZ` is not 0\npublic export\nPosSIsNotZ : Not (Pos (S k) = Pos 0)\nPosSIsNotZ Refl impossible\n\n||| A negative `ZZ` is not 0\npublic export\nNegSIsNotZ : Not (NegS (S k) = Pos 0)\nNegSIsNotZ Refl impossible\n", "meta": {"hexsha": "7ab24a4125bb0ee675e262993ad416a55b97d9fd", "size": 2320, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "bautzen1945/idris/Data/ZZ/Extra.idr", "max_stars_repo_name": "steshaw/hsgames", "max_stars_repo_head_hexsha": "4cf8cd02fcc93d1e030144676e2e1cbf9da2514f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bautzen1945/idris/Data/ZZ/Extra.idr", "max_issues_repo_name": "steshaw/hsgames", "max_issues_repo_head_hexsha": "4cf8cd02fcc93d1e030144676e2e1cbf9da2514f", "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": "bautzen1945/idris/Data/ZZ/Extra.idr", "max_forks_repo_name": "steshaw/hsgames", "max_forks_repo_head_hexsha": "4cf8cd02fcc93d1e030144676e2e1cbf9da2514f", "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": 33.6231884058, "max_line_length": 92, "alphanum_fraction": 0.6482758621, "num_tokens": 811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7123398253952672}} {"text": "module Main\n\nimport Data.Vect\nimport Prelude.Nat\n\nMatrix : Nat -> Nat -> Type -> Type\nMatrix n m a = Vect n (Vect m a)\n\nempties : Vect m (Vect 0 a)\nempties {m = Z} = []\nempties {m = (S k)} = [] :: empties\n\ntranspose_helper : (row : Vect m a) -> (row_trans : Vect m (Vect k a)) -> Vect m (Vect (S k) a)\ntranspose_helper [] [] = []\ntranspose_helper (x :: xs) (y :: ys) = (x :: y) :: transpose_helper xs ys\n\n--transpose_vec: Vect n (Vect m a) -> Vect m (Vect n a)\ntranspose_vec: Matrix n m a -> Matrix m n a\ntranspose_vec [] = empties\ntranspose_vec (row :: rows) = let row_trans = transpose_vec rows in\n transpose_helper row row_trans\n\ntestMatrix : Matrix 3 4 Nat\ntestMatrix = ( 1 :: 2 :: 3 :: 4 :: Nil) :: ( 10 :: 20 :: 30 :: 40 :: Nil) :: ( 100 :: 200 :: 300 :: 400 :: Nil) :: Nil\n\ntransposed : Matrix 4 3 Nat\ntransposed = transpose_vec testMatrix\n\nmain : IO ()\nmain = putStrLn (show testMatrix ++ \"\\n--after transpose--\\n\" ++ show transposed)\n", "meta": {"hexsha": "6867fe6a19d61c8f46a1328082727064946474e0", "size": 945, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "transpose.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": "transpose.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": "transpose.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": 30.4838709677, "max_line_length": 118, "alphanum_fraction": 0.6232804233, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7123398093329621}} {"text": "isEven' : Nat -> Bool\nisEven' Z = True\nisEven' (S k) = not (isEven' k)\n\nmutual\n isEven : Nat -> Bool\n isEven Z = True\n isEven (S k) = isOdd k\n\n isOdd : Nat -> Bool\n isOdd Z = False\n isOdd (S k) = isEven k\n", "meta": {"hexsha": "4e412e24a5e5b52a672d814d44955e542836d9de", "size": 211, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter03/IsEven.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": "Chapter3/IsEven.idr", "max_issues_repo_name": "gdevanla/TypeDD-Samples", "max_issues_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_issues_repo_licenses": ["MIT"], "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": "Chapter3/IsEven.idr", "max_forks_repo_name": "gdevanla/TypeDD-Samples", "max_forks_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-03-19T11:01:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-10T05:30:22.000Z", "avg_line_length": 16.2307692308, "max_line_length": 31, "alphanum_fraction": 0.5829383886, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7122242760643119}} {"text": "data Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nShow a => Show (Vect n a) where\n show xs = \"[\" ++ showV xs ++ \"]\"\n where\n showV : forall n . Vect n a -> String\n showV [] = \"\"\n showV [x] = show x\n showV (x :: xs) = show x ++ \", \" ++ showV xs\n\nfilter : (a -> Bool) -> Vect n a -> (p ** Vect p a)\nfilter pred [] = (_ ** [])\nfilter pred (x :: xs)\n = let (n ** xs') = filter pred xs in\n if pred x\n then (_ ** x :: xs')\n else (_ ** xs')\n\ntest : (x ** Vect x Nat)\ntest = (_ ** [1,2])\n\nfoo : String\nfoo = show test\n\neven : Nat -> Bool\neven Z = True\neven (S k) = not (even k)\n\nmain : IO ()\nmain = printLn (filter even [S Z,2,3,4,5,6])\n", "meta": {"hexsha": "0d116fca82b1deb9392ce33e36df7ffba6db5eff", "size": 739, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/chez/chez005/Filter.idr", "max_stars_repo_name": "boxfire/rapid", "max_stars_repo_head_hexsha": "91f012caad854dc454cef0375b49bcf9e1af20c7", "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/chez/chez005/Filter.idr", "max_issues_repo_name": "boxfire/rapid", "max_issues_repo_head_hexsha": "91f012caad854dc454cef0375b49bcf9e1af20c7", "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/chez/chez005/Filter.idr", "max_forks_repo_name": "boxfire/rapid", "max_forks_repo_head_hexsha": "91f012caad854dc454cef0375b49bcf9e1af20c7", "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": 22.3939393939, "max_line_length": 51, "alphanum_fraction": 0.4641407307, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7121500813993142}} {"text": "module PLFI.Part1.Equality\n\nimport Syntax.PreorderReasoning\n\ndata Equal0 : {t : Type} -> (x : t) -> t -> Type where\n Refl0 : Equal0 x x\n\n{-\npublic export\ndata Equal : forall a, b . a -> b -> Type where\n [search a b]\n Refl : {0 x : a} -> Equal x x\n\n(~=~) : (x : a) -> (y : b) -> Type\n(~=~) = Equal\n-}\n\n%hide sym\n%hide trans\n%hide cong\n\nsym : {A : Type} -> {x, y : A} ->\n x = y ->\n ----------\n y = x\nsym Refl = Refl\n\ntrans : {A : Type} -> {x,y,z : A} ->\n x = y ->\n y = z ->\n ----------\n x = z\ntrans Refl p = ?h1\n\ntrans1 : {ta,tb,tc : Type} -> {x : ta} -> {y : tb} -> {z : tc} ->\n x ~=~ y ->\n y ~=~ z ->\n ----------\n x ~=~ z\ntrans1 {tb = ta} {tc = ta} Refl Refl = Refl\n\n\n{-\npublic export\ndata Equal : forall a, b . a -> b -> Type where\n [search a b]\n Refl : {0 x : a} -> Equal x x\n\n(~=~) : (x : a) -> (y : b) -> Type\n(~=~) = Equal\n-}\n\n\ncong : {A, B : Type} -> (f : A -> B) -> {x, y : A} ->\n x = y ->\n -----------\n f x = f y\ncong f Refl = Refl\n\n-- Wrong:\n-- injectivity : {A, B : Type} -> (f : A -> B) -> {x, y : A} ->\n-- f x = f y ->\n-- ------------\n-- x = y\n-- injectivity f {x} {y} Refl = ?injectivity_rhs\n\n\ncongApp : {A, B : Type} -> {f, g : A -> B} ->\n f = g ->\n --------------------\n forall x . f x = g x\ncongApp Refl = Refl\n\nsubst : {A : Type} -> {x, y : A} -> (P : A -> Type) ->\n x = y ->\n ----------\n P x -> P y\nsubst p Refl = \\z => z\n\n-- Chain of equations\n\n{-\n||| Until Idris2 starts supporting the 'syntax' keyword, here's a\n||| poor-man's equational reasoning\nmodule Syntax.PreorderReasoning\n\ninfixl 0 ~~\nprefix 1 |~\ninfix 1 ...\n\n|||Slightly nicer syntax for justifying equations:\n|||```\n||| |~ a\n||| ~~ b ...( justification )\n|||```\n|||and we can think of the `...( justification )` as ASCII art for a thought bubble.\npublic export\ndata Step : a -> b -> Type where\n (...) : (0 y : a) -> (0 step : x ~=~ y) -> Step x y\n\npublic export\ndata FastDerivation : (x : a) -> (y : b) -> Type where\n (|~) : (0 x : a) -> FastDerivation x x\n (~~) : FastDerivation x y -> (step : Step y z) -> FastDerivation x z\n\npublic export\nCalc : {0 x : a} -> {0 y : b} -> FastDerivation x y -> x ~=~ y\nCalc (|~ x) = Refl\nCalc ((~~) der (_ ...(Refl))) = Calc der\n\n-- requires import Data.Nat\n0\nexample : (x : Nat) -> (x + 1) + 0 = 1 + x\nexample x =\n Calc $\n |~ (x + 1) + 0\n ~~ x+1 ...( plusZeroRightNeutral $ x + 1 )\n ~~ 1+x ...( plusCommutative x 1 )\n\n-}\n\ntrans' : {a : Type} -> {x,y,z : a} ->\n x = y ->\n y = z ->\n --------\n x = z\ntrans' {a,x,y,z} xy yz =\n Calc $\n |~ x\n ~~ y ... ( xy )\n ~~ z ... ( yz )\n\n-- Chain of equations another example\n\nplusIdentity : forall m . m + Z = m\nplusSucc : forall m . forall n . m + S n = S (m + n)\n\nplusComm : (m, n : Nat) -> m + n = n + m\nplusComm m 0 = Calc $\n |~ m + Z\n ~~ m ... (plusIdentity)\nplusComm m (S k) = Calc $\n |~ m + (S k)\n ~~ S (m + k) ... (plusSucc)\n ~~ S (k + m) ... (cong S (plusComm m k))\n ~~ (S k) + m ... (Refl)\n\n-- Exercise LTE-Reasoning (strech)\n\n-- Rewriting\n\n", "meta": {"hexsha": "baf40d1c7381735eaa501059558dfa362733461f", "size": 3041, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "PLFI/Part1/Equality.idr", "max_stars_repo_name": "andorp/PLFI", "max_stars_repo_head_hexsha": "820c304515711e2b6ca5a28571725a0136fdfa2d", "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": "PLFI/Part1/Equality.idr", "max_issues_repo_name": "andorp/PLFI", "max_issues_repo_head_hexsha": "820c304515711e2b6ca5a28571725a0136fdfa2d", "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": "PLFI/Part1/Equality.idr", "max_forks_repo_name": "andorp/PLFI", "max_forks_repo_head_hexsha": "820c304515711e2b6ca5a28571725a0136fdfa2d", "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": 20.0065789474, "max_line_length": 84, "alphanum_fraction": 0.4584018415, "num_tokens": 1150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8128673155708976, "lm_q1q2_score": 0.7118986209127786}} {"text": "> module NonNegDouble.NonNegDouble\n\n\n> import Double.Predicates\n\n\n> %default total\n> %access public export\n\n\n> ||| Non negative double precision floating point numbers as sigma types\n> NonNegDouble : Type\n> -- NonNegDouble = Subset Double NonNegative\n> NonNegDouble = Subset Double (\\ x => 0.0 `LTE` x)\n", "meta": {"hexsha": "594d2c544ff4491b5e7221adc6cb1aae69e07341", "size": 303, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegDouble/NonNegDouble.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "NonNegDouble/NonNegDouble.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "NonNegDouble/NonNegDouble.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2, "max_line_length": 73, "alphanum_fraction": 0.7326732673, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942041005327, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7117336867524883}} {"text": "module Weaken\n\nimport Data.Fin\n\nweaken1 : (fn : Fin n) -> (fsn : Fin (S n) ** finToNat fn = finToNat fsn)\nweaken1 FZ = (FZ ** Refl)\nweaken1 (FS n) with (weaken1 n)\n | (nw ** nat_n_eq_nat_nw) = (FS nw ** eqSucc (finToNat n) (finToNat nw) nat_n_eq_nat_nw)\n", "meta": {"hexsha": "8926b2d50ef2989a15ce5171223761bdb44b1404", "size": 255, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Weaken.idr", "max_stars_repo_name": "buzden/idris-playground", "max_stars_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-23T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T02:45:50.000Z", "max_issues_repo_path": "Weaken.idr", "max_issues_repo_name": "buzden/idris-playground", "max_issues_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_issues_repo_licenses": ["CC0-1.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": "Weaken.idr", "max_forks_repo_name": "buzden/idris-playground", "max_forks_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3333333333, "max_line_length": 90, "alphanum_fraction": 0.6470588235, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.7116937289643712}} {"text": "module NatExtension\n\n%default total\n%access public export\n\nzeroYCancel : (x : Nat) -> (y : Nat) -> x + y = 0 -> x = 0\nzeroYCancel x Z e = rewrite plusCommutative 0 x in e\nzeroYCancel x (S k) e = void $ SIsNotZ (trans (plusCommutative (S k) x) e)\n\nmultLeftCancel : (x : Nat) -> (y : Nat) -> (z : Nat) -> S x * y = S x * z -> y = z\nmultLeftCancel x Z z e = sym (zeroYCancel _ _ (sym (rewrite multCommutative 0 x in e)))\nmultLeftCancel x y Z e = zeroYCancel _ _ (rewrite multCommutative 0 x in e)\nmultLeftCancel x (S k) (S j) e = rewrite multLeftCancel x k j _ss3 in Refl\n where\n _ss1 : k + (x + x * k) = j + (x + x * j)\n _ss1 =\n rewrite sym $ multRightSuccPlus x k in\n rewrite sym $ multRightSuccPlus x j in\n succInjective _ _ e\n\n _ss2 : x + (k + x * k) = x + (j + x * j)\n _ss2 =\n rewrite plusAssociative x k (x * k) in\n rewrite plusAssociative x j (x * j) in\n rewrite plusCommutative x k in\n rewrite plusCommutative x j in\n rewrite sym $ plusAssociative k x (x * k) in\n rewrite sym $ plusAssociative j x (x * j) in\n _ss1\n\n _ss3 : k + x * k = j + x * j\n _ss3 = plusLeftCancel _ _ _ _ss2\n\ntakeY : (x : Nat) -> (y : Nat) -> (z : Nat) -> x * (y * z) = y * x * z\ntakeY x y z =\n rewrite multAssociative x y z in\n rewrite multCommutative x y in\n Refl\n", "meta": {"hexsha": "8afbe8f2016f6c1a9d6f188507b263f105f295f5", "size": 1353, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "hw6/NatExtension.idr", "max_stars_repo_name": "lytr777/tt", "max_stars_repo_head_hexsha": "f06810f3d6b33ad0601e3bf4b5f65dca98eafb1b", "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": "hw6/NatExtension.idr", "max_issues_repo_name": "lytr777/tt", "max_issues_repo_head_hexsha": "f06810f3d6b33ad0601e3bf4b5f65dca98eafb1b", "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": "hw6/NatExtension.idr", "max_forks_repo_name": "lytr777/tt", "max_forks_repo_head_hexsha": "f06810f3d6b33ad0601e3bf4b5f65dca98eafb1b", "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": 34.6923076923, "max_line_length": 87, "alphanum_fraction": 0.5801921656, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.711576069988425}} {"text": "module ReverseVec\n\nimport Data.Nat\nimport Data.Vect\n\n%default total\n\nmyReverse : Vect n elem -> Vect n elem\nmyReverse [] = []\nmyReverse { n = S k } (x :: xs) = let rev = myReverse xs ++ [x] in\n rewrite plusCommutative 1 k in rev\n\nourReverse : Vect n elem -> Vect n elem\nourReverse [] = []\nourReverse (x :: xs) = reverseProof (ourReverse xs ++ [x]) where\n reverseProof : Vect (len + 1) elem -> Vect (S len) elem\n reverseProof { len } xs = rewrite plusCommutative 1 len in xs\n", "meta": {"hexsha": "3df5c6e25b194f4e8cfc64818f2e28ab45d5bd3e", "size": 501, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter8/ReverseVec.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter8/ReverseVec.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": "chapter8/ReverseVec.idr", "max_forks_repo_name": "timmyjose-study/tdd-with-idris", "max_forks_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "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": 27.8333333333, "max_line_length": 66, "alphanum_fraction": 0.6367265469, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7114815807095922}} {"text": "\nmodule ExactLength\n\nimport EqNat\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z ty\n (::) : ty -> Vect n ty -> Vect (S n) ty\n\nexactLength : (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength {m} len input = case checkEqNat m len of\n Nothing => Nothing\n Just (Same len) => Just input\n", "meta": {"hexsha": "e70f4304f4fdbf1af1557d90ec6bd99bbd99c443", "size": 378, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter8/ExactLength.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter8/ExactLength.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter8/ExactLength.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 27.0, "max_line_length": 69, "alphanum_fraction": 0.5132275132, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9572778073288128, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.7114182308708156}} {"text": "module HRAL\n\n-- Based on https://www.cambridge.org/core/services/aop-cambridge-core/content/view/CC82B2E79DC5CCAD57E0AC5DF0D43DEC/S0956796820000064a.pdf/div-class-title-heterogeneous-binary-random-access-lists-div.pdf\n\ndata Tree : Type -> Nat -> Type where\n Leaf : a -> Tree a Z\n Node : Tree a n -> Tree a n -> Tree a (S n)\n\ndata Path : Nat -> Type where\n Here : Path Z\n Left : Path n -> Path (S n)\n Right : Path n -> Path (S n)\n\nnamespace Tree\n lookup : Tree a n -> Path n -> a\n lookup (Leaf x) Here = x\n lookup (Node t1 t2) (Left p) = lookup t1 p\n lookup (Node t1 t2) (Right p) = lookup t2 p\n\n\ndata Bin : Type where\n End : Bin\n One : Bin -> Bin\n Zero : Bin -> Bin\n\nbsucc : Bin -> Bin\nbsucc End = One End\nbsucc (One b) = Zero (bsucc b)\nbsucc (Zero b) = One b\n\ndata RAL : Type -> Nat -> Bin -> Type where\n Nil : RAL a n End\n Cons1 : Tree a n -> RAL a (S n) b -> RAL a n (One b)\n Cons0 : RAL a (S n) b -> RAL a n (Zero b)\n\ndata Pos : Nat -> Bin -> Type where\n PosHere : Path n -> Pos n (One b)\n There0 : Pos (S n) b -> Pos n (Zero b)\n There1 : Pos (S n) b -> Pos n (One b)\n\nnamespace RAL\n lookup : RAL a n b -> Pos n b -> a\n lookup [] (PosHere _) impossible\n lookup [] (There0 _) impossible\n lookup [] (There1 _) impossible\n lookup (Cons1 t r) (PosHere p) = Tree.lookup t p\n lookup (Cons1 t r) (There1 p) = lookup r p\n lookup (Cons0 r) (There0 p) = lookup r p\n\n consTree : Tree a n -> RAL a n b -> RAL a n (bsucc b)\n consTree t [] = Cons1 t Nil\n consTree t (Cons1 t' r) = Cons0 (consTree (Node t t') r)\n consTree t (Cons0 r) = Cons1 t r\n\n cons : a -> RAL a Z b -> RAL a Z (bsucc b)\n cons x r = consTree (Leaf x) r\n\ndata HTree : Tree Type n -> Type where\n HLeaf : u -> HTree (Leaf u)\n HNode : HTree us -> HTree vs -> HTree (Node us vs)\n\ndata HPath : Tree Type n -> Type -> Type where\n HHere : HPath (Leaf u) u\n HLeft : HPath us u -> HPath (Node us vs) u\n HRight : HPath vs u -> HPath (Node us vs) u\n\nnamespace HTree\n lookup : HTree us -> HPath us u -> u\n lookup (HLeaf u) HHere = u\n lookup (HNode t1 t2) (HLeft p) = lookup t1 p\n lookup (HNode t1 t2) (HRight p) = lookup t2 p\n\ndata HRAL : RAL Type n b -> Type where\n HNil : HRAL Nil\n HCons1 : HTree t -> HRAL r -> HRAL (Cons1 t r)\n HCons0 : HRAL r -> HRAL (Cons0 r)\n\ndata HPos : RAL Type n b -> Type -> Type where\n HPosHere : HPath t u -> HPos (Cons1 t r) u\n HThere0 : HPos r u -> HPos (Cons0 r) u\n HThere1 : HPos r u -> HPos (Cons1 t r) u\n\nnamespace HRAL\n lookup : HRAL r -> HPos r u -> u\n lookup HNil (HPosHere _) impossible\n lookup HNil (HThere0 _) impossible\n lookup HNil (HThere1 _) impossible\n lookup (HCons1 t r) (HPosHere p) = HTree.lookup t p\n lookup (HCons1 t r) (HThere1 p) = lookup r p\n lookup (HCons0 r) (HThere0 p) = lookup r p\n\n consTree : HTree t -> HRAL r -> HRAL (RAL.consTree t r)\n consTree t HNil = HCons1 t HNil\n consTree t (HCons1 t' r) = HCons0 (consTree (HNode t t') r)\n consTree t (HCons0 r) = HCons1 t r\n\n cons : (u : Type) -> HRAL r -> HRAL (RAL.cons Type r)\n cons x r = consTree (HLeaf x) r\n", "meta": {"hexsha": "b3ac56ec3f110c1de7c89c3cf42422ff1c3ff6e6", "size": 3025, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/HRAL.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/HRAL.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/HRAL.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": 30.5555555556, "max_line_length": 204, "alphanum_fraction": 0.6214876033, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7108222934063306}} {"text": "{- 1 -}\n\nsame_cons : {xs : List a} -> {ys : List a} ->\n xs = ys -> x :: xs = x :: ys\nsame_cons Refl = Refl\n\n{- 2 -}\n\nsame_lists : {xs : List a} -> {ys : List a} ->\n x = y -> xs = ys -> x :: xs = y :: ys\nsame_lists Refl Refl = Refl\n\n{- 3 -}\n\ndata ThreeEq : a -> b -> c -> Type where\n AllSame : ThreeEq x x x\n\n{- 4 -}\n\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS x x x AllSame = AllSame\n\n-- If you add a successor to three equal Nats, the results are all equal\n", "meta": {"hexsha": "3653a3e89c43951f1eb4fa118657ebea6901d8f2", "size": 525, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter8/Exercises/ex_8_1.idr", "max_stars_repo_name": "PiotrJander/TypeDD-Samples", "max_stars_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 161, "max_stars_repo_stars_event_min_datetime": "2017-02-27T02:28:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T22:17:47.000Z", "max_issues_repo_path": "Chapter8/Exercises/ex_8_1.idr", "max_issues_repo_name": "gdevanla/TypeDD-Samples", "max_issues_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2017-03-26T23:27:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:32:25.000Z", "max_forks_repo_path": "Chapter8/Exercises/ex_8_1.idr", "max_forks_repo_name": "gdevanla/TypeDD-Samples", "max_forks_repo_head_hexsha": "a5c08a13e6a6ec804171526aca10aae946588323", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-03-19T11:01:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-10T05:30:22.000Z", "avg_line_length": 21.875, "max_line_length": 72, "alphanum_fraction": 0.5123809524, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7106941655911636}} {"text": "import Data.Vect\n\n-- `minus` is saturating subtraction, so this works like we want it to\neq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k\neq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl\neq_max Z (S _) = Refl\neq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl\n\nleftPad : (x : a) -> (n : Nat) -> (xs : Vect k a) -> Vect (maximum k n) a\nleftPad {k} x n xs = rewrite eq_max n k in replicate (n `minus` k) x ++ xs\n\nleftPadProp : {xs : Vect k a} -> (m : Nat ** leftPad x n xs = {- rewrite somehow? `the Type (rewrite xxx in replicate ...)`? -} replicate m x ++ xs)\nleftPadProp {n} {k} = (n `minus` k ** ?x)\n", "meta": {"hexsha": "10567b17bb36d170c37a2caef7ff93cedca0c672", "size": 704, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Leftpad2.idr", "max_stars_repo_name": "buzden/idris-playground", "max_stars_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-23T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T02:45:50.000Z", "max_issues_repo_path": "Leftpad2.idr", "max_issues_repo_name": "buzden/idris-playground", "max_issues_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_issues_repo_licenses": ["CC0-1.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": "Leftpad2.idr", "max_forks_repo_name": "buzden/idris-playground", "max_forks_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.2857142857, "max_line_length": 148, "alphanum_fraction": 0.6235795455, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.7106325917974367}} {"text": "data Expr num = Val num \n | Add (Expr num) (Expr num)\n | Sub (Expr num) (Expr num)\n | Mul (Expr num) (Expr num)\n | Div (Expr num) (Expr num)\n | Abs (Expr num)\n\nNum ty => Num (Expr ty) where\n (+) = Add\n (*) = Mul\n fromInteger = Val . fromInteger\n\nNeg ty => Neg (Expr ty) where\n negate x = 0 - x\n (-) = Sub\n\nAbs ty => Abs (Expr ty) where\n abs = Abs\n\n\neval: (Abs num, Neg num, Integral num) => Expr num -> num\neval (Val x) = x\neval (Add x y) = eval x + eval y\neval (Sub x y) = eval x - eval y\neval (Mul x y) = eval x * eval y\neval (Div x y) = div (eval x) (eval y)\neval (Abs x) = abs (eval x)\n\nexprShowHelper: Show ty => (left: ty) -> (symb: Char) -> (right: ty) -> String\nexprShowHelper left symb right =\n \"(\" ++ show left ++ \" \" ++ cast symb ++ \" \" ++ show right ++ \")\"\n \nShow ty => Show (Expr ty) where\n show (Val x) = show x\n show (Add x y) = exprShowHelper x '+' y\n show (Sub x y) = exprShowHelper x '-' y\n show (Mul x y) = exprShowHelper x '*' y\n show (Div x y) = exprShowHelper x '/' y\n show (Abs x) = \"|\"++ show x ++\"|\"\n\n(Abs ty, Neg ty, Integral ty, Eq ty) => Eq (Expr ty) where\n (==) x y = eval x == eval y\n\n(Abs ty, Neg ty, Integral ty) => Cast (Expr ty) ty where\n cast = eval\n\nFunctor Expr where\n map func (Val x) = Val (func x)\n map func (Add x y) = Add (map func x)(map func y)\n map func (Sub x y) = Sub (map func x)(map func y)\n map func (Mul x y) = Mul (map func x)(map func y)\n map func (Div x y) = Div (map func x)(map func y)\n map func (Abs x) = Abs (map func x)\n \nexample1: Expr Integer\nexample1 = Add (Val 6) (Mul (Val 3) (Abs(Val (-12))))\n\nexample2: Expr Integer\nexample2 = 6 + 3 * 12\n\nexample3: Expr Integer\nexample3 = 6 * 3 + 12\n\nexample4: Expr Integer\nexample4 = 1 + 2 * 3", "meta": {"hexsha": "5c8bf33659b1036d4a1d04ae8b7e6ca104372ec5", "size": 1784, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Expr.idr", "max_stars_repo_name": "coffius/idris-exercises", "max_stars_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "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": "Expr.idr", "max_issues_repo_name": "coffius/idris-exercises", "max_issues_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "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": "Expr.idr", "max_forks_repo_name": "coffius/idris-exercises", "max_forks_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "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": 27.4461538462, "max_line_length": 78, "alphanum_fraction": 0.5627802691, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.7103897836941208}} {"text": "\nmodule ReverseVec\n\nimport Data.Vect\n\n\nmyReverse : Vect n elem -> Vect n elem\nmyReverse [] = []\nmyReverse (x :: xs) = reverseProof (myReverse xs ++ [x])\n where\n reverseProof : Vect (k + 1) elem -> Vect (S k) elem\n reverseProof {k} res = rewrite sym (plusCommutative k 1) in res\n -- Used sym for fun to get the hang of reversing direction of rewrites\n", "meta": {"hexsha": "5b63245a09ec52ed12ba0571009313d81fa6740f", "size": 360, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter8/ReverseVec.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter8/ReverseVec.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "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": "Chapter8/ReverseVec.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 25.7142857143, "max_line_length": 74, "alphanum_fraction": 0.6722222222, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897459384732, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.7102162890753269}} {"text": "import Data.Vect\n\n||| A type synonym for describing positions as (x,y) coordinates.\nPosition : Type\nPosition = (Double, Double)\n\n||| A type synonym for describing polygons with n corners.\nPolygon : Nat -> Type\nPolygon n = Vect n Position\n\ntri : Polygon 3\ntri = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)]\n", "meta": {"hexsha": "08d4c13f0dbdd3d0b467074c3f5de846adf3d243", "size": 298, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter06/TypeSynonym.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter06/TypeSynonym.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter06/TypeSynonym.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9230769231, "max_line_length": 65, "alphanum_fraction": 0.6744966443, "num_tokens": 94, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.7101192330308198}} {"text": "module Main\nimport Data.Vect\n\nmyVectAdd : Num elem => Vect len elem -> Vect len elem -> Vect len elem\nmyVectAdd [] [] = []\nmyVectAdd (x::xs) (y::ys) = (x+y) :: myVectAdd xs ys\n\nv1 : Vect 3 Int\nv1 = [1, 2, 3]\n\nv2: Vect 3 Int\nv2 = [4, 5, 6]\n\nmain : IO ()\nmain = printLn $ myVectAdd v1 v2\n\n", "meta": {"hexsha": "23e530e3b295437bd078a75ba2e980f429d267e7", "size": 288, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "10_vector_addition.idr", "max_stars_repo_name": "jeetu7/idris2_examples", "max_stars_repo_head_hexsha": "b96be6fbb2db2f3ac89109f5c78b1881849a3910", "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": "10_vector_addition.idr", "max_issues_repo_name": "jeetu7/idris2_examples", "max_issues_repo_head_hexsha": "b96be6fbb2db2f3ac89109f5c78b1881849a3910", "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": "10_vector_addition.idr", "max_forks_repo_name": "jeetu7/idris2_examples", "max_forks_repo_head_hexsha": "b96be6fbb2db2f3ac89109f5c78b1881849a3910", "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": 16.9411764706, "max_line_length": 71, "alphanum_fraction": 0.5972222222, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7100371937813602}} {"text": "module Quicksort\r\n\r\nimport Data.Vect\r\n\r\npartitionVect : Ord elem => {n : Nat} -> (elem) -> (Vect n elem) -> (l1 : Nat ** (l2 : Nat ** (n = (l1 + l2), (Vect l1 elem, Vect l2 elem))))\r\npartitionVect pivot [] = (0 ** 0 ** (Refl, [], []))\r\npartitionVect pivot (x :: xs) with (partitionVect pivot xs)\r\n partitionVect pivot (x :: xs) | (l1 ** l2 ** ( equality, v1, v2)) = if (x <= pivot) then (S (l1) ** l2 ** (cong {f = S} equality, (x :: v1), v2)) else\r\n (l1 ** S (l2) ** (trans (cong {f = S} equality) (plusSuccRightSucc l1 l2), v1, x :: v2))\r\n\r\nnLTESn : (n : Nat) -> LTE n (S n)\r\nnLTESn Z = LTEZero\r\nnLTESn (S k) = LTESucc (nLTESn k)\r\n\r\n\r\n-- qsort : Ord elem => Vect n elem -> (l1 ** l2 ** (Vect (l1 + l2) elem, (l1 + l2) = n))\r\ndata PreOrder : (a : Type) -> (a -> a -> Type)-> Type where\r\n PreOrd : {rel : a -> a -> Type} -> ((x : a) -> rel x x) -> ((x : a) -> (y : a) -> (z : a) -> rel x y -> rel y z -> rel x z) -> PreOrder a rel\r\n\r\ndata TotalOrder : (a : Type) -> (a -> a -> Type) -> Type where\r\n TotOrd : {rel : a -> a -> Type} -> PreOrder a rel -> ((x : a) -> (y : a) -> Either (rel x y) (rel y x)) -> TotalOrder a rel\r\n\r\ndata ForAll : (elem -> Type) -> List elem -> Type where\r\n None: ForAll p []\r\n Append: p x -> ForAll p xs -> ForAll p (x :: xs)\r\n\r\nforAllConcat : (xs : List elem) -> (ForAll p xs) -> (ys : List elem) -> (ForAll p ys) -> (ForAll p (xs ++ ys))\r\nforAllConcat [] None ys pfys = pfys\r\nforAllConcat (x :: xs) (Append px pfxs) ys pfys = Append px (forAllConcat xs pfxs ys pfys)\r\n\r\nforAllBreak : (xs : List elem) -> (ys : List elem) -> (ForAll p (xs ++ ys)) -> (ForAll p xs, ForAll p ys)\r\nforAllBreak [] ys pf = (None, pf)\r\nforAllBreak (x :: xs) ys (Append px pfxs) = let (faxs, fays) = forAllBreak xs ys pfxs in (Append px faxs, fays)\r\n\r\n\r\nforAllMap : (p : elem -> Type) -> (q : elem -> Type) -> (f : (x : elem) -> p x -> q x) -> (xs : List elem) -> ForAll p xs -> ForAll q xs\r\nforAllMap p q f [] None = None\r\nforAllMap p q f (x :: xs) (Append px pfxs) = Append (f x px) (forAllMap p q f xs pfxs)\r\n\r\ndata LTEforList : List elem -> List elem -> Type where\r\n LTEEmpty : LTEforList [] xs\r\n LTEAppend : LTEforList xs ys -> LTEforList (x :: xs) (y :: ys)\r\n\r\nlemma1 : LTEforList xs ys -> LTEforList xs (y :: ys)\r\nlemma1 LTEEmpty = LTEEmpty\r\nlemma1 (LTEAppend pf) = LTEAppend (lemma1 pf)\r\n\r\nlemma2 : (xs : List elem) -> LTEforList xs xs\r\nlemma2 [] = LTEEmpty\r\nlemma2 (x :: xs) = LTEAppend (lemma2 xs)\r\n\r\nlemma3 : LTEforList xs ys -> LTEforList ys zs -> LTEforList xs zs\r\nlemma3 LTEEmpty _ = LTEEmpty\r\nlemma3 (LTEAppend pf1) (LTEAppend pf2) = LTEAppend (lemma3 pf1 pf2)\r\n\r\ndata IsSortedAlternate : (elem -> elem -> Type) -> List elem -> Type where\r\n EmptySorted : IsSortedAlternate lte []\r\n AppendSorted : {lte : elem -> elem -> Type} -> ForAll (lte x) xs -> IsSortedAlternate lte xs -> IsSortedAlternate lte (x :: xs)\r\n\r\ndata Permutation : List elem -> List elem -> Type where\r\n Empty : Permutation [] []\r\n Split : (xs : List elem) -> (ys : List elem) -> (zs : List elem) -> Permutation xs (ys ++ zs) -> Permutation (x :: xs) (ys ++ (x :: zs))\r\n Compos : Permutation xs ys -> Permutation ys zs -> Permutation xs zs\r\n Cat : Permutation ws ys -> Permutation xs zs -> Permutation (ws ++ xs) (ys ++ zs)\r\n\r\nforAllPerm : (xs : List elem) -> ForAll p xs -> (ys : List elem) -> Permutation xs ys -> ForAll p ys\r\nforAllPerm [] None [] Empty = None\r\nforAllPerm (x :: xs) (Append px faxs) (ws ++ (x :: ys)) (Split xs ws ys pfperm) =\r\n let (faws,fays) = forAllBreak ws ys (forAllPerm xs faxs (ws ++ ys) pfperm) in forAllConcat ws faws (x :: ys) (Append px fays)\r\nforAllPerm xs {p} pfxs zs (Compos {ys} permxsys permyszs) = forAllPerm ys (forAllPerm xs pfxs ys permxsys) zs permyszs\r\nforAllPerm (ws ++ xs) pfwscatxs (ys ++ zs) (Cat pfwsys pfxszs) =\r\n let (pfws,pfxs) = (forAllBreak ws xs pfwscatxs) in forAllConcat ys (forAllPerm ws pfws ys pfwsys) zs (forAllPerm xs pfxs zs pfxszs)\r\n\r\npartitionFunc : {p : elem -> Type} -> {q : elem -> Type} -> (f : (x : elem) -> Either (p x) (q x)) ->\r\n (xs : List elem) -> (ys : List elem ** (zs : List elem ** (LTEforList ys xs,LTEforList zs xs , ForAll p ys, ForAll q zs, Permutation xs (ys ++ zs))))\r\npartitionFunc f [] = ([] ** ([] ** (LTEEmpty, LTEEmpty, None, None, Empty)))\r\n-- partitionFunc f (x :: xs) =\r\n-- let (ys ** (zs ** (pfmn, pfkn, pfys, pfzs, pfperm))) = partitionFunc f xs in\r\n-- case (f x) of\r\n-- (Left px) => ((x :: ys) ** (zs ** (LTESucc pfmn, lteTransitive pfkn (nLTESn (length xs)), Append px pfys, pfzs, Split [] (ys ++ zs) xs (permAddEmpty pfperm))))\r\n", "meta": {"hexsha": "76b26aaa19e6a84e12daf4280a34e927fef3295c", "size": 4552, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Quicksort.idr", "max_stars_repo_name": "adithyaupadhya/LTS2019", "max_stars_repo_head_hexsha": "b7cd4b678330ad1028400187bfb66684505fa725", "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": "Code/Quicksort.idr", "max_issues_repo_name": "adithyaupadhya/LTS2019", "max_issues_repo_head_hexsha": "b7cd4b678330ad1028400187bfb66684505fa725", "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": "Code/Quicksort.idr", "max_forks_repo_name": "adithyaupadhya/LTS2019", "max_forks_repo_head_hexsha": "b7cd4b678330ad1028400187bfb66684505fa725", "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": 56.1975308642, "max_line_length": 167, "alphanum_fraction": 0.5883128295, "num_tokens": 1604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7098712067836672}} {"text": "module MoreNatProofs\n\n%access public export\n%default total\n\n||| If a /= b then b /= a\nnotEqReflexive : ((a = b) -> Void) -> (b = a) -> Void\nnotEqReflexive f Refl = f Refl\n\n||| A decision procedure for `DecEq Nat`\n||| @ m the first number\n||| @ n the second number\nisEq : (m : Nat) -> (n : Nat) -> Dec (m = n)\nisEq m n = decEq m n\n\neQImpliesEq : {m, n : Nat} -> (m = n) -> (n = m)\neQImpliesEq {m = n} {n = n} Refl = Refl\n\neQAndNotEqImpossible : {n, k : Nat} -> (contra1 : (n = k) -> Void) -> (n = k) -> a\neQAndNotEqImpossible {n} {k} contra1 prf = void (contra1 prf)\n\n||| Proofs that `m` is not equal to `n`\n||| @ m the first number\n||| @ n the second number\nNotEq : (m, n : Nat) -> Type\nNotEq m n = Not (m=n)\n\n||| Not (m = n) implies m /= n\nnotEqImpliesNotEq : (contra : (m = n) -> Void) -> ((m = n) -> Void)\nnotEqImpliesNotEq contra Refl = contra Refl\n\n||| (m = n) implies Not (m /= n)\neqImpliesNotNotEq : (prf : m = n) -> (((m = n) -> Void) -> Void)\neqImpliesNotNotEq Refl f = f Refl\n\n||| A decision procedure for `NotEq`\nisNotEq : (m : Nat) -> (n : Nat) -> Dec (NotEq m n)\nisNotEq m n = case (isEq m n) of\n (Yes prf) => No (eqImpliesNotNotEq prf)\n (No contra) => Yes (notEqImpliesNotEq contra)\n\n\n||| A successor is always greater than or equal zero\nsuccGTEzero : GTE (S k) Z\nsuccGTEzero = LTEZero\n\n||| Zero cannot be greater than or equal to a successor\nzeroNotGTESucc : LTE (S k) 0 -> Void\nzeroNotGTESucc LTEZero impossible\nzeroNotGTESucc (LTESucc _) impossible\n\n||| A decision procedure for `GTE`\nisGTE : (m : Nat) -> (n : Nat) -> Dec (GTE m n)\nisGTE Z Z = Yes LTEZero\nisGTE Z (S k) = No zeroNotGTESucc\nisGTE (S k) Z = Yes succGTEzero\nisGTE (S k) (S j) with (isGTE k j)\n isGTE (S k) (S j) | (Yes prf) = Yes (LTESucc prf)\n isGTE (S k) (S j) | (No contra) = No (contra . fromLteSucc)\n\n||| If n > m, then n + 1 > m + 1\nGTSucc : (prf : LTE j k) -> LTE (S j) (S k)\nGTSucc prf = LTESucc prf\n\n||| Zero cannot be less than itself\nzeroNotLTZero : LT 0 0 -> Void\nzeroNotLTZero LTEZero impossible\nzeroNotLTZero (LTESucc _) impossible\n\n||| If 1 <= n + 1, then n + 1 > 0\nsuccGTZero : LTE 1 (S k)\nsuccGTZero = LTESucc LTEZero\n\n\n||| A decision procedure for `GT`\nisGT : (m : Nat) -> (n : Nat) -> Dec (GT m n)\nisGT Z Z = No zeroNotLTZero\nisGT Z (S k) = No zeroNotGTESucc\nisGT (S k) Z = Yes succGTZero\nisGT (S k) (S j) with (isGT k j)\n isGT (S k) (S j) | (Yes prf) = Yes (GTSucc prf)\n isGT (S k) (S j) | (No contra) = No (contra . fromLteSucc)\n\n||| A decision procedure for `LT`\nisLT : (m : Nat) -> (n : Nat) -> Dec (LT m n)\nisLT Z Z = No zeroNotLTZero\nisLT Z (S k) = Yes (LTESucc LTEZero)\nisLT (S k) Z = No succNotLTEzero\nisLT (S k) (S j) with (isLT k j)\n isLT (S k) (S j) | (Yes prf) = Yes (LTESucc prf)\n isLT (S k) (S j) | (No contra) = No (contra . fromLteSucc)\n\n\neqImpliesLTE : (n = k) -> LTE n k\neqImpliesLTE {n = Z} Refl = LTEZero\neqImpliesLTE {n = (S (S (S k)))} Refl = LTESucc (LTESucc (LTESucc (eqImpliesLTE Refl)))\neqImpliesLTE {n = (S k)} Refl = LTESucc (eqImpliesLTE Refl)\n\neqABImpliesEqBA : (prf : n = k) -> k = n\neqABImpliesEqBA Refl = Refl\n\nnotLTEandEqImpossible : (contra : LTE n k -> Void) -> (prf : n = k) -> LTE k n\nnotLTEandEqImpossible contra prf = eqImpliesLTE (eqABImpliesEqBA prf)\n\n\ngTImpliesLTE : (prf : GT n k) -> LTE k n\ngTImpliesLTE {n = (S left)} {k = (S right)} (LTESucc x) = LTESucc (gTImpliesLTE x)\ngTImpliesLTE {n = Z} {k = Z} LTEZero impossible\ngTImpliesLTE {n = Z} {k = Z} (LTESucc _) impossible\ngTImpliesLTE {n = Z} {k = (S _)} LTEZero impossible\ngTImpliesLTE {n = Z} {k = (S _)} (LTESucc _) impossible\ngTImpliesLTE {n = (S j)} {k = Z} (LTESucc x) = LTEZero\n\nnotGTImpliesLTE : Not (GT a b) -> LTE a b\nnotGTImpliesLTE {a = Z} _ = LTEZero\nnotGTImpliesLTE {b = Z} {a = S k} notGt = absurd (notGt (LTESucc LTEZero))\nnotGTImpliesLTE {b = S k} {a = S j} notGt = LTESucc (notLTImpliesGTE (notGt . LTESucc))\n\nnotLTEFlips : (contra : LTE n k -> Void) -> LTE k n\nnotLTEFlips {n} {k} contra = case isEq n k of\n (Yes prf) => notLTEandEqImpossible contra prf\n (No contra1) => (case isGT n k of\n (Yes prf) => gTImpliesLTE prf\n (No contra2) => gTImpliesLTE (void (contra (notGTImpliesLTE contra2))))\n\nlTESkk : (k : Nat) -> ((S k) `LTE` k) -> Void\nlTESkk Z LTEZero impossible\nlTESkk Z (LTESucc _) impossible\nlTESkk (S k) (LTESucc x) = lTESkk k x\n\nlTELeftNotSuccOfRight : (x : LTE (S k) k) -> Void\nlTELeftNotSuccOfRight {k} x = lTESkk k x\n\n||| k <= k\nlTEkk : Nat.LTE k k\nlTEkk {k = Z} = LTEZero\nlTEkk {k = (S k)} = LTESucc lTEkk\n", "meta": {"hexsha": "90c5933b35f29a7d2510dd4c95272e9edaef3694", "size": 4655, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "MoreNatProofs.idr", "max_stars_repo_name": "zenntenn/Idris-NumericProofs", "max_stars_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": "MoreNatProofs.idr", "max_issues_repo_name": "zenntenn/Idris-NumericProofs", "max_issues_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": "MoreNatProofs.idr", "max_forks_repo_name": "zenntenn/Idris-NumericProofs", "max_forks_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "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": 33.731884058, "max_line_length": 127, "alphanum_fraction": 0.5984962406, "num_tokens": 1823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.709820653321262}} {"text": "import Data.Vect\n\n%default total\n\ninterface ArrayM where\n Array : (n : Nat) -> (a : Type) -> Type\n create : (n : Nat) -> a -> Array n a\n\n lkp : (i : Nat) -> (prf : LTE (S i) n) -> Array n a -> a\n upd : a -> (i : Nat) -> (prf : LT i n) -> Array n a -> Array n a\n\nusing (ArrayM)\n sumArrayHelp : Num a => (k : Nat) -> LT k (S n) -> Array n a -> a\n sumArrayHelp Z x y = 0\n sumArrayHelp (S k) (LTESucc prf) y \n = lkp k prf y + sumArrayHelp k (lteSuccRight prf) y\n\n sumArray : Array n Int -> Int\n sumArray {n} x = sumArrayHelp n lteRefl x\n\nimplementation ArrayM where\n Array = Vect \n\n create n x = replicate n x\n\n lkp Z (LTESucc x) (y :: xs) = y\n lkp (S k) (LTESucc x) (y :: xs) = lkp k x xs\n\n upd val Z (LTESucc p) (_ :: xs) = val :: xs \n upd val (S k) (LTESucc p) (x :: xs) = x :: upd val k p xs\n\n-- using (ArrayM as vectArray)\n\ntestSum : Array n Int -> Int\ntestSum = sumArray \n\nmain : IO ()\nmain = printLn (testSum (upd 11 1 (LTESucc (LTESucc LTEZero)) (create 4 10)))\n", "meta": {"hexsha": "9804bb370b622bcc4fc0580d667a539bc8196792", "size": 984, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/idris-dev/interfaces002/interfaces002.idr", "max_stars_repo_name": "grin-compiler/idris-grin", "max_stars_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2019-06-06T10:35:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T08:48:30.000Z", "max_issues_repo_path": "test/idris-dev/interfaces002/interfaces002.idr", "max_issues_repo_name": "grin-compiler/idris-grin", "max_issues_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-11-21T20:45:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T12:29:23.000Z", "max_forks_repo_path": "test/idris-dev/interfaces002/interfaces002.idr", "max_forks_repo_name": "grin-compiler/idris-grin", "max_forks_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-14T13:14:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-07T06:20:45.000Z", "avg_line_length": 25.2307692308, "max_line_length": 77, "alphanum_fraction": 0.5782520325, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7096032978424542}} {"text": "module Proof\n\n%default total\n%access export\n\ninvert : (a : Nat) -> (b : Nat) -> (a + a = b + b) -> a = b\ninvert Z Z = const Refl\ninvert Z (S k) = absurd . SIsNotZ . sym\ninvert (S k) Z = absurd . SIsNotZ\ninvert (S k) (S j) = rewrite sym $ plusSuccRightSucc k k in rewrite sym $ plusSuccRightSucc j j in\n eqSucc k j . invert k j . succInjective (k+k) (j+j) . succInjective (S $ k+k) (S $ j+j)\n", "meta": {"hexsha": "6664ae0e3e2d38a43b856f572be986d67c569630", "size": 427, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codewars/Proof.idr", "max_stars_repo_name": "buzden/idris-playground", "max_stars_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-23T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T02:45:50.000Z", "max_issues_repo_path": "codewars/Proof.idr", "max_issues_repo_name": "buzden/idris-playground", "max_issues_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_issues_repo_licenses": ["CC0-1.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": "codewars/Proof.idr", "max_forks_repo_name": "buzden/idris-playground", "max_forks_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5833333333, "max_line_length": 108, "alphanum_fraction": 0.5690866511, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.7095546832353027}} {"text": "module Rationals\n\ndata NotZero : Integer -> Type where --Proof that a number is not zero, needed to construct Q\n OneNotZero : NotZero 1\n NegativeNotZero : ( n: Integer ) -> NotZero n -> NotZero (-n)\n PositiveNotZero : ( m: Integer ) -> LTE 1 (fromIntegerNat m) -> NotZero m\n\nrational : (p: Nat) -> (q: Integer) -> NotZero q -> (Integer, Integer)\nrational Z q x = (toIntegerNat(0), q)\nrational (S k) q x = (toIntegerNat(S k), q)\n\nSecondPart : (Integer, Integer) -> Integer\nSecondPart x = (snd x)\n\nInclusionMap : (n : Nat) -> (Integer, Integer) --Includes the naturals in Q\nInclusionMap n = rational n 1 OneNotZero\n\nAddRationals : (Integer, Integer) -> (Integer, Integer) -> (Integer, Integer) --Need to implement proof checking for nonzero denominators\nAddRationals x y = ((fst x)*(snd y) + (snd x)*(fst y), (snd x)*(snd y))\n\nMultiplyRationals : (Integer, Integer) -> (Integer, Integer) -> (Integer, Integer) --Need to implement proof checking for nonzero denominators\nMultiplyRationals x y = ((fst x)*(fst y), (snd x)*(snd y))\n\n--Need to create multiplicative inverses of rationals as well\n\n--A GCD function with proof that it is the GCD would be useful to reduce rationals into simplified form\n\ntest : Nat\ntest = fct 3\n", "meta": {"hexsha": "2c57687efcdc165ec3abcd6049e6527d70a8bca0", "size": 1225, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/rationals/Rationals.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": "_local-site/Code/rationals/Rationals.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": "_local-site/Code/rationals/Rationals.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": 40.8333333333, "max_line_length": 142, "alphanum_fraction": 0.6955102041, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7520125626441471, "lm_q1q2_score": 0.7094092271082915}} {"text": "module VectMonadLaws\n\nimport Data.Vect\n\n%default total\n\nmapFuses : (g : b -> c) -> (f : a -> b) -> (xs : Vect n a) -> map g (map f xs) = map (g . f) xs\nmapFuses g f [] = Refl\nmapFuses g f (_::xs) = rewrite mapFuses g f xs in Refl\n\nbindPureIsMap : (xs : Vect n a) -> (f : a -> b) -> map f xs = xs >>= \\x => pure $ f x\nbindPureIsMap [] f = Refl\nbindPureIsMap {n=S n} (_::xs) f = rewrite bindPureIsMap xs f in\n rewrite mapFuses tail (\\x => f x :: replicate n (f x)) xs in\n Refl\n\napThruBind' : (fs : Vect n (a -> b)) -> (xs : Vect n a) -> fs <*> xs = fs >>= (`map` xs)\napThruBind' [] [] = Refl\napThruBind' (_::fs) (x::xs) = rewrite mapFuses tail (\\f' => f' x :: map f' xs) fs in\n rewrite apThruBind' fs xs in\n Refl\n\n0 funext : {f, g : a -> b} -> ((x : a) -> f x = g x) -> f = g\nfunext _ = believe_me $ the (0 = 0) Refl\n\napThruBind : (fs : Vect n (a -> b)) -> (xs : Vect n a) -> fs <*> xs = fs >>= \\f' => xs >>= \\x' => pure (f' x')\napThruBind fs xs = trans (apThruBind' fs xs) $\n cong diag $ cong (`map` fs) $\n funext $ bindPureIsMap xs\n", "meta": {"hexsha": "4309ed020a3358a7c6cc90bd2ed12d2388456b0f", "size": 1203, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "VectMonadLaws.idr", "max_stars_repo_name": "buzden/idris-playground", "max_stars_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-23T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T02:45:50.000Z", "max_issues_repo_path": "VectMonadLaws.idr", "max_issues_repo_name": "buzden/idris-playground", "max_issues_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_issues_repo_licenses": ["CC0-1.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": "VectMonadLaws.idr", "max_forks_repo_name": "buzden/idris-playground", "max_forks_repo_head_hexsha": "414729c5dbd665fdb05cdfe5318f972fb277a726", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1, "max_line_length": 110, "alphanum_fraction": 0.4704904406, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7093955154321671}} {"text": "module Linear.Metric\n\nimport Linear.Epsilon\nimport Linear.Vect\n\npublic export\ninterface Additive f => Metric f where\n ||| Compute the inner product of two vectors or (equivalently)\n ||| convert a vector `f a` into a covector `f a -> a`.\n |||\n ||| ```idris example\n ||| V2 1 2 `dot` V2 3 4\n ||| ```\n dot : Num a => f a -> f a -> a\n\n ||| Compute the squared norm. The name quadrance arises from\n ||| Norman J. Wildberger's rational trigonometry.\n quadrance : Num a => f a -> a\n quadrance v = dot v v\n\n ||| Compute the quadrance of the difference\n qd : Neg a => f a -> f a -> a\n qd f g = quadrance (f ^-^ g)\n\n ||| Compute the distance between two vectors in a metric space\n distance : (Floating a, Neg a) => f a -> f a -> a\n distance f g = norm (f ^-^ g)\n\n ||| Compute the norm of a vector in a metric space\n norm : Floating a => f a -> a\n norm v = cast (sqrt (cast (quadrance v)))\n\n ||| Convert a non-zero vector to unit vector.\n signorm : Floating a => f a -> f a\n signorm v = let m = norm v in map (/m) v\n\npublic export\nimplementation (Additive f, Foldable f) => Metric f where\n dot x y = sum $ liftI2 (*) x y\n\n||| Normalize a 'Metric' functor to have unit 'norm'. This function\n||| does not change the functor if its 'norm' is 0 or 1.\nexport\nnormalize : (Floating a, Metric f, Epsilon a, Neg a) => f a -> f a\nnormalize v =\n let l = quadrance v\n in if nearZero l || nearZero (1 - l)\n then v\n else map (/ cast (sqrt (cast l))) v\n\n||| `project u v` computes the projection of `v` onto `u`.\nexport\nproject : (Metric v, Fractional a, Neg a) => v a -> v a -> v a\nproject u v = ((v `dot` u) / quadrance u) *^ u\n", "meta": {"hexsha": "2889a4ee78fcfa1c5686ea79a25e14f10a8eb878", "size": 1646, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Linear/Metric.idr", "max_stars_repo_name": "yurrriq/idris-linear", "max_stars_repo_head_hexsha": "987686f128f8c3442453e3b8970de4ea0c9e822b", "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/Linear/Metric.idr", "max_issues_repo_name": "yurrriq/idris-linear", "max_issues_repo_head_hexsha": "987686f128f8c3442453e3b8970de4ea0c9e822b", "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/Linear/Metric.idr", "max_forks_repo_name": "yurrriq/idris-linear", "max_forks_repo_head_hexsha": "987686f128f8c3442453e3b8970de4ea0c9e822b", "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": 29.9272727273, "max_line_length": 67, "alphanum_fraction": 0.6178614824, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7093646940850564}} {"text": "-- Intuitionistic propositional logic, PHOAS approach, initial encoding\n\nmodule Pi.Ip\n\n%default total\n\n\n-- Types\n\ninfixl 2 :&&\ninfixl 1 :||\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n (:&&) : Ty -> Ty -> Ty\n (:||) : Ty -> Ty -> Ty\n FALSE : Ty\n\ninfixr 0 :<=>\n(:<=>) : Ty -> Ty -> Ty\n(:<=>) a b = (a :=> b) :&& (b :=> a)\n\nNOT : Ty -> Ty\nNOT a = a :=> FALSE\n\nTRUE : Ty\nTRUE = FALSE :=> FALSE\n\n\n-- Context and truth judgement\n\nCx : Type\nCx = Ty -> Type\n\nisTrue : Ty -> Cx -> Type\nisTrue a tc = tc a\n\n\n-- Terms\n\ninfixl 1 :$\ndata Tm : Cx -> Ty -> Type where\n var : isTrue a tc -> Tm tc a\n lam' : (isTrue a tc -> Tm tc b) -> Tm tc (a :=> b)\n (:$) : Tm tc (a :=> b) -> Tm tc a -> Tm tc b\n pair : Tm tc a -> Tm tc b -> Tm tc (a :&& b)\n fst : Tm tc (a :&& b) -> Tm tc a\n snd : Tm tc (a :&& b) -> Tm tc b\n left : Tm tc a -> Tm tc (a :|| b)\n right : Tm tc b -> Tm tc (a :|| b)\n case' : Tm tc (a :|| b) -> (isTrue a tc -> Tm tc c) -> (isTrue b tc -> Tm tc c) -> Tm tc c\n abort : Tm tc FALSE -> Tm tc a\n\nlam'' : (Tm tc a -> Tm tc b) -> Tm tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\ncase'' : Tm tc (a :|| b) -> (Tm tc a -> Tm tc c) -> (Tm tc b -> Tm tc c) -> Tm tc c\ncase'' xy f g = case' xy (\\x => f (var x)) (\\y => g (var y))\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\nsyntax \"[\" [a] \",\" [b] \"]\" = pair a b\nsyntax \"case\" [ab] \"of\" {a} \":=>\" [c1] or {b} \":=>\" [c2] = case'' ab (\\a => c1) (\\b => c2)\n\nThm : Ty -> Type\nThm a = {tc : Cx} -> Tm tc a\n\n\n-- Example theorems\n\nt1 : Thm (a :=> NOT a :=> b)\nt1 =\n lam x :=>\n lam f :=> abort (f :$ x)\n\nt2 : Thm (NOT a :=> a :=> b)\nt2 =\n lam f :=>\n lam x :=> abort (f :$ x)\n\nt3 : Thm (a :=> NOT (NOT a))\nt3 =\n lam x :=>\n lam f :=> f :$ x\n\nt4 : Thm (NOT a :<=> NOT (NOT (NOT a)))\nt4 =\n [ lam f :=>\n lam g :=> g :$ f\n , lam g :=>\n lam x :=> g :$ (lam f :=> f :$ x)\n ]\n", "meta": {"hexsha": "ca39b37d79c26b0778fd4e9f89eed797758ea922", "size": 2002, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pi/Ip.idr", "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": ["X11"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_issues_repo_path": "src/Pi/Ip.idr", "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_licenses": ["X11"], "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/Pi/Ip.idr", "max_forks_repo_name": "mietek/formal-logic", "max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_forks_repo_licenses": ["X11"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5268817204, "max_line_length": 92, "alphanum_fraction": 0.4110889111, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.7092712238110456}} {"text": "data Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nappend : Vect n a -> Vect m a -> Vect (n + m) a\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n", "meta": {"hexsha": "dd8a348c994406afa0697e88b39a5dc81e6cae7d", "size": 207, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive001/LocType.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/interactive001/LocType.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/interactive001/LocType.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": 25.875, "max_line_length": 47, "alphanum_fraction": 0.5024154589, "num_tokens": 72, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.7088250451649994}} {"text": "-- 4.1.5 Exercises\n\n-- integer arithmetic expression\ndata Exp = Single Int\n | Add Exp Exp\n | Sub Exp Exp\n | Mul Exp Exp\n\n-- more flexible syntax\n-- data Exp : Type where\n-- Single : Int -> Exp\n-- Add : Exp -> Exp -> Exp\n-- Sub : Exp -> Exp -> Exp\n-- Mul : Exp -> Exp -> Exp\n\neval : Exp -> Int\neval (Single x) = x\neval (Add x y) = eval x + eval y\neval (Sub x y) = eval x - eval y\neval (Mul x y) = eval x * eval y\n\n-- *Chap4> eval (Add (Single 1) (Single 2))\n-- 3 : Int\n\ndata BSTree : Type -> Type where\n Empty : Ord e => BSTree e\n Node : Ord e => (left : BSTree e) -> (val : e) -> (right : BSTree e) -> BSTree e\n\n-- %name BSTree left, right\n-- using a %name directive to give naming hints for building definitions interactively\n\ninsert : elem -> BSTree elem -> BSTree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left val right) = case compare x val of\n LT => Node (insert x left) val right\n EQ => orig -- same as as-patterns in Haskell\n GT => Node left val (insert x right)\n-- match Ctrl-Alt-M\n\nlistToTree : Ord a => List a -> BSTree a\nlistToTree [] = Empty\nlistToTree (x :: xs) = insert x $ listToTree xs\n\n-- *starting/Chap4> listToTree ['p', 'r', 'a', 't']\n-- Node (Node Empty 'a' (Node (Node Empty 'p' Empty) 'r' Empty)) 't' Empty : BSTree Char\n\ntreeToList : BSTree a -> List a\ntreeToList Empty = []\ntreeToList (Node left val right) = treeToList left ++ [val] ++ treeToList right\n", "meta": {"hexsha": "0317c4ba5258ccff05b408f3772315e5d293c80d", "size": 1559, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "starting/chap04.idr", "max_stars_repo_name": "prt2121/tdd-playground", "max_stars_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "starting/chap04.idr", "max_issues_repo_name": "prt2121/tdd-playground", "max_issues_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": "starting/chap04.idr", "max_forks_repo_name": "prt2121/tdd-playground", "max_forks_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "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": 31.18, "max_line_length": 88, "alphanum_fraction": 0.5702373316, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.708463112012724}} {"text": "module RecursionSchemes\n\ndata Fix : (f : Type -> Type) -> Type where\n Fx : (f (Fix f)) -> Fix f\n\ndata ListF : Type -> Type -> Type where\n Nil : ListF a f\n Cons : a -> f -> ListF a f\n\nFunctor (ListF a) where\n map f [] = []\n map f (Cons x xs) = Cons x (f xs)\n\nList' : Type -> Type\nList' a = Fix (ListF a)\n\nnil : List' a\nnil = Fx Nil\n\n(::) : a -> List' a -> List' a\n(::) x xs = Fx (Cons x xs)\n\ncata : Functor f => (f a -> a) -> Fix f -> a\ncata alg (Fx f) = (alg . map (cata alg)) f\n\nana : Functor f => (a -> f a) -> a -> Fix f\nana f a = (Fx . map (ana f) . f) a\n\nhylo : Functor f => (f b -> b) -> (a -> f a) -> a -> b\nhylo f g a = (cata f . ana g) a\n\n-- Catamorphism examples\ncount : List' a -> Int\ncount xs = cata countF xs\n where\n countF : ListF a Int -> Int\n countF [] = 0\n countF (Cons _ c) = 1 + c\n\nsum : List' Int -> Int\nsum xs = cata sumF xs\n where\n sumF : ListF Int Int -> Int\n sumF [] = 0\n sumF (Cons x c) = x + c\n\nexample : List' Int\nexample = 1 :: 2 :: 3 :: 4 :: 5 :: nil\n\ntestCount : Int\ntestCount = count example\n\ntestSum : Int\ntestSum = sum example\n\n-- Anamorphism examples\nrepeat : Int -> List' Int\nrepeat n = ana countF n\n where\n countF : Int -> ListF Int Int\n countF n = if n <= 0 then Nil else Cons n (n - 1)\n\n\ntestRepeat : Int\ntestRepeat = sum (repeat 5)\n", "meta": {"hexsha": "96ab585287ee2e661f5b8ca15fea39412923f4a8", "size": 1303, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/RecursionSchemes.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/RecursionSchemes.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/RecursionSchemes.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": 19.7424242424, "max_line_length": 54, "alphanum_fraction": 0.5533384497, "num_tokens": 487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7083698031894263}} {"text": "module Main\n\nimport Data.Vect\n\nallLengths : Vect len String -> Vect len Nat\nallLengths [] = []\nallLengths (x :: xs) = length x :: allLengths xs\n", "meta": {"hexsha": "dccb8444ebfc7bd781d4a0093d67bdf702bd1ac5", "size": 151, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/book/2017-Type_Driven_Development_with_Idris/src/P067_all_length_vect.idr", "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_issues_repo_path": "idris/book/2017-Type_Driven_Development_with_Idris/src/P067_all_length_vect.idr", "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "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": "idris/book/2017-Type_Driven_Development_with_Idris/src/P067_all_length_vect.idr", "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "avg_line_length": 18.875, "max_line_length": 48, "alphanum_fraction": 0.6556291391, "num_tokens": 45, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7080360395602936}} {"text": "module Data.InSet.Equality\n\nimport Data.Lawful.Eqv\n\nimport Decidable.Equality\n\nimport public Syntax.WithProof\n\n%default total\n\ninfix 6 =?=\n\n||| Generalization of user-defined lawful equality (`Eq`, `Eqv` and `==`) and propositional equality (`DecEq` and `=`).\npublic export\ninterface Equality a where\n\n -- Type-level equality proofs\n\n EqPrf : a -> a -> Type\n NeqPrf : a -> a -> Type\n\n cant_eq_neq : {x, y : a} -> EqPrf x y -> NeqPrf x y -> Void\n\n -- Runtime equality operator\n\n (=?=) : (x, y : a) -> Bool\n\n -- Correspondence between type-level and runtime\n\n eq_prf_to_val : {x, y : a} -> EqPrf x y -> x =?= y = True\n eq_val_to_prf : {x, y : a} -> x =?= y = True -> EqPrf x y\n\n neq_prf_to_val : {x, y : a} -> NeqPrf x y -> x =?= y = False\n neq_val_to_prf : {x, y : a} -> x =?= y = False -> NeqPrf x y\n\n -- Properties of equality for equality operator\n\n equ_reflexive : (x : a) -> x =?= x = True\n\n equ_commutative : (x, y : a) -> x =?= y = y =?= x\n\n equ_transitive : (x, y, z : a) -> x =?= y = True -> y =?= z = True -> x =?= z = True\n\n-- TODO Maybe, to split `Equality` interface to two: one for equality relation, another to equivalence properties.\n-- Then, equality relation interace's implementations should be exported publicly, but properties proofs should not.\n\n0 decEq_refl : DecEq a => (x : a) -> decEq x x = Yes Refl\ndecEq_refl x = case @@(decEq x x) of\n (Yes Refl ** p) => p\n (No nn ** _) => absurd $ nn Refl\n\ntrueNotFalse : Not (True = False)\ntrueNotFalse Refl impossible\n\npublic export\n[PropositionalEq] DecEq a => Equality a where\n\n -- Type-level equality\n\n EqPrf x y = x = y\n NeqPrf x y = x = y -> Void\n\n cant_eq_neq xy nxy = nxy xy\n\n -- Value-level equality\n\n x =?= y = case decEq x y of\n Yes pxy => True\n No nxy => False\n\n -- Correspondence between type-level and runtime\n\n eq_prf_to_val eq_prf = rewrite eq_prf in\n rewrite decEq_refl y in\n Refl\n\n neq_prf_to_val neq_prf = case @@(decEq x y) of\n (No _ ** prf) => rewrite prf in Refl\n (Yes yy ** _) => absurd $ neq_prf yy\n\n eq_val_to_prf = case @@(decEq x y) of\n (Yes yy ** _) => \\_ => yy\n (No _ ** prf) => rewrite prf in \\ft => absurd $ trueNotFalse $ sym ft\n\n neq_val_to_prf = case @@(decEq x y) of\n (No nn ** _) => \\_ => nn\n (Yes _ ** prf) => rewrite prf in \\tf => absurd $ trueNotFalse tf\n\n -- Properties of value-level equality\n\n equ_reflexive x = rewrite decEq_refl x in Refl\n\n equ_commutative x y = case @@(decEq x y) of\n (Yes yy ** _) => rewrite yy in Refl\n (No _ ** no_xy) => case @@(decEq y x) of\n (Yes yy ** _) => rewrite yy in\n rewrite decEq_refl x in\n Refl\n (No _ ** no_yx) => rewrite no_xy in\n rewrite no_yx in\n Refl\n\n equ_transitive x y z xy yz = case (@@(decEq x y), @@(decEq y z)) of\n ((Yes eq_xy ** _), (Yes eq_yz ** _)) => rewrite eq_xy in\n rewrite sym eq_yz in\n rewrite decEq_refl y in\n Refl\n ((No _ ** no_xy), _) => absurd $ trueNotFalse $ sym $ rewrite sym xy in rewrite no_xy in Refl\n (_, (No _ ** no_yz)) => absurd $ trueNotFalse $ sym $ rewrite sym yz in rewrite no_yz in Refl\n\npublic export\n[StandardEq] Eqv a => Equality a where\n\n -- Type-level equality\n\n EqPrf x y = x == y = True\n NeqPrf x y = x == y = False\n\n cant_eq_neq xy nxy = trueNotFalse rewrite sym xy in nxy\n\n -- Value-level equality\n\n x =?= y = x == y\n\n -- Correspondence between type-level and runtime\n\n eq_prf_to_val = id\n eq_val_to_prf = id\n\n neq_prf_to_val = id\n neq_val_to_prf = id\n\n -- Properties of value-level equality\n\n equ_reflexive x = rewrite eqvReflexive x in Refl\n equ_commutative x y = rewrite eqvCommutative x y in Refl\n equ_transitive x y z xy yz = rewrite eqvTransitive x y z xy yz in Refl\n", "meta": {"hexsha": "d53f36c73013ffd3c94740ff9230d0585ff71300", "size": 3931, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/InSet/Equality.idr", "max_stars_repo_name": "buzden/prog-prove-exercises", "max_stars_repo_head_hexsha": "053fb3d07e09c4b2e70a66ca33aa61ec46ff1254", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data/InSet/Equality.idr", "max_issues_repo_name": "buzden/prog-prove-exercises", "max_issues_repo_head_hexsha": "053fb3d07e09c4b2e70a66ca33aa61ec46ff1254", "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": "Data/InSet/Equality.idr", "max_forks_repo_name": "buzden/prog-prove-exercises", "max_forks_repo_head_hexsha": "053fb3d07e09c4b2e70a66ca33aa61ec46ff1254", "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": 28.4855072464, "max_line_length": 121, "alphanum_fraction": 0.5868735691, "num_tokens": 1246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7078431845349389}} {"text": "data Last : List a -> a -> Type where\n LastOne : Last [value] value\n LastCons : (prf : Last xs value) -> Last (x :: xs) value\n\nlast123 : Last [1, 2, 3] 3\nlast123 = LastCons (LastCons LastOne)\n\nnotInNil : Last [] value -> Void\nnotInNil LastOne impossible\nnotInNil (LastCons _) impossible\n\nnotLast : (notHere : (value = x) -> Void) -> Last [x] value -> Void\nnotLast notHere LastOne = notHere Refl\nnotLast notHere (LastCons prf) = notInNil prf\n\nnotLastInTail : (notLastPrf : Last (y :: xs) value -> Void) -> Last (x :: (y :: xs)) value -> Void\nnotLastInTail notLastPrf (LastCons prf) = notLastPrf prf\n\nisLast : DecEq a => (xs : List a) -> (value : a) -> Dec (Last xs value)\nisLast [] value = No notInNil\nisLast (x :: []) value =\n case decEq value x of\n Yes Refl => Yes LastOne\n No notHere => No (notLast notHere)\nisLast (x :: (y :: xs)) value =\n case isLast (y :: xs) value of\n Yes prf => Yes (LastCons prf)\n No notLastPrf => No (notLastInTail notLastPrf)\n", "meta": {"hexsha": "6eda5edb0c14f8d9ea014ee4caa082dc13be61d2", "size": 993, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/Ex9.1.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/Ex9.1.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/Ex9.1.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": 34.2413793103, "max_line_length": 98, "alphanum_fraction": 0.6324269889, "num_tokens": 332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.7077186666880801}} {"text": "module AOC.Day.One\n\nimport AOC.Solution\n\nimport Data.String\nimport Data.List\n\n%default total\n\n----------------------------------------------------------------------------\n-- Types -------------------------------------------------------------------\n----------------------------------------------------------------------------\n\nInputType : Type\nInputType = List Integer\n\n----------------------------------------------------------------------------\n-- Helper Functions --------------------------------------------------------\n----------------------------------------------------------------------------\n\nascending : Ord a => List a -> Nat\nascending list = foldr (\\(x, y), acc => if x < y then S acc else acc) Z (zip list (drop 1 list))\n\nwindow : (Num a, Ord a) => List a -> List a\nwindow list = zipWith3 (\\a, b, c => a + b + c) list (drop 1 list) (drop 2 list)\n\n\n----------------------------------------------------------------------------\n-- Solutions ---------------------------------------------------------------\n----------------------------------------------------------------------------\n\npart1 : InputType -> Nat\npart1 = ascending\n\npart2 : InputType -> Nat\npart2 = ascending . window\n\n\n----------------------------------------------------------------------------\n-- Interface for input/output ----------------------------------------------\n----------------------------------------------------------------------------\n\nparser : String -> Maybe (InputType)\nparser = sequence . map (parseInteger {a=Integer}) . lines\n\nexport\nday1 : (inputType ** AOCSolution inputType)\nday1 = solutionToDP (MkAOCSolution {\n day = 1\n , parser = parser\n , part1 = show . part1\n , part2 = show . part2\n })\n", "meta": {"hexsha": "7721428994c6803b56c4c7bafee100da7d797c33", "size": 1694, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/AOC/Day/One.idr", "max_stars_repo_name": "ryanorendorff/aoc2021", "max_stars_repo_head_hexsha": "47a4d406ee8b70a73bcf6e4b168b02af83201ae7", "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/AOC/Day/One.idr", "max_issues_repo_name": "ryanorendorff/aoc2021", "max_issues_repo_head_hexsha": "47a4d406ee8b70a73bcf6e4b168b02af83201ae7", "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/AOC/Day/One.idr", "max_forks_repo_name": "ryanorendorff/aoc2021", "max_forks_repo_head_hexsha": "47a4d406ee8b70a73bcf6e4b168b02af83201ae7", "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": 31.3703703704, "max_line_length": 96, "alphanum_fraction": 0.3288075561, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7076970882897752}} {"text": "occurences : Eq ty => (item : ty) -> (values : List ty) -> Nat\noccurences item [] = 0\noccurences item (value :: values) = case value == item of\n False => occurences item values\n True => 1 + occurences item values\n\ndata Matter = Solid | Liquid | Gas\n\nEq Matter where\n (==) Solid Solid = True\n (==) Liquid Liquid = True\n (==) Gas Gas = True\n (==) _ _ = False\n\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n\nEq elem => Eq (Tree elem) where\n (==) Empty Empty = True\n (==) (Node left el right) (Node left' el' right') =\n left == left' && el == el' && right == right'\n (==) _ _ = False\n\nFunctor Tree where\n map func Empty = Empty\n map func (Node left el right) =\n Node (map func left) (func el) (map func right)\n\nFoldable Tree where\n foldr func acc Empty = acc\n foldr func acc (Node left el right) =\n let leftFold = foldr func acc left\n rightFold = foldr func leftFold right in\n func el rightFold\n\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\nEq Shape where\n (==) (Triangle x z) (Triangle y w) = x == y && z == w\n (==) (Rectangle x z) (Rectangle y w) = x == y && z == w\n (==) (Circle x) (Circle y) = x == y\n (==) _ _ = False\n\narea : Shape -> Double\narea (Triangle x y) = x * y * 0.5\narea (Rectangle x y) = x * y\narea (Circle x) = x * x * pi\n\nOrd Shape where\n compare x y = compare (area x) (area y)\n\ntestShapes : List Shape\ntestShapes = [\n Circle 3,\n Triangle 3 9,\n Rectangle 2 6,\n Circle 4,\n Rectangle 2 7\n]", "meta": {"hexsha": "a6b85de6dc18b00b69be5fcab764645674d2d888", "size": 1670, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/Interfaces.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/Interfaces.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/Interfaces.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": 27.3770491803, "max_line_length": 74, "alphanum_fraction": 0.5461077844, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.7072705903713798}} {"text": "{- Ctrl-Alt-A: Add definition\n Ctrl-Alt-C: Case split\n Ctrl-Alt-D: Documentation\n Ctrl-Alt-L: Lift hole: Lifts a hole to the top level as a new function definition\n Ctrl-Alt-M: Match: Replaces a hole with a case expression that matches on an intermediate result\n Ctrl-Alt-R: Reloads and typechecks the current buffer\n Ctrl-Alt-S: Search\n Ctrl-Alt-T: Type-check: Displays the type under cursor\n Ctrl-Alt-W: Add With View -}\nmodule Main\n\nimport Data.List.Views\nimport Data.Vect\nimport Data.Vect.Views\nimport Data.Nat.Views\n\n{-\nO(n) in time: because we travel the lists twice\nO(n) in space: because we build a helper SnocList structures.\n-}\ntotal\nequalSuffix : Eq a => List a -> List a -> List a\nequalSuffix input1 input2 with (snocList input1)\n equalSuffix [] input2 | Empty = []\n equalSuffix (xs ++ [x]) input2 | (Snoc xsrec) with (snocList input2)\n equalSuffix (xs ++ [x]) [] | (Snoc xsrec) | Empty = []\n equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec) =\n case x == y of\n True => (equalSuffix xs ys | xsrec | ysrec) ++ [x]\n False => []\n\ntotal\nmergeSort : (Ord a) => Vect n a -> Vect n a\nmergeSort xs with (splitRec xs)\n mergeSort [] | SplitRecNil = []\n mergeSort [x] | SplitRecOne = [x]\n mergeSort (ys ++ zs) | (SplitRecPair lrec rrec) =\n merge (mergeSort ys | lrec) (mergeSort zs | rrec)\n\ntotal\ntoBinary : Nat -> String\ntoBinary n with (halfRec n)\n toBinary Z | HalfRecZ = \"\"\n toBinary (x + x) | (HalfRecEven rec) = (toBinary x | rec) ++ \"0\"\n toBinary (S (x + x)) | (HalfRecOdd rec) = (toBinary x | rec) ++ \"1\"\n\ntotal\npalindrome : List Char -> Bool\npalindrome xs with (vList xs)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (x :: (ys ++ [y])) | (VCons rec) =\n case x == y of\n False => False\n True => palindrome ys | rec\n\nmain : IO ()\nmain = do\n printLn $ equalSuffix [] [1] -- []\n printLn $ equalSuffix [1,2,4,5] [1..5] -- [4,5]\n printLn $ equalSuffix [1,2,4,5,6] [1..5] -- []\n printLn $ equalSuffix [1,2,4,5,6] [1..6] -- [4,5,6]\n printLn $ mergeSort [1,2,3,8,4,3,6,7,9,7]\n putStrLn $ toBinary 42 -- \"101010\"\n putStrLn $ toBinary 94 -- \"1011110\"\n printLn $ palindrome (unpack \"abccba\") -- True\n printLn $ palindrome (unpack \"abcba\") -- True\n printLn $ palindrome (unpack \"abcb\") -- False\n", "meta": {"hexsha": "757d2c26e2f1081f63df7de0d5df48e5b907555a", "size": 2311, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/tdd/chapter10/02_Exercises.idr", "max_stars_repo_name": "pdani/idris-grin", "max_stars_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2019-06-06T10:35:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T08:48:30.000Z", "max_issues_repo_path": "test/tdd/chapter10/02_Exercises.idr", "max_issues_repo_name": "pdani/idris-grin", "max_issues_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-11-21T20:45:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T12:29:23.000Z", "max_forks_repo_path": "test/tdd/chapter10/02_Exercises.idr", "max_forks_repo_name": "pdani/idris-grin", "max_forks_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-14T13:14:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-07T06:20:45.000Z", "avg_line_length": 33.4927536232, "max_line_length": 99, "alphanum_fraction": 0.6321938555, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7069095891886376}} {"text": "import Data.Vect\n\n-- Exercise 2\ndata PowerSource = Petrol | Pedal | Electric\n\n-- Exercise 1\ndata Vehicle : PowerSource -> Type where\n Unicycle : Vehicle Pedal\n Bicycle : Vehicle Pedal\n Motorcycle : (fuel : Nat) -> Vehicle Petrol\n Car : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n\nwheels : Vehicle power -> Nat\nwheels Unicycle = 1\nwheels Bicycle = 2\nwheels (Motorcycle _) = 2\nwheels (Car _) = 4\nwheels (Bus _) = 4\n\nrefuel : Vehicle Petrol -> Vehicle Petrol\nrefuel (Motorcycle _) = Motorcycle 100\nrefuel (Car _) = Car 100\nrefuel (Bus _) = Bus 100\nrefuel Unicycle impossible\nrefuel Bicycle impossible\n\n-- Exercise 3 and Exercise 4\nvectTake : (n: Nat) -> Vect (n + m) a -> Vect n a\nvectTake Z xs = []\nvectTake (S k) (x :: xs) = x :: vectTake k xs\n\n-- Exercise 5\nsumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos xs ys\n = case integerToFin pos n of\n Nothing => Nothing\n (Just idx) => Just $ (Vect.index idx xs) + (Vect.index idx ys)\n", "meta": {"hexsha": "d12d167e88741aead9390032106d609058907e9a", "size": 1022, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter04/Exercises/ex_4_2.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter04/Exercises/ex_4_2.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "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": "TypeDrivenDevelopment/Chapter04/Exercises/ex_4_2.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "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.2051282051, "max_line_length": 72, "alphanum_fraction": 0.6545988258, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7065529379497153}} {"text": "module Category\n\nimport TypesAndFunctions\n\n%default total\n\n{- Often needed to do category theory in Idris. -}\npublic export\nfunctionalExtensionality : {a, b : Type} -> FunctionalExtensionality a b\nfunctionalExtensionality = believe_me\n\npublic export\nrecord Category where\n constructor MkCategory\n Object : Type\n Morphism : Object -> Object -> Type\n Identity : (a : Object) -> Morphism a a\n After : {a, b, c : Object} -> Morphism b c -> Morphism a b -> Morphism a c\n LeftIdentity : {a, b : Object} -> (m : Morphism a b) ->\n After (Identity b) m = m\n RightIdentity : {a, b : Object} -> (m : Morphism a b) ->\n After m (Identity a) = m\n Associativity : {a, b, c, d : Object} ->\n (h : Morphism c d) -> (g : Morphism b c) -> (f : Morphism a b) ->\n After (After h g) f = After h {a} {b=c} {c=d} (After {a} {b} {c} g f)\n\npublic export\ncatId : {cat : Category} -> (a : Object cat) -> Morphism cat a a\ncatId {cat} a = Identity cat a\n\ninfix 25 .*\npublic export\n(.*) : {cat : Category} -> {a, b, c : Object cat} ->\n Morphism cat b c -> Morphism cat a b -> Morphism cat a c\ng .* f = After cat g f\n\npublic export\npostCompose : {cat : Category} -> {a, b, c : Object cat} ->\n Morphism cat b c -> Morphism cat a b -> Morphism cat a c\npostCompose f = (.*) f\n\npublic export\npreCompose : {cat : Category} -> {a, b, c : Object cat} ->\n Morphism cat a b -> Morphism cat b c -> Morphism cat a c\npreCompose f = \\h => h .* f\n\npublic export\nTypeCategory : Category\nTypeCategory = MkCategory\n Type\n (\\a, b => a -> b)\n (\\_ => id)\n (\\g, f => g . f)\n (\\m => functionalExtensionality (\\_ => Refl))\n (\\m => functionalExtensionality (\\_ => Refl))\n (\\h, g, f => Refl)\n", "meta": {"hexsha": "f4adc9351e86da5e41439e408826f0cb94853cc8", "size": 1664, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Category.idr", "max_stars_repo_name": "rokopt/dao-fp-exercises", "max_stars_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-01-17T17:12:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:52:36.000Z", "max_issues_repo_path": "src/Category.idr", "max_issues_repo_name": "rokopt/dao-fp-exercises", "max_issues_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "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/Category.idr", "max_forks_repo_name": "rokopt/dao-fp-exercises", "max_forks_repo_head_hexsha": "e5291ca45015c4ee5af49c0d8a256cf7da5b08c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-17T17:12:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-17T17:12:19.000Z", "avg_line_length": 29.1929824561, "max_line_length": 76, "alphanum_fraction": 0.6153846154, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7062685640638654}} {"text": "\nmodule Term\n\n-- Untyped lambda calculus with built-in natural numbers. \n--\n-- Note that variables in the lambda calculus are not\n-- named but identified by their de Bruijn index.\n\n\nimport Data.Fin\nimport public Data.Vect\n\n\n%default total\n%access public export\n\n\n--------------------------------------\n-- Begin: TERMS OF THE LAMBDA CALCULUS\n\n-- Data type of well-scoped terms\n-- in the lambda calculus:\ndata Term : Nat -> Type where\n -- Variable:\n -- The data constructor for variables ('Var') takes\n -- as arguments a de Bruijn index ('i').\n TVar : (i : Fin n) -> Term n\n -- Abstraction:\n TAbs : Term (S n) -> Term n\n -- Application:\n TApp : Term n -> Term n -> Term n\n -- Constant 'Zero' (natural number):\n TZero : Term n\n -- Successor:\n TSucc : Term n -> Term n\n -- Predecessor:\n TPred : Term n -> Term n\n -- Test for equality with 'Zero' \n -- (with terms for the \"then\" and\n -- \"else\" branches):\n TIfz : Term n -> Term n -> Term n ->\n Term n\n\n-- End: TERMS OF THE LAMBDA CALCULUS\n------------------------------------\n\n\n\n---------------------------------------\n-- Begin: VALUES IN THE LAMBDA CALCULUS \n\n-- The following lambda calculus terms\n-- are values (i.e. normal forms for \n-- reduction under the \"Step\" relation):\n-- (1) lambda abstractions (that are\n-- not applied),\n-- (2) the constant 'Zero',\n-- (3) the natural number constants\n-- (formed by applying 'Succ' to\n-- another value). \ndata Value : Term 0 -> Type where\n VZero : Value TZero\n VSucc : Value e -> Value (TSucc e)\n VAbs : Value (TAbs e)\n\n\nvalueTerm : {e : Term 0} -> Value e -> Term 0\nvalueTerm {e = e} _ = e\n\n-- End: VALUES IN THE LAMBDA CALCULUS \n-------------------------------------\n", "meta": {"hexsha": "0797832c76f105c96202bf6f4b798e13c6b951d9", "size": 1718, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "untyped/src/Term.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "untyped/src/Term.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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": "untyped/src/Term.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "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.8611111111, "max_line_length": 58, "alphanum_fraction": 0.5791618161, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7061603598706228}} {"text": "module NatPrimes\n\nimport InductiveTypes\nimport NatUtils\nimport NatOrder\nimport NatDivisors\nimport NatGCD\n\n%default total\n%access public export\n\n----------------------------------------------------------------------------------------------\n\n-- Definitions\n\n|||A factorisation for a number\nFactorisation : (n : Nat) -> Type\nFactorisation n = (a : Nat ** (b : Nat ** ((LT 1 a, LT 1 b), n = a * b)))\n\n|||Type of proof that a number is prime\nisPrime : (p : Nat) -> Type\nisPrime p = ((LT 1 p), {a : Nat} -> {b : Nat} -> (isDivisible (a * b) p) -> Either (isDivisible a p) (isDivisible b p))\n\n|||Type of proof that a number is irreducible\nisIrreducible : (p : Nat) -> Type\nisIrreducible p = (a : Nat) -> (b : Nat) -> (p = a * b) -> Either (a = 1) (b = 1)\n\n|||Type of proof that a number is the smallest divisor (greater than 1) of a given number\nisMinDivisor : (n : Nat) -> (d : Nat) -> Type\nisMinDivisor n d = ((LT 1 d), ((isDivisible n d), {k : Nat} -> (LT 1 k) -> (isDivisible n k) -> (LTE d k)))\n\n-----------------------------------------------------------------------------------------------\n\n--Basic Proofs\n\n|||Proof that 1 < n implies n != 0\nltOneNotZ : {n : Nat} -> (LT 1 n) -> (Not (n = Z))\nltOneNotZ {n} ltProof = gtSuccImpliesNotZ n ltProof\n\n|||Proof that p is irreducible and r < p, r ! = 0 implies r and p are coprime\nremainderPrimeCoprime : {p : Nat} -> {r : Nat} ->\n\t\t\t\t (isIrreducible p) -> (LNEQ r p) -> (Not (r = Z)) -> (coprime r p)\nremainderPrimeCoprime {p} {r} proofIrreducible proofLNEQ rNotZ n (divr, (k ** (proofEq, notZ))) = case (proofIrreducible k n proofEq) of\n\t(Left kEq1) => void ((leqImpliesNotLNEQ (dividesImpliesGEQ (eqConservesDivisible divr Refl (sym (trans proofEq (trans (cong {f = (\\a => a * n)} kEq1) (multOneLeftNeutral n))))) rNotZ)) proofLNEQ)\n\t(Right nEq1) => nEq1\n\n|||Proof that if an irreducible does not divide a number, it is coprime to the number\nirredNotDivIsCoprime : {p : Nat} -> (n : Nat) ->\n\t\t\t\t (isIrreducible p) -> (Not (isDivisible n p)) -> (coprime n p)\nirredNotDivIsCoprime {p} n proofIrreducible notDiv k (divRight, (l ** (proofEq, notZ))) =\n\tcase (proofIrreducible l k proofEq) of\n\t(Left lEq1) => void (notDiv (eqConservesDivisible divRight Refl (sym (trans proofEq (trans (cong {f = (\\a => a * k)} lEq1) (multOneLeftNeutral k))))))\n\t(Right kEq1) => kEq1\n\n|||Proof that an irreducible either divides a number or is coprime to it\nirreducibleDividesOrCoprime : {p : Nat} -> (n : Nat) -> (isIrreducible p) -> Either (isDivisible n p) (coprime n p)\nirreducibleDividesOrCoprime {p} n proofIrreducible =\n\tcase (decDivisible n p) of\n\t\t(Yes proofDiv) => (Left proofDiv)\n\t\t(No notDiv) => (Right (irredNotDivIsCoprime n proofIrreducible notDiv))\n\n-----------------------------------------------------------------------------------------------\n\n--Equivalence of irreducibility and primality in the naturals\n\n|||Proof that a prime is irreducible\nprimeIsIrreducible : {p : Nat} -> (isPrime p) -> (isIrreducible p)\nprimeIsIrreducible {p} (proofLT, proofPrime) a b proofEq =\n\tcase (proofPrime (1 ** ((rewrite (multOneLeftNeutral p) in (sym proofEq)), (ltOneNotZ proofLT)))) of\n\t(Left dividesA) =>\n\t\tcase (dividesA) of\n\t\t(k ** (proofEq2, notZ)) => Right (sym (multLeftCancel p 1 b notZ (trans (rewrite (multOneRightNeutral p) in proofEq) (cong {f = (\\n => n * b)} (multAntiSymmetric proofEq2 (trans proofEq (multCommutative a b)))))))\n\t(Right dividesB) =>\n\t\tcase (dividesB) of\n\t\t(k ** (proofEq2, notZ)) => Left (sym (multRightCancel 1 a p notZ (trans (rewrite (multOneLeftNeutral p) in proofEq) (cong {f = (\\n => a * n)} (multAntiSymmetric proofEq2 proofEq)))))\n\n|||Proof that an irreducible greater than 1 is prime\nirreducibleIsPrime : {p : Nat} -> (isIrreducible p) -> (LT 1 p) -> (isPrime p)\nirreducibleIsPrime {p} proofIrreducible proofLT = (proofLT, proofPrime) where\n\tproofPrime : {a : Nat} -> {b : Nat} -> (isDivisible (a * b) p) -> Either (isDivisible a p) (isDivisible b p)\n\tproofPrime {a} {b} proofDiv =\n\t\tcase (irreducibleDividesOrCoprime a proofIrreducible) of\n\t\t(Left divA) => (Left divA)\n\t\t(Right coprimeA) => (Right (coprimeImpliesDiv proofDiv coprimeA))\n\n-----------------------------------------------------------------------------------------------\n\n|||Proof that the smallest divisor is unique\nminDivisorUnique : {n : Nat} -> {d1 : Nat} -> {d2 : Nat} ->\n\t\t\t (isMinDivisor n d1) -> (isMinDivisor n d2) -> (d1 = d2)\nminDivisorUnique {n} {d1} {d2} (ltLeft, (divLeft, minDivLeft)) (ltRight, (divRight, minDivRight)) = lteAntiSymmetric (minDivLeft ltRight divRight) (minDivRight ltLeft divLeft)\n\n|||Proof that the smallest divisor of an irreducible is the irreducible itself\nminDivOfIrreducible : {p : Nat} -> (LT 1 p) -> (isIrreducible p) -> (isMinDivisor p p)\nminDivOfIrreducible {p} proofLT proofIrred = (proofLT, ((divisionReflexive (ltOneNotZ proofLT)), minDiv)) where\n\tminDiv : {n : Nat} -> (LT 1 n) -> (isDivisible p n) -> (LTE p n)\n\tminDiv {n} nLT1 (k ** (proofEq, notZ)) =\n\t\tcase (proofIrred k n proofEq) of\n\t\t(Left kEq1) => lteSubstitutes lteRefl (sym (multOneLeftEqual proofEq kEq1)) Refl\n\t\t(Right nEq1) => void (succNotLTEzero (fromLteSucc (lteSubstitutes nLT1 Refl nEq1)))\n\n----------------------------------------------------------------------------------------------\n", "meta": {"hexsha": "adbdf612ff7d4f3a88d902806eb81628303e01f6", "size": 5241, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/NatPrimes.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/NatPrimes.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/NatPrimes.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": 50.8834951456, "max_line_length": 215, "alphanum_fraction": 0.6119061248, "num_tokens": 1732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.7061584737145362}} {"text": "module Specifications.Ring\n\nimport public Specifications.Group\n\n%default total\n%access public export\n\n||| specification\nisDistributativeL : Binop s -> Binop s -> Type\nisDistributativeL (+) (*) = (a,x,y : _) -> a * (x + y) = a * x + a * y\n\n||| specification\nisDistributativeR : Binop s -> Binop s -> Type\nisDistributativeR (+) (*) = (x,y,a : _) -> (x + y) * a = x * a + y * a\n\n||| composed specification\ndata PreRingSpec : Binop s -> Binop s -> Type where\n MkPreRing : isDistributativeL add mul -> isDistributativeR add mul ->\n isAbelian add -> PreRingSpec add mul\n\n||| forget\nabelian : PreRingSpec add _ -> isAbelian add\nabelian (MkPreRing _ _ a) = a\n\n||| composed specification\ndata RingSpec : Binop s -> s -> (s -> s) -> Binop s -> Type where\n MkRing : PreRingSpec add mul ->\n GroupSpec add zero neg ->\n isAssociative mul ->\n RingSpec add zero neg mul\n\n||| forget\ndistributativeL : RingSpec add _ _ mul -> isDistributativeL add mul\ndistributativeL (MkRing (MkPreRing l _ _) _ _) = l\n\n||| forget\ndistributativeR : RingSpec add _ _ mul -> isDistributativeR add mul\ndistributativeR (MkRing (MkPreRing _ r _) _ _) = r\n\n||| forget\ngroup : RingSpec add zero neg _ -> GroupSpec add zero neg\ngroup (MkRing preRing g _) = g\n\n||| forget\nabelianGroup : RingSpec add zero neg _ -> AbelianGroupSpec add zero neg\nabelianGroup (MkRing preRing g _) = MkAbelianGroup g (abelian preRing)\n\n||| forget\nplusAbelian : RingSpec add zero neg _ -> isAbelian add\nplusAbelian (MkRing preRing _ _) = abelian preRing\n\n||| composed specification\ndata UnitalRingSpec : Binop s -> s -> (s -> s) -> Binop s -> s -> Type where\n MkUnitalRing : RingSpec add zero neg mul ->\n isNeutralL mul one ->\n isNeutralR mul one ->\n UnitalRingSpec add zero neg mul one\n\n||| forget\nring : UnitalRingSpec add zero neg mul _ -> RingSpec add zero neg mul\nring (MkUnitalRing r _ _) = r\n\n||| forget\nmultiplicativeMonoid : UnitalRingSpec _ _ _ mul one -> MonoidSpec mul one\nmultiplicativeMonoid (MkUnitalRing (MkRing _ _ assoc) l r) = MkMonoid assoc l r\n", "meta": {"hexsha": "0df6a8df52aea71716b692200c68d57fce57318d", "size": 2025, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Specifications/Ring.idr", "max_stars_repo_name": "jeroennoels/verified-algebra", "max_stars_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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/Specifications/Ring.idr", "max_issues_repo_name": "jeroennoels/verified-algebra", "max_issues_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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/Specifications/Ring.idr", "max_forks_repo_name": "jeroennoels/verified-algebra", "max_forks_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "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.6818181818, "max_line_length": 79, "alphanum_fraction": 0.6933333333, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7057846718412839}} {"text": "module Stack\n\n%access export\n%default total\n\n-- | *Stack\ndata Stack : Nat -> Type -> Type where\n Nil : Stack Z a\n Cons : (x : a) -> (xs : Stack k a) -> Stack (S k) a\n\n%name Stack stack\n-- .end\n\n-- | *empty\nempty : Stack Z a\nempty = Nil\n-- .end\n\n-- | *head\nhead : Stack (S k) a -> a\nhead (Cons x _xs) = x\n-- .end\n\n-- | *tail\ntail : Stack (S k) a -> Stack k a\ntail (Cons _x xs) = xs\n-- .end\n\n-- | *cons\ncons : a -> Stack k a -> Stack (S k) a\ncons x Nil = Cons x Nil\ncons x (Cons y xs) = Cons x (Cons y xs)\n-- .end\n\n-- | *reverse\nreverse : Stack n a -> Stack n a\nreverse {n} stack = go empty stack\n where\n go : (acc : Stack k a) -> (curr : Stack j a) -> Stack (k + j) a\n go {k} acc [] = rewrite plusZeroRightNeutral k in acc\n go {k} {j = S j'} acc (Cons x xs) =\n rewrite sym $ plusSuccRightSucc k j' in go (cons x acc) xs\n-- .end\n", "meta": {"hexsha": "fdc395746b49c81714f5b71083224097a8dac4a8", "size": 851, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Structures/idr/Stack.idr", "max_stars_repo_name": "nomicflux/okasaki-visualization", "max_stars_repo_head_hexsha": "0b403cdbead2ea313dbc32994d08bb096ec7db8d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-08T06:22:30.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-17T02:41:43.000Z", "max_issues_repo_path": "src/Structures/idr/Stack.idr", "max_issues_repo_name": "nomicflux/okasaki-visualization", "max_issues_repo_head_hexsha": "0b403cdbead2ea313dbc32994d08bb096ec7db8d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-10-06T01:58:23.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-23T03:51:54.000Z", "max_forks_repo_path": "src/Structures/idr/Stack.idr", "max_forks_repo_name": "nomicflux/okasaki-visualization", "max_forks_repo_head_hexsha": "0b403cdbead2ea313dbc32994d08bb096ec7db8d", "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": 19.3409090909, "max_line_length": 67, "alphanum_fraction": 0.5558166863, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7052536730672244}} {"text": "module Equal\n\n-- Equality type\n\ndata Equal : x -> y -> Type where\n Reflexive : Equal a a\n\n-- Simple examples\n\nbool : Equal Bool Bool\nbool = ?bool\n\ntrue : Equal True True\ntrue = ?true\n\ntwo : Equal 2 (1 + 1)\ntwo = ?two\n\n-- Helpers\n\ntransitive : Equal a b -> Equal b c -> Equal a c\ntransitive ab bc = ?transitive\n\nsymmetric : Equal a b -> Equal b a\nsymmetric ab = ?symmetric\n\ncongruent : (f : t -> t) -> Equal a b -> Equal (f a) (f b)\ncongruent = ?congruent\n\n-- Stepping it up\n\nplusZero : (n : Nat) -> Equal (plus n Z) n\nplusZero n = ?plusZero\n\n-- Built-in equality\n\nplusZero' : (n : Nat) -> plus n Z = n\nplusZero' n = ?plusZero'\n", "meta": {"hexsha": "0ccc308d7c1bd8df7bbb32097fa6cc76556042c4", "size": 628, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "speakers/puffnfresh/Equal.idr", "max_stars_repo_name": "jamondouglas/lamdaconf2015", "max_stars_repo_head_hexsha": "8363906b10285f78448387ee067fc81542dc9ea1", "max_stars_repo_licenses": ["Artistic-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "speakers/puffnfresh/Equal.idr", "max_issues_repo_name": "jamondouglas/lamdaconf2015", "max_issues_repo_head_hexsha": "8363906b10285f78448387ee067fc81542dc9ea1", "max_issues_repo_licenses": ["Artistic-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": "speakers/puffnfresh/Equal.idr", "max_forks_repo_name": "jamondouglas/lamdaconf2015", "max_forks_repo_head_hexsha": "8363906b10285f78448387ee067fc81542dc9ea1", "max_forks_repo_licenses": ["Artistic-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": 16.1025641026, "max_line_length": 58, "alphanum_fraction": 0.6289808917, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9643214532237354, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.7049754765865988}} {"text": "module TransitivityOfDivisibility\n\ndata Divb : Nat -> Nat -> Type where\n DivbAx1 : a = k*b -> a `Divb` b\n\nlemma1 : a `Divb` b*c -> a `Divb` c\nlemma1 {a=a}{b=b}{c=c} (DivbAx1{k=k} aEqKBC) =\n let aEqKBC' = trans aEqKBC $ multAssociative k b c\n in DivbAx1 aEqKBC'\n\ntheorem : a `Divb` b -> b `Divb` c -> a `Divb` c\ntheorem aDivbB (DivbAx1{k=kb} bEqKbC) =\n let aDivbB' = replace bEqKbC aDivbB\n in lemma1 aDivbB'\n", "meta": {"hexsha": "47ba416a45f9ea8b4a215ef1544a0729a0a4d414", "size": 412, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "proofs/TransitivityOfDivisibility.idr", "max_stars_repo_name": "GoPavel/idris-proof", "max_stars_repo_head_hexsha": "36f30dc0133d7d968548c50b6aa76f6d6b382c59", "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": "proofs/TransitivityOfDivisibility.idr", "max_issues_repo_name": "GoPavel/idris-proof", "max_issues_repo_head_hexsha": "36f30dc0133d7d968548c50b6aa76f6d6b382c59", "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": "proofs/TransitivityOfDivisibility.idr", "max_forks_repo_name": "GoPavel/idris-proof", "max_forks_repo_head_hexsha": "36f30dc0133d7d968548c50b6aa76f6d6b382c59", "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": 27.4666666667, "max_line_length": 52, "alphanum_fraction": 0.645631068, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.7044871653868547}} {"text": "module Lemmas\n\nimport Data.Nat\nimport Data.Vect\nimport Decidable.Equality\nimport Injection\nimport Complex\n\n%default total\n\nexport\nlemmaplusOneRight : (n : Nat) -> n + 1 = S n\nlemmaplusOneRight n = rewrite plusCommutative n 1 in Refl\n\nexport\nlemmaPlusSRight : (n : Nat) -> (k : Nat) -> plus n (S k) = S (plus n k)\nlemmaPlusSRight Z k = Refl\nlemmaPlusSRight (S p) k = rewrite lemmaPlusSRight p k in Refl\n\n--LEMMAS ABOUT &&\n\nexport\nlemmaAndLeft : {a : Bool} -> {b : Bool} -> (a && b = True) -> (a = True)\nlemmaAndLeft {a = True} {b} p = Refl\nlemmaAndLeft {a = False} {b} p impossible\n\nexport\nlemmaAndRight : {a : Bool} -> {b : Bool} -> (a && b = True) -> (b = True)\nlemmaAndRight {a} {b = True} p = Refl\nlemmaAndRight {a = True} {b = False} p impossible\nlemmaAndRight {a = False} {b = False} p impossible\n\nexport\nlemmaAnd : {a : Bool} -> {b : Bool} -> (a = True) -> (b = True) -> (a && b = True)\nlemmaAnd {a = True} {b = True} p1 p2 = Refl\n\n\n\n\n\n--LEMMAS ABOUT <, >, =, /=, <=, >= : TRANSITIVITY\nexport\nlemmaTransLTELT : (i : Nat) -> (n : Nat) -> (p : Nat) -> (i <= n) = True -> (n < p) = True -> (i < p) = True\nlemmaTransLTELT 0 0 (S k) _ _ = Refl\nlemmaTransLTELT 0 (S k) (S j) _ _ = Refl\nlemmaTransLTELT (S k) (S n) (S p) prf1 prf2 = rewrite lemmaTransLTELT k n p prf1 prf2 in Refl\n\nexport\nlemmaTransLTLTE : (i : Nat) -> (n : Nat) -> (p : Nat) -> (i < n) = True -> (n <= p) = True -> (i < p) = True\nlemmaTransLTLTE 0 (S n) (S k) prf prf1 = Refl\nlemmaTransLTLTE (S k) (S n) (S p) prf prf1 = rewrite lemmaTransLTLTE k n p prf prf1 in Refl\n\nexport\nlemmaTransitivity : (i : Nat) -> (n : Nat) -> (p : Nat) -> (i < n) = True -> (n < p) = True -> (i < p) = True\nlemmaTransitivity 0 (S k) (S m) prf prf1 = Refl\nlemmaTransitivity (S k) (S m) (S l) prf prf1 = lemmaTransitivity k m l prf prf1\n\n\n\n\n\n\n\n\n--BASIC LEMMAS ABOUT <, >, =, /=, <=, >=\n\nexport\nlemmaLTERefl : (n : Nat) -> (n <= n) = True\nlemmaLTERefl 0 = Refl\nlemmaLTERefl (S k) = lemmaLTERefl k\n\nexport\nlemmaSymDiff : {x : Nat} -> {y : Nat} -> (x /= y) = True -> (y /= x) = True\nlemmaSymDiff {x = 0} {y = (S m)} _ = Refl\nlemmaSymDiff {x = (S k)} {y = 0} _ = Refl\nlemmaSymDiff {x = (S k)} {y = (S j)} prf = lemmaSymDiff {x = k} {y = j} prf\n\nexport\nlemma0LTSucc : (k : Nat) -> 0 < S k = True\nlemma0LTSucc k = Refl\n\nexport\nlemma1LTESucc : (k : Nat) -> 1 <= S k = True\nlemma1LTESucc 0 = Refl\nlemma1LTESucc (S k) = Refl\n\nexport\nlemmaLTEAddR : (n : Nat) -> (p : Nat) -> n <= (n + p) = True\nlemmaLTEAddR Z 0 = Refl\nlemmaLTEAddR Z (S k) = Refl\nlemmaLTEAddR (S n) p = lemmaLTEAddR n p\n\nexport\nlemmaLTEAddL : (n : Nat) -> (p : Nat) -> p <= (n + p) = True\nlemmaLTEAddL n p = rewrite plusCommutative n p in lemmaLTEAddR p n\n\n\nexport\nlemmaDiffSuccPlus : (k : Nat) -> (p : Nat) -> (k /= S (p + k)) = True\nlemmaDiffSuccPlus 0 p = Refl\nlemmaDiffSuccPlus (S k) j = rewrite sym $ plusSuccRightSucc j k in lemmaDiffSuccPlus k j\n\nexport\nlemmaLTSuccPlus : (k : Nat) -> (p : Nat) -> (k < S (k + p)) = True\nlemmaLTSuccPlus 0 p = Refl\nlemmaLTSuccPlus (S k) j = lemmaLTSuccPlus k j\n\nexport\nlemmaLTSucc : (k : Nat) -> (k < S k) = True\nlemmaLTSucc 0 = Refl\nlemmaLTSucc (S k) = lemmaLTSucc k\n\nexport\nlemmakLTSk : (k : Nat) -> (S k) < S (k + 1) = True\nlemmakLTSk k = rewrite lemmaplusOneRight k in lemmaLTSucc k\n\nexport\nlemmaLTSuccLT : (k : Nat) -> (n : Nat) -> (S k) < n = True -> k < n = True\nlemmaLTSuccLT k 0 prf impossible\nlemmaLTSuccLT 0 (S j) prf = Refl\nlemmaLTSuccLT (S k) (S j) prf = lemmaLTSuccLT k j prf\n\nexport\nlemmaLTESuccLT : (k : Nat) -> (n : Nat) -> (S k) <= n = True -> k < n = True\nlemmaLTESuccLT k 0 prf impossible\nlemmaLTESuccLT 0 (S j) prf = Refl\nlemmaLTESuccLT (S k) (S j) prf = lemmaLTESuccLT k j prf\n\n\nexport\nlemmaLTESuccLTE : (k : Nat) -> (n : Nat) -> (S k) <= n = True -> k <= n = True\nlemmaLTESuccLTE k 0 prf impossible\nlemmaLTESuccLTE 0 (S j) prf = Refl\nlemmaLTESuccLTE (S k) (S j) prf = lemmaLTESuccLTE k j prf\n\nexport \nlemmaSuccsLT : (k : Nat) -> (n : Nat) -> (S k) < (S n) = True -> k < n = True\nlemmaSuccsLT k n prf = prf\n\nexport\nlemmaCompLT0 : (n : Nat) -> (j : Nat) -> {auto prf : j < n = True} -> 0 < n = True\nlemmaCompLT0 n 0 {prf} = prf\nlemmaCompLT0 (S p) (S k) = Refl\n\n\n\n\n--LEMMAS USED BY THE APPLY FUNCTION\nexport\nindexInjectiveVect : (j : Nat) -> (n : Nat) -> (v : Vect i Nat) ->\n {prf : isInjective n v = True} -> {prf1 : j < i = True} ->\n (index j v < n) = True\nindexInjectiveVect Z n (x :: xs) {prf} = lemmaAndLeft (lemmaAndLeft prf)\nindexInjectiveVect (S k) n (x :: xs) {prf} =\n indexInjectiveVect k n xs {prf = lemmaAnd (lemmaAndRight (lemmaAndLeft prf)) (lemmaAndRight (lemmaAndRight prf))}\n\n\nexport\ndifferent' : (x : Nat) -> (m : Nat) -> (xs : Vect i Nat) ->\n {prf1 : m < i = True} -> {prf2 : isDifferent x xs = True} ->\n (x /= index m xs) = True\ndifferent' x 0 (y :: xs) = lemmaAndLeft prf2\ndifferent' x (S k) (y :: xs) =\n different' x k xs {prf1} {prf2 = lemmaAndRight prf2}\n\nprivate\ndifferent'' : (x : Nat) -> (m : Nat) -> (xs : Vect i Nat) ->\n {prf1 : m < i = True} -> {prf2 : isDifferent x xs = True} ->\n (index m xs /= x) = True\ndifferent'' x m xs = lemmaSymDiff (different' x m xs {prf1} {prf2})\n\n\nexport\ndifferentIndexInjectiveVect : (c : Nat) -> (t : Nat) -> (n : Nat) -> {prf1 : (c /= t) = True} ->\n (v : Vect i Nat) -> {prf2 : isInjective n v = True} ->\n {prf3 : c < i = True} -> {prf4 : t < i = True} ->\n (index c v /= index t v) = True\ndifferentIndexInjectiveVect 0 (S m) n (x :: xs) =\n different' x m xs {prf1 = prf4} {prf2 = lemmaAndLeft (lemmaAndRight prf2)}\ndifferentIndexInjectiveVect (S k) 0 n (x :: xs) =\n different'' x k xs {prf1 = prf3} {prf2 = lemmaAndLeft (lemmaAndRight prf2)}\ndifferentIndexInjectiveVect (S k) (S j) n (x :: xs) =\n let p2 = lemmaAnd (lemmaAndRight (lemmaAndLeft prf2)) (lemmaAndRight (lemmaAndRight prf2)) in\n differentIndexInjectiveVect k j n {prf1} xs {prf2 = p2} {prf3} {prf4}\n\n\n\n\n\n\n\n--LEMMAS USED BY THE CONTROLLED FUNCTION\n\nexport\nlemmaControlledInj : (n : Nat) -> (j : Nat) -> {auto prf : j < n = True} -> isInjective (S n) [0, S j] = True\nlemmaControlledInj 0 0 impossible\nlemmaControlledInj 0 (S k) {prf} = prf\nlemmaControlledInj (S k) 0 = Refl\nlemmaControlledInj (S p) (S k) {prf} = lemmaControlledInj p k {prf} \n\nexport\nlemmaControlledInj2 : (n : Nat) -> (c : Nat) -> (t : Nat) ->\n {auto prf1 : (c < n) = True} -> {auto prf2 : (t < n) = True} -> {auto prf3 : (c /= t) = True} ->\n isInjective (S n) [0, S c, S t] = True\nlemmaControlledInj2 0 0 t impossible\nlemmaControlledInj2 0 (S k) t {prf1} = prf1\nlemmaControlledInj2 (S k) 0 0 {prf3} = prf3\nlemmaControlledInj2 (S k) 0 (S j) = lemmaAnd (lemmaAnd prf2 Refl) Refl\nlemmaControlledInj2 (S k) (S j) 0 = lemmaAnd (lemmaAnd prf1 Refl) Refl\nlemmaControlledInj2 (S k) (S j) (S i) = lemmaControlledInj2 k j i {prf1} {prf2} {prf3}\n\n\n\n\n\n\n--LEMMAS USED BY THE TENSOR FUNCTION\nexport\nisDiffRangeVect : (k : Nat) -> (length : Nat) -> (p : Nat) -> isDifferent k (rangeVect (S (p + k)) length) = True\nisDiffRangeVect k 0 _ = Refl\nisDiffRangeVect k (S j) p = \n lemmaAnd (lemmaDiffSuccPlus k p) (isDiffRangeVect k j (S p))\n\nexport\nallDiffRangeVect : (startIndex : Nat) -> (length : Nat) -> allDifferent (rangeVect startIndex length) = True\nallDiffRangeVect startIndex 0 = Refl\nallDiffRangeVect startIndex (S k) = \n let p1 = isDiffRangeVect startIndex k 0\n in lemmaAnd p1 (allDiffRangeVect (S startIndex) k)\n\nexport\nallSmallerRangeVect : (startIndex : Nat) -> (length : Nat) -> allSmaller (rangeVect startIndex length) (startIndex + length) = True\nallSmallerRangeVect startIndex 0 = Refl\nallSmallerRangeVect startIndex (S k) = \n rewrite sym $ plusSuccRightSucc startIndex k in \n lemmaAnd (lemmaLTSuccPlus startIndex k) (allSmallerRangeVect (S startIndex) k) \n\nexport\nallSmallerPlus : (n : Nat) -> (p : Nat) -> (v : Vect k Nat) -> allSmaller v n = True -> allSmaller v (n + p) = True\nallSmallerPlus n p [] prf = Refl\nallSmallerPlus n p (x :: xs) prf = \n let p1 = lemmaAndLeft prf\n p2 = lemmaTransLTLTE x n (n + p) p1 (lemmaLTEAddR n p)\n p3 = lemmaAndRight prf\n in lemmaAnd p2 (allSmallerPlus n p xs p3)\n\n", "meta": {"hexsha": "f309a45a34df83f9be2b8c23a38162cb86f14a09", "size": 8216, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Lemmas.idr", "max_stars_repo_name": "zamdzhiev/Qimaera", "max_stars_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-08-24T14:36:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T00:36:11.000Z", "max_issues_repo_path": "Lemmas.idr", "max_issues_repo_name": "zamdzhiev/Qimaera", "max_issues_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "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": "Lemmas.idr", "max_forks_repo_name": "zamdzhiev/Qimaera", "max_forks_repo_head_hexsha": "3823cd1d103dd07ca0fb6fe3be08b535e56e3b87", "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.2631578947, "max_line_length": 131, "alphanum_fraction": 0.6108812074, "num_tokens": 3172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7043422553129591}} {"text": "module IntegerGroupTheory\n\n\n\nplusAssociativeBigInt : (left : Integer) ->\n (centre : Integer) ->\n (right : Integer) ->\n left + (centre + right) = left + centre + right\nplusAssociativeBigInt = believe_me \"Integer addition is associative.\"\n\n\n\nrdivBigInt : (x : Integer) -> (y : Integer) -> (x+y)-y = x\nrdivBigInt x y = believe_me \"Integer addition is right divisible.\"\n\nunRDivBigInt : (x : Integer) -> (y : Integer) -> (x-y)+y = x\nunRDivBigInt = believe_me \"Integer (right) subtraction is right divisible.\"\n\nlcancBigInt: (left1 : Integer) -> (left2 : Integer) -> (right : Integer) -> (left1+right = left2+right) -> (left1 = left2)\nlcancBigInt left1 left2 right = ?lcancBigIntpr\n\nlcancBigIntpr = proof\n intro\n intro\n intro\n intro prsum\n rewrite sym (sym $ rdivBigInt left1 right)\n rewrite sym (sym $ rdivBigInt left2 right)\n exact cong {f=\\x => x-right} prsum\n\n\n\nplusRightIdBigInt : (x : Integer) -> x = x+0\n-- plusRightIdBigInt x = believe_me \"assume x=x+0\"\nplusRightIdBigInt x = ?plusRightIdBigIntPr\n\nplusRightIdBigIntPr = proof\n intro\n claim addZeroTwice (x+0=(x+0)+0)\n unfocus\n exact lcancBigInt x (x+0) 0 addZeroTwice\n exact trans Refl (plusAssociativeBigInt x 0 0)\n\n\n\nnegSumImedBigInt : (x : Integer) -> (y : Integer) -> (x-y)+y = (x+(negate y))+y\nnegSumImedBigInt = proof\n intros\n rewrite sym (unRDivBigInt x y)\n rewrite sym (sym $ plusAssociativeBigInt x (negate y) y)\n rewrite sym (unRDivBigInt 0 y)\n rewrite sym (plusRightIdBigInt x)\n trivial\n\ndifferenceAsSum : (x : Integer) -> (y : Integer) -> x-y = x+(negate y)\ndifferenceAsSum x y = ?differenceAsSumPr\n\ndifferenceAsSumPr = proof\n intros\n claim pr0 ((x-y)+y = (x+(negate y))+y)\n unfocus\n let prf1 = replace pr0 {P= \\t => t-y=x-y}\n claim prf1Arg (((x - y) + y)-y = x - y)\n unfocus\n rewrite sym (sym $ prf1 prf1Arg)\n rewrite sym ( rdivBigInt (x+(0-y)) y )\n exact Refl\n claim prmainReAssoc (x = x + negate y + y)\n unfocus\n exact trans (unRDivBigInt x y) prmainReAssoc\n exact rdivBigInt (x-y) y\n claim prmain (x = x + (negate y + y))\n unfocus\n exact trans prmain (plusAssociativeBigInt x (negate y) y)\n claim prmainPlusZ (x+0 = x+(negate y + y))\n unfocus\n exact trans (plusRightIdBigInt x) prmainPlusZ\n exact cong (sym $ unRDivBigInt 0 y)\n\n\n\nplusCommutativeBigInt : (left : Integer) ->\n (right : Integer) ->\n left + right = right + left\nplusCommutativeBigInt = believe_me \"Integer addition is commutative.\"\n\n\n\nsubtractionexchange : (x : Integer) -> (y : Integer) -> (z : Integer)\n\t-> (x-y)+z = x+(z-y)\nsubtractionexchange = ?subtractionexchangepr\n\nsubtractionexchangepr = proof\n intros\n rewrite sym (differenceAsSum x y)\n rewrite sym (sym $ plusAssociativeBigInt x (0-y) z)\n rewrite sym (plusCommutativeBigInt (0-y) z)\n rewrite sym (sym $ differenceAsSum z y)\n trivial\n", "meta": {"hexsha": "3680e6531d20ce0effdb304b98716cedc1dcb296", "size": 2853, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_Archive/OldGCDAttempts/IntegerGroupTheory.idr", "max_stars_repo_name": "runKleisli/verified-integer-gaussian-elimination", "max_stars_repo_head_hexsha": "cbaed9c2d8d77db25bd13c8c53beea8ac320855c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2016-07-12T15:25:52.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T05:43:48.000Z", "max_issues_repo_path": "_Archive/OldGCDAttempts/IntegerGroupTheory.idr", "max_issues_repo_name": "runKleisli/verified-integer-gaussian-elimination", "max_issues_repo_head_hexsha": "cbaed9c2d8d77db25bd13c8c53beea8ac320855c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 16, "max_issues_repo_issues_event_min_datetime": "2016-06-10T02:31:24.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-07T16:16:50.000Z", "max_forks_repo_path": "_Archive/OldGCDAttempts/IntegerGroupTheory.idr", "max_forks_repo_name": "runKleisli/verified-integer-gaussian-elimination", "max_forks_repo_head_hexsha": "cbaed9c2d8d77db25bd13c8c53beea8ac320855c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.53, "max_line_length": 122, "alphanum_fraction": 0.6645636172, "num_tokens": 908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7042257502888105}} {"text": "> module SequentialDecisionProblems.applications.LowHigh\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Sigma.Sigma\n\n> %default total\n> %auto_implicits off\n> %access public export\n\n\n* Low / High emissions:\n\n> data LowHigh = Low | High \n\n\n* |LowHigh| is finite and non-empty:\n\n> to : LowHigh -> Fin 2\n> to Low = FZ\n> to High = FS FZ\n\n> from : Fin 2 -> LowHigh\n> from FZ = Low\n> from (FS FZ) = High\n> from (FS (FS k)) = absurd k\n\n> toFrom : (k : Fin 2) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS FZ) = Refl\n> toFrom (FS (FS k)) = absurd k\n\n> fromTo : (a : LowHigh) -> from (to a) = a\n> fromTo Low = Refl\n> fromTo High = Refl\n\n> ||| \n> finiteLowHigh : Finite LowHigh\n> finiteLowHigh = MkSigma 2 (MkIso to from toFrom fromTo)\n\n> |||\n> cardNotZLowHigh : CardNotZ finiteLowHigh\n> cardNotZLowHigh = cardNotZLemma finiteLowHigh Low\n\n\n* |LowHigh| is in |DecEq|:\n\n> lowNotHigh : Low = High -> Void\n> lowNotHigh Refl impossible\n\n> implementation [DecEqLowHigh] DecEq LowHigh where\n> decEq Low Low = Yes Refl\n> decEq Low High = No lowNotHigh\n> decEq High Low = No (negEqSym lowNotHigh)\n> decEq High High = Yes Refl\n\n\n* |LowHigh| is in |Eq|:\n\n> implementation Eq LowHigh where\n> (==) Low Low = True\n> (==) Low High = False\n> (==) High Low = False\n> (==) High High = True\n\n\n> {-\n\n> ---}\n\n\n \n", "meta": {"hexsha": "68cbda0e05bbc8c516b8802722cad13097a82a77", "size": 1462, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/LowHigh.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/applications/LowHigh.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "SequentialDecisionProblems/applications/LowHigh.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.987012987, "max_line_length": 57, "alphanum_fraction": 0.6196990424, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7041657833949486}} {"text": "data Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\nEq Shape where\n (==) (Triangle x z) (Triangle x' z') = x == x' && z == z'\n (==) (Rectangle x z) (Rectangle x' z') = x == x' && z == z'\n (==) (Circle x) (Circle x') = x == x'\n (==) _ _ = False\n\nOrd Shape where\n compare x y = compare (area x) (area y)\n", "meta": {"hexsha": "7a50d58cd2a9c5f37ac3a3a49630a0b26347f8be", "size": 531, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-07/shapes.idr", "max_stars_repo_name": "tekerson/type-driven-development", "max_stars_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-23T04:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-23T04:46:42.000Z", "max_issues_repo_path": "Chapter-07/shapes.idr", "max_issues_repo_name": "tekerson/type-driven-development", "max_issues_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": "Chapter-07/shapes.idr", "max_forks_repo_name": "tekerson/type-driven-development", "max_forks_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "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": 29.5, "max_line_length": 63, "alphanum_fraction": 0.5687382298, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133548753619, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.7040770755728988}} {"text": "module Algebra.Ring\n\nimport Syntax.PreorderReasoning\n\n%default total\n\npublic export %inline %tcinline\nneg : Neg a => a -> a\nneg = negate\n\n||| This interface is a witness that for a (primitive)\n||| integral type `a` the axioms of a commutative ring hold:\n|||\n||| 1. `a` is an abelian group under addition:\n||| 1. `+` is associative: `k + (m + n) = (k + m) + n` for all `k,m,n : a`.\n||| 2. `+` is commutative: `m + n = n + m` for all `m,n : a`.\n||| 3. 0 is the additive identity: `n + 0 = n` for all `n : a`.\n||| 4. `neg n` is the additive inverse of `n`:\n||| `n + neg n = 0` for all `n : a`.\n|||\n||| 2. `a` is a commutative monoid under multiplication:\n||| 1. `*` is associative: `k * (m * n) = (k * m) * n` for all `k,m,n : a`.\n||| 2. `*` is commutative: `m * n = n * m` for all `m,n : a`.\n||| 3. 1 is the multiplicative identity: `n * 1 = n` for all `n : a`.\n|||\n||| 3. Multiplication is distributive with respect to addition:\n||| `k * (m + n) = (k * m) + (k * n)` for all `k,m,n : a`.\n|||\n||| 4. Subtraction syntax: `m - n = m + neg n` for all `m,n : a`.\npublic export\ninterface Neg a => Ring a where\n ||| Addition is associative.\n 0 plusAssociative : {k,m,n : a} -> k + (m + n) === (k + m) + n\n\n ||| Addition is commutative.\n 0 plusCommutative : {m,n : a} -> m + n === n + m\n\n ||| 0 is the additive identity.\n 0 plusZeroLeftNeutral : {n : a} -> 0 + n === n\n\n ||| `neg n` is the additive inverse of `n`.\n 0 plusNegLeftZero : {n : a} -> neg n + n === 0\n\n ||| Multiplication is associative.\n 0 multAssociative : {k,m,n : a} -> k * (m * n) === (k * m) * n\n\n ||| Multiplication is commutative.\n 0 multCommutative : {m,n : a} -> m * n === n * m\n\n ||| 1 is the multiplicative identity.\n 0 multOneLeftNeutral : {n : a} -> 1 * n === n\n\n ||| Multiplication is distributive with respect to addition.\n 0 leftDistributive : {k,m,n : a} -> k * (m + n) === (k * m) + (k * n)\n\n ||| `m - n` is just \"syntactic sugar\" for `m + neg n`.\n 0 minusIsPlusNeg : {m,n : a} -> m - n === m + neg n\n\n--------------------------------------------------------------------------------\n-- Proofs on Addition\n--------------------------------------------------------------------------------\n\n||| `n + 0 === n` for all `n : a`.\nexport\n0 plusZeroRightNeutral : Ring a => {n : a} -> n + 0 === n\nplusZeroRightNeutral =\n Calc $\n |~ n + 0\n ~~ 0 + n ... plusCommutative\n ~~ n ... plusZeroLeftNeutral\n\n||| `n + neg n === 0` for all `n : a`.\nexport\n0 plusNegRightZero : Ring a => {n : a} -> n + neg n === 0\nplusNegRightZero =\n Calc $\n |~ n + neg n\n ~~ neg n + n ... plusCommutative\n ~~ 0 ... plusNegLeftZero\n\n||| `n - n === 0` for all `n : a`.\nexport\n0 minusSelfZero : Ring a => {n : a} -> n - n === 0\nminusSelfZero =\n Calc $\n |~ n - n\n ~~ n + neg n ... minusIsPlusNeg\n ~~ 0 ... plusNegRightZero\n\n||| Law of associativity for subtraction.\nexport\n0 plusMinusAssociative : Ring a\n => {k,m,n : a}\n -> k + (m - n) === (k + m) - n\nplusMinusAssociative =\n Calc $\n |~ k + (m - n)\n ~~ k + (m + neg n) ..> cong (k+) minusIsPlusNeg\n ~~ (k + m) + neg n ..> plusAssociative\n ~~ (k + m) - n ..< minusIsPlusNeg\n\n||| We can solve equations involving addition.\nexport\n0 solvePlusRight : Ring a\n => {k,m,n : a}\n -> k + m === n\n -> k === n - m\nsolvePlusRight prf =\n Calc $\n |~ k\n ~~ k + 0 ..< plusZeroRightNeutral\n ~~ k + (m - m) ..< cong (k +) minusSelfZero\n ~~ (k + m) - m ..> plusMinusAssociative\n ~~ n - m ..> cong (\\x => x - m) prf\n\n||| We can solve equations involving addition.\nexport\n0 solvePlusLeft : Ring a\n => {k,m,n : a}\n -> k + m === n\n -> m === n - k\nsolvePlusLeft prf =\n solvePlusRight $ Calc $\n |~ m + k\n ~~ k + m ... plusCommutative\n ~~ n ... prf\n\n||| Addition from the left is injective.\nexport\n0 plusLeftInjective : Ring a => {k,m,n : a} -> k + n === m + n -> k === m\nplusLeftInjective prf =\n Calc $\n |~ k\n ~~ (m + n) - n ..> solvePlusRight prf\n ~~ m + (n - n) ..< plusMinusAssociative\n ~~ m + 0 ..> cong (m +) minusSelfZero\n ~~ m ..> plusZeroRightNeutral\n\n||| Addition from the right is injective.\nexport\n0 plusRightInjective : Ring a => {k,m,n : a} -> n + k === n + m -> k === m\nplusRightInjective prf =\n plusLeftInjective $\n Calc $\n |~ k + n\n ~~ n + k ... plusCommutative\n ~~ n + m ... prf\n ~~ m + n ... plusCommutative\n\n||| From `m + n === 0` follows that `n` is the\n||| additive inverse of `m`.\nexport\n0 solvePlusNegRight : Ring a\n => {m,n : a}\n -> m + n === 0\n -> n === neg m\nsolvePlusNegRight prf =\n plusRightInjective (trans prf (sym plusNegRightZero))\n\n||| From `m + n === 0` follows that `m` is the\n||| additive inverse of `n`.\nexport\n0 solvePlusNegLeft : Ring a\n => {m,n : a}\n -> m + n === 0\n -> m === neg n\nsolvePlusNegLeft prf =\n solvePlusNegRight $ Calc $\n |~ n + m\n ~~ m + n ... plusCommutative\n ~~ 0 ... prf\n\n||| From `m + n === m` follows `n === 0`.\nexport\n0 solvePlusZeroRight : Ring a => {m,n : a} -> m + n === m -> n === 0\nsolvePlusZeroRight prf =\n Calc $\n |~ n\n ~~ m - m ... solvePlusLeft prf\n ~~ 0 ... minusSelfZero\n\n||| From `n + m === m` follows `n === 0`.\nexport\n0 solvePlusZeroLeft : Ring a => {m,n : a} -> n + m === m -> n === 0\nsolvePlusZeroLeft prf =\n solvePlusZeroRight $ Calc $\n |~ m + n\n ~~ n + m ... plusCommutative\n ~~ m ... prf\n\n||| Negation is involutory.\nexport\n0 negInvolutory : Ring a => {n : a} -> neg (neg n) === n\nnegInvolutory = sym $ solvePlusNegLeft plusNegRightZero\n\n||| From `neg n === 0` follows `n === 0`.\nexport\n0 solveNegZero : Ring a => {n : a} -> neg n === 0 -> n === 0\nsolveNegZero prf =\n Calc $\n |~ n\n ~~ n + 0 ..< plusZeroRightNeutral\n ~~ n + neg n ..< cong (n +) prf\n ~~ 0 ..> plusNegRightZero\n\n||| `neg 0 === 0`\nexport\n0 negZero : Ring a => neg {a} 0 === 0\nnegZero = solveNegZero negInvolutory\n\nexport\n0 negDistributes : Ring a => {m,n : a} -> neg (m + n) === neg m + neg n\nnegDistributes =\n sym $ solvePlusNegLeft $ Calc $\n |~ (neg m + neg n) + (m + n)\n ~~ (neg m + neg n) + (n + m) ... cong ((neg m + neg n) +) plusCommutative\n ~~ ((neg m + neg n) + n) + m ... plusAssociative\n ~~ (neg m + (neg n + n)) + m ..< cong (+m) plusAssociative\n ~~ (neg m + 0) + m ... cong (\\x => neg m + x + m) plusNegLeftZero\n ~~ neg m + m ... cong (+m) plusZeroRightNeutral\n ~~ 0 ... plusNegLeftZero\n\n--------------------------------------------------------------------------------\n-- Proofs on Multiplication\n--------------------------------------------------------------------------------\n\n||| `n * 1 === n` for all `n : a`.\nexport\n0 multOneRightNeutral : Ring a => {n : a} -> n * 1 === n\nmultOneRightNeutral =\n Calc $\n |~ n * 1\n ~~ 1 * n ... multCommutative\n ~~ n ... multOneLeftNeutral\n\n||| Zero is an absorbing element of multiplication.\nexport\n0 multZeroRightAbsorbs : Ring a => {n : a} -> n * 0 === 0\nmultZeroRightAbsorbs =\n solvePlusZeroRight $ Calc $\n |~ (n * 0) + (n * 0)\n ~~ n * (0 + 0) ..< leftDistributive\n ~~ n * 0 ..> cong (n *) plusZeroLeftNeutral\n\n\n||| Zero is an absorbing element of multiplication.\nexport\n0 multZeroLeftAbsorbs : Ring a => {n : a} -> 0 * n === 0\nmultZeroLeftAbsorbs =\n Calc $\n |~ 0 * n\n ~~ n * 0 ... multCommutative\n ~~ 0 ... multZeroRightAbsorbs\n\n||| Zero is an absorbing element of multiplication.\nexport\n0 multZeroAbsorbs : Ring a\n => {m,n : a}\n -> Either (m === 0) (n === 0)\n -> m * n === 0\nmultZeroAbsorbs (Left rfl) =\n Calc $\n |~ m * n\n ~~ 0 * n ... cong (*n) rfl\n ~~ 0 ... multZeroLeftAbsorbs\n\nmultZeroAbsorbs (Right rfl) =\n Calc $\n |~ m * n\n ~~ m * 0 ... cong (m*) rfl\n ~~ 0 ... multZeroRightAbsorbs\n\n||| `m * (-n) = - (m * n)`.\nexport\n0 multNegRight : Ring a => {m,n : a} -> m * neg n === neg (m * n)\nmultNegRight =\n solvePlusNegRight $ Calc $\n |~ m * n + m * neg n\n ~~ m * (n + neg n) ..< leftDistributive\n ~~ m * 0 ..> cong (m *) plusNegRightZero\n ~~ 0 ..> multZeroRightAbsorbs\n\n||| `- (m * (-n)) = m * n`.\nexport\n0 negMultNegRight : Ring a => {m,n : a} -> neg (m * neg n) === m * n\nnegMultNegRight =\n Calc $\n |~ neg (m * neg n)\n ~~ neg (neg (m * n)) ... cong neg multNegRight\n ~~ m * n ... negInvolutory\n\n||| `(- m) * n = - (m * n)`.\nexport\n0 multNegLeft : Ring a => {m,n : a} -> neg m * n === neg (m * n)\nmultNegLeft =\n Calc $\n |~ neg m * n\n ~~ n * neg m ... multCommutative\n ~~ neg (n * m) ... multNegRight\n ~~ neg (m * n) ... cong neg multCommutative\n\n||| `- ((-m) * n) = m * n`.\nexport\n0 negMultNegLeft : Ring a => {m,n : a} -> neg (neg m * n) === m * n\nnegMultNegLeft =\n Calc $\n |~ neg (neg m * n)\n ~~ neg (neg (m * n)) ... cong neg multNegLeft\n ~~ m * n ... negInvolutory\n\n||| Multiplication with `(-1)` is negation.\nexport\n0 multMinusOneRight : Ring a => {n : a} -> n * neg 1 === neg n\nmultMinusOneRight =\n Calc $\n |~ n * neg 1\n ~~ neg (n * 1) ... multNegRight\n ~~ neg n ... cong neg multOneRightNeutral\n\n||| Multiplication with `(-1)` is negation.\nexport\n0 multMinusOneLeft : Ring a => {n : a} -> neg 1 * n === neg n\nmultMinusOneLeft =\n Calc $\n |~ neg 1 * n\n ~~ neg (1 * n) ... multNegLeft\n ~~ neg n ... cong neg multOneLeftNeutral\n\n||| Multiplication of two negations removes negations.\nexport\n0 negMultNeg : Ring a => {m,n : a} -> neg m * neg n === m * n\nnegMultNeg =\n Calc $\n |~ neg m * neg n\n ~~ neg (m * neg n) ... multNegLeft\n ~~ neg (neg (m * n)) ... cong neg multNegRight\n ~~ m * n ... negInvolutory\n\n||| Multiplication is distributive with respect to addition.\nexport\n0 rightDistributive : Ring a\n => {k,m,n : a}\n -> (m + n) * k === m * k + n * k\nrightDistributive =\n Calc $\n |~ (m + n) * k\n ~~ k * (m + n) ... multCommutative\n ~~ (k * m) + (k * n) ... leftDistributive\n ~~ m * k + k * n ... cong (+ k * n) multCommutative\n ~~ m * k + n * k ... cong (m * k +) multCommutative\n\nexport\n0 multPlusSelf : Ring a => {m,n : a} -> m * n + m === m * (n + 1)\nmultPlusSelf =\n Calc $\n |~ m * n + m\n ~~ m * n + m * 1 ..< cong (m*n +) multOneRightNeutral\n ~~ m * (n + 1) ..< leftDistributive\n\n--------------------------------------------------------------------------------\n-- Implementations\n--------------------------------------------------------------------------------\n\nunsafeRefl : a === b\nunsafeRefl = believe_me (Refl {x = a})\n\nexport\nRing Bits8 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Bits16 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Bits32 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Bits64 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Int8 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Int16 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Int32 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Int64 where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Int where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n\nexport\nRing Integer where\n plusAssociative = unsafeRefl\n plusCommutative = unsafeRefl\n plusZeroLeftNeutral = unsafeRefl\n plusNegLeftZero = unsafeRefl\n multAssociative = unsafeRefl\n multCommutative = unsafeRefl\n multOneLeftNeutral = unsafeRefl\n leftDistributive = unsafeRefl\n minusIsPlusNeg = unsafeRefl\n", "meta": {"hexsha": "c1bb7a5629dedd70e70f9b4fd8b67b837b7c7d39", "size": 14301, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Ring.idr", "max_stars_repo_name": "stefan-hoeck/idris2-prim", "max_stars_repo_head_hexsha": "d342072f3b30f7930221bab620a836e0e67c2374", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2022-03-13T22:37:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T22:22:30.000Z", "max_issues_repo_path": "src/Algebra/Ring.idr", "max_issues_repo_name": "stefan-hoeck/idris2-prim", "max_issues_repo_head_hexsha": "d342072f3b30f7930221bab620a836e0e67c2374", "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/Algebra/Ring.idr", "max_forks_repo_name": "stefan-hoeck/idris2-prim", "max_forks_repo_head_hexsha": "d342072f3b30f7930221bab620a836e0e67c2374", "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": 29.4259259259, "max_line_length": 80, "alphanum_fraction": 0.5417802951, "num_tokens": 4694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.703866346180944}} {"text": "module Data.Vect.Sort\n\nimport Data.Vect\nimport Data.Nat.Views\n\nmutual\n sortBySplit : (n : Nat) -> (a -> a -> Ordering) -> Vect n a -> Vect n a\n sortBySplit Z cmp [] = []\n sortBySplit (S Z) cmp [x] = [x]\n sortBySplit n cmp xs with (half n)\n sortBySplit (k + k) cmp xs | HalfEven k = sortByMerge k k cmp xs\n sortBySplit (S (k + k)) cmp xs | HalfOdd k = sortByMerge (S k) k cmp xs\n\n sortByMerge : (n : Nat) -> (m : Nat) -> (a -> a -> Ordering) -> Vect (n + m) a -> Vect (n + m) a\n sortByMerge n m cmp xs =\n let (left, right) = splitAt n xs in\n mergeBy cmp\n (sortBySplit n cmp (assert_smaller xs left))\n (sortBySplit m cmp (assert_smaller xs right))\n\n||| Merge sort implementation for Vect n a\nexport total\nsortBy : {n : Nat} -> (cmp : a -> a -> Ordering) -> (xs : Vect n a) -> Vect n a\nsortBy {n} cmp xs = sortBySplit n cmp xs\n\nexport total\nsort : Ord a => {n : Nat} -> Vect n a -> Vect n a\nsort = sortBy compare\n", "meta": {"hexsha": "a011d2d01854e6817e4e8c3658c3584555a3ef10", "size": 948, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/Vect/Sort.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/contrib/Data/Vect/Sort.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": "idris2/libs/contrib/Data/Vect/Sort.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "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": 32.6896551724, "max_line_length": 98, "alphanum_fraction": 0.6012658228, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7038338981558018}} {"text": "module Proof.DeMorgan\n\n%access public export\n%default total\n\nsyntax \"($\" [x] \")\" = \\f => f x\n\ninfixl 8 .:\n(.:) : (c -> d) -> (a -> b -> c) -> (a -> b -> d)\n(.:) = (.) . (.)\n\nusing (P: Type, Q : Type, R : Type)\n\n ||| https://proofwiki.org/wiki/Rule_of_Addition/Proof_Rule#Proof_Rule\n add1 : P -> Either P Q\n add1 = Left\n\n add2 : Q -> Either P Q\n add2 = Right\n\n ||| https://proofwiki.org/wiki/Double_Negation/Double_Negation_Introduction/Proof_Rule\n doubleNegation : P -> Not (Not P)\n doubleNegation = flip id\n\n -- doubleNegation' : Not (Not P) -> P\n -- doubleNegation' = believe_me P\n\n idempotenceAnd : P -> (P, P)\n idempotenceAnd p = (p, p)\n\n idempotenceAnd' : (P, P) -> P\n idempotenceAnd' = fst\n\n idempotenceOr : P -> Either P P\n idempotenceOr = Right\n\n idempotenceOr' : Either P P -> P\n idempotenceOr' = fromEither\n\n contrapositive : (P -> Q) -> (Not Q -> Not P)\n contrapositive = flip (.)\n\n notE : P -> Not P -> Void\n notE = flip id\n\n notE' : Not P -> P -> Void\n notE' = flip notE\n\n -- notE_and : (P, Q) -> Not P -> Void\n -- notE_and = notE . fst\n\n ||| https://proofwiki.org/wiki/Modus_Ponendo_Ponens/Proof_Rule\n modusPonendoPonens : (P -> Q) -> P -> Q\n modusPonendoPonens = id\n\n modusTollendoPonens : (Either P Q) -> Not P -> Q\n modusTollendoPonens = either (void .: notE) const\n\n excludedMiddle : P -> Either P (Not P)\n excludedMiddle = Left\n\n excludedMiddle2 : Not (Not P -> Q) -> Not (Either P Q)\n excludedMiddle2 = (. modusTollendoPonens)\n\n ||| https://proofwiki.org/wiki/Rule_of_Material_Implication/Formulation_1/Forward_Implication\n materialImplication1F : P -> Q -> Either (Not P) Q\n materialImplication1F p q = Right q\n\n ||| https://proofwiki.org/wiki/Rule_of_Material_Implication/Formulation_1/Reverse_Implication\n materialImplication1R : Either (Not P) Q -> P -> Q\n materialImplication1R = (. doubleNegation) . modusTollendoPonens\n\n ||| https://proofwiki.org/wiki/Implication_Equivalent_to_Negation_of_Conjunction_with_Negative/Formulation_1/Forward_Implication\n implEquivNegConjWithNeg : (P -> Q) -> Not (P, Not Q)\n implEquivNegConjWithNeg f (p, notQ) = notE (modusPonendoPonens f p) notQ\n\n\n ||| https://proofwiki.org/wiki/De_Morgan%27s_Laws_(Logic)/Conjunction_of_Negations/Formulation_1/Forward_Implication\n deMorganConjNeg1F : (Not P, Not Q) -> Not (Either P Q)\n deMorganConjNeg1F (f, g) = notE' (either f g)\n\n ||| https://proofwiki.org/wiki/De_Morgan%27s_Laws_(Logic)/Conjunction_of_Negations/Formulation_1/Reverse_Implication\n deMorganConjNeg1R : Not (Either P Q) -> (Not P, Not Q)\n deMorganConjNeg1R f = (notE' f . add1, notE' f . add2)\n -- TODO: Arrows?\n\n ||| https://proofwiki.org/wiki/De_Morgan%27s_Laws_(Logic)/Disjunction_of_Negations/Formulation_1/Forward_Implication\n deMorganDisjNeg1F : Either (Not P) (Not Q) -> Not (P, Q)\n deMorganDisjNeg1F e (p, q) = either ($ p) ($ q) e\n\n ||| https://proofwiki.org/wiki/De_Morgan%27s_Laws_(Logic)/Disjunction_of_Negations/Formulation_1/Reverse_Implication\n -- deMorganDisjNeg1R : Not (P, Q) -> Either (Not P) (Not Q)\n -- deMorganDisjNeg1R x = ?deMorganDisjNeg1R_rhs\n\n ||| https://proofwiki.org/wiki/De_Morgan%27s_Laws_(Logic)/Conjunction_of_Negations/Formulation_2\n deMorganConjNeg2F : (Not P, Not Q) -> Not (Either P Q)\n deMorganConjNeg2F (notP, notQ) =\n either (deMorganDisjNeg1F (Left notP) . idempotenceAnd) notQ\n\n deMorganConjNeg2R : Not (Either P Q) -> (Not P, Not Q)\n deMorganConjNeg2R = deMorganConjNeg1R\n", "meta": {"hexsha": "c100fddd8f8bd6a6455aaf3d8b319be019ec6e1b", "size": 3447, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Proof/DeMorgan.idr", "max_stars_repo_name": "yurrriq/alice-in-puzzleland", "max_stars_repo_head_hexsha": "c7f7c056c3de1f3ba5046bf62806f124f5bcb620", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-25T00:05:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-25T00:05:29.000Z", "max_issues_repo_path": "src/Proof/DeMorgan.idr", "max_issues_repo_name": "yurrriq/alice-in-puzzleland", "max_issues_repo_head_hexsha": "c7f7c056c3de1f3ba5046bf62806f124f5bcb620", "max_issues_repo_licenses": ["WTFPL"], "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/Proof/DeMorgan.idr", "max_forks_repo_name": "yurrriq/alice-in-puzzleland", "max_forks_repo_head_hexsha": "c7f7c056c3de1f3ba5046bf62806f124f5bcb620", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-25T00:05:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-25T00:05:31.000Z", "avg_line_length": 33.7941176471, "max_line_length": 130, "alphanum_fraction": 0.6895851465, "num_tokens": 1255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.7038338850984868}} {"text": "module Data.DistinctElements\n\nimport public Data.Vect\nimport public Data.Function\n\n%access public export\n%default total\n\nDistinctElements : Vect n a -> Type\nDistinctElements [] = ()\nDistinctElements (x :: xs) = (Not (Elem x xs), DistinctElements xs)\n\nisDistinctElements : DecEq a => (xs : Vect n a) -> Dec (DistinctElements xs)\nisDistinctElements [] = Yes ()\nisDistinctElements (x :: xs) with (isElem x xs)\n | Yes p = No (\\(f, _) => f p)\n | No p1 with (isDistinctElements xs)\n | Yes p2 = Yes (p1,p2)\n | No p2 = No (\\(_, d) => p2 d)\n\nelemSplit : Elem x (y::xs) -> Either (x=y) (Elem x xs)\nelemSplit Here {x = y} {y = y} {xs = xs} = Left Refl\nelemSplit (There later) {x = x} {y = y} {xs = xs} = Right later\n\nequalityElem : x=y -> Elem x (y::xs)\nequalityElem Refl {x = x} {y = x} = Here\n\nreduceNotElem : Not (Elem x (y::xs)) -> Not (Elem x xs)\nreduceNotElem p Here {x = x} {xs = xs} impossible\nreduceNotElem p (There _) {x = x} {xs = xs} impossible\n\nnotElemMapInjective : Injective f -> DistinctElements xs -> Not (Elem x xs) -> Elem (f x) (Prelude.Functor.map f xs) -> Void\nnotElemMapInjective inj p ne el {x} {xs=[]} = absurd el\nnotElemMapInjective inj (p,ps) ne el {f} {x} {xs=(y::xs)} = case elemSplit el of\n Left p2 => ne (equalityElem (inj p2))\n Right p2 => notElemMapInjective inj ps (reduceNotElem ne) p2\n\nmapInjectiveFunction : Injective f -> DistinctElements xs -> DistinctElements (Prelude.Functor.map f xs)\nmapInjectiveFunction inj p {f} {xs = []} = p\nmapInjectiveFunction inj (p, ps) {f} {xs = (x::xs)} = (notElemMapInjective inj ps p, mapInjectiveFunction inj ps)\n", "meta": {"hexsha": "c1ce0fe88afd5c9694aa1cacdca86665a0c671bf", "size": 1602, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/DistinctElements.idr", "max_stars_repo_name": "mat8913/l2idris", "max_stars_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data/DistinctElements.idr", "max_issues_repo_name": "mat8913/l2idris", "max_issues_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "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": "Data/DistinctElements.idr", "max_forks_repo_name": "mat8913/l2idris", "max_forks_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "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": 39.0731707317, "max_line_length": 124, "alphanum_fraction": 0.6560549313, "num_tokens": 529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.703804587490338}} {"text": "import Data.Nat\n\npartial fizzBuzzSimple: (x: Nat) -> String\nfizzBuzzSimple x with (modNat x (the Nat 3), modNat x (the Nat 5))\n fizzBuzzSimple x | (Z, Z) = \"fizzbuzz\"\n fizzBuzzSimple x | (Z, _) = \"fizz\"\n fizzBuzzSimple x | (_, Z) = \"buzz\"\n fizzBuzzSimple x | _ = show x\n", "meta": {"hexsha": "8be164a1623454457cbf85681bda9c8a73658698", "size": 274, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "simple.idr", "max_stars_repo_name": "magpie-engineering/provable_fizz_buzz", "max_stars_repo_head_hexsha": "a8920e9ce196bb69f9ba256fdd0b7ba0e3eaf7e1", "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": "simple.idr", "max_issues_repo_name": "magpie-engineering/provable_fizz_buzz", "max_issues_repo_head_hexsha": "a8920e9ce196bb69f9ba256fdd0b7ba0e3eaf7e1", "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": "simple.idr", "max_forks_repo_name": "magpie-engineering/provable_fizz_buzz", "max_forks_repo_head_hexsha": "a8920e9ce196bb69f9ba256fdd0b7ba0e3eaf7e1", "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.4444444444, "max_line_length": 66, "alphanum_fraction": 0.6532846715, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7745833737577159, "lm_q1q2_score": 0.7038003083959546}} {"text": "> module Fraction.LTEProperties\n\n> import Syntax.PreorderReasoning\n\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.Predicates\n> import Fraction.BasicProperties\n> import PNat.PNat\n> import PNat.Operations\n> import PNat.Properties\n> import Nat.LTEProperties\n> import Nat.LTProperties\n> import Nat.OperationsProperties\n> import Nat.Positive\n\n> %default total\n> %access export\n> -- %access public export\n\n> -- %freeze PNatOperations.toNat\n\n|LTE| is a total preorder:\n\n> ||| LTE is reflexive\n> reflexiveLTE : (x : Fraction) -> x `LTE` x\n> reflexiveLTE (n, d') = Nat.LTEProperties.reflexiveLTE (n * (toNat d'))\n\n\n> ||| LTE is transitive\n> transitiveLTE : (x, y, z : Fraction) -> x `LTE` y -> y `LTE` z -> x `LTE` z\n> transitiveLTE (nx, dx') (ny, dy') (nz, dz') xLTEy yLTEz = s8 where\n> dx : Nat\n> dx = toNat dx'\n> dy : Nat\n> dy = toNat dy'\n> dz : Nat\n> dz = toNat dz'\n> s1 : LTE ((nx * dy) * dz) ((ny * dx) * dz)\n> s1 = monotoneNatMultLTE xLTEy (Nat.LTEProperties.reflexiveLTE dz)\n> s2 : LTE ((ny * dz) * dx) ((nz * dy) * dx)\n> s2 = monotoneNatMultLTE yLTEz (Nat.LTEProperties.reflexiveLTE dx)\n> s3 : LTE ((ny * dx) * dz) ((nz * dy) * dx)\n> s3 = replace {P = \\ ZUZ => LTE ZUZ ((nz * dy) * dx)} (multSwapRight ny dz dx) s2\n> s4 : LTE ((nx * dy) * dz) ((nz * dy) * dx)\n> s4 = Nat.LTEProperties.transitiveLTE ((nx * dy) * dz)\n> ((ny * dx) * dz)\n> ((nz * dy) * dx)\n> s1 s3\n> s5 : LTE ((nx * dz) * dy) ((nz * dy) * dx)\n> s5 = replace {P = \\ ZUZ => LTE ZUZ ((nz * dy) * dx)} (multSwapRight nx dy dz) s4\n> s6 : LTE ((nx * dz) * dy) ((nz * dx) * dy)\n> s6 = replace {P = \\ ZUZ => LTE ((nx * dz) * dy) ZUZ} (multSwapRight nz dy dx) s5\n> s7 : LTE (nx * dz) (nz * dx)\n> s7 = elimRightMultLTE {a = nx * dz} {b = nz * dx} {c = dy} {d = dy}\n> s6 Refl (gtZisnotZ (denLTLemma (ny, dy')))\n> s8 : (nx, dx') `LTE` (nz, dz')\n> s8 = s7\n\n \n> ||| LTE is total\n> totalLTE : (x, y : Fraction) -> Either (x `LTE` y) (y `LTE` x) \n> totalLTE (n1, d1') (n2, d2') = \n> let d1 = toNat d1' in\n> let d2 = toNat d2' in\n> Nat.LTEProperties.totalLTE (n1 * d2) (n2 * d1)\n\n\nProperties of |LTE| and |plus|:\n\n> ||| LTE is monotone w.r.t. `plus`\n> monotonePlusLTE : {a, b, c, d : Fraction} -> \n> a `LTE` b -> c `LTE` d -> (a `plus` c) `LTE` (b `plus` d)\n> monotonePlusLTE {a = (na, da')} {b = (nb, db')} {c = (nc, dc')} {d = (nd, dd')} aLTEb cLTEd = s16 where\n> da : Nat\n> da = toNat da'\n> db : Nat\n> db = toNat db'\n> dc : Nat\n> dc = toNat dc'\n> dd : Nat\n> dd = toNat dd'\n> s1 : LTE (na * db) (nb * da)\n> s1 = aLTEb\n> s2 : LTE (nc * dd) (nd * dc)\n> s2 = cLTEd\n> s3 : LTE ((na * db) * (dc * dd)) ((nb * da) * (dc * dd))\n> s3 = monotoneNatMultLTE s1 (Nat.LTEProperties.reflexiveLTE (dc * dd))\n> s4 : LTE ((nc * dd) * (da * db)) ((nd * dc) * (da * db))\n> s4 = monotoneNatMultLTE s2 (Nat.LTEProperties.reflexiveLTE (da * db))\n> s5 : LTE ((na * db) * (dc * dd) + (nc * dd) * (da * db)) \n> ((nb * da) * (dc * dd) + (nd * dc) * (da * db))\n> s5 = monotoneNatPlusLTE s3 s4 \n> s6 : LTE ((na * dc) * (db * dd) + (nc * dd) * (da * db)) \n> ((nb * da) * (dc * dd) + (nd * dc) * (da * db))\n> s6 = replace {P = \\ ZUZ => LTE ( ZUZ + (nc * dd) * (da * db)) \n> ((nb * da) * (dc * dd) + (nd * dc) * (da * db))} \n> (multSwap23 na db dc dd) s5 \n> s7 : LTE ((na * dc) * (db * dd) + (nc * da) * (dd * db)) \n> ((nb * da) * (dc * dd) + (nd * dc) * (da * db))\n> s7 = replace {P = \\ ZUZ => LTE ((na * dc) * (db * dd) + ZUZ ) \n> ((nb * da) * (dc * dd) + (nd * dc) * (da * db))} \n> (multSwap23 nc dd da db) s6\n> s8 : LTE ((na * dc) * (db * dd) + (nc * da) * (dd * db)) \n> ((nb * dd) * (dc * da) + (nd * dc) * (da * db))\n> s8 = replace {P = \\ ZUZ => LTE ((na * dc) * (db * dd) + (nc * da) * (dd * db)) \n> ( ZUZ + (nd * dc) * (da * db))} \n> (multSwap24 nb da dc dd) s7\n> s9 : LTE ((na * dc) * (db * dd) + (nc * da) * (dd * db)) \n> ((nb * dd) * (dc * da) + (nd * db) * (da * dc))\n> s9 = replace {P = \\ ZUZ => LTE ((na * dc) * (db * dd) + (nc * da) * (dd * db)) \n> ((nb * dd) * (dc * da) + ZUZ )} \n> (multSwap24 nd dc da db) s8 \n> s10 : LTE ((na * dc) * (db * dd) + (nc * da) * (db * dd)) \n> ((nb * dd) * (dc * da) + (nd * db) * (da * dc))\n> s10 = replace {P = \\ ZUZ => LTE ((na * dc) * (db * dd) + (nc * da) * ZUZ ) \n> ((nb * dd) * (dc * da) + (nd * db) * (da * dc))} \n> (multCommutative dd db) s9\n> s11 : LTE ((na * dc) * (db * dd) + (nc * da) * (db * dd)) \n> ((nb * dd) * (da * dc) + (nd * db) * (da * dc))\n> s11 = replace {P = \\ ZUZ => LTE ((na * dc) * (db * dd) + (nc * da) * (db * dd)) \n> ((nb * dd) * ZUZ + (nd * db) * (da * dc))} \n> (multCommutative dc da) s10\n> s12 : LTE ((na * dc + nc * da) * (db * dd)) \n> ((nb * dd) * (da * dc) + (nd * db) * (da * dc))\n> s12 = replace {P = \\ ZUZ => LTE ZUZ ((nb * dd) * (da * dc) + (nd * db) * (da * dc))} \n> (sym (multDistributesOverPlusLeft (na * dc) (nc * da) (db * dd))) s11\n> s13 : LTE ((na * dc + nc * da) * (db * dd)) ((nb * dd + nd * db) * (da * dc))\n> s13 = replace {P = \\ ZUZ => LTE (((na * dc) + (nc * da)) * (db * dd)) ZUZ} \n> (sym (multDistributesOverPlusLeft (nb * dd) (nd * db) (da * dc))) s12\n> s14 : LTE ((na * dc + nc * da) * (toNat (db' * dd'))) ((nb * dd + nd * db) * (da * dc))\n> s14 = replace {P = \\ ZUZ => LTE ((na * dc + nc * da) * ZUZ) ((nb * dd + nd * db) * (da * dc))} \n> (sym toNatMultLemma) s13\n> s15 : LTE ((na * dc + nc * da) * (toNat (db' * dd'))) ((nb * dd + nd * db) * (toNat (da' * dc')))\n> s15 = replace {P = \\ ZUZ => LTE ((na * dc + nc * da) * (toNat (db' * dd'))) ((nb * dd + nd * db) * ZUZ)}\n> (sym toNatMultLemma) s14\n> s16 : ((na, da') `plus` (nc, dc')) `LTE` ((nb, db') `plus` (nd, dd'))\n> s16 = s15\n\n\nProperties of |LTE| and |mult|:\n\n> ||| LTE is monotone w.r.t. `(*)`\n> monotoneMultLTE : {a, b, c, d : Fraction} -> \n> a `LTE` b -> c `LTE` d -> (a `mult` c) `LTE` (b `mult` d)\n> monotoneMultLTE {a = (na, da')} {b = (nb, db')} {c = (nc, dc')} {d = (nd, dd')} aLTEb cLTEd = s13 where\n> da : Nat\n> da = toNat da'\n> db : Nat\n> db = toNat db'\n> dc : Nat\n> dc = toNat dc'\n> dd : Nat\n> dd = toNat dd'\n> s01 : LTE (na * db) (nb * da)\n> s01 = aLTEb\n> s02 : LTE (nc * dd) (nd * dc)\n> s02 = cLTEd\n> s03 : LTE ((na * db) * (nc * dd)) ((nb * da) * (nc * dd))\n> s03 = monotoneNatMultLTE s01 (Nat.LTEProperties.reflexiveLTE (nc * dd))\n> s04 : LTE ((nc * dd) * (da * nb)) ((nd * dc) * (da * nb))\n> s04 = monotoneNatMultLTE s02 (Nat.LTEProperties.reflexiveLTE (da * nb))\n> s05 : LTE ((da * nb) * (nc * dd)) ((nd * dc) * (da * nb))\n> s05 = replace {P = \\ ZUZ => LTE ZUZ ((nd * dc) * (da * nb))} \n> (multCommutative (nc * dd) (da * nb)) s04\n> s06 : LTE ((nb * da) * (nc * dd)) ((nd * dc) * (da * nb))\n> s06 = replace {P = \\ ZUZ => LTE (ZUZ * (nc * dd)) ((nd * dc) * (da * nb))} \n> (multCommutative da nb) s05\n> s07 : LTE ((na * db) * (nc * dd)) ((nd * dc) * (da * nb))\n> s07 = Nat.LTEProperties.transitiveLTE ((na * db) * (nc * dd)) ((nb * da) * (nc * dd)) ((nd * dc) * (da * nb)) s03 s06\n> s08 : LTE ((na * nc) * (db * dd)) ((nd * dc) * (da * nb))\n> s08 = replace {P = \\ ZUZ => LTE ZUZ ((nd * dc) * (da * nb))} \n> (multSwap23 na db nc dd) s07\n> s09 : LTE ((na * nc) * (db * dd)) ((nd * nb) * (da * dc))\n> s09 = replace {P = \\ ZUZ => LTE ((na * nc) * (db * dd)) ZUZ} \n> (multSwap24 nd dc da nb) s08\n> s10 : LTE ((na * nc) * (db * dd)) ((nb * nd) * (da * dc))\n> s10 = replace {P = \\ ZUZ => LTE ((na * nc) * (db * dd)) (ZUZ * (da * dc))} \n> (multCommutative nd nb) s09\n> s11 : LTE ((na * nc) * (toNat (db' * dd'))) ((nb * nd) * (da * dc))\n> s11 = replace {P = \\ ZUZ => LTE ((na * nc) * ZUZ) ((nb * nd) * (da * dc))} \n> (sym toNatMultLemma) s10\n> s12 : LTE ((na * nc) * (toNat (db' * dd'))) ((nb * nd) * (toNat (da' * dc')))\n> s12 = replace {P = \\ ZUZ => LTE ((na * nc) * (toNat (db' * dd'))) ((nb * nd) * ZUZ)}\n> (sym toNatMultLemma) s11\n> s13 : ((na, da') `mult` (nc, dc')) `LTE` ((nb, db') `mult` (nd, dd'))\n> s13 = s12\n\n\n", "meta": {"hexsha": "87ef20f8395cd34a60cff98552499c6874131d86", "size": 8849, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fraction/LTEProperties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Fraction/LTEProperties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Fraction/LTEProperties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.5736842105, "max_line_length": 121, "alphanum_fraction": 0.4312351678, "num_tokens": 3509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.7037085684560668}} {"text": "module Demo\n\nimport Data.Vect\n\n%default total\n\ndata Nat' : Type where\n Z' : Nat'\n S' : Nat' -> Nat'\n\n%name Nat' n,m,o\n\nplus' : Nat' -> Nat' -> Nat'\nplus' Z' m = m\nplus' (S' n) m = S' (plus' n m)\n\ndata Vect' : Nat -> Type -> Type where\n Nil : Vect' Z a\n (::) : a -> Vect' n a -> Vect' (S n) a\n\n%name Vect' xs,ys,zs\n\nappend : Vect' n a -> Vect' m a -> Vect' (n + m) a\nappend Nil ys = ys\nappend (x :: xs) ys = x :: (append xs ys)\n\nzip : Vect' n a -> Vect' n b -> Vect' n (a, b)\nzip [] [] = []\nzip (x :: xs) (y :: ys) = (x, y) :: (zip xs ys)\n\ntake' : (n : Nat) -> Vect (n + m) a -> Vect n a\ntake' Z xs = []\ntake' (S k) (x :: xs) = x :: take' k xs\n\ndrop' : (n : Nat) -> Vect (n + m) a -> Vect m a\ndrop' Z xs = xs\ndrop' (S k) (x :: xs) = drop' k xs\n\n\ndata SnocList : List a -> Type where\n SnocNil : SnocList []\n Snoc : (xs : List a) -> (x :a) -> SnocList (xs ++ [x])\n\nsnocced : (xs : List a) -> SnocList xs\nsnocced [] = SnocNil\nsnocced (x :: xs) with (snocced xs)\n snocced (x :: []) | SnocNil = Snoc [] x\n snocced (x :: (ys ++ [y])) | (Snoc ys y) = Snoc (x :: ys) y\n\nrot : Nat -> List a -> List a\nrot Z xs = xs\nrot (S k) xs with (snocced xs)\n rot (S k) [] | SnocNil = []\n rot (S k) (ys ++ [x]) | (Snoc ys x) = rot k (x::ys)\n", "meta": {"hexsha": "8adc06c4414406244ed9e59ca9932f5911ce82aa", "size": 1322, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/CheatSheet.idr", "max_stars_repo_name": "tgrospic/dependently-typed-slides", "max_stars_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "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/CheatSheet.idr", "max_issues_repo_name": "tgrospic/dependently-typed-slides", "max_issues_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "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/CheatSheet.idr", "max_forks_repo_name": "tgrospic/dependently-typed-slides", "max_forks_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "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": 24.0363636364, "max_line_length": 61, "alphanum_fraction": 0.462934947, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7034917150602218}} {"text": "{-\nImplement the following function, which states that if you add the same value onto the front of\nequal lists, the resulting lists are also equal: \n -}\nsame_cons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys\nsame_cons prf = cong (x ::) prf\n\n{-\nBecause this function represents an equality proof, it’s sufficient to know that your definition type-checks and is total:\n\n*ex_8_1> :total same_cons\nMain.same_cons is Total\n -}\n\nsame_lists : {xs : List a} -> {ys : List a} -> x = y -> xs = ys -> x :: xs = y :: ys\nsame_lists Refl prf = cong (x ::) prf\n\ndata ThreeEq : a -> b -> c -> Type where\n Same : (a : ty) -> ThreeEq a a a\n\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS x x x (Same x) = Same (S x)\n", "meta": {"hexsha": "694cd4860b7f16af258f78b83910eebc73848faa", "size": 758, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch8/ex_8_1.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "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/ch8/ex_8_1.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": "src/ch8/ex_8_1.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "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": 32.9565217391, "max_line_length": 122, "alphanum_fraction": 0.6213720317, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.70339301928974}} {"text": "module ReadVect\n\nimport Data.Vect\n\nreadVectLen : (len : Nat) -> IO (Vect len String)\nreadVectLen Z = pure []\nreadVectLen (S k) = do x <- getLine\n xs <- readVectLen k\n pure (x :: xs) -- nice..\n\n---- why do we have to define the length??\n--data VectUnknown : Type -> Type where\n-- MkVect : (len : Nat) -> Vect len a -> VectUnknown a\n--\n--readVect : IO (VectUnknown String)\n--readVect = do x <- getLine\n-- if x == \"\" then pure (MkVect 0 [])\n-- else do MkVect len xs <- readVect\n-- pure (MkVect (S len) (x :: xs))\n\ndata VectUnknown : Type -> Type where\n MkVect : Vect len a -> VectUnknown a\n\nreadVect' : IO (VectUnknown String)\nreadVect' = do\n x <- getLine\n if x == \"\"\n then pure (MkVect [])\n else do\n MkVect xs <- readVect'\n pure (MkVect (x :: xs))\n\n\nreadVect : IO (n ** Vect n String) -- Oooh, interesting!\nreadVect = do\n x <- getLine\n if x == \"\"\n then pure (_ ** [])\n else do\n (_ ** xs) <- readVect\n pure (_ ** x :: xs)\n\n-- This is fairly ugly. Do we have (a : Nat) -> (b : Nat) -> Maybe (a with (_)\n -- This is fairly ugly. Do we have (a : Nat) -> (b : Nat) -> Maybe (a | with_pat = ?This_rhs\nmyExactLength : (l : Nat) -> (Vect len a) -> Maybe (Vect l a)\nmyExactLength Z [] = Just []\nmyExactLength Z (x :: xs) = Nothing\nmyExactLength (S k) [] = Nothing\nmyExactLength (S k) (x :: xs) = case myExactLength k xs of\n Nothing => Nothing\n Just ys => Just (x :: ys)\n\nzipInputs : IO ()\nzipInputs = do\n putStrLn \"Enter first vector (blank line to end): \"\n (l1 ** v1) <- readVect\n putStrLn \"Enter second vector (blank line to end): \"\n (l2 ** v2) <- readVect\n --(Just v2l1) <- exactLength l1 v2 | Nothing putStrLn \"Vectors have different lengths.\"\n case myExactLength l1 v2 of -- how DO we implement exact length?\n Nothing => putStrLn \"Vectors have different lengths.\"\n Just v2l1 => putStrLn (show (zip v1 v2l1))\n\n-- Go back to Chapter5.idr\n", "meta": {"hexsha": "6a32c78dadada20ecbbb8262f758476beae9a96d", "size": 2088, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ReadVect.idr", "max_stars_repo_name": "neduard/type-driven-development", "max_stars_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "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": "ReadVect.idr", "max_issues_repo_name": "neduard/type-driven-development", "max_issues_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "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": "ReadVect.idr", "max_forks_repo_name": "neduard/type-driven-development", "max_forks_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "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.1230769231, "max_line_length": 95, "alphanum_fraction": 0.5517241379, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7033123660718957}} {"text": "module LinearAlgebra\n\nimport MultiSolver\nimport Data.Matrix.Numeric\nimport Data.Vect\nimport Data.Fin\nimport Data.Matrix\nimport ZZ\nimport Rationals\n\n%access public export\n\n-- Some auxillary functions for elementary operations\n\n--Euclid's div\nEucl: (a: Nat) -> (b: Nat) -> (Nat, Nat)\nEucl Z b = (0,0)\nEucl (S k) b = case (lte (S (S k)) b) of\n False => (S(fst(Eucl (minus (S k) b) b)), snd(Eucl (minus (S k) b) b))\n True => (0, S k)\n\n--Nat to Fin (modular values)\ntofinNat: (a: Nat) -> (n: Nat) -> Fin n\ntofinNat Z (S j) = FZ\ntofinNat (S k) (S j) = case lte (S k) (S j) of\n True => FS (tofinNat k j)\n False => (tofinNat (snd(Eucl (S k) (S j))) (S j))\n\nFST: ZZPair -> ZZ\nFST (a, b) = a\n\nPred: Nat -> Nat\nPred Z = Z\nPred (S k) = k\n\n--Takes the first m elements from a vector\nVecttake : (m:Nat)->Vect n elem->Vect m elem\nVecttake Z xs = []\nVecttake (S k) (x::xs) = x::(Vecttake k xs)\n\nSimpleCast: (v1:(Vect (k+ (S Z)) elem)) ->( Vect (S k) elem) -- necessary for type matching, taken from Shafil's code\nSimpleCast {k} v1 = (Vecttake (S k) v1)\n\nRowN: Matrix n n ZZPair -> (k: Nat) -> Vect n ZZPair -- returns the nth row (indexing from 0)\nRowN {n} x k = Data.Vect.index (tofinNat k n) x\n\nij: Matrix n n ZZPair -> (i: Nat) -> (j: Nat) -> ZZPair\nij {n} x i j = Data.Vect.index (tofinNat j n) (RowN x i)\n\nColumnN: Matrix n n ZZPair -> (k: Nat) -> Vect n ZZPair --returns the nth column (indexing from 0)\nColumnN {n} x k = Data.Vect.index (tofinNat k n) (transpose x)\n\nVectorSubtract: (n: Nat) -> (a: Vect n ZZPair) -> (b: Vect n ZZPair) -> (Vect n ZZPair) --subtracts components\nVectorSubtract n a b = a - b\n\nScaleVect: (n: Nat) -> (Vect n ZZPair) -> (c: ZZPair) -> (Vect n ZZPair) --scales by a rational\nScaleVect n xs c = c <# xs\n\n--returns the row scaled by a constant minus another vector (used in row operations)\n\naxpy: (n: Nat) -> (a: Vect n ZZPair) -> (b: Vect n ZZPair) -> (c: ZZPair) -> (Vect n ZZPair)\naxpy n a b c = VectorSubtract (n) (a) (ScaleVect (n) b c)\n\n--Auxillary functions, will be used in the Gauss-Jordan process\n\nFirst_k_rows: (n: Nat) -> (x: Matrix n n ZZPair) -> (k: Nat) -> Matrix k n ZZPair\nFirst_k_rows n x Z = []\nFirst_k_rows n x (S k) = [RowN x k] ++ (First_k_rows n x k)\n\nLast_k_rows: (n: Nat) -> (x: Matrix n n ZZPair) -> (k: Nat) -> Matrix k n ZZPair\nLast_k_rows n x k = reverse (First_k_rows n (reverse x) k)\n\nFirst_k_rows_from_RowP: (n: Nat) -> (x: Matrix n n ZZPair) -> (p: Nat) -> (k: Nat) -> Matrix k n ZZPair\nFirst_k_rows_from_RowP n x p Z = []\nFirst_k_rows_from_RowP n x p (S k) = SimpleCast ((First_k_rows_from_RowP n x p k) ++ [RowN x (p+k)])\n\n-- A section on elementary operations (to eventually implement the Gauss-Jordan process)\n\n-- Scales a row by dividing it by a rational number.\n\nScaleRow: (n: Nat) -> Matrix n n ZZPair -> (row_a: Nat) -> (c: ZZPair) -> Matrix n n ZZPair\nScaleRow n x row_a c = replaceAt (tofinNat row_a n) (ScaleVect n (RowN x row_a) c) (x)\n\n-- Swaps two rows in a matrix (indexing from 0)\n\nSwapRows: (n: Nat) -> Matrix n n ZZPair -> (a: Nat) -> (b: Nat) -> Matrix n n ZZPair\nSwapRows n x a b = replaceAt (tofinNat b n) (RowN x a) (replaceAt (tofinNat a n) (RowN x b) (x))\n\n-- Performs an elementary row operation, subtracts from row a the row b scaled by c\n\nRowOperation: (n: Nat) -> Matrix n n ZZPair -> (a: Nat) -> (b: Nat) -> (c: ZZPair) -> Matrix n n ZZPair\nRowOperation n x a b c = replaceAt (tofinNat a n) (axpy n (RowN x a) (RowN x b) c) (x)\n\n-- Makes the kth number in Row A zero by subtracting a scaling of Row B (for upper triangularizing)\n-- As usual, indexing starts from 0\n\nMakeElementZero: (n: Nat) -> (x: Matrix n n ZZPair) -> (row_a : Nat) -> (row_b : Nat) -> (pos : Nat) -> Matrix n n ZZPair\nMakeElementZero n x row_a row_b pos = case (FST(ij x row_a pos)) of\n (Pos Z) => x\n (Pos (S k)) => case ((fst (ij x row_b pos))) of\n (Pos Z) => (SwapRows n x row_a row_b)\n (Pos (S k)) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n (NegS k) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n (NegS k) => case ((fst (ij x row_b pos))) of\n (Pos Z) => (SwapRows n x row_a row_b)\n (Pos (S k)) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n (NegS k) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n\n-- Explanation: We want to transform the element x[row_a][pos] into zero by a row operation. There are a few different cases\n-- 1. If x[row_a][pos] is already zero, nothing needs to be done.\n-- 2. If not, we scale row_b appropriately and do a row operation (A -> A - cB)\n-- 3. If x[row_b][pos] is zero, however, no row operation will work. We simply swap the\n-- row_a and row_b here; then, x[row_a][pos] will become zero.\n\n-- This algorithm is important to make a matrix upper-triangular.\n\nMakeColumnZero: (n: Nat) -> (x: Matrix n n ZZPair) -> (col : Nat) -> (iter : Nat) -> Matrix n n ZZPair\nMakeColumnZero n x col Z = x\nMakeColumnZero n x col (S k) = case (isLTE (S k) col) of\n (Yes prf) => x\n (No contra) => (MakeColumnZero n (MakeElementZero n x (S k) col col) col k)\n\n-- This function turns a column into what it should be in upper-triangular form by adding in the necessary zeros.\n-- iter is a variable to induct on (trick courtesy Sriram)\n-- When using this, make sure to set \"iter\" as n-1 (1 less than the number of rows)\n\n-- The next step here is to use the above function to make a matrix upper triangular. This can be\n-- done by inducting on the number of columns.\n\n-- A helper function, which recursively fills zeros into columns.\n\nUpperTriangularize: (x: Matrix n n ZZPair) -> (iter: Nat) -> Matrix n n ZZPair\nUpperTriangularize {n} x Z = (MakeColumnZero n x Z (Pred n)) -- Column Zero is the base case\nUpperTriangularize {n} x (S k) = (MakeColumnZero n (UpperTriangularize x k) (S k) (Pred n))\n\n-- Enter a matrix, get the upper triangular form.\n\nUpperTriangularForm: (x: Matrix n n ZZPair) -> Matrix n n ZZPair\nUpperTriangularForm {n} x = UpperTriangularize x (Pred (Pred n))\n\n-- The function below converts a matrix into a Diagonal Form (note that this is NOT diagonalization!) by converting to upper-triangular\n-- form, transposing that (to get a lower triangular matrix) and finding the upper-triangular form of the tranpose. This is going to be useful\n-- as it is the next step of the Gauss-Jordan algorithm (what's next: divide out the rows to get an identity matrix; an inverse can be\n-- found this way by applying all the above row operations to an identity matrix.\n\nDiagonalForm: (x: Matrix n n ZZPair) -> Matrix n n ZZPair\nDiagonalForm {n} x = UpperTriangularForm (transpose (UpperTriangularForm x))\n\n-- once a matrix is in diagonal form, we can convert it to the identity by dividing each row by its only nonzero element\n\nReduceRow: (x: Matrix n n ZZPair) -> (iter: Nat) -> Matrix n n ZZPair\nReduceRow {n = n} x Z = case (FST(ij x Z Z)) of\n (Pos Z) => x\n (Pos (S k)) => ScaleRow n x Z (divZZ (1,1) (ij x 0 0))\n (NegS k) => ScaleRow n x Z (divZZ (1,1) (ij x 0 0))\nReduceRow {n = n} x (S k) = case ((FST(ij x (S k) (S k)))) of\n (Pos Z) => x\n (Pos (S k)) => ScaleRow n (ReduceRow x k) (S k) (divZZ (1,1) (ij x (S k) (S k)))\n (NegS k) => ScaleRow n (ReduceRow x k) (S k) (divZZ (1,1) (ij x (S k) (S k)))\n\n-- This function converts any matrix into the identity. Applying the row operations which do this to an identity matrix would convert it\n-- to an inverse. If we want to solve linear equations, this would be enough (for proof, we would need to prove that AA^-1 = I). \n-- Another possibility would be to use back-substitution from the upper-triangular form. This would be simpler because the function\n-- GeneralEqSolver from Linear.idr could be modified a bit to solve n successive 1 - variable equations, and generating a proof would\n-- be easier.\n\nTotalReduce: (x: Matrix n n ZZPair) -> (Matrix n n ZZPair)\nTotalReduce {n} x = ReduceRow (DiagonalForm x) (Pred n)\n\n-- Once we have a matrix in diagonal (or even upper triangular) form, we can calculate the magnitude of its determinant by multiplying\n-- the diagonal elements.\n\nDiagonalProductHelper: (x: Matrix n n ZZPair) -> (iter: Nat) -> ZZPair\nDiagonalProductHelper x Z = (ij x 0 0)\nDiagonalProductHelper x (S k) = (ij x (S k) (S k)) * (DiagonalProductHelper x k)\n\n-- Calculates the determinant up to the sign ( (-1)^n to be implemented later ). Effectively, this calculates the \"volume\" of n-vectors in\n-- n-dimensional Euclidean space. \n\nDetUpToSign: (x: Matrix n n ZZPair) -> ZZPair\nDetUpToSign {n} x = simplifyRational (DiagonalProductHelper (DiagonalForm x) (Pred n))\n\n-- I propose a simple way to calculate the sign factor: in the conversion to upper-triangular form, the last column is untouched\n-- except for by Row Swapping. The last column in upper - triangular form is thus a permutation of the last column of the original \n-- matrix. We just need to check if this is an odd or even permutation (simplification of all elements of the matrices will be \n-- necessary to ensure that this can be carried out) and multiply appropriately.\n\n-- A short section consisting of functions used to simplify a matrix of ZZPairs\n\nChangeElementRow: (n: Nat) -> Vect n ZZPair -> (pos: Nat) -> (new: ZZPair) -> Vect n ZZPair\nChangeElementRow n xs pos new = replaceAt (tofinNat pos n) (new) xs\n\nChangeElementMatrix: (n: Nat) -> (x: Matrix n n ZZPair) -> (i: Nat) -> (j: Nat) -> (new: ZZPair) -> Matrix n n ZZPair\nChangeElementMatrix n x i j new = replaceAt (tofinNat i n) (ChangeElementRow n (RowN x i) j new) (x)\n\nSimplifyElement: (n: Nat) -> (x: Matrix n n ZZPair) -> (i: Nat) -> (j: Nat) -> Matrix n n ZZPair\nSimplifyElement n x i j = ChangeElementMatrix n x i j (simplifyRational (ij x i j))\n\nsimplifyRowHelper: (n: Nat) -> (x: Matrix n n ZZPair) -> (row: Nat) -> (iter: Nat) -> Matrix n n ZZPair\nsimplifyRowHelper n x row Z = SimplifyElement n x row Z\nsimplifyRowHelper n x row (S k) = SimplifyElement n (simplifyRowHelper n x row k) row (S k)\n\nsimplifyRow: (n: Nat) -> (x: Matrix n n ZZPair) -> (row: Nat) -> (Matrix n n ZZPair)\nsimplifyRow n x row = simplifyRowHelper n x row (Pred n)\n\nsimplifyMatrixHelper: (n: Nat) -> (x: Matrix n n ZZPair) -> (iter: Nat) -> Matrix n n ZZPair\nsimplifyMatrixHelper n x Z = simplifyRow n x Z\nsimplifyMatrixHelper n x (S k) = simplifyMatrixHelper n (simplifyMatrixHelper n x k) (S k)\n\nsimplifyMatrix: (x: Matrix n n ZZPair) -> (Matrix n n ZZPair) -- simplifies all the rationals in the matrix, takes a while to run\nsimplifyMatrix {n} x = simplifyMatrixHelper n x (Pred n) \n\n\n", "meta": {"hexsha": "f9de3a5eccb5d87f36b1679bab17d18283d4612b", "size": 11387, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/LinearAlgebra.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/LinearAlgebra.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "Code/LinearAlgebra.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 53.2102803738, "max_line_length": 162, "alphanum_fraction": 0.6272064635, "num_tokens": 3396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7032881411792309}} {"text": "module Coproduct\n\nimport Basic\nimport Unit\nimport Void\n\n%default total\n\ninfixl 5 +\n\nnamespace Coproduct\n public export\n data (+) : Type -> Type -> Type where\n Inl : a -> a + b\n Inr : b -> a + b\n\npublic export\nSumInduction : (p : a + b -> Type)\n -> ((x : a) -> p (Inl x))\n -> ((y : b) -> p (Inr y))\n -> (z : a + b) -> p z\nSumInduction p f g (Inl x) = f x\nSumInduction p f g (Inr y) = g y\n\npublic export\nSumRecursion : (p : Type)\n -> ((x : a) -> p)\n -> ((y : b) -> p)\n -> (z : a + b) -> p\nSumRecursion p = SumInduction (const p)\n\npublic export\nTwo : Type\nTwo = Unit + Unit\n\npublic export\nTwoInduction : (p : Two -> Type)\n -> p (Inl ())\n -> p (Inr ())\n -> (two : Two) -> p two\nTwoInduction p pl pr = SumInduction p\n (UnitInduction (p `compose` Inl) pl) (UnitInduction (p `compose` Inr) pr)\n\n", "meta": {"hexsha": "91ec5c05596030f2c6a2a937cbab6e804f44f509", "size": 894, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Coproduct.idr", "max_stars_repo_name": "Russoul/Idris2-HoTT", "max_stars_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-17T05:44:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T09:36:13.000Z", "max_issues_repo_path": "src/Coproduct.idr", "max_issues_repo_name": "Russoul/Idris2-HoTT", "max_issues_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "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/Coproduct.idr", "max_forks_repo_name": "Russoul/Idris2-HoTT", "max_forks_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "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": 20.3181818182, "max_line_length": 75, "alphanum_fraction": 0.5055928412, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.7718434925908524, "lm_q1q2_score": 0.7032881278918047}} {"text": "> module Fun.FunExp\n\nfrom https://github.com/DSLsofMath/DSLsofMath/blob/master/L/DSLsofMath/FunExp.lhs\n\n> %default total\n> %access public export\n> %auto_implicits on -- off\n\n\n> ||| Functions as expressions\n> data FunExp : Type -> Type where\n> Const : t -> FunExp t\n> Id : FunExp t\n> (+) : FunExp t -> FunExp t -> FunExp t\n> (-) : FunExp t -> FunExp t -> FunExp t\n> (*) : FunExp t -> FunExp t -> FunExp t\n> (/) : FunExp t -> FunExp t -> FunExp t\n> (.) : FunExp t -> FunExp t -> FunExp t\n> Exp : FunExp t -> FunExp t\n> -- etc.\n\n\n> interface (Num ty) => Math ty where\n> exp : ty -> ty \n\n\n> ||| Evaluation\n> eval : (Num t, Fractional t, Neg t, Math t) => FunExp t -> t -> t\n> eval (Const c) x = (const c) x \n> eval Id x = id x\n> eval (e1 + e2) x = (eval e1 x) + (eval e2 x)\n> eval (e1 - e2) x = (eval e1 x) - (eval e2 x)\n> eval (e1 * e2) x = (eval e1 x) * (eval e2 x)\n> eval (e1 / e2) x = (eval e1 x) / (eval e2 x)\n> eval (e1 . e2) x = (eval e1 (eval e2 x))\n> eval (Exp e) x = exp (eval e x)\n\n\n> ||| Differentiation\n> derivative : (Num t, Fractional t, Neg t) => FunExp t -> FunExp t\n> derivative (Const c) = Const 0\n> derivative Id = Const 1\n> derivative (e1 + e2) = derivative e1 + derivative e2 \n> derivative (e1 - e2) = derivative e1 - derivative e2 \n> derivative (e1 * e2) = (derivative e1) * e2 + e1 * (derivative e2) \n> derivative (e1 / e2) = (derivative e1) / e2 - e1 * (derivative e2) / (e2 * e2)\n> derivative (e1 . e2) = ((derivative e1) . e2) * (derivative e2) \n> derivative (Exp e) = (Exp e) * (derivative e)\n\nThis needs to be tested!\n", "meta": {"hexsha": "a5d14458b687999e4a9674c3a895a71d9a541473", "size": 1598, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fun/FunExp.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "Fun/FunExp.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "Fun/FunExp.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.3333333333, "max_line_length": 81, "alphanum_fraction": 0.571339174, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7029231835698614}} {"text": "--Applications of stuff in Primes.idr\n\nmodule PrimeApple\n\nimport Primes\nimport NatUtils\nimport gcd\nimport Data.Fin\nimport NatOrder\nimport SriramAssRecRule\n\n%access public export\n%default total\n\n--Prime type\nisPrime : (p : Nat) -> LTE 2 p -> Type\nisPrime p proofLTE = {k : Nat} -> isDivisible p k -> Either (k=1)(k=p)\n\n--Transitivity of divisibility\ntransDiv : (isDivisible b a) -> (isDivisible c b) -> isDivisible c a\ntransDiv {a} {b} {c} (n ** pf1) (m ** pf2) = (m*n **\n (lteMultIsLTE (fst pf2) (fst pf1) ,\n rewrite (snd pf2) in\n rewrite (snd pf1) in\n rewrite sym (multAssociative a n m) in\n rewrite multCommutative n m in Refl))\n\n--The smallest factor of a number is prime\nleastDivIsPrime : (m : Nat) -> LTE 2 m ->\n (p : Nat) -> (pGt2 : LTE 2 p) -> isDivisible m p ->\n ((b : Nat) -> LTE b p -> (isDivisible m b) ->\n Either (b=1)(b=p)) ->\n isPrime p pGt2\nleastDivIsPrime m mGt2 p pGt2 pDivm func = g where\n g : {k : Nat} -> isDivisible p k -> Either (k=1)(k=p)\n g {k = a} pff = func a (bDivAImpAGtB p a (fst pff) pff) (transDiv pff pDivm)\n\nhelp10 : (a : Nat) -> (q : Nat) -> (S (S q)) = a ->\n (b : Nat) -> (k : Nat) -> (S (S k)) = b ->\n (prf : isDivisible a b) ->\n (lst : List Nat ** (foldList Nat 1 (*) lst = a,\n (b : NonEmpty lst ** (LTE 1 (last {ok=b} lst),\n (a = mult (head {ok=b} lst) (last {ok=b} lst),\n Either (x: LTE 2 (last {ok=b} lst) ** isPrime (last {ok=b} lst) x) (last {ok=b} lst = 1))))))\nhelp10 a q ww b k ee prf with (prf)\n help10 a q ww b k ee prf | (m ** (pfPos , pfDiv)) =\n ([m , (S (S k))] ** (rewrite multOneRightNeutral (S k) in\n rewrite ee in\n rewrite multCommutative m b in (sym pfDiv),\n (IsNonEmpty ** ((LTESucc LTEZero),\n ((rewrite ee in\n rewrite multCommutative m b in pfDiv),\n Left (LTESucc (LTESucc LTEZero) **\n leastDivIsPrime\n (S (S q)) (LTESucc (LTESucc LTEZero))\n (S (S k)) (LTESucc (LTESucc LTEZero))\n (m ** (pfPos,\n rewrite ww in\n rewrite multConstantRight m ee in pfDiv))\n (?func))\n)))))\n\nhelp11 : (x : Nat) -> (lst : List Nat) -> (ntMT : NonEmpty lst) ->\n last (x :: lst) = last {ok=ntMT} lst\nhelp11 x (y :: xs) IsNonEmpty = Refl\n\n--Factors a number into 2 other numbers, such that the\n--first one is smaller and is prime (not proven yet)\n--and that the list of factors folded gives back the number\n\n--Give var as n-1\nfactor2 : (n : Nat) -> (var : Nat) -> (GT n 0) ->\n (lst : List Nat ** (foldList Nat 1 (*) lst = n,\n (b : NonEmpty lst ** (LTE 1 (last {ok=b} lst),\n (n = mult (head {ok=b} lst) (last {ok=b} lst),\n Either (x: LTE 2 (last {ok=b} lst) ** isPrime (last {ok=b} lst) x) (last {ok=b} lst = 1))))))\nfactor2 Z _ LTEZero impossible\nfactor2 Z _ (LTESucc _) impossible\nfactor2 (S Z) _ (LTESucc LTEZero) =\n ([1,1] ** (Refl, (IsNonEmpty **\n ((LTESucc LTEZero), (Refl, Right Refl)))))\nfactor2 (S (S k)) Z (LTESucc LTEZero) = assert_unreachable\nfactor2 (S (S k)) (S Z) (LTESucc LTEZero) =\n ([(S (S k)), 1] **\n (rewrite multOneRightNeutral k in Refl,\n (IsNonEmpty ** ((LTESucc LTEZero),\n (rewrite multOneRightNeutral k in Refl, Right Refl)))))\nfactor2 (S (S k)) (S (S x)) (LTESucc LTEZero) =\n case decDiv (S (S k)) (LTESucc (LTESucc LTEZero)) (S (S x))\n {euc = eculidDivideAux (S (S k)) (S (S x)) (SIsNotZ)} of\n (Yes prf) => help10 (S (S k)) (k) Refl (S (S x)) (x) Refl prf\n (No contra) => factor2 (S (S k)) (S x) (LTESucc LTEZero)\n\n--Factorises a number completely with proof of folding\nfactorise : (n : Nat) -> (GT n 0) ->\n (lst : List Nat ** (foldList Nat 1 (*) lst = n))\nfactorise Z LTEZero impossible\nfactorise Z (LTESucc _) impossible\nfactorise (S Z) (LTESucc LTEZero) = ([] ** Refl)\nfactorise (S (S k)) (LTESucc LTEZero) with\n (factor2 (S (S k)) (S k) (LTESucc LTEZero))\n factorise (S (S k)) (LTESucc LTEZero) |\n (lst ** (fol, (ntMT ** (lastLt, (pf2, primepf))))) = assert_total(\n (( (head {ok=ntMT} lst) ::\n (fst (factorise (last {ok=ntMT} lst) lastLt))) **\n (rewrite (snd (factorise (last {ok=ntMT} lst) lastLt))\n in (sym pf2)) ))\n\n-- creates a list with all the factors of a number upto the second argument\ngenFact : (n : Nat) -> Nat -> List (k : Nat ** isDivisible n k)\ngenFact Z Z = []\ngenFact Z (S k) = []\ngenFact (S j) Z = []\ngenFact (S Z) (S k) = [(S Z ** oneDiv (S Z))]\ngenFact (S (S j)) (S k) =\n case (decDiv (S (S j)) (LTESucc (LTESucc (LTEZero{right = j}))) (S k)\n {euc=eculidDivideAux (S (S j)) (S k) SIsNotZ }) of\n (Yes prf) => (genFact (S (S j)) k) ++ [(S k ** prf)]\n (No contra) => (genFact (S (S j)) k)\n\n\n--if the List has only 2 elements, i.e 1 and p, then the number is prime. the function outputs a list (secretly genFact)\n-- along with the proof that the length of the list of factors is 2\nisPrimeWithoutProof : (p: Nat) -> {auto pf: LTE 2 p} -> Type\nisPrimeWithoutProof p = length (genFact p p) = 2\n\n-- more than 2 factors implies number is composite\nisCompositeWithoutProof : (n: Nat) -> {auto pf: LTE 2 n} -> Type\nisCompositeWithoutProof n = Prelude.Nat.GT (Prelude.List.length (genFact n n)) 2\n\n-- Two is a prime\ntwoPr : (isPrime 2 (LTESucc (LTESucc (LTEZero {right =0}))))\ntwoPr {k=Z} (x ** pf) = void (SIsNotZ (snd pf))\ntwoPr {k=(S Z)} (x ** pf) = Left Refl\ntwoPr {k=(S (S Z))} (x ** pf) = Right Refl\ntwoPr {k=(S (S (S k)))} pf = void (bGtAImpNotbDivA 2 (S (S (S k))) k (LTESucc (LTESucc (LTESucc (LTEZero {right = k})))) (pf))\n\n--Composite proof\nisComposite : (n : Nat) -> LTE 2 n -> Type\nisComposite n pflte = (a : Nat ** (b : Nat ** ((GT a 1, GT b 1), n = a*b)))\n\n-- --deciability for Composite numbers\n-- decComposite : (n: Nat) -> (pf : LTE 2 n) -> Dec (isComposite n pf)\n-- decComposite Z LTEZero impossible\n-- decComposite Z (LTESucc _) impossible\n-- decComposite (S Z) (LTESucc LTEZero) impossible\n-- decComposite (S Z) (LTESucc (LTESucc _)) impossible\n-- decComposite (S (S k)) pf = ?decCompositerhs_1\n--\n--\n\n\n--if 1 LTE 1 a -> (n : Nat) -> LTE 2 n -> (a = a*n) -> Void\naNotEqToMultA _ _ Z LTEZero _ impossible\naNotEqToMultA _ _ Z (LTESucc _) _ impossible\naNotEqToMultA _ _ (S Z) (LTESucc LTEZero) _ impossible\naNotEqToMultA _ _ (S Z) (LTESucc (LTESucc _)) _ impossible\naNotEqToMultA Z LTEZero (S (S _)) _ _ impossible\naNotEqToMultA Z (LTESucc _) (S (S _)) _ _ impossible\naNotEqToMultA (S j) (LTESucc (LTEZero {right = j})) (S (S k)) (LTESucc (LTESucc (LTEZero {right = k}))) prf =\n SIsNotZ {x = j+(k*(S j))} (sym (pfeq)) where\n pfeq = plusLeftCancel (S j) Z ((S k)*(S j)) pfeq1 where\n pfeq1 = rewrite (multCommutative (S (S k)) (S j)) in\n trans (plusZeroRightNeutral (S j)) prf\n\n--helper apNat function\napNat : (f: Nat -> Nat) -> (n: Nat) -> (m: Nat) -> n = m -> f n = f m\napNat f m m Refl = Refl\n\n--n is not both prime and composite\nnotBothPrimeandComp : {n : Nat} -> (pf : LTE 2 n) -> Not (isPrime n pf, isComposite n pf)\nnotBothPrimeandComp {n = Z} LTEZero _ impossible\nnotBothPrimeandComp {n = Z} (LTESucc _) _ impossible\nnotBothPrimeandComp {n = (S Z)} (LTESucc LTEZero) _ impossible\nnotBothPrimeandComp {n = (S Z)} (LTESucc (LTESucc _)) _ impossible\nnotBothPrimeandComp {n = (S (S k))} pftwolten (pfprime , (a ** (b ** ((pfagtone, pfbgtone), pfneqab)))) =\n void (aNotEqToMultA (S (S k)) (lteTransitive (LTESucc (LTEZero {right = (S Z)})) pftwolten) b pfbgtone pfeq) where\n pfeq = (trans pfneqab funceq) where\n funceq = (apNat (\\x=>(x*b)) a (S (S k)) pfaeqn) where\n pfaeqn = case (pfprime (b ** ((lteTransitive (LTESucc (LTEZero {right = (S Z)})) pfbgtone), pfneqab))) of\n Left pf => void ((Prelude.Basics.fst (ltImpliesNotEqNotGT {a=(S Z)} {b = a} pfagtone)) (sym pf))\n Right pf => pf\n--\n-- -- given n >= 2, it is either prime or Composite\n-- eitherPrimeOrComp : {n : Nat} -> (pf : LTE 2 n) -> Either (isPrime n pf)(isComposite n pf)\n-- eitherPrimeOrComp {n = Z} LTEZero impossible\n-- eitherPrimeOrComp {n = Z} (LTESucc _) impossible\n-- eitherPrimeOrComp {n = (S Z)} (LTESucc LTEZero) impossible\n-- eitherPrimeOrComp {n = (S Z)} (LTESucc (LTESucc _)) impossible\n-- eitherPrimeOrComp {n = (S (S k))} pflte = ?rhs_1\n", "meta": {"hexsha": "28941f7eeef77db5b31cce84bc71c10b145424a5", "size": 9025, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/PrimeApple.idr", "max_stars_repo_name": "adithyaupadhya/LTS2019", "max_stars_repo_head_hexsha": "b7cd4b678330ad1028400187bfb66684505fa725", "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": "Code/PrimeApple.idr", "max_issues_repo_name": "adithyaupadhya/LTS2019", "max_issues_repo_head_hexsha": "b7cd4b678330ad1028400187bfb66684505fa725", "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": "Code/PrimeApple.idr", "max_forks_repo_name": "adithyaupadhya/LTS2019", "max_forks_repo_head_hexsha": "b7cd4b678330ad1028400187bfb66684505fa725", "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": 47.0052083333, "max_line_length": 142, "alphanum_fraction": 0.5491412742, "num_tokens": 3029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7026857411440305}} {"text": "module Basen\n\nimport Data.Fin\n\n%access public export\n--Fin to Nat\ntonatFin: (n: Nat) -> Fin(n) -> Nat\ntonatFin (S k) FZ = Z\ntonatFin (S k) (FS x) = S (tonatFin k x)\n\n--List Fin to Nat\ntonat: (n: Nat) -> List (Fin(n)) -> Nat\ntonat n [] = Z\ntonat n (x :: xs) = (tonatFin n x)*(power n (length xs)) + (tonat n xs)\n\n\n--Euclid's div\nEucl: (a: Nat) -> (b: Nat) -> (Nat, Nat)\nEucl Z b = (0,0)\nEucl (S k) b = case (lte (S (S k)) b) of\n False => (S(fst(Eucl (minus (S k) b) b)), snd(Eucl (minus (S k) b) b))\n True => (0, S k)\n\n--Nat to Fin (modular values)\ntofinNat: (a: Nat) -> (n: Nat) -> Fin n\ntofinNat Z (S j) = FZ\ntofinNat (S k) (S j) = case lte (S k) (S j) of\n True => FS (tofinNat k j)\n False => (tofinNat (snd(Eucl (S k) (S j))) (S j))\n\n--left strips FZ from lists\nstrp: List (Fin n) -> List (Fin n)\nstrp [] = []\nstrp (x :: xs) = case x of\n FZ => strp(xs)\n (FS y) => x::xs\n\n-- Nat to List Fin n (base n representation)\ntofin: Nat -> (n: Nat) -> List (Fin n)\ntofin Z (S j) = [FZ]\ntofin (S k) (S j) = strp(reverse(rem :: reverse(tofin q (S j)))) where\n rem = tofinNat (snd(Eucl (S k) (S j))) (S j)\n q = fst(Eucl (S k) (S j))\n\n--adding two Fin n's\naddfin: (n: Nat) -> Fin (S n) -> Fin (S n) -> Fin (S n) -> (Fin (S n), Fin (S n))\naddfin n x y z = case (tofin ((tonatFin (S n) x)+ (tonatFin (S n) y) + (tonatFin (S n) z)) (S n)) of\n [l] => (FZ, l)\n [k, l] => (k,l)\n\n--adding two reversed lists as specified\naddfinl: (n: Nat) -> List (Fin (S n)) -> List (Fin (S n)) -> List (Fin (S n))\naddfinl n [] ys = strp(ys)\naddfinl n (x :: xs) [] = strp(x::xs)\naddfinl n (x :: xs) (y :: ys) = (snd(addfin n FZ x y)::(addfinl n (addfinl n [fst(addfin n FZ x y)] xs) ys))\n\n--adding two lists\naddfinlist: (n: Nat) -> List (Fin (S n)) -> List (Fin (S n)) -> List (Fin (S n))\naddfinlist n xs ys = reverse(addfinl n (reverse xs) (reverse ys))\n\n--embedding Fin n in Fin S n vertically\nembn: (n: Nat) -> Fin n -> Fin (S n)\nembn (S k) FZ = FZ\nembn (S k) (FS x) = FS (embn k x)\n\n--Unused mulfinNat - multiplies two Fin n's\nmulfinNat: (n: Nat) -> Fin (n) -> Fin (n) -> (Fin (n), Fin (n))\nmulfinNat (S n) x y = case tofin ((tonatFin (S n) x)*(tonatFin (S n) y)) (S n) of\n [l] => (FZ, l)\n [k,l] => (k,l)\n\n--multiply two reversed lists in Fin S n\nmulfinl: (n: Nat) -> List (Fin (S n)) -> List (Fin (S n)) -> List (Fin (S n))\nmulfinl n xs [] = []\nmulfinl n xs (FZ :: ys) = FZ :: (mulfinl n xs ys)\nmulfinl n xs ((FS x) :: ys) = addfinl n (mulfinl n xs ((embn n x)::ys)) xs\n\n--multpily two lists\nmulfinList: (n: Nat) -> List (Fin (S n)) -> List (Fin (S n)) -> List (Fin (S n))\nmulfinList n xs ys = reverse(mulfinl n (reverse xs) (reverse ys))\n\n--proof that right addition preserves equality (somehow cong was messing up)\naddl: (x: Type) -> (z: List x) -> (l = y) -> (l ++ z = y ++ z)\naddl x z Refl = Refl\n\n-- Proof that the auxiliary reverseOnto used to define rev behaves the way it should (semi-pseudo-contravariantly as I choose to call it)\nrevontoeq: (x: Type) -> (y: List x) -> (l: List x) -> ((reverseOnto y l) = ((reverseOnto [] l) ++ y))\nrevontoeq x y [] = Refl\nrevontoeq x [] (z :: xs) = sym (appendNilRightNeutral (reverseOnto [] (z::xs)))\nrevontoeq x (y :: ys) (z :: xs) = trans (trans (revontoeq x (z::y::ys) xs) ((appendAssociative (reverseOnto [] xs) [z] (y::ys)))) (sym (addl x (y::ys) (revontoeq x [z] xs)))\n\n--Proof that reverse is pseudo-contravariant on concatenation\nreviscontra: (x: Type) -> (y: List x) -> (l: List x) -> (reverse(y++l) = reverse(l)++reverse(y))\nreviscontra x [] z = sym (appendNilRightNeutral (reverseOnto [] z))\nreviscontra x (y :: xs) z = trans (trans (trans (revontoeq x [y] (xs++z)) (addl x [y] (reviscontra x xs z))) (sym (appendAssociative (reverse z) (reverse xs) [y]))) (cong(sym (revontoeq x [y] xs)))\n\n-- Proof that the reverse function is self-inverse\nreveq: (x: Type) -> (l: List x) -> (l = reverse(reverse l))\nreveq x [] = Refl\nreveq x (y :: xs) = sym (trans (trans (cong(reviscontra x [y] xs)) (reviscontra x (reverse xs) (reverse [y]))) (cong(sym (reveq x xs))))\n", "meta": {"hexsha": "65a2ae25ae235caf3e13b433ffdb18e6f629f4eb", "size": 4211, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/BaseN.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "_local-site/Code/BaseN.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "_local-site/Code/BaseN.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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.6930693069, "max_line_length": 197, "alphanum_fraction": 0.551412966, "num_tokens": 1595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7024068504915282}} {"text": "data SplitList : List a -> Type where\n SplitNil : SplitList []\n SplitOne : SplitList [x]\n SplitPair : (lefts : List a) -> (rights : List a) -> SplitList (lefts ++ rights)\n\ntotal\nsplitList : (input : List a) -> SplitList input\nsplitList input = splitListHelp input input\n where\n splitListHelp : List a -> (input : List a) -> SplitList input\n splitListHelp _ [] = SplitNil\n splitListHelp _ [x] = SplitOne\n splitListHelp (_ :: _ :: counter) (item :: items) =\n case splitListHelp counter items of\n SplitNil => SplitOne\n SplitOne {x} => SplitPair [item] [x]\n SplitPair lefts rights => SplitPair (item :: lefts) rights\n splitListHelp _ items = SplitPair [] items\n\nmergeSort : Ord a => List a -> List a\nmergeSort input with (splitList input)\n mergeSort [] | SplitNil = []\n mergeSort [x] | SplitOne = [x]\n mergeSort (lefts ++ rights) | (SplitPair lefts rights) =\n merge (mergeSort lefts) (mergeSort rights)\n", "meta": {"hexsha": "6b3193cdee99b9c38cc792d3112aed37bd0837e9", "size": 1008, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/MergeSort.idr", "max_stars_repo_name": "0nkery/tt-tutorials", "max_stars_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/MergeSort.idr", "max_issues_repo_name": "0nkery/tt-tutorials", "max_issues_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": "idris-exercises/MergeSort.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "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": 38.7692307692, "max_line_length": 84, "alphanum_fraction": 0.6170634921, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.7021304647201401}} {"text": "module Interfaces.HeytingAlgebra\n\nimport Control.Algebra.Lattice\nimport Interfaces.Verified\n\n%hide Prelude.Monad.join\n%access public export\n\n\n--------------------------------------------------------------------------------\n-- Interfaces\n--------------------------------------------------------------------------------\n\ninterface (BoundedJoinSemilattice a, BoundedMeetSemilattice a, Ord a) => HeytingAlgebra a where\n not : a -> a\n implies : a -> a -> a\n\n\n--------------------------------------------------------------------------------\n-- Verified Interfaces\n--------------------------------------------------------------------------------\n\ninterface (VerifiedJoinSemilattice a, BoundedJoinSemilattice a) => VerifiedBoundedJoinSemilattice a where\n boundedJoinSemilatticeIdentity : (x : a) -> join x Control.Algebra.Lattice.bottom = x\n\ninterface (VerifiedMeetSemilattice a, BoundedMeetSemilattice a) => VerifiedBoundedMeetSemilattice a where\n boundedMeetSemilatticeIdentity : (x : a) -> meet x Control.Algebra.Lattice.top = x\n\ninterface (VerifiedJoinSemilattice a, VerifiedMeetSemilattice a) => VerifiedLattice a where {}\n\ninterface Lattice a => VerifiedDistributiveLattice a where\n meetDistributesOverJoin : (x, y, z : a) -> x `meet` (y `join` z) = (x `meet` y) `join` (x `meet` z)\n\ninterface (VerifiedLattice a, VerifiedDistributiveLattice a, HeytingAlgebra a) => VerifiedHeytingAlgebra a where\n total heytingAlgebraPseudoComplement : (x : a) -> HeytingAlgebra.not x = x `implies` Control.Algebra.Lattice.bottom\n total heytingAlgebraRelativePseudoComplement : (x, y, z : a) -> (z `meet` x) <= y = z <= (x `implies` y)\n\ninterface VerifiedHeytingAlgebra a => VerifiedInvolutiveHeytingAlgebra a where\n heytingAlgebraInvolution : (x : a) -> HeytingAlgebra.not (HeytingAlgebra.not x) = x\n\n\n--------------------------------------------------------------------------------\n-- Implementations\n--------------------------------------------------------------------------------\n\nJoinSemilattice Bool where\n join x y = x || y\n\nBoundedJoinSemilattice Bool where\n bottom = False\n\nMeetSemilattice Bool where\n meet x y = x && y\n\nBoundedMeetSemilattice Bool where\n top = True\n\nLattice Bool where {}\n\nHeytingAlgebra Bool where\n not = Prelude.Bool.not\n implies x y = (not x) || y\n\n\n--------------------------------------------------------------------------------\n-- Verified Implementations\n--------------------------------------------------------------------------------\n\nVerifiedJoinSemilattice Bool where\n joinSemilatticeJoinIsAssociative False False False = Refl\n joinSemilatticeJoinIsAssociative False False True = Refl\n joinSemilatticeJoinIsAssociative False True False = Refl\n joinSemilatticeJoinIsAssociative False True True = Refl\n joinSemilatticeJoinIsAssociative True False False = Refl\n joinSemilatticeJoinIsAssociative True False True = Refl\n joinSemilatticeJoinIsAssociative True True False = Refl\n joinSemilatticeJoinIsAssociative True True True = Refl\n joinSemilatticeJoinIsCommutative False False = Refl\n joinSemilatticeJoinIsCommutative False True = Refl\n joinSemilatticeJoinIsCommutative True False = Refl\n joinSemilatticeJoinIsCommutative True True = Refl\n joinSemilatticeJoinIsIdempotent False = Refl\n joinSemilatticeJoinIsIdempotent True = Refl\n\nVerifiedBoundedJoinSemilattice Bool where\n boundedJoinSemilatticeIdentity False = Refl\n boundedJoinSemilatticeIdentity True = Refl\n\nVerifiedMeetSemilattice Bool where\n meetSemilatticeMeetIsAssociative False False False = Refl\n meetSemilatticeMeetIsAssociative False False True = Refl\n meetSemilatticeMeetIsAssociative False True False = Refl\n meetSemilatticeMeetIsAssociative False True True = Refl\n meetSemilatticeMeetIsAssociative True False False = Refl\n meetSemilatticeMeetIsAssociative True False True = Refl\n meetSemilatticeMeetIsAssociative True True False = Refl\n meetSemilatticeMeetIsAssociative True True True = Refl\n meetSemilatticeMeetIsCommutative False False = Refl\n meetSemilatticeMeetIsCommutative False True = Refl\n meetSemilatticeMeetIsCommutative True False = Refl\n meetSemilatticeMeetIsCommutative True True = Refl\n meetSemilatticeMeetIsIdempotent False = Refl\n meetSemilatticeMeetIsIdempotent True = Refl\n\nVerifiedBoundedMeetSemilattice Bool where\n boundedMeetSemilatticeIdentity False = Refl\n boundedMeetSemilatticeIdentity True = Refl\n\nVerifiedLattice Bool where {}\n\nVerifiedDistributiveLattice Bool where\n meetDistributesOverJoin False False False = Refl\n meetDistributesOverJoin False False True = Refl\n meetDistributesOverJoin False True False = Refl\n meetDistributesOverJoin False True True = Refl\n meetDistributesOverJoin True False False = Refl\n meetDistributesOverJoin True False True = Refl\n meetDistributesOverJoin True True False = Refl\n meetDistributesOverJoin True True True = Refl\n\nVerifiedHeytingAlgebra Bool where\n heytingAlgebraPseudoComplement False = Refl\n heytingAlgebraPseudoComplement True = Refl\n heytingAlgebraRelativePseudoComplement False False False = Refl\n heytingAlgebraRelativePseudoComplement False False True = Refl\n heytingAlgebraRelativePseudoComplement False True False = Refl\n heytingAlgebraRelativePseudoComplement False True True = Refl\n heytingAlgebraRelativePseudoComplement True False False = Refl\n heytingAlgebraRelativePseudoComplement True False True = Refl\n heytingAlgebraRelativePseudoComplement True True False = Refl\n heytingAlgebraRelativePseudoComplement True True True = Refl\n\nVerifiedInvolutiveHeytingAlgebra Bool where\n heytingAlgebraInvolution False = Refl\n heytingAlgebraInvolution True = Refl\n", "meta": {"hexsha": "b131bb0e9193e8acc3be89a1021dd36d9ff14861", "size": 5585, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Interfaces/HeytingAlgebra.idr", "max_stars_repo_name": "Risto-Stevcev/idris-heyting-algebra", "max_stars_repo_head_hexsha": "122489e5a615837c47e67ebc5828fbbe3939a5b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-07-03T16:47:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-27T01:02:01.000Z", "max_issues_repo_path": "Interfaces/HeytingAlgebra.idr", "max_issues_repo_name": "Risto-Stevcev/idris-heyting-algebra", "max_issues_repo_head_hexsha": "122489e5a615837c47e67ebc5828fbbe3939a5b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-07-03T17:08:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-17T15:51:46.000Z", "max_forks_repo_path": "Interfaces/HeytingAlgebra.idr", "max_forks_repo_name": "Risto-Stevcev/idris-heyting-algebra", "max_forks_repo_head_hexsha": "122489e5a615837c47e67ebc5828fbbe3939a5b8", "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.0661764706, "max_line_length": 117, "alphanum_fraction": 0.7190689346, "num_tokens": 1408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.7020089652396457}} {"text": "> module NonNegRational.LTEProperties\n\n> import Syntax.PreorderReasoning\n\n> import NonNegRational.NonNegRational\n> import NonNegRational.BasicOperations\n> import NonNegRational.BasicProperties\n> import NonNegRational.Predicates\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.Predicates\n> import Fraction.BasicProperties\n> import Fraction.Normalize\n> import Fraction.NormalizeProperties\n> import Fraction.EqProperties\n> import Fraction.LTEProperties\n> import Fraction.Normal\n> import Subset.Properties\n> import Unique.Predicates\n> import Nat.Positive\n> import Num.Refinements\n> import Pairs.Operations\n> import Nat.LTEProperties\n> import Nat.OperationsProperties\n> -- import ListProperties \n> import Rel.TotalPreorder \n\n> %default total\n> %access public export\n\n\n|LTE| is a total preorder:\n\n> ||| LTE is reflexive\n> reflexiveLTE : (x : NonNegRational) -> x `LTE` x\n> reflexiveLTE x = reflexiveLTE (toFraction x)\n> %freeze reflexiveLTE\n\n\n> ||| LTE is transitive\n> transitiveLTE : (x, y, z : NonNegRational) -> x `LTE` y -> y `LTE` z -> x `LTE` z\n> transitiveLTE x y z xLTEy yLTEz = transitiveLTE (toFraction x) (toFraction y) (toFraction z) xLTEy yLTEz\n> %freeze transitiveLTE\n\n\n> ||| LTE is total\n> totalLTE : (x, y : NonNegRational) -> Either (x `LTE` y) (y `LTE` x) \n> totalLTE x y = totalLTE (toFraction x) (toFraction y)\n> %freeze totalLTE\n\n\n> ||| LTE is a total preorder\n> totalPreorderLTE : TotalPreorder NonNegRational.Predicates.LTE\n> totalPreorderLTE = MkTotalPreorder LTE reflexiveLTE transitiveLTE totalLTE\n\n\nProperties of |LTE| and |plus|:\n\n> ||| LTE is monotone w.r.t. `plus`\n> monotonePlusLTE : {a, b, c, d : NonNegRational} -> \n> a `LTE` b -> c `LTE` d -> (a + c) `LTE` (b + d)\n> monotonePlusLTE {a} {b} {c} {d} aLTEb cLTEd = s4 where\n> s1 : LTE (toFraction a + toFraction c) (toFraction b + toFraction d)\n> s1 = Fraction.LTEProperties.monotonePlusLTE aLTEb cLTEd\n> s2 : LTE (normalize (toFraction a + toFraction c)) \n> (normalize (toFraction b + toFraction d))\n> s2 = normalizeLTELemma (toFraction a + toFraction c) (toFraction b + toFraction d) s1\n> s3 : LTE (toFraction (fromFraction (toFraction a + toFraction c)))\n> (toFraction (fromFraction (toFraction b + toFraction d)))\n> s3 = s2\n> s4 : LTE (fromFraction (toFraction a + toFraction c)) (fromFraction (toFraction b + toFraction d))\n> s4 = s3\n> s5 : LTE (a + c) (b + d)\n> s5 = s4\n> %freeze monotonePlusLTE\n\n\nProperties of |LTE| and |mult|:\n\n> ||| LTE is monotone w.r.t. `(*)`\n> monotoneMultLTE : {a, b, c, d : NonNegRational} -> \n> a `LTE` b -> c `LTE` d -> (a * c) `LTE` (b * d)\n> monotoneMultLTE {a} {b} {c} {d} aLTEb cLTEd = s4 where\n> s1 : LTE (toFraction a * toFraction c) (toFraction b * toFraction d)\n> s1 = Fraction.LTEProperties.monotoneMultLTE aLTEb cLTEd\n> s2 : LTE (normalize (toFraction a * toFraction c)) \n> (normalize (toFraction b * toFraction d))\n> s2 = normalizeLTELemma (toFraction a * toFraction c) (toFraction b * toFraction d) s1\n> s3 : LTE (toFraction (fromFraction (toFraction a * toFraction c)))\n> (toFraction (fromFraction (toFraction b * toFraction d)))\n> s3 = s2\n> s4 : LTE (fromFraction (toFraction a * toFraction c)) (fromFraction (toFraction b * toFraction d))\n> s4 = s3\n> s5 : LTE (a * c) (b * d)\n> s5 = s4\n> %freeze monotoneMultLTE\n\n\n> {-\n\n> ---}\n \n", "meta": {"hexsha": "0746cbe4509a3030a02a7ee2df4452b3289004bd", "size": 3405, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegRational/LTEProperties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-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": "NonNegRational/LTEProperties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-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": "NonNegRational/LTEProperties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0582524272, "max_line_length": 106, "alphanum_fraction": 0.6772393539, "num_tokens": 1089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7017366259365344}} {"text": "-- examples in \"Type-Driven Development with Idris\"\n-- chapter 9\n\nimport Data.Vect\n\n-- check that all functions are total\n%default total\n\n--\n-- section 9.1\n--\n\nmaryInVector : Elem \"Mary\" [\"Peter\", \"Paul\", \"Mary\"]\nmaryInVector = There (There Here)\n\nremoveElem2 : (value : a) -> (xs : Vect (S n) a) ->\n (prf : Elem value xs) ->\n Vect n a\nremoveElem2 value (value :: ys) Here = ys\nremoveElem2 {n = Z} value (y :: []) (There later) = absurd later\nremoveElem2 {n = (S k)} value (y :: ys) (There later)\n = y :: removeElem2 value ys later\n\nremoveElem_auto : (value : a) -> (xs : Vect (S n) a) ->\n {auto prf : Elem value xs} ->\n Vect n a\nremoveElem_auto value xs {prf} = removeElem2 value xs prf\n\n\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--\n-- section 9.2\n-- see Hangman.idr\n--\n", "meta": {"hexsha": "9170b87010d61d6b55d9eac9e9609b8a6d91afbc", "size": 1115, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter9/examples.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": "chapter9/examples.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": "chapter9/examples.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": 26.5476190476, "max_line_length": 69, "alphanum_fraction": 0.5721973094, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7017233335179833}} {"text": "module LinearAlgebra\n\nimport BaseN\nimport Linear.MultiSolver\nimport Data.Matrix.Numeric\nimport Data.Vect\nimport Data.Fin\nimport Merge\nimport Data.Matrix\nimport ZZ\nimport Rationals\n\n%access public export\n\n-- Some auxillary functions for elementary operations\n\nFST: ZZPair -> ZZ --some issue with fst\nFST (a, b) = a\n\nPred: Nat -> Nat -- needed to get (n-1) for number of operations\nPred Z = Z\nPred (S k) = k\n\nSimpleCast: (v1:(Vect (k+ (S Z)) elem)) ->( Vect (S k) elem) -- necessary for type matching, taken from Shafil's code\nSimpleCast {k} v1 = (Vecttake (S k) v1)\n\nRowN: Matrix n n ZZPair -> (k: Nat) -> Vect n ZZPair -- returns the nth row (indexing from 0)\nRowN {n} x k = Data.Vect.index (tofinNat k n) x\n\nij: Matrix n n ZZPair -> (i: Nat) -> (j: Nat) -> ZZPair\nij {n} x i j = Data.Vect.index (tofinNat j n) (RowN x i)\n\nColumnN: Matrix n n ZZPair -> (k: Nat) -> Vect n ZZPair --returns the nth column (indexing from 0)\nColumnN {n} x k = Data.Vect.index (tofinNat k n) (transpose x)\n\nVectorSubtract: (n: Nat) -> (a: Vect n ZZPair) -> (b: Vect n ZZPair) -> (Vect n ZZPair) --subtracts components\nVectorSubtract n a b = a - b\n\nScaleVect: (n: Nat) -> (Vect n ZZPair) -> (c: ZZPair) -> (Vect n ZZPair) --scales by a rational\nScaleVect n xs c = c <# xs\n\n--returns the row scaled by a constant minus another vector (used in row operations)\n\naxpy: (n: Nat) -> (a: Vect n ZZPair) -> (b: Vect n ZZPair) -> (c: ZZPair) -> (Vect n ZZPair)\naxpy n a b c = VectorSubtract (n) (a) (ScaleVect (n) b c)\n\n--Auxillary functions, will be used in the Gauss-Jordan process\n\nFirst_k_rows: (n: Nat) -> (x: Matrix n n ZZPair) -> (k: Nat) -> Matrix k n ZZPair\nFirst_k_rows n x Z = []\nFirst_k_rows n x (S k) = [RowN x k] ++ (First_k_rows n x k)\n\nLast_k_rows: (n: Nat) -> (x: Matrix n n ZZPair) -> (k: Nat) -> Matrix k n ZZPair\nLast_k_rows n x k = reverse (First_k_rows n (reverse x) k)\n\nFirst_k_rows_from_RowP: (n: Nat) -> (x: Matrix n n ZZPair) -> (p: Nat) -> (k: Nat) -> Matrix k n ZZPair\nFirst_k_rows_from_RowP n x p Z = []\nFirst_k_rows_from_RowP n x p (S k) = SimpleCast ((First_k_rows_from_RowP n x p k) ++ [RowN x (p+k)])\n\n-- A section on elementary operations (to eventually implement the Gauss-Jordan process)\n\n-- Swaps two rows in a matrix (indexing from 0)\n\nSwapRows: (n: Nat) -> Matrix n n ZZPair -> (a: Nat) -> (b: Nat) -> Matrix n n ZZPair\nSwapRows n x a b = replaceAt (tofinNat b n) (RowN x a) (replaceAt (tofinNat a n) (RowN x b) (x))\n\n-- Performs an elementary row operation, subtracts from row a the row b scaled by c\n\nRowOperation: (n: Nat) -> Matrix n n ZZPair -> (a: Nat) -> (b: Nat) -> (c: ZZPair) -> Matrix n n ZZPair\nRowOperation n x a b c = replaceAt (tofinNat a n) (axpy n (RowN x a) (RowN x b) c) (x)\n\n-- Makes the kth number in Row A zero by subtracting a scaling of Row B (for upper triangularizing)\n-- As usual, indexing starts from 0\n\nMakeElementZero: (n: Nat) -> (x: Matrix n n ZZPair) -> (row_a : Nat) -> (row_b : Nat) -> (pos : Nat) -> Matrix n n ZZPair\nMakeElementZero n x row_a row_b pos = case (FST(ij x row_a pos)) of\n (Pos Z) => x\n (Pos (S k)) => case ((fst (ij x row_b pos))) of\n (Pos Z) => (SwapRows n x row_a row_b)\n (Pos (S k)) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n (NegS k) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n (NegS k) => case ((fst (ij x row_b pos))) of\n (Pos Z) => (SwapRows n x row_a row_b)\n (Pos (S k)) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n (NegS k) => (RowOperation n x row_a row_b (divZZ (ij x row_a pos) (ij x row_b pos)) )\n\n-- Explanation: We want to transform the element x[row_a][pos] into zero by a row operation. There are a few different cases\n-- 1. If x[row_a][pos] is already zero, nothing needs to be done.\n-- 2. If not, we scale row_b appropriately and do a row operation (A -> A - cB)\n-- 3. If x[row_b][pos] is zero, however, no row operation will work. We simply swap the\n-- row_a and row_b here; then, x[row_a][pos] will become zero.\n\n-- This algorithm is important to make a matrix upper-triangular.\n\nMakeColumnZero: (n: Nat) -> (x: Matrix n n ZZPair) -> (col : Nat) -> (iter : Nat) -> Matrix n n ZZPair\nMakeColumnZero n x col Z = x\nMakeColumnZero n x col (S k) = case (isLTE (S k) col) of\n (Yes prf) => x\n (No contra) => (MakeColumnZero n (MakeElementZero n x (S k) col col) col k)\n\n-- This function turns a column into what it should be in upper-triangular form by adding in the necessary zeros.\n-- iter is a variable to induct on (trick courtesy Sriram)\n-- When using this, make sure to set \"iter\" as n-1 (1 less than the number of rows)\n\n-- The next step here is to use the above function to make a matrix upper triangular. This can be\n-- done by inducting on the number of columns.\n\n-- A helper function, which recursively fills zeros into columns.\n\nUpperTriangularize: (x: Matrix n n ZZPair) -> (iter: Nat) -> Matrix n n ZZPair\nUpperTriangularize {n} x Z = (MakeColumnZero n x Z (Pred n)) -- Column Zero is the base case\nUpperTriangularize {n} x (S k) = (MakeColumnZero n (UpperTriangularize x k) (S k) (Pred n))\n\n-- Enter a matrix, get the upper triangular form.\n\nUpperTriangularForm: (x: Matrix n n ZZPair) -> Matrix n n ZZPair\nUpperTriangularForm {n} x = UpperTriangularize x (Pred (Pred n))\n\n-- The function below converts a matrix into a Diagonal Form (note that this is NOT diagonalization!) by converting to upper-triangular\n-- form, transposing that (to get a lower triangular matrix) and finding the upper-triangular form of the tranpose. This is going to be useful\n-- as it is the next step of the Gauss-Jordan algorithm (what's next: divide out the rows to get an identity matrix; an inverse can be\n-- found this way by applying all the above row operations to an identity matrix.\n\nDiagonalForm: (x: Matrix n n ZZPair) -> Matrix n n ZZPair\nDiagonalForm {n} x = UpperTriangularForm (transpose (UpperTriangularForm x))\n", "meta": {"hexsha": "f428a94c3e326d9e098f0d2b3df55cdf56aa55f4", "size": 6569, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/LinearAlgebra.idr", "max_stars_repo_name": "NabarunDeka/LTS2019", "max_stars_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "_local-site/Code/LinearAlgebra.idr", "max_issues_repo_name": "NabarunDeka/LTS2019", "max_issues_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": "_local-site/Code/LinearAlgebra.idr", "max_forks_repo_name": "NabarunDeka/LTS2019", "max_forks_repo_head_hexsha": "61531e577c313975418f440bf9f6afe21a31ac81", "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": 52.1349206349, "max_line_length": 162, "alphanum_fraction": 0.6142487441, "num_tokens": 1903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.7010827876424446}} {"text": "= IndProp : Inductively Defined Propositions\n\n> module IndProp\n>\n> import Basics\n> import Induction\n> import Tactics\n> import Logic\n>\n> %hide Basics.Numbers.pred\n>\n> %access public export\n> %default total\n\n\n== Inductively Defined Propositions\n\nIn the `Logic` chapter, we looked at several ways of writing propositions,\nincluding conjunction, disjunction, and quantifiers. In this chapter, we bring a\nnew tool into the mix: _inductive definitions_.\n\nRecall that we have seen two ways of stating that a number \\idr{n} is even: We\ncan say (1) \\idr{evenb n = True}, or (2) \\idr{(k ** n = double k)}. Yet another\npossibility is to say that \\idr{n} is even if we can establish its evenness from\nthe following rules:\n\n - Rule \\idr{ev_0}: The number \\idr{0} is even.\n - Rule \\idr{ev_SS}: If \\idr{n} is even, then \\idr{S (S n)} is even.\n\nTo illustrate how this definition of evenness works, let's imagine using it to\nshow that \\idr{4} is even. By rule \\idr{ev_SS}, it suffices to show that \\idr{2}\nis even. This, in turn, is again guaranteed by rule \\idr{ev_SS}, as long as we\ncan show that \\idr{0} is even. But this last fact follows directly from the\n\\idr{ev_0} rule.\n\nWe will see many definitions like this one during the rest of the course. For\npurposes of informal discussions, it is helpful to have a lightweight notation\nthat makes them easy to read and write. _Inference rules_ are one such notation:\n\n\\[\n \\begin{prooftree}\n \\infer0[\\idr{ev_0}]{\\idr{ev 0}}\n \\end{prooftree}\n\\]\n\n\\[\n \\begin{prooftree}\n \\hypo{\\idr{ev n}}\n \\infer1[\\idr{ev_SS}]{\\idr{ev (S (S n))}}\n \\end{prooftree}\n\\]\n\nEach of the textual rules above is reformatted here as an inference rule; the\nintended reading is that, if the _premises_ above the line all hold, then the\nconclusion below the line follows. For example, the rule \\idr{ev_SS} says that,\nif \\idr{n} satisfies \\idr{ev}, then \\idr{S (S n)} also does. If a rule has no\npremises above the line, then its conclusion holds unconditionally.\n\nWe can represent a proof using these rules by combining rule applications into a\n_proof tree_. Here's how we might transcribe the above proof that \\idr{4} is\neven:\n\n\\[\n \\begin{prooftree}\n \\infer0[\\idr{ev_0}]{\\idr{ev 0}}\n \\infer1[\\idr{ev_SS}]{\\idr{ev 2}}\n \\infer1[\\idr{ev_SS}]{\\idr{ev 4}}\n \\end{prooftree}\n\\]\n\nWhy call this a \"tree\" (rather than a \"stack\", for example)? Because, in\ngeneral, inference rules can have multiple premises. We will see examples of\nthis below.\n\nPutting all of this together, we can translate the definition of evenness into a\nformal Idris definition using an \\idr{data} declaration, where each constructor\ncorresponds to an inference rule:\n\n> data Ev : Nat -> Type where\n> Ev_0 : Ev Z\n> Ev_SS : {n : Nat} -> Ev n -> Ev (S (S n))\n>\n\nThis definition is different in one crucial respect from previous uses of\n\\idr{data}: its result is not a \\idr{Type}, but rather a function from \\idr{Nat}\nto \\idr{Type} -- that is, a property of numbers. Note that we've already seen\nother inductive definitions that result in functions, such as \\idr{List}, whose\ntype is \\idr{Type -> Type}. What is new here is that, because the \\idr{Nat}\nargument of \\idr{Ev} appears unnamed, to the right of the colon, it is allowed\nto take different values in the types of different constructors: \\idr{Z} in the\ntype of \\idr{Ev_0} and \\idr{S (S n)} in the type of \\idr{Ev_SS}.\n\nIn contrast, the definition of \\idr{List} names the \\idr{x} parameter globally,\nforcing the result of \\idr{Nil} and \\idr{(::)} to be the same (\\idr{List x}).\nHad we tried to name \\idr{Nat} in defining \\idr{Ev}, we would have seen an\nerror:\n\n```idris\ndata Wrong_ev : (n : Nat) -> Type where\n Wrong_ev_0 : Wrong_ev Z\n Wrong_ev_SS : n -> Wrong_ev n -> Wrong_ev (S (S n))\n```\n\n```idris\nWhen checking type of IndType.Wrong_ev_SS:\nWhen checking argument n to IndType.Wrong_ev:\n Type mismatch between\n Type (Type of n)\n and\n Nat (Expected type)\n```\n\n\\todo[inline]{Edit the explanation, it works fine if you remove the first \n\\idr{n ->} in \\idr{Wrong_ev_SS}}\n\n(\"Parameter\" here is Idris jargon for an argument on the left of the colon in an\nInductive definition; \"index\" is used to refer to arguments on the right of the\ncolon.)\n\nWe can think of the definition of \\idr{Ev} as defining a Idris property\n\\idr{Ev : Nat -> Type}, together with theorems \\idr{Ev_0 : Ev Z} and\n\\idr{Ev_SS : n -> Ev n -> Ev (S (S n))}. Such \"constructor theorems\" have the\nsame status as proven theorems. In particular, we can apply rule names as\nfunctions to each other to prove \\idr{Ev} for particular numbers...\n\n> ev_4 : Ev 4\n> ev_4 = Ev_SS {n=2} $ Ev_SS {n=0} Ev_0\n>\n\nWe can also prove theorems that have hypotheses involving \\idr{Ev}.\n\n> ev_plus4 : Ev n -> Ev (4 + n)\n> ev_plus4 x = Ev_SS $ Ev_SS x\n>\n\nMore generally, we can show that any number multiplied by 2 is even:\n\n\n==== Exercise: 1 star (ev_double)\n\n> ev_double : Ev (double n)\n> ev_double = ?ev_double_rhs\n>\n\n$\\square$\n\n\n== Using Evidence in Proofs\n\nBesides _constructing_ evidence that numbers are even, we can also _reason\nabout_ such evidence.\n\nIntroducing \\idr{Ev} with a \\idr{data} declaration tells Idris not only that the\nconstructors \\idr{Ev_0} and \\idr{Ev_SS} are valid ways to build evidence that\nsome number is even, but also that these two constructors are the _only_ ways to\nbuild evidence that numbers are even (in the sense of \\idr{Ev}).\n\nIn other words, if someone gives us evidence \\idr{e} for the assertion \\idr{Ev\nn}, then we know that \\idr{e} must have one of two shapes:\n\n - \\idr{e} is \\idr{Ev_0} (and \\idr{n} is \\idr{Z}), or\n\n - \\idr{e} is \\idr{Ev_SS {n=n'} e'} (and \\idr{n} is \\idr{S (S n')}, where\n \\idr{e'} is evidence for \\idr{Ev n'}).\n\nThis suggests that it should be possible to analyze a hypothesis of the form\n\\idr{Ev n} much as we do inductively defined data structures; in particular, it\nshould be possible to argue by _induction_ and _case analysis_ on such evidence.\nLet's look at a few examples to see what this means in practice.\n\n\n=== Pattern Matching on Evidence\n\n\\ \\todo[inline]{Edit the whole section to talk about dependent pattern matching}\n\nSuppose we are proving some fact involving a number \\idr{n}, and we are given\n\\idr{Ev n} as a hypothesis. We already know how to perform case analysis on\n\\idr{n} using the `inversion` tactic, generating separate subgoals for the case\nwhere \\idr{n = Z} and the case where \\idr{n = S n'} for some \\idr{n'}. But for\nsome proofs we may instead want to analyze the evidence that \\idr{Ev n}\ndirectly.\n\nBy the definition of \\idr{Ev}, there are two cases to consider:\n\n - If the evidence is of the form \\idr{Ev_0}, we know that \\idr{n = Z}.\n\n - Otherwise, the evidence must have the form \\idr{Ev_SS {n=n'} e'}, where\n \\idr{n = S (S n')} and \\idr{e'} is evidence for \\idr{Ev n'}.\n\nWe can perform this kind of reasoning in Idris, again using pattern matching.\nBesides allowing us to reason about equalities involving constructors,\n`inversion` provides a case-analysis principle for inductively defined\npropositions. When used in this way, its syntax is similar to `destruct`: We\npass it a list of identifiers separated by `|` characters to name the arguments\nto each of the possible constructors.\n\n> ev_minus2 : Ev n -> Ev (pred (pred n))\n> ev_minus2 Ev_0 = Ev_0\n> ev_minus2 (Ev_SS e') = e'\n>\n\nIn words, here is how the pattern match reasoning works in this proof:\n\n - If the evidence is of the form \\idr{Ev_0}, we know that \\idr{n = Z}.\n Therefore, it suffices to show that \\idr{Ev (pred (pred Z))} holds. By the\n definition of \\idr{pred}, this is equivalent to showing that \\idr{Ev Z}\n holds, which directly follows from \\idr{Ev_0}.\n\n - Otherwise, the evidence must have the form \\idr{Ev_SS {n=n'} e'}, where\n \\idr{n = S (S n')} and \\idr{e'} is evidence for \\idr{Ev n'}. We must then\n show that \\idr{Ev (pred (pred (S (S n'))))} holds, which, after\n simplification, follows directly from \\idr{e'}.\n\nSuppose that we wanted to prove the following variation of \\idr{ev_minus2}:\n\n> evSS_ev : Ev (S (S n)) -> Ev n\n\nIntuitively, we know that evidence for the hypothesis cannot consist just of the\n\\idr{Ev_0} constructor, since \\idr{Z} and \\idr{S} are different constructors of\nthe type \\idr{Nat}; hence, \\idr{Ev_SS} is the only case that applies.\nUnfortunately, destruct is not smart enough to realize this, and it still\ngenerates two subgoals. Even worse, in doing so, it keeps the final goal\nunchanged, failing to provide any useful information for completing the proof.\n\nThe inversion tactic, on the other hand, can detect (1) that the first case does\nnot apply, and (2) that the \\idr{n'} that appears on the \\idr{Ev_SS} case must\nbe the same as \\idr{n}. This allows us to complete the proof\n\n> evSS_ev (Ev_SS e') = e'\n>\n\nBy using dependent pattern matching, we can also apply the principle of\nexplosion to \"obviously contradictory\" hypotheses involving inductive\nproperties. For example:\n\n> one_not_even : Not (Ev 1)\n> one_not_even Ev_0 impossible\n> one_not_even (Ev_SS _) impossible\n>\n\n\n=== Exercise: 1 star (inversion_practice)\n\nProve the following results using pattern matching.\n\n> SSSSev__even : Ev (S (S (S (S n)))) -> Ev n\n> SSSSev__even e = ?SSSSev__even_rhs\n>\n> even5_nonsense : Ev 5 -> 2 + 2 = 9\n> even5_nonsense e = ?even5_nonsense_rhs\n>\n\n$\\square$\n\n\\todo[inline]{Edit}\n\nThe way we've used `inversion` here may seem a bit mysterious at first. Until now,\nwe've only used `inversion` on equality propositions, to utilize injectivity of\nconstructors or to discriminate between different constructors. But we see here\nthat `inversion` can also be applied to analyzing evidence for inductively defined\npropositions.\n\nHere's how `inversion` works in general. Suppose the name `I` refers to an\nassumption `P` in the current context, where `P` has been defined by an\n`Inductive` declaration. Then, for each of the constructors of `P`, `inversion\nI` generates a subgoal in which `I` has been replaced by the exact, specific\nconditions under which this constructor could have been used to prove `P`. Some\nof these subgoals will be self-contradictory; `inversion` throws these away. The\nones that are left represent the cases that must be proved to establish the\noriginal goal. For those, `inversion` adds all equations into the proof context\nthat must hold of the arguments given to `P` (e.g., \\idr{S (S n') = n} in the\nproof of \\idr{evSS_ev}).\n\nThe \\idr{ev_double} exercise above shows that our new notion of evenness is\nimplied by the two earlier ones (since, by \\idr{even_bool_prop} in chapter\n`Logic`, we already know that those are equivalent to each other). To show that\nall three coincide, we just need the following lemma:\n\n> ev_even : Ev n -> (k ** n = double k)\n\nWe proceed by case analysis on \\idr{Ev n}. The first case can be solved\ntrivially.\n\n> ev_even Ev_0 = (Z ** Refl)\n\nUnfortunately, the second case is harder. We need to show \n\\idr{(k ** S (S n') = double k}, but the only available assumption is \\idr{e'},\nwhich states that \\idr{Ev n'} holds. Since this isn't directly useful, it seems\nthat we are stuck and that performing case analysis on \\idr{Ev n} was a waste of\ntime.\n\nIf we look more closely at our second goal, however, we can see that something\ninteresting happened: By performing case analysis on \\idr{Ev n}, we were able to\nreduce the original result to an similar one that involves a _different_ piece\nof evidence for \\idr{Ev n}: \\idr{e'}. More formally, we can finish our proof by\nshowing that\n\n```idris\n(k' ** n' = double k')\n```\n\nwhich is the same as the original statement, but with \\idr{n'} instead of\n\\idr{n}. Indeed, it is not difficult to convince Idris that this intermediate\nresult suffices.\n\n> ev_even (Ev_SS e') = I $ ev_even e'\n> where\n> I : (k' ** n' = double k') -> (k ** S (S n') = double k)\n> I (k' ** prf) = (S k' ** cong {f=S} $ cong {f=S} prf)\n>\n\n\n=== Induction on Evidence\n\n\\ \\todo[inline]{Edit, we've already just done an induction-style proof, the\nfollowing is basically replacing `where` with `let`}\n\nIf this looks familiar, it is no coincidence: We've encountered similar problems\nin the `Induction` chapter, when trying to use case analysis to prove results\nthat required induction. And once again the solution is... induction!\n\nThe behavior of `induction` on evidence is the same as its behavior on data: It\ncauses Idris to generate one subgoal for each constructor that could have used\nto build that evidence, while providing an induction hypotheses for each\nrecursive occurrence of the property in question.\n\nLet's try our current lemma again:\n\n> ev_even' : Ev n -> (k ** n = double k)\n> ev_even' Ev_0 = (Z ** Refl)\n> ev_even' (Ev_SS e') =\n> let\n> (k**prf) = ev_even e'\n> cprf = cong {f=S} $ cong {f=S} prf\n> in\n> rewrite cprf in (S k ** Refl)\n>\n\nHere, we can see that Idris produced an `IH` that corresponds to `E'`, the\nsingle recursive occurrence of ev in its own definition. Since E' mentions n',\nthe induction hypothesis talks about n', as opposed to n or some other number.\n\nThe equivalence between the second and third definitions of evenness now\nfollows.\n\n> ev_even_iff : (Ev n) <-> (k ** n = double k)\n> ev_even_iff = (ev_even, fro)\n> where\n> fro : (k ** n = double k) -> (Ev n)\n> fro (k ** prf) = rewrite prf in ev_double {n=k}\n>\n\nAs we will see in later chapters, induction on evidence is a recurring technique\nacross many areas, and in particular when formalizing the semantics of\nprogramming languages, where many properties of interest are defined\ninductively.\n\nThe following exercises provide simple examples of this technique, to help you\nfamiliarize yourself with it.\n\n\n==== Exercise: 2 stars (ev_sum)\n\n> ev_sum : Ev n -> Ev m -> Ev (n + m)\n> ev_sum x y = ?ev_sum_rhs\n>\n\n$\\square$\n\n\n=== Exercise: 4 stars, advanced, optional (ev_alternate)\n\nIn general, there may be multiple ways of defining a property inductively. For\nexample, here's a (slightly contrived) alternative definition for \\idr{Ev}:\n\n> data Ev' : Nat -> Type where\n> Ev'_0 : Ev' Z\n> Ev'_2 : Ev' 2\n> Ev'_sum : Ev' n -> Ev' m -> Ev' (n + m)\n>\n\nProve that this definition is logically equivalent to the old one. (You may want\nto look at the previous theorem when you get to the induction step.)\n\n> ev'_ev : (Ev' n) <-> Ev n\n> ev'_ev = ?ev__ev_rhs\n>\n\n$\\square$\n\n\n=== Exercise: 3 stars, advanced, recommended (ev_ev__ev)\n\nFinding the appropriate thing to do induction on is a bit tricky here:\n\n> ev_ev__ev : Ev (n+m) -> Ev n -> Ev m\n> ev_ev__ev x y = ?ev_ev__ev_rhs\n>\n\n$\\square$\n\n\n==== Exercise: 3 stars, optional (ev_plus_plus)\n\nThis exercise just requires applying existing lemmas. No induction or even case\nanalysis is needed, though some of the rewriting may be tedious.\n\n> ev_plus_plus : Ev (n+m) -> Ev (n+p) -> Ev (m+p)\n> ev_plus_plus x y = ?ev_plus_plus_rhs\n>\n\n$\\square$\n\n\n== Inductive Relations\n\nA proposition parameterized by a number (such as \\idr{Ev}) can be thought of as\na _property_ -- i.e., it defines a subset of \\idr{Nat}, namely those numbers for\nwhich the proposition is provable. In the same way, a two-argument proposition\ncan be thought of as a _relation_ -- i.e., it defines a set of pairs for which\nthe proposition is provable.\n\nOne useful example is the \"less than or equal to\" relation on numbers.\n\nThe following definition should be fairly intuitive. It says that there are two\nways to give evidence that one number is less than or equal to another: either\nobserve that they are the same number, or give evidence that the first is less\nthan or equal to the predecessor of the second.\n\n> data Le : Nat -> Nat -> Type where\n> Le_n : Le n n\n> Le_S : Le n m -> Le n (S m)\n>\n> syntax [m] \"<='\" [n] = Le m n\n>\n\nProofs of facts about \\idr{<='} using the constructors \\idr{Le_n} and \\idr{Le_S}\nfollow the same patterns as proofs about properties, like \\idr{Ev} above. We can\napply the constructors to prove \\idr{<='} goals (e.g., to show that \\idr{3<='3}\nor \\idr{3<='6}), and we can use pattern matching to extract information from\n\\idr{<='} hypotheses in the context (e.g., to prove that \\idr{(2<='1) ->\n2+2=5}.)\n\nHere are some sanity checks on the definition. (Notice that, although these are\nthe same kind of simple \"unit tests\" as we gave for the testing functions we\nwrote in the first few lectures, we must construct their proofs explicitly --\n\\idr{Refl} doesn't do the job, because the proofs aren't just a matter of\nsimplifying computations.)\n\n> test_le1 : 3 <=' 3\n> test_le1 = Le_n\n>\n> test_le2 : 3 <=' 6\n> test_le2 = Le_S $ Le_S $ Le_S Le_n\n>\n> test_le3 : (2<='1) -> 2+2=5\n> test_le3 (Le_S Le_n) impossible\n> test_le3 (Le_S (Le_S _)) impossible\n>\n\nThe \"strictly less than\" relation \\idr{n < m} can now be defined in terms of\n\\idr{Le}.\n\n> Lt : (n, m : Nat) -> Type\n> Lt n m = Le (S n) m\n>\n> syntax [m] \"<'\" [n] = Lt m n\n>\n\nHere are a few more simple relations on numbers:\n\n> data Square_of : Nat -> Nat -> Type where\n> Sq : Square_of n (n * n)\n>\n> data Next_nat : Nat -> Nat -> Type where\n> Nn : Next_nat n (S n)\n>\n> data Next_even : Nat -> Nat -> Type where\n> Ne_1 : Ev (S n) -> Next_even n (S n)\n> Ne_2 : Ev (S (S n)) -> Next_even n (S (S n))\n\n\n==== Exercise: 2 stars, optional (total_relation)\n\nDefine an inductive binary relation \\idr{Total_relation} that holds between\nevery pair of natural numbers.\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n=== Exercise: 2 stars, optional (empty_relation)\n\nDefine an inductive binary relation \\idr{Empty_relation} (on numbers) that never\nholds.\n\n> --FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 3 stars, optional (le_exercises)\n\nHere are a number of facts about the \\idr{<='} and \\idr{<'} relations that we\nare going to need later in the course. The proofs make good practice exercises.\n\n> le_trans : (m <=' n) -> (n <=' o) -> (m <=' o)\n> le_trans x y = ?le_trans_rhs\n>\n> O_le_n : Z <=' n\n> O_le_n = ?O_le_n_rhs\n>\n> n_le_m__Sn_le_Sm : (n <=' m) -> ((S n) <=' (S m))\n> n_le_m__Sn_le_Sm x = ?n_le_m__Sn_le_Sm_rhs\n>\n> Sn_le_Sm__n_le_m : ((S n) <=' (S m)) -> (n <=' m)\n> Sn_le_Sm__n_le_m x = ?Sn_le_Sm__n_le_m_rhs\n>\n> le_plus_l : a <=' (a + b)\n> le_plus_l = ?le_plus_l_rhs\n>\n> plus_lt : ((n1 + n2) <' m) -> (n1 <' m, n2 <' m)\n> plus_lt x = ?plus_lt_rhs\n>\n> lt_S : (n <' m) -> (n <' S m)\n> lt_S x = ?lt_S_rhs\n>\n> lte_complete : lte n m = True -> (n <=' m)\n> lte_complete prf = ?lte_complete_rhs\n>\n\nHint: The next one may be easiest to prove by induction on \\idr{m}.\n\n> lte_correct : (n <=' m) -> lte n m = True\n> lte_correct x = ?lte_correct_rhs\n>\n\nHint: This theorem can easily be proved without using induction.\n\n> lte_true_trans : lte n m = True -> lte m o = True -> lte n o = True\n> lte_true_trans prf prf1 = ?lte_true_trans_rhs\n>\n\n\n==== Exercise: 2 stars, optional (lte_iff)\n\n> lte_iff : (lte n m = True) <-> (n <=' m)\n> lte_iff = ?lte_iff_rhs\n>\n\n$\\square$\n\n> namespace R\n>\n\n==== Exercise: 3 stars, recommended (R_provability)\n\nWe can define three-place relations, four-place relations, etc., in just the\nsame way as binary relations. For example, consider the following three-place\nrelation on numbers:\n\n> data R : Nat -> Nat -> Nat -> Type where\n> C1 : R 0 0 0\n> C2 : R m n o -> R (S m) n (S o)\n> C3 : R m n o -> R m (S n) (S o)\n> C4 : R (S m) (S n) (S (S o)) -> R m n o\n> C5 : R m n o -> R n m o\n>\n\nWhich of the following propositions are provable?\n\n - \\idr{R 1 1 2}\n\n - \\idr{R 2 2 6}\n\n - If we dropped constructor \\idr{C5} from the definition of \\idr{R}, would the\n set of provable propositions change? Briefly (1 sentence) explain your\n answer.\n\n - If we dropped constructor \\idr{C4} from the definition of \\idr{R}, would the\n set of provable propositions change? Briefly (1 sentence) explain your\n answer.\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 3 stars, optional (R_fact)\n\nThe relation \\idr{R} above actually encodes a familiar function. Figure out\nwhich function; then state and prove this equivalence in Idris?\n\n> fR : Nat -> Nat -> Nat\n> fR k j = ?fR_rhs\n>\n> R_equiv_fR : (R m n o) <-> (fR m n = o)\n> R_equiv_fR = ?R_equiv_fR_rhs\n>\n\n$\\square$\n\n\n=== Exercise: 4 stars, advanced (subsequence)\n\nA list is a _subsequence_ of another list if all of the elements in the first\nlist occur in the same order in the second list, possibly with some extra\nelements in between. For example,\n\n```idris\n [1,2,3]\n```\n\nis a subsequence of each of the lists\n\n```idris\n [1,2,3]\n [1,1,1,2,2,3]\n [1,2,7,3]\n [5,6,1,9,9,2,7,3,8]\n```\n\nbut it is not a subsequence of any of the lists\n\n```idris\n [1,2]\n [1,3]\n [5,6,2,1,7,3,8]\n```\n\n - Define an inductive type \\idr{Subseq} on \\idr{List Nat} that captures what\n it means to be a subsequence. (Hint: You'll need three cases.)\n\n - Prove \\idr{subseq_refl} that subsequence is reflexive, that is, any list is\n a subsequence of itself.\n\n - Prove \\idr{subseq_app} that for any lists \\idr{l1}, \\idr{l2}, and \\idr{l3},\n if \\idr{l1} is a subsequence of \\idr{l2}, then \\idr{l1} is also a\n subsequence of \\idr{l2 ++ l3}.\n\n - (Optional, harder) Prove \\idr{subseq_trans} that subsequence is transitive\n -- that is, if \\idr{l1} is a subsequence of \\idr{l2} and \\idr{l2} is a\n subsequence of \\idr{l3}, then \\idr{l1} is a subsequence of \\idr{l3}. Hint:\n choose your induction carefully!\n\n> -- FILL IN HERE\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional (R_provability2)\n\nSuppose we give Idris the following definition:\n\n> data R' : Nat -> List Nat -> Type where\n> C1' : R' 0 []\n> C2' : R' n l -> R' (S n) (n :: l)\n> C3' : R' (S n) l -> R' n l\n>\n\nWhich of the following propositions are provable?\n\n - \\idr{R' 2 [1,0]}\n\n - \\idr{R' 1 [1,2,1,0]}\n\n - \\idr{R' 6 [3,2,1,0]}\n\n$\\square$\n\n\n== Case Study: Regular Expressions\n\nThe \\idr{Ev} property provides a simple example for illustrating inductive\ndefinitions and the basic techniques for reasoning about them, but it is not\nterribly exciting -- after all, it is equivalent to the two non-inductive of\nevenness that we had already seen, and does not seem to offer any concrete\nbenefit over them. To give a better sense of the power of inductive definitions,\nwe now show how to use them to model a classic concept in computer science:\n_regular expressions_.\n\nRegular expressions are a simple language for describing strings, defined as\nfollows:\n\n> data Reg_exp : (t : Type) -> Type where\n> EmptySet : Reg_exp t\n> EmptyStr : Reg_exp t\n> Chr : t -> Reg_exp t\n> App : Reg_exp t -> Reg_exp t -> Reg_exp t\n> Union : Reg_exp t -> Reg_exp t -> Reg_exp t\n> Star : Reg_exp t -> Reg_exp t\n>\n\nNote that this definition is _polymorphic_: Regular expressions in \n\\idr{Reg_exp t} describe strings with characters drawn from\\idr{t} -- that is,\nlists of elements of \\idr{t}.\n\n(We depart slightly from standard practice in that we do not require the type\n\\idr{t} to be finite. This results in a somewhat different theory of regular\nexpressions, but the difference is not significant for our purposes.)\n\nWe connect regular expressions and strings via the following rules, which define\nwhen a regular expression _matches_ some string:\n\n - The expression \\idr{EmptySet} does not match any string.\n\n - The expression \\idr{EmptyStr} matches the empty string \\idr{[]}.\n\n - The expression \\idr{Chr x} matches the one-character string \\idr{[x]}.\n\n - If \\idr{re1} matches \\idr{s1}, and \\idr{re2} matches \\idr{s2}, then \n \\idr{App re1 re2} matches \\idr{s1 ++ s2}.\n\n - If at least one of \\idr{re1} and \\idr{re2} matches \\idr{s}, then \n \\idr{Union re1 re2} matches \\idr{s}.\n\n - Finally, if we can write some string \\idr{s} as the concatenation of a\n sequence of strings \\idr{s = s_1 ++ ... ++ s_k}, and the expression \\idr{re}\n matches each one of the strings \\idr{s_i}, then \\idr{Star re} matches\n \\idr{s}.\n\n As a special case, the sequence of strings may be empty, so \\idr{Star re}\n always matches the empty string \\idr{[]} no matter what \\idr{re} is.\n\nWe can easily translate this informal definition into a \\idr{data} one as\nfollows:\n\n> data Exp_match : List t -> Reg_exp t -> Type where\n> MEmpty : Exp_match [] EmptyStr\n> MChar : Exp_match [x] (Chr x)\n> MApp : Exp_match s1 re1 -> Exp_match s2 re2 ->\n> Exp_match (s1 ++ s2) (App re1 re2)\n> MUnionL : Exp_match s1 re1 ->\n> Exp_match s1 (Union re1 re2)\n> MUnionR : Exp_match s2 re2 ->\n> Exp_match s2 (Union re1 re2)\n> MStar0 : Exp_match [] (Star re)\n> MStarApp : Exp_match s1 re ->\n> Exp_match s2 (Star re) ->\n> Exp_match (s1 ++ s2) (Star re)\n>\n\nAgain, for readability, we can also display this definition using inference-rule\nnotation. At the same time, let's introduce a more readable infix notation.\n\n> syntax [s] \"=~\" [re] = (Exp_match s re)\n>\n\n\\[\n \\begin{prooftree}\n \\infer0[\\idr{MEmpty}]{\\idr{[] =~ EmptyStr}}\n \\end{prooftree}\n\\]\n\n\\[\n \\begin{prooftree}\n \\infer0[\\idr{MChar}]{\\idr{[x] =~ Chr x}}\n \\end{prooftree}\n\\]\n\n\\[\n \\begin{prooftree}\n \\hypo{\\idr{s1 =~ re1}}\n \\hypo{\\idr{s2 =~ r2}}\n \\infer2[\\idr{MApp}]{\\idr{s1 ++ s2 =~ App re1 re2}}\n \\end{prooftree}\n\\]\n\n\\[\n \\begin{prooftree}\n \\hypo{\\idr{s1 =~ re1}}\n \\infer1[\\idr{MUnionL}]{\\idr{s1 =~ Union re1 re2}}\n \\end{prooftree}\n\\]\n\n\n\\[\n \\begin{prooftree}\n \\hypo{\\idr{s2 =~ re2}}\n \\infer1[\\idr{MUnionR}]{\\idr{s2 =~ Union re1 re2}}\n \\end{prooftree}\n\\]\n\n\\[\n \\begin{prooftree}\n \\infer0[\\idr{MStar0}]{\\idr{[] =~ Star re}}\n \\end{prooftree}\n\\]\n\n\\[\n \\begin{prooftree}\n \\hypo{\\idr{s1 =~ re}}\n \\hypo{\\idr{s2 =~ Star re}}\n \\infer2[\\idr{MStarApp}]{\\idr{s1 ++ s2 =~ Star re}}\n \\end{prooftree}\n\\]\n\nNotice that these rules are not _quite_ the same as the informal ones that we\ngave at the beginning of the section. First, we don't need to include a rule\nexplicitly stating that no string matches \\idr{EmptySet}; we just don't happen\nto include any rule that would have the effect of some string matching\n\\idr{EmptySet}. (Indeed, the syntax of inductive definitions doesn't even\n_allow_ us to give such a \"negative rule.\")\n\nSecond, the informal rules for \\idr{Union} and \\idr{Star} correspond to two\nconstructors each: \\idr{MUnionL} / \\idr{MUnionR}, and \\idr{MStar0} /\n\\idr{MStarApp}. The result is logically equivalent to the original rules but\nmore convenient to use in Idris, since the recursive occurrences of\n\\idr{Exp_match} are given as direct arguments to the constructors, making it\neasier to perform induction on evidence. (The \\idr{exp_match_ex1} and\n\\idr{exp_match_ex2} exercises below ask you to prove that the constructors given\nin the inductive declaration and the ones that would arise from a more literal\ntranscription of the informal rules are indeed equivalent.)\n\nLet's illustrate these rules with a few examples.\n\n> reg_exp_ex1 : [1] =~ (Chr 1)\n> reg_exp_ex1 = MChar\n>\n\n```idris\nreg_exp_ex2 : [1,2] =~ (App (Chr 1) (Chr 2))\nreg_exp_ex2 = MApp {s1=[1]} {s2=[2]} MChar MChar\n```\n\nNotice how the last example applies \\idr{MApp} to the strings \\idr{[1]} and\n\\idr{[2]} directly. While the goal mentions \\idr{[1,2]} instead of \n\\idr{[1] ++ [2]}, Idris is able to figure out how to split the string on its\nown, so we can drop the implicits:\n\n> reg_exp_ex2 : [1,2] =~ (App (Chr 1) (Chr 2))\n> reg_exp_ex2 = MApp MChar MChar\n>\n\nUsing pattern matching, we can also show that certain strings do not match a\nregular expression:\n\n> reg_exp_ex3 : Not ([1,2] =~ (Chr 1))\n> reg_exp_ex3 MEmpty impossible\n> reg_exp_ex3 MChar impossible\n> reg_exp_ex3 (MApp _ _) impossible\n> reg_exp_ex3 (MUnionL _) impossible\n> reg_exp_ex3 (MUnionR _) impossible\n> reg_exp_ex3 MStar0 impossible\n> reg_exp_ex3 (MStarApp _ _) impossible\n>\n\nWe can define helper functions to help write down regular expressions. The\n\\idr{reg_exp_of_list} function constructs a regular expression that matches\nexactly the list that it receives as an argument:\n\n> reg_exp_of_list : List t -> Reg_exp t\n> reg_exp_of_list [] = EmptyStr\n> reg_exp_of_list (x :: xs) = App (Chr x) (reg_exp_of_list xs)\n>\n> reg_exp_ex4 : [1,2,3] =~ (reg_exp_of_list [1,2,3])\n> reg_exp_ex4 = MApp MChar $ MApp MChar $ MApp MChar MEmpty\n>\n\nWe can also prove general facts about \\idr{Exp_match}. For instance, the\nfollowing lemma shows that every string \\idr{s} that matches \\idr{re} also\nmatches \\idr{Star re}.\n\n> MStar1 : (s =~ re) -> (s =~ Star re)\n> MStar1 {s} h =\n> rewrite sym $ appendNilRightNeutral s in\n> MStarApp h MStar0\n>\n\n(Note the use of \\idr{appendNilRightNeutral} to change the goal of the theorem\nto exactly the same shape expected by \\idr{MStarApp}.)\n\n\n==== Exercise: 3 stars (exp_match_ex1)\n\nThe following lemmas show that the informal matching rules given at the\nbeginning of the chapter can be obtained from the formal inductive definition.\n\n> empty_is_empty : Not (s =~ EmptySet)\n> empty_is_empty = ?empty_is_empty_rhs\n>\n> MUnion' : (s =~ re1, s =~ re2) -> s =~ Union re1 re2\n> MUnion' m = ?MUnion__rhs\n>\n\nThe next lemma is stated in terms of the \\idr{fold} function from the \\idr{Poly}\nchapter: If \\idr{ss : List (List t)} represents a sequence of strings \\idr{s1,\n..., sn}, then \\idr{fold (++) ss []} is the result of concatenating them all\ntogether.\n\n\\todo[inline]{Copied from \\idr{Poly}, cannot import it due to tuple sugar\nissues}\n\n> fold : (f : x -> y -> y) -> (l : List x) -> (b : y) -> y\n> fold f [] b = b\n> fold f (h::t) b = f h (fold f t b)\n>\n> MStar' : ((s : List t) -> (In s ss) -> (s =~ re)) ->\n> (fold (++) ss []) =~ Star re\n> MStar' f = ?MStar__rhs\n>\n\n$\\square$\n\n\n==== Exercise: 4 stars (reg_exp_of_list)\n\nProve that \\idr{reg_exp_of_list} satisfies the following specification:\n\n> reg_exp_of_list_spec : (s1 =~ reg_exp_of_list s2) <-> (s1 = s2)\n> reg_exp_of_list_spec = ?reg_exp_of_list_spec_rhs\n>\n\n$\\square$\n\nSince the definition of \\idr{Exp_match} has a recursive structure, we might\nexpect that proofs involving regular expressions will often require induction on\nevidence. For example, suppose that we wanted to prove the following intuitive\nresult: If a regular expression \\idr{re} matches some string \\idr{s}, then all\nelements of \\idr{s} must occur somewhere in \\idr{re}. To state this theorem, we\nfirst define a function \\idr{re_chars} that lists all characters that occur in a\nregular expression:\n\n> re_chars : (re : Reg_exp t) -> List t\n> re_chars EmptySet = []\n> re_chars EmptyStr = []\n> re_chars (Chr x) = [x]\n> re_chars (App re1 re2) = re_chars re1 ++ re_chars re2\n> re_chars (Union re1 re2) = re_chars re1 ++ re_chars re2\n> re_chars (Star re) = re_chars re\n>\n> re_star : re_chars (Star re) = re_chars re\n> re_star = Refl\n>\n\nWe can then phrase our theorem as follows:\n\n\\todo[inline]{Some unfortunate implicit plumbing}\n\n> destruct : In x (s1 ++ s2) -> (In x s1) `Either` (In x s2)\n> destruct {x} {s1} {s2} = fst $ in_app_iff {a=x} {l=s1} {l'=s2}\n>\n> construct : (In x (re_chars re1)) `Either` (In x (re_chars re2)) ->\n> In x ((re_chars re1) ++ (re_chars re2))\n> construct {x} {re1} {re2} =\n> snd $ in_app_iff {a=x} {l=(re_chars re1)} {l'=(re_chars re2)}\n>\n> in_re_match : (s =~ re) -> In x s -> In x (re_chars re)\n> in_re_match MEmpty prf = prf\n> in_re_match MChar prf = prf\n> in_re_match (MApp m1 m2) prf = construct $ case destruct prf of\n> Left prf1 => Left $ in_re_match m1 prf1\n> Right prf2 => Right $ in_re_match m2 prf2\n> in_re_match (MUnionL ml) prf = construct $ Left $ in_re_match ml prf\n> in_re_match (MUnionR mr) prf = construct $ Right $ in_re_match mr prf\n> in_re_match MStar0 prf = absurd prf\n> in_re_match (MStarApp m ms) prf = case destruct prf of\n\n\\todo[inline]{Edit}\n\nSomething interesting happens in the \\idr{MStarApp} case. We obtain two\ninduction hypotheses: One that applies when \\idr{x} occurs in \\idr{s1} (which\nmatches \\idr{re}), and a second one that applies when \\idr{x} occurs in \\idr{s2}\n(which matches \\idr{Star re}). This is a good illustration of why we need\ninduction on evidence for \\idr{Exp_match}, as opposed to \\idr{re}: The latter\nwould only provide an induction hypothesis for strings that match \\idr{re},\nwhich would not allow us to reason about the case \\idr{In x s2}.\n\n> Left prf' => in_re_match m prf'\n> Right prfs => in_re_match ms prfs\n>\n\n\n==== Exercise: 4 stars (re_not_empty)\n\nWrite a recursive function \\idr{re_not_empty} that tests whether a regular\nexpression matches some string. Prove that your function is correct.\n\n> re_not_empty : (re : Reg_exp t) -> Bool\n> re_not_empty re = ?re_not_empty_rhs\n>\n> re_not_empty_correct : (s ** s =~ re) <-> re_not_empty re = True\n> re_not_empty_correct = ?re_not_empty_correct_rhs\n>\n\n$\\square$\n\n\n=== The remember Tactic\n\n\\ \\todo[inline]{Rewrite the section, dependent pattern matching figures all of\nthis out}\n\nOne potentially confusing feature of the induction tactic is that it happily\nlets you try to set up an induction over a term that isn't sufficiently general.\nThe effect of this is to lose information (much as destruct can do), and leave\nyou unable to complete the proof. Here's an example:\n\n> star_app : (s1 =~ Star re) -> (s2 =~ Star re) -> (s1 ++ s2) =~ Star re\n> star_app MStar0 m2 = m2\n> star_app {s2} (MStarApp {s1=s11} {s2=s21} m ms) m2 =\n> rewrite sym $ appendAssociative s11 s21 s2 in\n> MStarApp m (star_app ms m2)\n>\n\nJust doing an inversion on H1 won't get us very far in the recursive cases. (Try\nit!). So we need induction. Here is a naive first attempt:\n\n```coq\n induction H1\n as [|x'|s1 re1 s2' re2 Hmatch1 IH1 Hmatch2 IH2\n |s1 re1 re2 Hmatch IH|re1 s2' re2 Hmatch IH\n |re''|s1 s2' re'' Hmatch1 IH1 Hmatch2 IH2].\n```\n\nBut now, although we get seven cases (as we would expect from the definition of\nExp_match), we have lost a very important bit of information from H1: the fact\nthat s1 matched something of the form Star re. This means that we have to give\nproofs for all seven constructors of this definition, even though all but two of\nthem (MStar0 and MStarApp) are contradictory. We can still get the proof to go\nthrough for a few constructors, such as MEmpty...\n\n```coq\n - (* MEmpty *)\n simpl. intros H. apply H.\n```\n\n... but most cases get stuck. For MChar, for instance, we must show that\n\n```coq\n s2 =~ Char x' -> x' :: s2 =~ Char x',\n```\n\nwhich is clearly impossible.\n\n```coq\n - (* MChar. Stuck... *)\nAbort.\n```\n\nThe problem is that induction over a Type hypothesis only works properly with\nhypotheses that are completely general, i.e., ones in which all the arguments\nare variables, as opposed to more complex expressions, such as Star re.\n\n(In this respect, induction on evidence behaves more like destruct than like\ninversion.)\n\nWe can solve this problem by generalizing over the problematic expressions with\nan explicit equality:\n\n```coq\nLemma star_app: forall T (s1 s2 : list T) (re re' : Reg_exp T),\n s1 =~ re' ->\n re' = Star re ->\n s2 =~ Star re ->\n s1 ++ s2 =~ Star re.\n```\n\nWe can now proceed by performing induction over evidence directly, because the\nargument to the first hypothesis is sufficiently general, which means that we\ncan discharge most cases by inverting the re' = Star re equality in the context.\n\nThis idiom is so common that Idris provides a tactic to automatically generate\nsuch equations for us, avoiding thus the need for changing the statements of our\ntheorems.\n\nInvoking the tactic remember e as x causes Idris to (1) replace all occurrences\nof the expression e by the variable x, and (2) add an equation x = e to the\ncontext. Here's how we can use it to show the above result:\n\n```coq\nAbort.\n\nLemma star_app: forall T (s1 s2 : list T) (re : Reg_exp T),\n s1 =~ Star re ->\n s2 =~ Star re ->\n s1 ++ s2 =~ Star re.\nProof.\n intros T s1 s2 re H1.\n remember (Star re) as re'.\n```\n\nWe now have Heqre' : re' = Star re.\n\n```coq\n generalize dependent s2.\n induction H1\n as [|x'|s1 re1 s2' re2 Hmatch1 IH1 Hmatch2 IH2\n |s1 re1 re2 Hmatch IH|re1 s2' re2 Hmatch IH\n |re''|s1 s2' re'' Hmatch1 IH1 Hmatch2 IH2].\n```\n\nThe Heqre' is contradictory in most cases, which allows us to conclude\nimmediately.\n\n```coq\n - (* MEmpty *) inversion Heqre'.\n - (* MChar *) inversion Heqre'.\n - (* MApp *) inversion Heqre'.\n - (* MUnionL *) inversion Heqre'.\n - (* MUnionR *) inversion Heqre'.\n```\n\nThe interesting cases are those that correspond to Star. Note that the induction\nhypothesis IH2 on the MStarApp case mentions an additional premise Star re'' =\nStar re', which results from the equality generated by remember.\n\n```coq\n - (* MStar0 *)\n inversion Heqre'. intros s H. apply H.\n\n - (* MStarApp *)\n inversion Heqre'. rewrite H0 in IH2, Hmatch1.\n intros s2 H1. rewrite <- app_assoc.\n apply MStarApp.\n + apply Hmatch1.\n + apply IH2.\n * reflexivity.\n * apply H1.\nQed.\n```\n\n\n==== Exercise: 4 stars (exp_match_ex2)\n\nThe \\idr{MStar''} lemma below (combined with its converse, the \\idr{MStar'}\nexercise above), shows that our definition of \\idr{Exp_match} for \\idr{Star} is\nequivalent to the informal one given previously.\n\n> MStar'' : (s =~ Star re) ->\n> (ss : List (List t) **\n> (s = fold (++) ss [], (s': List t) -> In s' ss -> s' =~ re)\n> )\n> MStar'' m = ?MStar___rhs\n>\n\n$\\square$\n\n\n==== Exercise: 5 stars, advanced (pumping)\n\nOne of the first really interesting theorems in the theory of regular\nexpressions is the so-called _pumping lemma_, which states, informally, that any\nsufficiently long string \\idr{s} matching a regular expression \\idr{re} can be\n\"pumped\" by repeating some middle section of \\idr{s} an arbitrary number of\ntimes to produce a new string also matching \\idr{re}.\n\nTo begin, we need to define \"sufficiently long.\" Since we are working in a\nconstructive logic, we actually need to be able to calculate, for each regular\nexpression \\idr{re}, the minimum length for strings \\idr{s} to guarantee\n\"pumpability.\"\n\n> namespace Pumping\n>\n> pumping_constant : (re : Reg_exp t) -> Nat\n> pumping_constant EmptySet = 0\n> pumping_constant EmptyStr = 1\n> pumping_constant (Chr _) = 2\n> pumping_constant (App re1 re2) =\n> pumping_constant re1 + pumping_constant re2\n> pumping_constant (Union re1 re2) =\n> pumping_constant re1 + pumping_constant re2\n> pumping_constant (Star _) = 1\n>\n\nNext, it is useful to define an auxiliary function that repeats a string\n(appends it to itself) some number of times.\n\n> napp : (n : Nat) -> (l : List t) -> List t\n> napp Z _ = []\n> napp (S k) l = l ++ napp k l\n>\n> napp_plus: (n, m : Nat) -> (l : List t) ->\n> napp (n + m) l = napp n l ++ napp m l\n> napp_plus Z _ _ = Refl\n> napp_plus (S k) m l =\n> rewrite napp_plus k m l in\n> appendAssociative l (napp k l) (napp m l)\n>\n\nNow, the pumping lemma itself says that, if \\idr{s =~ re} and if the length of\n\\idr{s} is at least the pumping constant of \\idr{re}, then \\idr{s} can be split\ninto three substrings \\idr{s1 ++ s2 ++ s3} in such a way that \\idr{s2} can be\nrepeated any number of times and the result, when combined with \\idr{s1} and\n\\idr{s3} will still match \\idr{re}. Since \\idr{s2} is also guaranteed not to be\nthe empty string, this gives us a (constructive!) way to generate strings\nmatching \\idr{re} that are as long as we like.\n\n> pumping : (s =~ re) -> ((pumping_constant re) <=' (length s)) ->\n> (s1 ** s2 ** s3 ** ( s = s1 ++ s2 ++ s3\n> , Not (s2 = [])\n> , (m:Nat) -> (s1 ++ napp m s2 ++ s3) =~ re\n> ))\n\n\\todo[inline]{Edit hint}\n\nTo streamline the proof (which you are to fill in), the `omega` tactic, which is\nenabled by the following `Require`, is helpful in several places for\nautomatically completing tedious low-level arguments involving equalities or\ninequalities over natural numbers. We'll return to `omega` in a later chapter,\nbut feel free to experiment with it now if you like. The first case of the\ninduction gives an example of how it is used.\n\n> pumping m le = ?pumping_rhs\n>\n\n\n== Case Study: Improving Reflection\n\nWe've seen in the \\idr{Logic} chapter that we often need to relate boolean\ncomputations to statements in \\idr{Type}. But performing this conversion in the\nway we did it there can result in tedious proof scripts. Consider the proof of\nthe following theorem:\n\n> filter_not_empty_In : {n : Nat} -> Not (filter ((==) n) l = []) -> In n l\n> filter_not_empty_In {l=[]} contra = contra Refl\n> filter_not_empty_In {l=(x::_)} {n} contra with (n == x) proof h\n> filter_not_empty_In contra | True =\n> Left $ sym $ beq_nat_true $ sym h\n> filter_not_empty_In contra | False =\n> Right $ filter_not_empty_In contra\n>\n\nIn the second case we explicitly apply the \\idr{beq_nat_true} lemma to the\nequation generated by doing a dependent match on \\idr{n == x}, to convert the\nassumption \\idr{n == x = True} into the assumption \\idr{n = m}.\n\nWe can streamline this by defining an inductive proposition that yields a better\ncase-analysis principle for \\idr{n == m}. Instead of generating an equation such\nas \\idr{n == m = True}, which is generally not directly useful, this principle\ngives us right away the assumption we really need: \\idr{n = m}.\n\nWe'll actually define something a bit more general, which can be used with\narbitrary properties (and not just equalities):\n\n\\todo[inline]{Update the text: seems that additional \\idr{(b=...)} constructor\nparameter is needed for this to work in Idris.}\n\n```idris\ndata Reflect : Type -> Bool -> Type where\n ReflectT : (p : Type) -> (b=True) -> Reflect p b\n ReflectF : (p : Type) -> (Not p) -> (b=False) -> Reflect p b\n ```\n\nBefore explaining this, let's rearrange it a little: Since the types of both\n\\idr{ReflectT} and \\idr{ReflectF} begin with \\idr{(p : Type)}, we can make the\ndefinition a bit more readable and easier to work with by making \\idr{p} a\nparameter of the whole \\idr{data} declaration.\n\n> data Reflect : (p : Type) -> (b : Bool) -> Type where\n> ReflectT : p -> (b=True) -> Reflect p b\n> ReflectF : (Not p) -> (b=False) -> Reflect p b\n>\n\nThe reflect property takes two arguments: a proposition \\idr{p} and a boolean\n\\idr{b}. Intuitively, it states that the property \\idr{p} is _reflected_ in\n(i.e., equivalent to) the boolean \\idr{b}: \\idr{p} holds if and only if \n\\idr{b = True}. To see this, notice that, by definition, the only way we can\nproduce evidence that \\idr{Reflect p True} holds is by showing that \\idr{p} is\ntrue and using the \\idr{ReflectT} constructor. If we invert this statement, this\nmeans that it should be possible to extract evidence for \\idr{p} from a proof of\n\\idr{Reflect p True}. Conversely, the only way to show \\idr{Reflect p False} is\nby combining evidence for \\idr{Not p} with the \\idr{ReflectF} constructor.\n\nIt is easy to formalize this intuition and show that the two statements are\nindeed equivalent:\n\n> iff_reflect : (p <-> (b = True)) -> Reflect p b\n> iff_reflect {b = False} (pb, _) = ReflectF (uninhabited . pb) Refl\n> iff_reflect {b = True} (_, bp) = ReflectT (bp Refl) Refl\n>\n\n\n==== Exercise: 2 stars, recommended (reflect_iff)\n\n> reflect_iff : Reflect p b -> (p <-> (b = True))\n> reflect_iff x = ?reflect_iff_rhs\n>\n\n$\\square$\n\nThe advantage of \\idr{Reflect} over the normal \"if and only if\" connective is\nthat, by destructing a hypothesis or lemma of the form \\idr{Reflect p b}, we can\nperform case analysis on \\idr{b} while at the same time generating appropriate\nhypothesis in the two branches (\\idr{p} in the first subgoal and \\idr{Not p} in\nthe second).\n\n> beq_natP : {n, m : Nat} -> Reflect (n = m) (n == m)\n> beq_natP {n} {m} = iff_reflect $ iff_sym $ beq_nat_true_iff n m\n>\n\n\\todo[inline]{Edit - we basically trade the invocation of \\idr{beq_nat_true} in\n\\idr{Left} for an indirect rewrite in \\idr{Right}}\n\nThe new proof of \\idr{filter_not_empty_In} now goes as follows. Notice how the\ncalls to destruct and apply are combined into a single call to destruct.\n\n(To see this clearly, look at the two proofs of \\idr{filter_not_empty_In} with\nIdris and observe the differences in proof state at the beginning of the first\ncase of the destruct.)\n\n> filter_not_empty_In' : {n : Nat} -> Not (filter ((==) n) l = []) -> In n l\n> filter_not_empty_In' {l=[]} contra = contra Refl\n> filter_not_empty_In' {n} {l=(x::xs)} contra with (beq_natP {n} {m=x})\n> filter_not_empty_In' _ | (ReflectT eq _) = Left $ sym eq\n> filter_not_empty_In' {n} {l=(x::xs)} contra | (ReflectF _ notbeq) =\n> let\n\n\\todo[inline]{How to rewrite more neatly here?}\n\n> contra' = replace notbeq contra\n> {P = \\a =>\n> Not ((if a\n> then x :: filter ((==) n) xs\n> else filter ((==) n) xs) = [])}\n> in\n> Right $ filter_not_empty_In' contra'\n>\n\n\n==== Exercise: 3 stars, recommended (beq_natP_practice)\n\nUse \\idr{beq_natP} as above to prove the following:\n\n> count : (n : Nat) -> (l : List Nat) -> Nat\n> count _ [] = 0\n> count n (x :: xs) = (if n == x then 1 else 0) + count n xs\n>\n> beq_natP_practice : count n l = 0 -> Not (In n l)\n> beq_natP_practice prf = ?beq_natP_practice_rhs\n>\n\n$\\square$\n\nThis technique gives us only a small gain in convenience for the proofs we've\nseen here, but using \\idr{Reflect} consistently often leads to noticeably\nshorter and clearer scripts as proofs get larger. We'll see many more examples\nin later chapters.\n\n\\todo[inline]{Add http://math-comp.github.io/math-comp/ as a link}\n\nThe use of the reflect property was popularized by `SSReflect`, a Coq library\nthat has been used to formalize important results in mathematics, including as\nthe 4-color theorem and the Feit-Thompson theorem. The name `SSReflect` stands\nfor _small-scale reflection_, i.e., the pervasive use of reflection to simplify\nsmall proof steps with boolean computations.\n\n\n== Additional Exercises\n\n\n==== Exercise: 3 stars, recommended (nostutter)\n\nFormulating inductive definitions of properties is an important skill you'll\nneed in this course. Try to solve this exercise without any help at all.\n\nWe say that a list \"stutters\" if it repeats the same element consecutively. The\nproperty \"\\idr{Nostutter mylist}\" means that \\idr{mylist} does not stutter.\nFormulate an inductive definition for \\idr{Nostutter}. (This is different from\nthe \\idr{NoDup} property in the exercise below; the sequence \\idr{[1,4,1]}\nrepeats but does not stutter.)\n\n> data Nostutter : List t -> Type where\n> -- FILL IN HERE\n> RemoveMe : Nostutter [] -- needed for typechecking, data shouldn't be empty\n>\n\nMake sure each of these tests succeeds, but feel free to change the suggested\nproof (in comments) if the given one doesn't work for you. Your definition might\nbe different from ours and still be correct, in which case the examples might\nneed a different proof. (You'll notice that the suggested proofs use a number of\ntactics we haven't talked about, to make them more robust to different possible\nways of defining \\idr{Nostutter}. You can probably just uncomment and use them\nas-is, but you can also prove each example with more basic tactics.)\n\n> test_nostutter_1 : Nostutter [3,1,4,1,5,6]\n> test_nostutter_1 = ?test_nostutter_1_rhs\n>\n\n```coq\n(*\n Proof. repeat constructor; apply beq_nat_false_iff; auto.\n Qed.\n*)\n```\n\n> test_nostutter_2 : Nostutter []\n> test_nostutter_2 = ?test_nostutter_2_rhs\n>\n\n```coq\n(*\n Proof. repeat constructor; apply beq_nat_false_iff; auto.\n Qed.\n*)\n```\n\n> test_nostutter_3 : Nostutter [5]\n> test_nostutter_3 = ?test_nostutter_3_rhs\n>\n\n```coq\n(*\n Proof. repeat constructor; apply beq_nat_false; auto. Qed.\n*)\n```\n\n> test_nostutter_4 : Not (Nostutter [3,1,1,4])\n> test_nostutter_4 = ?test_nostutter_4_rhs\n>\n\n```coq\n(*\n Proof. intro.\n repeat match goal with\n h: nostutter _ |- _ => inversion h; clear h; subst\n end.\n contradiction H1; auto. Qed.\n*)\n```\n\n$\\square$\n\n\n==== Exercise: 4 stars, advanced (filter_challenge)\n\nLet's prove that our definition of \\idr{filter} from the \\idr{Poly} chapter\nmatches an abstract specification. Here is the specification, written out\ninformally in English:\n\nA list \\idr{l} is an \"in-order merge\" of \\idr{l1} and \\idr{l2} if it contains\nall the same elements as \\idr{l1} and \\idr{l2}, in the same order as \\idr{l1}\nand \\idr{l2}, but possibly interleaved. For example,\n\n```idris\n [1,4,6,2,3]\n```\n\nis an in-order merge of\n\n```idris\n [1,6,2]\n```\n\nand\n\n```idris\n [4,3]\n```\n\nNow, suppose we have a set \\idr{t}, a function \\idr{test : t->Bool}, and a list\n\\idr{l} of type \\idr{List t}. Suppose further that \\idr{l} is an in-order merge\nof two lists, \\idr{l1} and \\idr{l2}, such that every item in \\idr{l1} satisfies\n\\idr{test} and no item in \\idr{l2} satisfies \\idr{test}. Then \n\\idr{filter test l = l1}.\n\nTranslate this specification into a Idris theorem and prove it. (You'll need to\nbegin by defining what it means for one list to be a merge of two others. Do\nthis with an inductive \\idr{data} type, not a function.)\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 5 stars, advanced, optional (filter_challenge_2)\n\nA different way to characterize the behavior of \\idr{filter} goes like this:\nAmong all subsequences of \\idr{l} with the property that \\idr{test} evaluates to\n\\idr{True} on all their members, \\idr{filter test l} is the longest. Formalize\nthis claim and prove it.\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 4 stars, optional (palindromes)\n\nA palindrome is a sequence that reads the same backwards as forwards.\n\n - Define an inductive proposition \\idr{Pal} on \\idr{List t} that captures what\n it means to be a palindrome. (Hint: You'll need three cases. Your definition\n should be based on the structure of the list; just having a single\n constructor like\n\n```idris\n C : (l : List t) -> l = rev l -> Pal l\n```\n\n may seem obvious, but will not work very well.)\n\n - Prove (\\idr{pal_app_rev}) that\n\n```idris\n (l : List t) -> Pal (l ++ rev l)\n```\n\n - Prove (\\idr{pal_rev}) that\n\n```idris\n (l : List t) -> Pal l -> l = rev l\n```\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 5 stars, optional (palindrome_converse)\n\nAgain, the converse direction is significantly more difficult, due to the lack\nof evidence. Using your definition of \\idr{Pal} from the previous exercise,\nprove that\n\n```idris\n (l : List t) -> l = rev l -> Pal l\n```\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n=== Exercise: 4 stars, advanced, optional (NoDup)\n\nRecall the definition of the \\idr{In} property from the \\idr{Logic} chapter,\nwhich asserts that a value \\idr{x} appears at least once in a list \\idr{l}:\n\n```idris\nIn : (x : t) -> (l : List t) -> Type\nIn x [] = Void\nIn x (x' :: xs) = (x' = x) `Either` In x xs\n```\n\nYour first task is to use \\idr{In} to define a proposition \n\\idr{Disjoint {t} l1 l2}, which should be provable exactly when \\idr{l1} and\n\\idr{l2} are lists (with elements of type \\idr{t}) that have no elements in\ncommon.\n\n> -- FILL IN HERE\n>\n\nNext, use \\idr{In} to define an inductive proposition \\idr{NoDup {t} l}, which\nshould be provable exactly when \\idr{l} is a list (with elements of type\n\\idr{t}) where every member is different from every other. For example,\n\\idr{NoDup {t=Nat} [1,2,3,4]} and \\idr{NoDup {t=Bool} []} should be provable,\nwhile \\idr{NoDup {t=Nat} [1,2,1]} and \\idr{NoDup {t=Bool} [True,True]} should\nnot be.\n\n> -- FILL IN HERE\n>\n\nFinally, state and prove one or more interesting theorems relating\n\\idr{Disjoint}, \\idr{NoDup} and \\idr{(++)} (list append).\n\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 4 stars, advanced, optional (pigeonhole principle)\n\nThe _pigeonhole principle_ states a basic fact about counting: if we distribute\nmore than \\idr{n} items into \\idr{n} pigeonholes, some pigeonhole must contain\nat least two items. As often happens, this apparently trivial fact about numbers\nrequires non-trivial machinery to prove, but we now have enough...\n\nFirst prove an easy useful lemma.\n\n> in_split : In x l -> (l1 ** l2 ** l = l1 ++ x :: l2)\n> in_split prf = ?in_split_rhs\n>\n\nNow define a property \\idr{Repeats} such that \\idr{Repeats {t} l} asserts that\n\\idr{l} contains at least one repeated element (of type \\idr{t}).\n\n> data Repeats : List t -> Type where\n> -- FILL IN HERE\n> RemoveMe' : Repeats [] -- needed for typechecking, data shouldn't be empty\n>\n\nNow, here's a way to formalize the pigeonhole principle. Suppose list \\idr{l2}\nrepresents a list of pigeonhole labels, and list \\idr{l1} represents the labels\nassigned to a list of items. If there are more items than labels, at least two\nitems must have the same label -- i.e., list \\idr{l1} must contain repeats.\n\nThis proof is much easier if you use the \\idr{excluded_middle} hypothesis to\nshow that \\idr{In} is decidable, i.e., \\idr{(In x l) `Either` (Not (In x l))}.\nHowever, it is also possible to make the proof go through _without_ assuming\nthat \\idr{In} is decidable; if you manage to do this, you will not need the\n\\idr{excluded_middle} hypothesis.\n\n> pigeonhole_principle : ((x : t) -> In x l1 -> In x l2) ->\n> ((length l2) <' (length l1)) ->\n> Repeats l1\n> pigeonhole_principle f prf = ?pigeonhole_principle_rhs\n> where\n> excluded_middle : (p : Type) -> p `Either` (Not p)\n> excluded_middle p = really_believe_me p\n>\n\n$\\square$\n", "meta": {"hexsha": "db2bd87a6c1da8e573872d080bfb2ea70319aa5f", "size": 53078, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/IndProp.lidr", "max_stars_repo_name": "diseraluca/software-foundations", "max_stars_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 452, "max_stars_repo_stars_event_min_datetime": "2016-06-23T10:03:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T22:25:00.000Z", "max_issues_repo_path": "src/IndProp.lidr", "max_issues_repo_name": "diseraluca/software-foundations", "max_issues_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 53, "max_issues_repo_issues_event_min_datetime": "2016-06-27T07:14:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-23T06:16:57.000Z", "max_forks_repo_path": "src/IndProp.lidr", "max_forks_repo_name": "diseraluca/software-foundations", "max_forks_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2016-11-21T10:55:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T00:21:55.000Z", "avg_line_length": 32.9063856169, "max_line_length": 82, "alphanum_fraction": 0.6891932627, "num_tokens": 16131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7010249396018857}} {"text": "module Main\n\nimport Data.Vect\n\nappend' : Vect n elem -> Vect m elem -> Vect (n+m) elem\n\ntri : Vect 3 (Double, Double)\ntri = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)]\n\nPosition : Type\nPosition = (Double, Double)\n\nquad : Vect 4 Position\n\nPolygon : Nat -> Type\nPolygon n = Vect n Position\n\nquint : Polygon 5\nquint = ?quint_rhs\n\nStringOrInt : Bool -> Type\nStringOrInt False = String\nStringOrInt True = Int\n\ngetStringOrInt : (isInt : Bool) -> StringOrInt isInt\ngetStringOrInt False = \"Ninety nine\"\ngetStringOrInt True = 99\n\nstringify : (isInt : Bool) -> StringOrInt isInt -> String\nstringify False x = trim x\nstringify True x = cast x\n\nvalToString : (isInt : Bool) ->\n (\n case isInt of\n True => Int\n False => String\n ) ->\n String\n\nAdderType : (numargs : Nat) -> Type -> Type\nAdderType Z numType = numType\nAdderType (S k) numType = (next : numType) -> AdderType k numType\n\nadder : Num numType =>\n (numargs : Nat) -> numType -> AdderType numargs numType\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (next + acc)\n\ndata Format = Character Format\n | Float Format\n | Number Format\n | Str Format\n | Lit String Format\n | End\n\nPrintfType : Format -> Type\nPrintfType (Character fmt) = (c : Char) -> PrintfType fmt\nPrintfType (Float fmt) = (d : Float) -> PrintfType fmt\nPrintfType (Number fmt) = (i : Int) -> PrintfType fmt\nPrintfType (Str fmt) = (s : String) -> PrintfType fmt\nPrintfType (Lit _ fmt) = PrintfType fmt\nPrintfType End = String\n\nprintfFmt : (fmt : Format) -> (acc : String) -> PrintfType fmt\nprintfFmt (Character fmt) acc = \\c => printfFmt fmt (acc ++ show c)\nprintfFmt (Float fmt) acc = \\d => printfFmt fmt (acc ++ show d)\nprintfFmt (Lit lit fmt) acc = printfFmt fmt (acc ++ lit)\nprintfFmt (Number fmt) acc = \\i => printfFmt fmt (acc ++ show i)\nprintfFmt (Str fmt) acc = \\str => printfFmt fmt (acc ++ str)\nprintfFmt End acc = acc\n\ntoFormat : (xs : List Char) -> Format\ntoFormat [] = End\ntoFormat ('%' :: 'c' :: chars) = Character (toFormat chars)\ntoFormat ('%' :: 'd' :: chars) = Number (toFormat chars)\ntoFormat ('%' :: 'f' :: chars) = Float (toFormat chars)\ntoFormat ('%' :: 's' :: chars) = Str (toFormat chars)\ntoFormat (c :: chars) = case toFormat chars of\n Lit lit chars' => Lit (strCons c lit) chars'\n fmt => Lit (strCons c \"\") fmt\n\nprintf : (fmt : String) -> PrintfType (toFormat (unpack fmt))\nprintf fmt = printfFmt _ \"\"\n\nMatrix : Num t => (n : Nat) -> (m : Nat) -> (t : Type) -> Type\nMatrix n m t = Vect n (Vect m t)\n\ntestMatrix : Matrix 2 3 Double\ntestMatrix = [[0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0]]\n\nTupleVect : (n : Nat) -> (t : Type) -> Type\nTupleVect Z t = ()\nTupleVect (S k) t = (t, TupleVect k t)\n\nPair : (Nat, (Nat, ()))\n-- (Nat, (Nat, ())) === (Nat, Nat, ())\n\ntestTupleVect : TupleVect 4 Nat\ntestTupleVect = (1,2,3,4,())\n", "meta": {"hexsha": "6cdd879f0133b78dc2935c973f588b4775627137", "size": 2967, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/6-FirstClassTypes.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/6-FirstClassTypes.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/6-FirstClassTypes.idr", "max_forks_repo_name": "ostera/asdf", "max_forks_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "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": 29.0882352941, "max_line_length": 73, "alphanum_fraction": 0.5915065723, "num_tokens": 913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.7003903713462799}} {"text": "data State : (stateType : Type) -> Type -> Type where\n Get : State stateType stateType\n Put : stateType -> State stateType ()\n\n Pure : ty -> State stateType ty\n Bind : State stateType a -> (a -> State stateType b) -> State stateType b\n\nget : State stateType stateType \nget = Get\n\nput : stateType -> State stateType () \nput = Put\n\npure : ty -> State stateType ty\npure = Pure\n\n(>>=) : State stateType a -> (a -> State stateType b) -> State stateType b\n(>>=) = Bind\n\n{- Functor (State stateType) where\n map func x = Bind x (\\val => Pure (func val))\n\nApplicative (State stateType) where\n pure = Pure\n (<*>) f a = Bind f (\\f' =>\n Bind a (\\a' =>\n Pure (f' a')))\n\nMonad (State stateType) where\n (>>=) = Bind-}\n\nmutual\n Functor (State stateType) where\n map func x = do val <- x\n pure (func val)\n\n Applicative (State stateType) where\n pure = Pure\n (<*>) f a = do f' <- f\n a' <- a\n pure (f' a')\n\n Monad (State stateType) where\n (>>=) = Bind\n\naddIfPositive : Integer -> State Integer Bool\naddIfPositive val = do when (val > 0) $\n do current <- get\n put (current + val)\n pure (val > 0)\n\naddPositives : List Integer -> State Integer Nat\naddPositives vals = do added <- traverse addIfPositive vals\n pure (length (filter id added))\n\nrunState : State stateType a -> (st : stateType) -> (a, stateType)\nrunState Get st = (st, st)\nrunState (Put newState) st = ((), newState)\nrunState (Pure x) st = (x, st)\nrunState (Bind cmd prog) st = let (val, nextState) = runState cmd st in\n runState (prog val) nextState\n", "meta": {"hexsha": "44f512e51f7f398a3f39f2232cfe80b1f5436be0", "size": 1737, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp12/StateMonad.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp12/StateMonad.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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": "type_driven_book/chp12/StateMonad.idr", "max_forks_repo_name": "Ryxai/idris_book_notes", "max_forks_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "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.0161290323, "max_line_length": 75, "alphanum_fraction": 0.5561312608, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7003181393405769}} {"text": "module Data.Algebraic.Graph\n\n%default total\n%access public export\n\ndata Graph : Type -> Type where\n Empty : Graph type\n Vertex : (elem : type) -> Graph type\n Overlay : Graph type -> Graph type -> Graph type\n Connect : Graph type -> Graph type -> Graph type\n\nShow type => Show (Graph type) where\n show Empty = \"Empty\"\n show (Vertex elem) = unwords [\"Vertex\", show elem]\n show (Overlay x y) = unwords [\"Overlay\", show x, show y]\n show (Connect x y) = unwords [\"Connect\", show x, show y]\n\nFunctor Graph where\n map func Empty = Empty\n map func (Vertex elem) = Vertex $ func elem\n map func (Overlay x y) = Overlay (map func x) (map func y)\n map func (Connect x y) = Connect (map func x) (map func y)\n\nFoldable Graph where\n foldr func init Empty = init\n foldr func init (Vertex x) = func x init\n foldr func init (Overlay x y) = foldr func (foldr func init y) x\n foldr func init (Connect x y) = foldr func (foldr func init y) x\n\nTraversable Graph where\n traverse func Empty = pure Empty\n traverse func (Vertex elem) = [| Vertex (func elem)|]\n traverse func (Overlay x y) = [| Overlay (traverse func x) (traverse func y) |]\n traverse func (Connect x y) = [| Connect (traverse func x) (traverse func y) |]\n\nNum type => Num (Graph type) where\n fromInteger x = Vertex (fromInteger x)\n (+) = Overlay\n (*) = Connect\n\n-- Do we need abs, negate, and signum?\n\nempty : Graph a\nempty = Empty\n\nvertex : a -> Graph a\nvertex a = Vertex a\n\nconnect : Graph a -> Graph a -> Graph a\nconnect = Connect\n\nedge : a -> a -> Graph a\nedge x y = connect (vertex x) (vertex y)\n\ncombine : Graph a -> Graph a -> Graph a\ncombine = Overlay\n\noverlay : Graph a -> Graph a -> Graph a\noverlay = combine\n\nfoldg : (init : type)\n -> (whenVertex : a -> type)\n -> (whenOverlay : type -> type -> type)\n -> (whenConnect : type -> type -> type)\n -> (graph : Graph a)\n -> type\nfoldg init whenVertex whenOverlay whenConnect = go\n where\n go : Graph a -> type\n go Empty = init\n go (Vertex elem) = whenVertex elem\n go (Overlay x y) = whenOverlay (go x) (go y)\n go (Connect x y) = whenConnect (go x) (go y)\n\n\noverlays : List (Graph a) -> Graph a\noverlays = foldr overlay empty\n\nvertices : List a -> Graph a\nvertices = overlays . map vertex\n\nconnects : List (Graph a) -> Graph a\nconnects = foldr connect empty\n\nedges : List (a,a) -> Graph a\nedges = overlays . map (uncurry edge)\n\ngraph : List a -> List (a,a) -> Graph a\ngraph vs es = overlay (vertices vs) (edges es)\n\ndata HasVertex : (elem : type) -> Graph type -> Type where\n Here : HasVertex e (Vertex e)\n ThereOL : HasVertex e l\n -> HasVertex e (Overlay l r)\n ThereOR : HasVertex e r\n -> HasVertex e (Overlay l r)\n ThereCL : HasVertex e l\n -> HasVertex e (Connect l r)\n ThereCR : HasVertex e r\n -> HasVertex e (Connect l r)\n\ngraphIsEmpty : HasVertex e Empty -> Void\ngraphIsEmpty Here impossible\ngraphIsEmpty (ThereOL _) impossible\ngraphIsEmpty (ThereOR _) impossible\ngraphIsEmpty (ThereCL _) impossible\ngraphIsEmpty (ThereCR _) impossible\n\nnotSameVertex : (contra : (e = x) -> Void) -> HasVertex e (Vertex x) -> Void\nnotSameVertex contra Here = contra Refl\n\nnotOverlay : (contra : HasVertex e x -> Void)\n -> (f : HasVertex e y -> Void)\n -> HasVertex e (Overlay x y)\n -> Void\nnotOverlay contra f x with (x)\n notOverlay contra f x | (ThereOL y) = contra y\n notOverlay contra f x | (ThereOR y) = f y\n\n\nnotConnect : (contra : HasVertex e x -> Void)\n -> (f : HasVertex e y -> Void)\n -> HasVertex e (Connect x y)\n -> Void\nnotConnect contra f x with (x)\n notConnect contra f x | (ThereCL y) = contra y\n notConnect contra f x | (ThereCR y) = f y\n\n\nhasVertex : DecEq type => (elem : type) -> (graph : Graph type) -> Dec (HasVertex elem graph)\nhasVertex elem Empty = No graphIsEmpty\nhasVertex elem (Vertex x) with (decEq elem x)\n hasVertex x (Vertex x) | (Yes Refl) = Yes Here\n hasVertex elem (Vertex x) | (No contra) = No (notSameVertex contra)\n\nhasVertex elem (Overlay x y) with (hasVertex elem x)\n hasVertex elem (Overlay x y) | (Yes prf) = Yes (ThereOL prf)\n hasVertex elem (Overlay x y) | (No contra) with (hasVertex elem y)\n hasVertex elem (Overlay x y) | (No contra) | (Yes prf) = Yes (ThereOR prf)\n hasVertex elem (Overlay x y) | (No contra) | (No f) = No (notOverlay contra f)\n\n\nhasVertex elem (Connect x y) with (hasVertex elem x)\n hasVertex elem (Connect x y) | (Yes prf) = Yes (ThereCL prf)\n hasVertex elem (Connect x y) | (No contra) with (hasVertex elem y)\n hasVertex elem (Connect x y) | (No contra) | (Yes prf) = Yes (ThereCR prf)\n hasVertex elem (Connect x y) | (No contra) | (No f) = No (notConnect contra f)\n", "meta": {"hexsha": "4e821b07766e3282eb2f88c330d9dc63faaf7304", "size": 4685, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Algebraic/Graph.idr", "max_stars_repo_name": "MarcelineVQ/idris-containers", "max_stars_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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/Algebraic/Graph.idr", "max_issues_repo_name": "MarcelineVQ/idris-containers", "max_issues_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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/Algebraic/Graph.idr", "max_forks_repo_name": "MarcelineVQ/idris-containers", "max_forks_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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.6554054054, "max_line_length": 93, "alphanum_fraction": 0.6499466382, "num_tokens": 1383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.700316259373275}} {"text": "module BinomialHeap\n\nimport Heap\n\n%default total\n%access private\n\ndata Tree a = Node Int a (List (Tree a))\n\nexport\ndata BinomialHeap a = BH (List (Tree a))\n\nrank : Tree a -> Int\nrank (Node r x c) = r\n\nroot : Tree a -> a\nroot (Node r x c) = x\n\nlink : Ord a => Tree a -> Tree a -> Tree a\nlink t1@(Node r x1 c1) t2@(Node _ x2 c2) =\n if x1 <= x2 then Node (r + 1) x1 (t2 :: c1) else Node (r + 1) x2 (t1 :: c2)\n\ninsTree : Ord a => Tree a -> List (Tree a) -> List (Tree a)\ninsTree t [] = [t]\ninsTree t ts@(t' :: ts') =\n if rank t < rank t' then t :: ts else insTree (link t t') ts'\n\nmrg : Ord a => List (Tree a) -> List (Tree a) -> List (Tree a)\nmrg ts1 [] = ts1\nmrg [] ts2 = ts2\nmrg ts1@(t1 :: ts1') ts2@(t2 :: ts2') = case compare (rank t1) (rank t2) of\n LT => t1 :: mrg ts1' ts2\n GT => t2 :: mrg ts1 ts2'\n EQ => insTree (link t1 t2) (mrg ts1' ts2')\n\nremoveMinTree : Ord a => List (Tree a) -> (Tree a, List (Tree a))\nremoveMinTree [] = idris_crash \"empty heap\"\nremoveMinTree [t] = (t, [])\nremoveMinTree (t :: ts) = let (t', ts') = removeMinTree ts in\n if root t < root t' then (t, ts) else (t', t :: ts')\n\nHeap BinomialHeap where\n empty = BH []\n isEmpty (BH ts) = isNil ts\n\n insert x (BH ts) = BH (insTree (Node 0 x []) ts)\n\n merge (BH ts1) (BH ts2) = BH (mrg ts1 ts2)\n\n findMin (BH ts) = root (fst (removeMinTree ts))\n\n deleteMin (BH ts) = let (Node _ x ts1, ts2) = removeMinTree ts\n in BH (mrg (reverse ts1) ts2)\n", "meta": {"hexsha": "34ffad170776657f3be498baa4a7e229aa16a2d2", "size": 1492, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/BinomialHeap.idr", "max_stars_repo_name": "ska80/idris-okasaki-pfds", "max_stars_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-08T00:55:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-08T00:55:51.000Z", "max_issues_repo_path": "src/BinomialHeap.idr", "max_issues_repo_name": "ska80/idris-okasaki-pfds", "max_issues_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_issues_repo_licenses": ["CC0-1.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": "src/BinomialHeap.idr", "max_forks_repo_name": "ska80/idris-okasaki-pfds", "max_forks_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6296296296, "max_line_length": 77, "alphanum_fraction": 0.5616621984, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.7001959593475682}} {"text": "module Data.SnocVect.Elem\n\nimport Data.SnocVect\nimport Decidable.Equality\n\n%default total\n\npublic export\ndata Elem : SnocVect k a -> a -> Type where\n Here : Elem (sx :< x) x\n There : Elem sx x -> Elem (sx :< y) x\n\nexport\n{sx : SnocVect 0 a} -> Uninhabited (Elem sx x) where\n uninhabited Here impossible\n uninhabited (There x) impossible\n\nneitherHereNorThere : DecEq a => {0 x,y : a} ->\n Not (x = y) ->\n Not (Elem sy x) ->\n Not (Elem (sy :< y) x)\nneitherHereNorThere Refl _ Here impossible\nneitherHereNorThere _ g (There z) = g z\n\nexport\nisElem : DecEq a => (x : a) -> (sx : SnocVect k a) -> Dec (Elem sx x)\nisElem x [<] = No absurd\nisElem x (sx :< y) with (decEq x y)\n isElem y (sx :< y) | (Yes Refl) = Yes Here\n isElem x (sx :< y) | (No contra) with (isElem x sx)\n isElem x (sx :< y) | (No _) | (Yes prf) = Yes (There prf)\n isElem x (sx :< y) | (No yNotX) | (No xNotInSx) =\n No (neitherHereNorThere yNotX xNotInSx)\n\n", "meta": {"hexsha": "562b9d936ad73e19a3a533515a1bad6cd944f77d", "size": 998, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/SnocVect/Elem.idr", "max_stars_repo_name": "mattpolzin/idris-snocvect", "max_stars_repo_head_hexsha": "f6148c3d06c7a9989062a2425f925fc844468215", "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/Data/SnocVect/Elem.idr", "max_issues_repo_name": "mattpolzin/idris-snocvect", "max_issues_repo_head_hexsha": "f6148c3d06c7a9989062a2425f925fc844468215", "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/SnocVect/Elem.idr", "max_forks_repo_name": "mattpolzin/idris-snocvect", "max_forks_repo_head_hexsha": "f6148c3d06c7a9989062a2425f925fc844468215", "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.5142857143, "max_line_length": 69, "alphanum_fraction": 0.5871743487, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.7000804404947197}}