{"text": "plus_commutes_Z : (m : Nat) -> m = plus m Z\nplus_commutes_Z Z = Refl\nplus_commutes_Z (S k)\n = let rec = plus_commutes_Z k in\n rewrite sym rec in Refl\n\nplus_commutes_S : (k : Nat) -> (m : Nat) -> S (plus m k) = plus m (S k)\nplus_commutes_S k Z = Refl\nplus_commutes_S k (S j)\n = rewrite plus_commutes_S k j in Refl\n\ntotal\nplus_commutes : (n : Nat) -> (m : Nat) -> n + m = m + n\nplus_commutes Z m = plus_commutes_Z m\nplus_commutes (S k) m \n = rewrite plus_commutes k m in\n plus_commutes_S k m\n", "meta": {"hexsha": "59c63857f9f16ca1ad369ea3f3d3590ac47c0891", "size": 518, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/samples/proofs/pluscomm.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/pluscomm.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/pluscomm.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": 28.7777777778, "max_line_length": 71, "alphanum_fraction": 0.6370656371, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6498795773314946}} {"text": "module Data.Matrix.ZZGaussianElimination\n\nimport Control.Algebra\nimport Classes.Verified\nimport Control.Algebra.VectorSpace -- definition of module\n\nimport Data.Matrix\nimport Data.Matrix.Algebraic -- module instances; from Idris 0.9.20\nimport Data.Matrix.AlgebraicVerified\n\nimport Data.Vect.Structural\nimport Data.Matrix.Structural\n\nimport Data.ZZ\nimport Control.Algebra.NumericInstances\nimport Control.Algebra.ZZVerifiedInstances\nimport Data.Matrix.ZZVerified\n\nimport Data.Matrix.ZZModuleSpan\nimport Data.Matrix.LinearCombinations\n\nimport Data.Matrix.RowEchelon\nimport Control.Algebra.ZZDivisors\nimport Data.Matrix.ZZGaussianEliminationLemmas\n\nimport Data.Fin.FinOrdering\n\nimport Control.Isomorphism\n\n{-\n(bezQTy) is the only thing actually used from here in the proof,\nsomething req.d to potentially generalize to other Bezout domains.\n\nHowever, the example (bezoutZT) is applied here to give a specific algorithm.\n-}\nimport Control.Algebra.ZZBezoutsIdentity\n\n-- Extension of a GCD operation to any number of arguments arguments\nimport Control.Algebra.ZZGCDOfVectAlg\n\n-- Dependent pattern matching using (do) notation binds improves clarity\nimport Control.Monad.Identity\n\n\n\n{-\nMain elimination algorithms.\n\nIndex:\n\n* Template & usage for do notation pattern matching technique\n* elimFirstCol\n* gaussElimlzIfVectGCD2\n* gaussElimlzIfVectGCD\n* gaussElimlzIfGCD\n* The gaussian elimination instantiation derived from (bezoutZT)\n* Appendix Elim.General.Meta\n-}\n\n\n\n{-\nDependent pattern matching using (do) notation binds improves clarity\n\n---\n\nTemplate & usage for technique:\n\n> f : (a : ZZ ** a = Pos Z)\n> f = runIdentity $ do {\n> \t\tclause <- Id $ 'c'\n> \t\t(s ** s_pr) <- Id $ the (r : ZZ ** r = Pos Z) (Pos 0 ** Refl)\n> \t\t(t ** t_pr) <- Id $ (s ** s_pr)\n> \t\t(a, b, c) <- Id $ ('x', ('y', 'z'))\n> \t\treturn $ believe_me \"Placeholder for while argument incomplete\"\n> \t\t-- return (the ZZ _ ** ?foo)\n> \t}\n\nNote that two dependent pattern matches have occurred without nesting (with) blocks.\n\nIf we figure out the witness of the dependent pair value, we can test things out\ninteractively, which is sometimes helpful. Note that (clause) won't get recognized\nas being ('c'), it's still only a monadic bind.\n\n> g : (a : ZZ ** a = Pos Z)\n> g = runIdentity $ do {\n> \t\tclause <- Id $ 'c'\n> \t\t(s ** s_pr) <- Id $ the (r : ZZ ** r = Pos Z) (Pos 0 ** Refl)\n> \t\t-- return $ believe_me \"Placeholder for while argument incomplete\"\n> \t\treturn (the ZZ (Pos 0) ** ?bar)\n> \t}\n\nLikewise, we can't recognize (s_pr) is a proof that (Pos 0 = Pos 0), so it doesn't\nmatch the actual goal. However, we can still change the last line to\n\n> \t\treturn (s ** ?bar)\n\nat which point `s_pr` solves the goal.\n\n\n\nWhile (Reader) without (runReader) can simulate a (parameters) block at the same time,\nthis adds some plumbing overhead, and (ask) may have to be passed its (MonadReader)\ninstance explicitly:\n\n> z <- ask @{the (MonadReader ZZ _) %instance}\n\n-}\n\n\n\n{-\nMain elimination algorithms\n-}\n\n\n\nparameters (\n\tgcdOfVectAlg :\n\t\t-- Will making argument \"k\" implicit work?\n\t\t(k : Nat)\n\t\t-> (x : Vect k ZZ)\n\t\t-> ( v : Vect k ZZ **\n\t\t\t( i : Fin k )\n\t\t\t-> (index i x) `quotientOverZZ` (v <:> x) )\n\t) {\n\n\n\n{-\nStructure of (elimFirstCol):\n\nsuccImplWknStep_Qfunclemma => succImplWknStep_stepQfunc => succImplWknStep_unplumbed => succImplWknStep => foldedFully\n\n(mkQfunc, foldedFully) => elimFirstCol (after some work)\n\n---\n\nBetter to refine this to a type that depends on (m=S predm) so that the case (m=Z) may also be covered.\n\nShall start from the bottom of the matrix (last) and work up to row (FS FZ) using a traversal based on (weaken) and a binary map from index (Fin n) and oldvals to newvals.\n-}\n\ntotal\nelimFirstCol :\n\t(xs : Matrix n (S predm) ZZ)\n\t-> (gexs : Matrix (S n) (S predm) ZZ **\n\t\t(downAndNotRightOfEntryImpliesZ gexs FZ FZ\n\t\t, gexs `bispanslz` xs))\nelimFirstCol [] {predm}\n\t= ( row {n=S predm} $ neutral ** ( nosuch, ([] ** Refl), ([neutral] ** Refl) ) )\n\twhere\n\t\tnosuch : (i : Fin _) -> (j : Fin _)\n\t\t\t-> LTRel Z (finToNat i)\n\t\t\t-> LTERel (finToNat j) Z\n\t\t\t-> indices i j (row {n=S predm} Prelude.Algebra.neutral) = Pos 0\n\t\tnosuch FZ FZ _ = either (const Refl) (const Refl)\n\t\tnosuch (FS k) FZ _ = absurd k\n\t\tnosuch _ (FS k) _ = void . ( either succNotLTEzero SIsNotZ )\nelimFirstCol mat {n=S predn} {predm} = runIdentity $ do {\n\n\t\t-- The application of (gcdOfVectAlg) to (mat) column 0.\n\t\t(v ** fn) <- Id $ vAndFn\n\n\t\t-- Refines endgoal\n\t\tlet bisWithGCD = the ( (v<\\>mat)::mat `bispanslz` mat )\n\t\t\t(extendSpanningLZsByPreconcatTrivially {zs=[_]} spanslzrefl\n\t\t\t, mergeSpannedLZs spanslzRowTimesSelf spanslzrefl)\n\n\t\t-- ( _ ** forall i. succImplWknProp mat (v<\\>mat) _ i endmat_i )\n\t\t(endmat ** endmatPropFn)\n\t\t\t<- Id $ foldedFully _ _ mat v $ mkQFunc _ _ v mat fn\n\n\t\t-- (_, danrz endmat_0 0 0, endmat_0 bispans v<\\>mat::mat)\n\t\t(_, leftColZBelow, endmatBispansMatandgcd) <- Id $ endmatPropFn FZ\n\t\treturn $ ( index FZ endmat **\n\t\t\t(leftColZBelow\n\t\t\t, endmatBispansMatandgcd `bispanslztrans` bisWithGCD) )\n\t}\n\twhere\n\t\tvAndFn : ( v : Vect (S predn) ZZ **\n\t\t\t( i : Fin (S predn) )\n\t\t\t-> (index i (getCol FZ mat))\n\t\t\t\t`quotientOverZZ` (v <:> (getCol FZ mat)) )\n\t\tvAndFn = gcdOfVectAlg (S predn) (getCol FZ mat)\n\n\n\n{- Gaussian elimination for width > 0 -}\n\ntotal\ngaussElimlzIfVectGCD2 :\n\t(xs : Matrix n (S predm) ZZ)\n\t-> ( n' : Nat\n\t\t** (gexs : Matrix n' (S predm) ZZ\n\t\t\t** (rowEchelonPre gexs, gexs `bispanslz` xs)) )\n\n{-\nSuppose case width = 1.\n\nIf desired:\n\ngaussElimlzIfVectGCD2 xs {predm=Z} with (elimFirstCol xs)\n\t| (gexs ** (danrz, bis)) = (_ ** ( gexs ** (echelonPreFromDanrzLast danrz, bis) ))\n\ncan't be done, because the typechecker thinks it's a (Vect 1 ZZ = ZZ) situation.\n\nNot fixed if the (danrz, bis) is matched as (danrzAndBis).\nNot fixed by passing (S n) into the hole.\n-}\n\ngaussElimlzIfVectGCD2 xs {predm=Z} = runIdentity $ do {\n\t\t(gexs ** (danrz, bis)) <- Id $ elimFirstCol xs\n\t\treturn $ (_ ** ( gexs ** (echelonPreFromDanrzLast danrz, bis) ))\n\t}\n\n{-\nElse case width > 1.\n\nWe handle recursion in different ways depending on whether the first column is neutral.\nSince (with) blocks can't access local functions unless local to the case, and (case)\nblocks have totality problems, we write it as a wrapping of a local function which\npattern matches on the equality decision.\n\nThe locally scoped functions in question were involved in partially completing the\nproof, and this is retained as an artifact to retain compatibility this implementation\ntool used.\n-}\n\ngaussElimlzIfVectGCD2 xs {predm = S prededm}\n\t= gaussElimlzIfVectGCD2_gen $ decEq (getCol FZ xs) Algebra.neutral\n\twhere\n\t\tgaussElimlzIfVectGCD2_gen :\n\t\t\tDec (getCol FZ xs = Algebra.neutral)\n\t\t\t-> ( n' : Nat\n\t\t\t\t** (gexs : Matrix n' (S $ S prededm) ZZ\n\t\t\t\t\t** (rowEchelonPre gexs, gexs `bispanslz` xs)) )\n\n\t\t{-\n\t\tIf first col neutral then we can reduce the process\n\t\tto that on the value of (map tail).\n\t\t-}\n\n\t\tgaussElimlzIfVectGCD2_gen (Yes prNeut) = runIdentity $ do {\n\t\t\t( nold ** (matold ** (echold, bisold)) )\n\t\t\t\t<- Id $ gaussElimlzIfVectGCD2 $ map tail xs\n\t\t\treturn ( nold **\n\t\t\t\t\t(map ((Pos 0)::) matold\n\t\t\t\t\t** (echelonPreNullcolExtension echold\n\t\t\t\t\t, bispansNullcolExtension prNeut bisold)) )\n\t\t\t}\n\n\t\t{-\n\t\tOtherwise it's nonneutral, so we can show that since the elimFirstCol\n\t\tis DANRZ FZ FZ, its first row's leading nonzero entry is FZ. This leads\n\t\tto promoting the (rowEchelon) of one matrix to one with the same\n\t\tfirst row as the elimFirstCol.\n\n\t\tFor a proof, compare with \"Appendix Elim.General.Meta\"\n\t\t-}\n\n\t\tgaussElimlzIfVectGCD2_gen (No prNonneut) = runIdentity $ do {\n\t\t\t-- Perform elimination on the first column.\n\t\t\t(xFCE::xsFCE ** (xnxsFCEdanrz, fceBisxs))\n\t\t\t\t\t<- Id $ elimFirstCol xs\n\t\t\t-- Recurse, eliminating the tail.\n\t\t\t(elimLen ** (xselim ** (xselimEch, coltailxsFCEBisElim)))\n\t\t\t\t<- Id $ gaussElimlzIfVectGCD2 $ map tail xsFCE\n\n\t\t\t{-\n\t\t\tAdd the head of the first-column elimination\n\t\t\tto the tail's elimination to get the final elim.\n\t\t\t-}\n\n\t\t\tlet endmat = xFCE::map ((Pos Z)::) xselim\n\n\t\t\t-- The final elim is bispannable with the original matrix.\n\t\t\tlet xsNullcolextElimBisFCE = bispansNulltailcolExtension\n\t\t\t\txnxsFCEdanrz coltailxsFCEBisElim\n\t\t\t-- Bispannability is preserved by consing a common vector\n\t\t\tlet endmatBisxnFCE = bispansSamevecExtension\n\t\t\t\txsNullcolextElimBisFCE xFCE\n\t\t\t-- This is hence bispannable with the original matrix.\n\t\t\tlet endmatBisxs = bispanslztrans endmatBisxnFCE fceBisxs\n\n\t\t\t{-\n\t\t\tThe first column being nonzero is invariant over the\n\t\t\tbispannability class,\n\t\t\tand we assumed (prNonneut) this to hold for (xs),\n\t\t\tthus it holds for (endmat).\n\n\t\t\tThe first column being nonzero and the danrz for (endmat)\n\t\t\timply (head endmat = xFCE) has (leadingNonzeroNum xFCE = Just 0).\n\t\t\t-}\n\n\t\t\tlet headxFCELeadingNonzero = either\n\t\t\t\t( void\n\t\t\t\t. prNonneut\n\t\t\t\t. spansImpliesSameFirstColNeutrality (fst fceBisxs) )\n\t\t\t\tid\n\t\t\t\t$ danrzLeadingZeroAlt xnxsFCEdanrz\n\n\t\t\t{-\n\t\t\tThus the hypothesis of (rowEchelonPreExtension) applies,\n\t\t\tand the final elim is row echelon.\n\t\t\t-}\n\n\t\t\tlet endmatEch = rowEchelonPreExtension {x=xFCE}\n\t\t\t\theadxFCELeadingNonzero xselimEch\n\n\t\t\treturn (_ ** (endmat ** (endmatEch, endmatBisxs)))\n\n\t\t\t}\n\n\n\n{- Gaussian elimination in general -}\n\ntotal\ngaussElimlzIfVectGCD :\n\t(xs : Matrix n m ZZ)\n\t-> ( n' : Nat\n\t\t** (gexs : Matrix n' m ZZ\n\t\t\t** (rowEchelonPre gexs, gexs `bispanslz` xs)) )\ngaussElimlzIfVectGCD {m=Z} xs = (_ ** (Algebra.neutral\n\t** (rowEchelonPreZeroWidth, bispanslzreflFromEq $ sym $ zeroVecVecId xs)))\ngaussElimlzIfVectGCD {m=S predm} xs = gaussElimlzIfVectGCD2 xs\n\n}\n\n\n\n{-\nGaussian elimination from a GCD algorithm.\nThe premise of (gaussElimlzIfVect)s is equivalent to having a GCD.\n-}\n\n{- (gaussElimlzIfGCD) parameters -}\nparameters (\n\tgcdAlg : (c, d : ZZ)\n\t\t-> ( zpar : (ZZ, ZZ) ** uncurry (bezQTy c d) zpar )\n\t) {\n\ntotal\ngaussElimlzIfGCD2 :\n\t(xs : Matrix n m ZZ)\n\t-> ( n' : Nat\n\t\t** (gexs : Matrix n' m ZZ\n\t\t\t** (rowEchelonPre gexs, gexs `bispanslz` xs)) )\ngaussElimlzIfGCD2 = gaussElimlzIfVectGCD $ gcdToVectGCD gcdAlg\n\n{- Render proper row echelon property -}\n\ntotal\ngaussElimlzIfGCD :\n\t(xs : Matrix n m ZZ)\n\t-> ( n' : Nat\n\t\t** (gexs : Matrix n' m ZZ\n\t\t\t** (rowEchelon gexs, gexs `bispanslz` xs)) )\ngaussElimlzIfGCD xs = runIdentity $ do {\n\t\t(n' ** (gexs ** (echPre, bis))) <- Id $ gaussElimlzIfGCD2 xs\n\t\treturn $ (n' ** (gexs ** (toRowEchelon echPre, bis)))\n\t}\n\n} {- (gaussElimlzIfGCD) parameters -}\n\n\n\n{-\nThe gaussian elimination instantiation derived from (bezoutZT)\n-}\n\n\n\ngaussElimlz :\n\t(xs : Matrix n m ZZ)\n\t-> ( n' : Nat\n\t\t** (gexs : Matrix n' m ZZ\n\t\t\t** (rowEchelon gexs, gexs `bispanslz` xs)) )\ngaussElimlz = gaussElimlzIfGCD bezoutZT\n\n\n\n{-\n\nAppendix Elim.General.Meta\n\nCase matrix has height > 0, width > 1 of gaussian elimination.\n\nThe following meta-analytic proof translates between the mathematical ideas and the realization in the formal logic.\n\n---\n\nSuppose we are to produce from a given (x::xs) of width > 1 a row-span-equivalent\nrow echelon matrix, given how to do this for all matrices of lesser height\nand (nonzero) width, and given that the first column of (x::xs) is nonzero.\n\nBy (rowEchelonPreExtension), (leadingNonzeroNum v = Just FZ) & (rowEchelonPre vs)\n--> row echelon v :: 0|vs\n\nEliminating the first column\n\n\tmatchbind\n\nconverts a y::ys of width > 0 to an equivalent y' :: 0|ys' =: (yy'::yys') :: 0|ys'.\n\nBeing of this form is an unspoken equivalence to \"danrz\" (abbrev.): tautologically,\n(downAndNotRightOfEntryImpliesZ (y'::0|ys') 0 0). Whence the type of & intention\nbehind (elimFirstCol).\n\n\t\"y::ys === m where (m = y'::0|ys')\"\n\t<==>\n\ty::ys `bispanslz` m & downAndNotRightOfEntryImpliesZ m 0 0\n\nSince x::xs didn't have a 0 column, & bispannability preserves this (spansImpliesSameFirstColNeutrality), bispannability implies that xx' /= 0:\n\n\t\"xx' /= 0\"\n\t<==>\n\tlnzn x' = Just 0,\n\n& the latter is proved through (danrzLeadingZeroAlt):\n\n\tdanrz (_1::_2) 0 0, getCol 0 (_1::_2) /= 0\n\t==>\t(danrzLeadingZeroAlt)\n\t(getCol 0 (_1::_2) = 0 | lnzn _1 = Just 0) & getCol 0 (_1::_2) /= 0\n\t==>\n\tlnzn _1 = Just 0\n\nEliminating ys' then gives a matrix equivalent to ys under bispannability\n\n\tmatchbind\n\nwhich is preserved (bispansSamevecExtension) by consing a common vector. Thus we can\nconvert each y::ys of width > 1 to an equivalent y' :: 0|zs =: (yy'::yys') :: 0|zs such\nthat yy' /= 0 and 0|zs is row echelon.\n\nSharing the head y' means preserving the leading nonzero of the head, shown to\nbe (Just 0).\n\nThus the hypothesis of (rowEchelonPreExtension) applies\n\n\ty'_0 /= 0 ==> leadingNonzeroNum y' = Just FZ\n\n& we have that the y'::0|zs equivalent to the original y::ys is row echelon.\n\nSuch a matrix with the property of being equivalent to the original but row echelon is\nwwtbd.\n\n-}\n", "meta": {"hexsha": "20caeb4cdb707a7904ecb428d9d4b346dea25ece", "size": 12637, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Matrix/ZZGaussianElimination.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": "Data/Matrix/ZZGaussianElimination.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": "Data/Matrix/ZZGaussianElimination.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.0822222222, "max_line_length": 171, "alphanum_fraction": 0.6943103585, "num_tokens": 4167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.649792323614987}} {"text": "> import Data.Vect\n\n> import Enumerated.Enumerated\n\n> %default total\n> %auto_implicits off\n> %access public export\n\n> data Foo = Zero | One\n> \n> implementation Enumerated Foo 2 where\n> values = [Zero, One]\n> toFin Zero = 0\n> toFin One = 1\n> values_match_toFin = Refl\n> \n> implementation Eq Foo where\n> x == y = toFin x == toFin y\n", "meta": {"hexsha": "2b2a14b6e67adfa31eb0cd62db8f5f614c5c8a2a", "size": 345, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Testing/implementation.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": "Testing/implementation.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": "Testing/implementation.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.1578947368, "max_line_length": 39, "alphanum_fraction": 0.6550724638, "num_tokens": 116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6497576599789392}} {"text": "||| Instances of algebraic classes (group, ring, etc) for numeric data types,\n||| and Complex number types.\nmodule Control.Algebra.NumericInstances\n\nimport Control.Algebra\nimport Control.Algebra.VectorSpace\nimport Data.Complex\nimport Data.ZZ\n\n\ninstance Semigroup Integer where\n (<+>) = (+)\n\ninstance Monoid Integer where\n neutral = 0\n\ninstance Group Integer where\n inverse = (* -1)\n\ninstance AbelianGroup Integer\n\ninstance Ring Integer where\n (<.>) = (*)\n\ninstance RingWithUnity Integer where\n unity = 1\n\n\ninstance Semigroup Int where\n (<+>) = (+)\n\ninstance Monoid Int where\n neutral = 0\n\ninstance Group Int where\n inverse = (* -1)\n\ninstance AbelianGroup Int\n\ninstance Ring Int where\n (<.>) = (*)\n\ninstance RingWithUnity Int where\n unity = 1\n\n\ninstance Semigroup Float where\n (<+>) = (+)\n\ninstance Monoid Float where\n neutral = 0\n\ninstance Group Float where\n inverse = (* -1)\n\ninstance AbelianGroup Float\n\ninstance Ring Float where\n (<.>) = (*)\n\ninstance RingWithUnity Float where\n unity = 1\n\ninstance Field Float where\n inverseM f _ = 1 / f\n\n\ninstance Semigroup Nat where\n (<+>) = (+)\n\ninstance Monoid Nat where\n neutral = 0\n\ninstance Semigroup ZZ where\n (<+>) = (+)\n\ninstance Monoid ZZ where\n neutral = 0\n\ninstance Group ZZ where\n inverse = (* -1)\n\ninstance AbelianGroup ZZ\n\ninstance Ring ZZ where\n (<.>) = (*)\n\ninstance RingWithUnity ZZ where\n unity = 1\n\n\ninstance Semigroup a => Semigroup (Complex a) where\n (<+>) (a :+ b) (c :+ d) = (a <+> c) :+ (b <+> d)\n\ninstance Monoid a => Monoid (Complex a) where\n neutral = (neutral :+ neutral)\n\ninstance Group a => Group (Complex a) where\n inverse (r :+ i) = (inverse r :+ inverse i)\n\ninstance Ring a => AbelianGroup (Complex a) where {}\n\ninstance Ring a => Ring (Complex a) where\n (<.>) (a :+ b) (c :+ d) = (a <.> c <-> b <.> d) :+ (a <.> d <+> b <.> c)\n\ninstance RingWithUnity a => RingWithUnity (Complex a) where\n unity = (unity :+ neutral)\n\ninstance RingWithUnity a => Module a (Complex a) where\n (<#>) x = map (x <.>)\n\ninstance RingWithUnity a => InnerProductSpace a (Complex a) where\n (x :+ y) <||> z = realPart $ (x :+ inverse y) <.> z\n", "meta": {"hexsha": "b5b360597fd6f1757ad51f51049e99d269436637", "size": 2119, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Control/Algebra/NumericInstances.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/Control/Algebra/NumericInstances.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/Control/Algebra/NumericInstances.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": 18.5877192982, "max_line_length": 77, "alphanum_fraction": 0.6554978764, "num_tokens": 627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6495862430099663}} {"text": "module Data.Matrix.LinearCombinations\n\nimport Control.Algebra\nimport Control.Algebra.VectorSpace -- definition of module\nimport Classes.Verified -- definition of verified algebras other than modules\nimport Control.Algebra.DiamondInstances\nimport Data.Matrix\nimport Data.Matrix.Algebraic -- module instances; from Idris 0.9.20\n\nimport Data.Vect.Structural\nimport Data.Matrix.Structural\n\nimport Data.ZZ\n\nimport Control.Algebra.ZZVerifiedInstances\nimport Data.Matrix.AlgebraicVerified\n\n%default total\n\n\n\nmonoidsum : (Foldable t, Monoid a) => t a -> a\n{-\n-- Idris version 0.9.18\nmonoidsum = Control.Algebra.sum\n-}\n-- Idris version 0.9.20\nmonoidsum = sum'\n--\n\n\n\n{-\nBasic theorems regarding\n* Abelian groups\n* Vect _ _\n* Matrix _ _ _\n* Vect _ ZZ\n\tideally generalized from ZZ to other verified rings\n* Matrix _ _ ZZ\n\tideally generalized from ZZ to other verified rings\n-}\n\n\n\ndoubleSumInnerSwap : VerifiedAbelianGroup t => (a, b, c, d : t) -> (a<+>b)<+>(c<+>d) = (a<+>c)<+>(b<+>d)\ndoubleSumInnerSwap a b c d = trans (sym $ semigroupOpIsAssociative a b (c<+>d))\n\t$ trans ( cong {f=(a<+>)} $ trans (semigroupOpIsAssociative b c d)\n\t\t$ trans (cong {f=(<+>d)} $ abelianGroupOpIsCommutative b c)\n\t\t$ sym $ semigroupOpIsAssociative c b d)\n\t$ semigroupOpIsAssociative a c (b<+>d)\n\ndoubleSumInnerSwap_Vect : VerifiedRingWithUnity t => (a, b, c, d : Vect n t)\n\t-> (a<+>b)<+>(c<+>d) = (a<+>c)<+>(b<+>d)\ndoubleSumInnerSwap_Vect a b c d = trans (sym $ semigroupOpIsAssociative_Vect a b (c<+>d))\n\t$ trans ( cong {f=(a<+>)} $ trans (semigroupOpIsAssociative_Vect b c d)\n\t\t$ trans (cong {f=(<+>d)} $ abelianGroupOpIsCommutative_Vect b c)\n\t\t$ sym $ semigroupOpIsAssociative_Vect c b d)\n\t$ semigroupOpIsAssociative_Vect a c (b<+>d)\n\n\n\ntotal\nlemma_VectAddHead : (v, w : Vect (S n) ZZ) -> head(v<+>w) = (head v)<+>(head w)\nlemma_VectAddHead (vv::vvs) (ww::wws) = Refl\n\ntotal\nmatrixAddHead : (x, y : Matrix (S predn) m ZZ) -> Vect.head (x<+>y) = (Vect.head x)<+>(Vect.head y)\nmatrixAddHead (x::xs) (y::ys) = Refl\n\ntotal\nlemma_VectAddTail : (x, y : Vect (S predn) ZZ) -> Vect.tail (x<+>y) = (Vect.tail x)<+>(Vect.tail y)\nlemma_VectAddTail (x::xs) (y::ys) = Refl\n\ntotal\nmatrixAddTail : (x, y : Matrix (S predn) m ZZ) -> Vect.tail (x<+>y) = (Vect.tail x)<+>(Vect.tail y)\nmatrixAddTail (x::xs) (y::ys) = Refl\n\nlemma_VectAddEntrywise : .{n : Nat} -> (ni : Fin n) -> (v, w : Vect n ZZ) -> index ni (v<+>w) = (index ni v)<+>(index ni w)\n{-\n-- -- This proof follows the structure of `index`'s definition\n--\n-- without ni arg: (.) void FinZAbsurd; >> No such variable __pi_arg7; seems a silly failure of type inference\nlemma_VectAddEntrywise {n=Z} ni = void $ FinZAbsurd ni\nlemma_VectAddEntrywise FZ = ?lemma_VectAddEntrywise_rhs_1\nlemma_VectAddEntrywise (FS npredi) = ?lemma_VectAddEntrywise_rhs_2\nlemma_VectAddEntrywise_rhs_1 = proof\n intros\n rewrite sym (indexFZIsheadValued {xs=v})\n rewrite sym (indexFZIsheadValued {xs=w})\n exact (rewrite (indexFZIsheadValued {xs=v<+>w}) in (lemma_VectAddHead v w))\nlemma_VectAddEntrywise_rhs_2 = proof\n\tintros\n\tclaim indpred ( (r : ZZ) -> (rs : Vect k ZZ) -> index (FS npredi) (r::rs) = index npredi rs )\n\t-- ^ trivial\n\tunfocus\n\t{-\n\t-- No-opping stuff demonstrating the problem how the thm fails\n\trewrite sym ( indpred (head $ v<+>w) (tail $ v<+>w) )\n\trewrite sym ( indpred (head v) (tail v) )\n\trewrite sym ( indpred (head w) (tail w) )\n\t-}\n\trewrite sym ( the (v = (head v)::(tail v)) Refl )\n\t>> When checking argument value to function Prelude.Basics.the:\n Unifying v and head v :: tail v would lead to infinite value\n-}\n-- -- Alternative proof (>points):\nlemma_VectAddEntrywise {n=Z} ni v w = void $ FinZAbsurd ni\nlemma_VectAddEntrywise FZ (vv::vvs) (ww::wws) = Refl\nlemma_VectAddEntrywise (FS npredi) (vv::vvs) (ww::wws) = lemma_VectAddEntrywise npredi vvs wws\n\n\n\nmonoidrec1D : {v : ZZ} -> {vs : Vect n ZZ} -> monoidsum (v::vs) = v <+> monoidsum vs\nmonoidrec1D = monoidrec _ _\n\nmonoidrec2D : {v : Vect m ZZ} -> {vs : Vect n (Vect m ZZ)} -> monoidsum (v::vs) = v <+> (monoidsum vs)\nmonoidrec2D = monoidrec _ _\n\ntotal\nheadOfSumIsSumOfHeadsArg : ((v : Vect (S n) ZZ) ->\n (w : Vect (S n) ZZ) -> head (v <+> w) = head v <+> head w) -> (xs : Vect (S m) (Vect (S n) ZZ)) -> head (monoidsum xs) = monoidsum (map head xs)\nheadOfSumIsSumOfHeadsArg {n} pr (v::[]) = rewrite sym (pr v (replicate (S n) (Pos 0))) in Refl\nheadOfSumIsSumOfHeadsArg {m = S m'} {n} pr (v::(vsv::vss)) = conclusion3\n\twhere\n\t\tvs : Vect (S m') (Vect (S n) ZZ)\n\t\tvs = vsv::vss\n\t\timedform0: monoidsum (map head (v::vs)) = monoidsum ( (head v) :: (map head vs) )\n\t\timedform0 = cong {f=monoidsum} (mapheadrec {v=v} {vs=vs})\n\t\trecappl : monoidsum (map head (v::vs)) = head v <+> monoidsum (map head vs)\n\t\trecappl = trans imedform0 (the (monoidsum ( (head v) :: (map head vs) ) = (head v) <+> monoidsum (map head vs) ) monoidrec1D)\n\t\timedform1 : head (monoidsum (v::vs)) = head ( v <+> monoidsum vs )\n\t\t{-\n\t\toriginal: imedform1 = cong {f=head} monoidrec2D\n\t\tSpurious type mismatch error results. monoidrec2D is assumed the wrong implicit args, perhaps, or else one of the foldrImpl gets one recursion rewrite instead of none.\n\t\t-}\n\t\timedform1 = cong {f=head} (monoidrec2D {v=v} {vs=vs})\n\t\thomomorphismapply : head (monoidsum (v::vs)) = head v <+> (head (monoidsum vs))\n\t\thomomorphismapply = trans imedform1 (lemma_VectAddHead v (monoidsum vs))\n\t\tconclusion0 : (head (monoidsum (v::vs)) = head v <+> (head (monoidsum vs)), head v <+> monoidsum (map head vs) = monoidsum (map head (v::vs)))\n\t\tconclusion0 = (homomorphismapply, sym recappl)\n\t\tconclusion1 : head (monoidsum vs) = monoidsum (map head vs) -> (head (monoidsum (v::vs)) = head v <+> monoidsum (map head vs), head v <+> monoidsum (map head vs) = monoidsum (map head (v::vs)))\n\t\tconclusion1 pr = (rewrite sym pr in homomorphismapply, sym recappl)\n\t\tconclusion2 : head (monoidsum vs) = monoidsum (map head vs) -> head (monoidsum (v::vs)) = monoidsum (map head (v::vs))\n\t\tconclusion2 pr = uncurry trans (conclusion1 pr)\n\t\t-- bizarrely, this does not work\n\t\t-- conclusion2 pr = trans (rewrite sym pr in homomorphismapply) (sym recappl)\n\t\tproof0 : head (monoidsum vs) = monoidsum (map head vs)\n\t\tproof0 = headOfSumIsSumOfHeadsArg pr vs\n\t\tconclusion3 : head (monoidsum (v::vs)) = monoidsum (map head (v::vs))\n\t\tconclusion3 = conclusion2 proof0\n\ntotal\nheadOfSumIsSumOfHeads : (xs : Vect m (Vect (S n) ZZ)) -> head (monoidsum xs) = monoidsum (map head xs)\nheadOfSumIsSumOfHeads {m=Z} [] = Refl\nheadOfSumIsSumOfHeads {m=S m} xs = headOfSumIsSumOfHeadsArg lemma_VectAddHead xs\n{-\n-- This should work but is picky.\nheadOfSumIsSumOfHeads {m=Z} xs = trans zveqpr (sym $ trans bandy bundy)\n\twhere\n\t\tbandy : (the (Vect Z ZZ -> ZZ) monoidsum) (map head xs) = monoidsum (map head Data.Vect.Nil)\n\t\t-- bandy = trans ( sym $ trans ( cong {f=monoidsum . (map head)} (the ([]=xs) zeroVecEq) ) ( the ((monoidsum . (map head)) $ xs = monoidsum (map head xs)) Refl ) ) (the ((monoidsum . map head) [] = monoidsum (map Data.Vect.head Data.Vect.Nil)) Refl)\n\t\tbundy : monoidsum (map Data.Vect.head Data.Vect.Nil) = Pos Z\n\t\tbundy = Refl\n\t\tzveqpr : Data.Vect.head $ monoidsum xs = monoidsum (map Data.Vect.head xs)\n\t\tzveqpr = ?zveqpr'\n\t\tzveqpr' = proof\n\t\t\trewrite sym (the (xs=[]) zeroVecEq)\n\t\t\ttrivial\n-}\n{-\n-- Works in REPL\nheadOfSumIsSumOfHeads {m=Z} = ?headOfSumIsSumOfHeads_Z_pr\nheadOfSumIsSumOfHeads_Z_pr = proof\n intros\n let bandy = trans ( sym $ trans ( cong {f=monoidsum . (map head)} (the ([]=xs) zeroVecEq) ) ( the ((monoidsum . (map head)) $ xs = monoidsum (map head xs)) Refl ) ) (the ((monoidsum . map head) [] = monoidsum (map Data.Vect.head Data.Vect.Nil)) Refl)\n unfocus\n unfocus\n unfocus\n unfocus\n unfocus\n search\n search\n search\n let bundy = the (monoidsum (map Data.Vect.head Data.Vect.Nil) = Pos Z) $ Refl\n exact trans _ (sym $ trans bandy bundy)\n unfocus\n unfocus\n rewrite sym (the (xs=[]) zeroVecEq)\n trivial\n exact n\n exact n\n-}\n\ntailOfSumIsSumOfTails :\n\t{vs : Matrix n (S predw) ZZ}\n\t-> tail (monoidsum vs) = monoidsum (map tail vs)\ntailOfSumIsSumOfTails {vs=[]} = Refl\ntailOfSumIsSumOfTails {vs=v::vs} =\n\ttrans ( cong {f=tail} monoidrec2D )\n\t$ trans ( lemma_VectAddTail _ _ )\n\t$ trans ( cong {f=(<+>) (tail v)} $ tailOfSumIsSumOfTails {vs=vs} )\n\t$ sym $ monoidrec2D\n\n\n\ntotal\ndotproductRewrite : {v : Vect _ ZZ} -> v <:> w = monoidsum (zipWith (<.>) v w)\ndotproductRewrite = Refl\n\n\n\n{-\nCentral theorems:\n* timesVectMatAsLinearCombo\n* timesMatMatAsMultipleLinearCombos\n-}\n\n\n\ntimesMatMatAsTVecMat_EntryChariz : (vs : Matrix (S n') n ZZ) -> (xs : Matrix n w ZZ) -> Data.Vect.head (vs <> xs) = (Data.Vect.head vs) <\\> xs\ntimesMatMatAsTVecMat_EntryChariz vs [] = ?timesMatMatAsTVecMat_EntryCharizTriv\ntimesMatMatAsTVecMat_EntryChariz vs (xx::xxs) = ?timesMatMatAsTVecMat_EntryChariz'\n\ntimesMatMatAsTVecMat_EntryCharizTriv = proof\n intros\n rewrite sym $ headtails vs\n rewrite sym $ zeroVecVecId vs\n exact Refl\n\ntimesMatMatAsTVecMat_EntryChariz' = proof\n intros\n rewrite sym $ headtails vs\n exact Refl\n\n\n\ntotal\nzippyLemA : (the (Vect 0 ZZ) []) <\\> (the (Matrix 0 w ZZ) []) = replicate w (Pos 0)\nzippyLemA {w = Z} = Refl\nzippyLemA {w = S n} = cong (zippyLemA {w=n})\n\ntotal\nzippyLemB : replicate w (Pos 0) = monoidsum (zipWith (<#>) (the (Vect 0 ZZ) []) (the (Matrix 0 w ZZ) []))\nzippyLemB {w = Z} = Refl\nzippyLemB {w = S n} = cong (zippyLemB {w=n})\n\n\n\ntimesVectMatAsLinearCombo_EntryCharizLeft : (v : Vect n ZZ) -> (xs : Matrix n (S predw) ZZ) -> head (v <\\> xs) = monoidsum $ zipWith (*) v (map head xs)\ntimesVectMatAsLinearCombo_EntryCharizLeft [] [] = Refl\n-- Order of definitions issue - below line should be uncommented, line below it eliminated along with proof, and this whole section moved below the definition of timesVectMatAsHeadTail_ByTransposeElimination, requiring many declarations to move.\n-- timesVectMatAsLinearCombo_EntryCharizLeft (vv::vvs) (xx::xxs) = cong {f=head} $ timesVectMatAsHeadTail_ByTransposeElimination {scals=(vv::vvs)} {vects=(xx::xxs)}\ntimesVectMatAsLinearCombo_EntryCharizLeft (vv::vvs) (xx::xxs) = ?timesVectMatAsLinearCombo_EntryCharizLeft'\n\n-- Reduce addition over (Vect n ZZ) to entrywise addition over ZZ to change (head.monoidsum) into (monoidsum.(map head)).\ntimesVectMatAsLinearCombo_EntryCharizRight : (v : Vect n ZZ) -> (xs : Matrix n (S predw) ZZ) -> monoidsum $ zipWith (*) v (map head xs) = head $ monoidsum (zipWith (<#>) v xs)\ntimesVectMatAsLinearCombo_EntryCharizRight [] [] = Refl\ntimesVectMatAsLinearCombo_EntryCharizRight (vv::vvs) (xx::xxs) = ?timesVectMatAsLinearCombo_EntryCharizRight'\n{-\nWriting the proof as direct processing of equalities, rather than in the shell, resulted in tragedy.\n\ntimesVectMatAsLinearCombo_EntryCharizRight (vv::vvs) (xx::xxs) = sym $ reductComposition putHeadInside reduceMultUnderHeadTo1D\n\twhere\n\t\tputHeadInside : Data.Vect.head (monoidsum (zipWith (<#>) (vv::vvs) (xx::xxs))) = monoidsum (map head (zipWith (<#>) (vv::vvs) (xx::xxs)))\n\t\tputHeadInside = headOfSumIsSumOfHeads (zipWith (<#>) (vv::vvs) (xx::xxs))\n\t\treduceMultUnderHeadTo1D : map head (zipWith (<#>) (vv::vvs) (xx::xxs)) = zipWith (*) (vv::vvs) (map head (xx::xxs))\n\t\treduceMultUnderHeadTo1D = ?reduceMultUnderHeadTo1D'\n\t\treductComposition : head (monoidsum (zipWith (<#>) (vv::vvs) (xx::xxs))) = monoidsum (map head (zipWith (<#>) (vv::vvs) (xx::xxs))) -> map head (zipWith (<#>) (vv::vvs) (xx::xxs)) = zipWith (*) (vv::vvs) (map head (xx::xxs)) -> head (monoidsum (zipWith (<#>) (vv::vvs) (xx::xxs))) = monoidsum (zipWith (*) (vv::vvs) (map head (xx::xxs)))\n\t\treductComposition pr0 pr1 = ?reductComposition'\n\t\t{-\n\t\tFor some reason, trying any of these proofs makes Idris claim (vv) is expected to be a (Nat).\n\n\t\tcomposeReducts = rewrite sym reduceMultUnderHeadTo1D in putHeadInside\n\t\tcomposeReducts = trans putHeadInside (cong {f=monoidsum} reduceMultUnderHeadTo1D)\n\t\t-}\n\t\t-- composeReducts : head (monoidsum (zipWith (<#>) (vv::vvs) (xx::xxs))) = monoidsum (zipWith (*) (vv::vvs) (map head (xx::xxs)))\n\t\t-- composeReducts = reductComposition putHeadInside reduceMultUnderHeadTo1D\n-}\n\nreduceMultUnderHeadTo1D : {xxs : Matrix n (S m) ZZ} -> map Data.Vect.head (zipWith (<#>) (vv::vvs) (xx::xxs)) = zipWith (the (ZZ -> ZZ -> ZZ) (*)) (vv::vvs) (map Data.Vect.head (xx::xxs))\nreduceMultUnderHeadTo1D {n=Z} {vv} {xx}\n\t= vecHeadtailsEq (headMapChariz {xs=xx}) zeroVecEq\nreduceMultUnderHeadTo1D {n=S predn} {vv} {xx} {vvs} {xxs}\n\t= vecHeadtailsEq (headMapChariz {f=multZ vv} {xs=xx})\n\t$ rewrite headtails vvs in rewrite headtails xxs in\n\treduceMultUnderHeadTo1D {vv=head vvs} {vvs=tail vvs} {xx=head xxs} {xxs=tail xxs}\n\ntimesVectMatAsLinearCombo_EntryCharizRight' = proof\n intros\n claim putHeadInside head (monoidsum (zipWith (<#>) (vv::vvs) (xx::xxs))) = monoidsum (map head (zipWith (<#>) (vv::vvs) (xx::xxs)))\n unfocus\n exact sym $ trans putHeadInside (cong {f=monoidsum} $ reduceMultUnderHeadTo1D {vv=vv} {xx=xx})\n exact headOfSumIsSumOfHeads (zipWith (<#>) (vv::vvs) (xx::xxs))\n\ntimesVectMatAsLinearCombo_EntryChariz : (v : Vect n ZZ) -> (xs : Matrix n (S predw) ZZ) -> head (v <\\> xs) = head $ monoidsum (zipWith (<#>) v xs)\ntimesVectMatAsLinearCombo_EntryChariz v xs = trans (timesVectMatAsLinearCombo_EntryCharizLeft v xs) (timesVectMatAsLinearCombo_EntryCharizRight v xs)\n\n\n\ntransParaphraseGeneral0 : (vs : Matrix n (S predw) ZZ) -> transpose vs = (head $ transpose vs) :: (tail $ transpose vs)\ntransParaphraseGeneral0 vs = headtails (transpose vs)\n\ntransposeNTail2 : {xs : Matrix n (S predw) ZZ} -> tail $ transpose xs = transpose $ map tail xs\ntransposeNTail2 = ?transposeNTail2'\ntransposeNTail2' = proof\n intros\n rewrite sym (sym $ transposeIsInvolution {xs=tail (transpose xs)})\n exact cong {f=transpose} transposeNTail\n\ntransParaphraseGeneral1 : (vs : Matrix n (S predw) ZZ) -> transpose vs = (map Data.Vect.head vs) :: ( transpose $ map Data.Vect.tail vs )\ntransParaphraseGeneral1 {n} {predw} vs = ?transParaphraseGeneral1'\n\ntransParaphraseGeneral1' = proof\n intros\n rewrite sym (transParaphraseGeneral0 vs)\n rewrite sym (transposeNTail2 {xs=vs})\n rewrite sym (transposeNHead {xs=vs})\n exact Refl\n\nobservationTransposeFormInMult0 : {vects : Matrix n (S predw) ZZ} -> scals <\\> vects = map (\\ARG => scals <:> ARG) ( (map Data.Vect.head vects) :: ( transpose $ map Data.Vect.tail vects ) )\nobservationTransposeFormInMult0 {scals} {vects} = cong {f=map (\\ARG => scals <:> ARG)} (transParaphraseGeneral1 vects)\n\nobservationTransposeFormInMult1 : {vects : Matrix n (S predw) ZZ} -> scals <\\> vects = ( scals <:> (map Data.Vect.head vects) ) :: map (\\ARG => scals <:> ARG) ( transpose $ map Data.Vect.tail vects )\nobservationTransposeFormInMult1 = observationTransposeFormInMult0\n\n{-\nRecurses over the inner dimension of the matrix.\nHence, reduces (timesVectMatAsLinearCombo scals vects) to the cases ( timesVectMatAsLinearCombo (_::_) ([] :: _) )\n-}\ntimesVectMatAsHeadTail_ByTransposeElimination : {vects : Matrix n (S predw) ZZ} -> scals <\\> vects = (scals <:> map Data.Vect.head vects) :: ( scals <\\> map Data.Vect.tail vects )\ntimesVectMatAsHeadTail_ByTransposeElimination = observationTransposeFormInMult1\n\n\n\ncompressMonoidsum_lem1 : {vects : Matrix n (S predw) ZZ} -> monoidsum ( zipWith (<.>) scals (map Data.Vect.head vects) ) :: monoidsum ( zipWith (<#>) scals (map Data.Vect.tail vects) ) = ( head $ monoidsum ( zipWith (<#>) scals vects ) ) :: monoidsum ( zipWith (<#>) scals (map Data.Vect.tail vects) )\ncompressMonoidsum_lem1 {scals} {vects} = cong {f=(:: monoidsum ( zipWith (<#>) scals (map Data.Vect.tail vects) ) )} (timesVectMatAsLinearCombo_EntryCharizRight scals vects)\n\ncompressMonoidsum_lem2 : {n : Nat} -> {scals : Vect n ZZ} -> {predw : Nat} -> {vects : Vect n (Vect (S predw) ZZ)} -> Data.Vect.(::) (Data.Vect.head $ monoidsum ( zipWith (<#>) scals vects )) ( monoidsum ( zipWith (<#>) scals (map Data.Vect.tail vects) ) ) = monoidsum ( zipWith (<#>) scals vects )\ncompressMonoidsum_lem2 = ?compressMonoidsum_lem2'\n\nrewriteZipWithUnderTail : {scals : Vect n ZZ} -> {vects : Matrix n (S predw) ZZ} -> map Data.Vect.tail $ Data.Vect.zipWith (<#>) scals vects = Data.Vect.zipWith (<#>) scals (map Data.Vect.tail vects)\nrewriteZipWithUnderTail {scals=[]} {vects=[]} = Refl\nrewriteZipWithUnderTail {scals=z::zs} {vects=v::vs}\n\t= vecHeadtailsEq\n\t\t(rewrite headtails v in Refl)\n\t$ rewriteZipWithUnderTail {scals=zs} {vects=vs}\n\ncompressMonoidsum_lem3 : {n : Nat} -> {scals : Vect n ZZ} -> {predw : Nat} -> {vects : Vect n (Vect (S predw) ZZ)} -> monoidsum ( zipWith (<#>) scals (map Data.Vect.tail vects) ) = tail $ monoidsum ( zipWith (<#>) scals vects )\ncompressMonoidsum_lem3 {predw=Z} {n} = zeroVecEq\ncompressMonoidsum_lem3 {predw=S predpredw} {n=Z} = ?compressMonoidsum_lem3_rhs_majZ\ncompressMonoidsum_lem3 {predw=S predpredw} {n=S predn} {scals} {vects} = trans (cong {f=monoidsum} $ sym rewriteZipWithUnderTail) (sym tailOfSumIsSumOfTails)\n\ncompressMonoidsum_lem3_rhs_majZ = proof\n intros\n rewrite sym $ the (scals=[]) zeroVecEq\n rewrite sym $ the (vects=[]) zeroVecEq\n trivial\n\ncompressMonoidsum_lem2' = proof\n\tintros\n\trewrite sym (headtails $ monoidsum ( zipWith (<#>) scals vects ))\n\texact (vectConsCong ( head (monoidsum (zipWith (<#>) scals vects)) ) _ _ compressMonoidsum_lem3)\n\ncompressMonoidsum : {vects : Matrix n (S predw) ZZ} -> monoidsum ( zipWith (<.>) scals (map Data.Vect.head vects) ) :: monoidsum ( zipWith (<#>) scals (map Data.Vect.tail vects) ) = monoidsum ( zipWith (<#>) scals vects )\ncompressMonoidsum = ?compressMonoidsum'\n\ncompressMonoidsum' = proof\n\tintros\n\texact trans (compressMonoidsum_lem1 {scals=scals} {vects=vects}) compressMonoidsum_lem2\n\n\n\ntimesVectMatAsLinearCombo_EntryCharizLeft' = proof\n intros\n exact cong {f=head} $ timesVectMatAsHeadTail_ByTransposeElimination {scals=(vv::vvs)} {vects=(xx::xxs)}\n\n\n\ntimesVectMatAsLinearCombo :\n\t(v : Vect n ZZ) -> (xs : Matrix n w ZZ)\n\t-> ( v <\\> xs = monoidsum (zipWith (<#>) v xs) )\ntimesVectMatAsLinearCombo [] [] = trans zippyLemA zippyLemB\ntimesVectMatAsLinearCombo zs xs {n=S predn} {w=Z} = zeroVecEq\ntimesVectMatAsLinearCombo zs xs {n=S predn} {w=S predw}\n\t= flip trans (compressMonoidsum {scals=zs} {vects=xs})\n\t$ trans (timesVectMatAsHeadTail_ByTransposeElimination {scals=zs} {vects=xs})\n\t$ vecHeadtailsEq dotproductRewrite\n\t$ timesVectMatAsLinearCombo zs (map Data.Vect.tail xs)\n\n\n\ntimesMatMatAsMultipleLinearCombos_EntryChariz : (vs : Matrix (S n') n ZZ) -> (xs : Matrix n w ZZ) -> Data.Vect.head (vs <> xs) = monoidsum $ zipWith (<#>) (Data.Vect.head vs) xs\ntimesMatMatAsMultipleLinearCombos_EntryChariz vs xs = rewrite sym (timesVectMatAsLinearCombo (head vs) xs) in (timesMatMatAsTVecMat_EntryChariz vs xs)\n\ntimesMatMatAsMultipleLinearCombos : (vs : Matrix n' n ZZ) -> (xs : Matrix n w ZZ) -> vs <> xs = map (\\zs => monoidsum $ zipWith (<#>) zs xs) vs\ntimesMatMatAsMultipleLinearCombos [] xs = Refl\ntimesMatMatAsMultipleLinearCombos (v::vs) xs\n\t= trans ( headtails $ (v::vs)<>xs )\n\t$ vecHeadtailsEq ( timesMatMatAsMultipleLinearCombos_EntryChariz (v::vs) xs )\n\t$ timesMatMatAsMultipleLinearCombos vs xs\n\n\n\n{-\n* Prove the dot product is a bilinear map from (ZZ)-(Vect)s to (ZZ) (or at least, up to symmetry in the arguments).\n* Prove ZZ matrices form an algebra. Should work for ring. Proof it's a ring follows from associativity of matrix multiplication for a commutative ground ring.\n* Distributivities of matrix-matrix, vector-matrix, and matrix-vector multiplication over matrix addition and vector addition.\n* Prove transposition is an antiendomorphism of multiplication for ZZ matrices, and an endomorphism of addition, hence an antiendomorphism of the matrix ring.\n* Some Algebra.neutral is a zero element proofs.\n* Prove scalar multiplication of the left factor in a vector- or matrix-matrix product\nis the same as multiplying the product by the same scalar. (Note rel. to bilinearity)\n-}\n\n\n\n-- This & the mirrored statement form the theorem that the dot product is a bilinear map from vects to the scalar ring.\n-- This would be better with binary cong / leibniz equality on the (<+>)s.\ndotProductRightDistributesOverVectorPlus : (l, c, r : Vect n ZZ) -> (l<+>c)<:>r = (l<:>r)<+>(c<:>r)\ndotProductRightDistributesOverVectorPlus [] [] [] = Refl\ndotProductRightDistributesOverVectorPlus (l::ls) (c::cs) (r::rs) = trans monoidrec1D $\n\ttrans (cong {f=(((l<+>c)<.>r) <+>)} $ dotProductRightDistributesOverVectorPlus ls cs rs)\n\t$ trans (cong {f=(<+>((ls<:>rs)<+>(cs<:>rs)))} $ ringOpIsDistributiveR_ZZ l c r)\n\t$ trans (doubleSumInnerSwap (l<.>r) (c<.>r) (ls<:>rs) (cs<:>rs))\n\t$ rewrite monoidrec1D {v=l<.>r} {vs=zipWith (<.>) ls rs} in rewrite monoidrec1D {v=c<.>r} {vs=zipWith (<.>) cs rs} in Refl\n\ndotProductLeftDistributesOverVectorPlus : (l, c, r : Vect n ZZ) -> l<:>(c<+>r) = (l<:>c)<+>(l<:>r)\ndotProductLeftDistributesOverVectorPlus [] [] [] = Refl\ndotProductLeftDistributesOverVectorPlus (l::ls) (c::cs) (r::rs) = trans monoidrec1D $\n\ttrans (cong {f=((l<.>(c<+>r)) <+>)} $ dotProductLeftDistributesOverVectorPlus ls cs rs)\n\t$ trans (cong {f=(<+>((ls<:>cs)<+>(ls<:>rs)))} $ ringOpIsDistributiveL_ZZ l c r)\n\t$ trans (doubleSumInnerSwap (l<.>c) (l<.>r) (ls<:>cs) (ls<:>rs))\n\t$ rewrite monoidrec1D {v=l<.>r} {vs=zipWith (<.>) ls rs} in rewrite monoidrec1D {v=l<.>c} {vs=zipWith (<.>) ls cs} in Refl\n\nmatrixMultLeftDistributesOverVectorPlus : (l : Matrix n m ZZ) -> (c, r : Vect m ZZ) -> l(c<+>r) = (lc)<+>(lr)\nmatrixMultLeftDistributesOverVectorPlus [] c r = Refl\nmatrixMultLeftDistributesOverVectorPlus (x::xs) c r = vecHeadtailsEq (dotProductRightDistributesOverVectorPlus c r x) $ matrixMultLeftDistributesOverVectorPlus xs c r\n\nmatrixMultRightDistributesOverVectorPlus : (l, c : Vect n ZZ) -> (r : Matrix n m ZZ) -> (l<+>c)<\\>r = (l<\\>r)<+>(c<\\>r)\nmatrixMultRightDistributesOverVectorPlus l c r = matrixMultLeftDistributesOverVectorPlus (transpose r) l c\n\nmatrixAddEntrywise : (x, y : Matrix n m ZZ)\n\t-> (i : Fin n) -> (j : Fin m)\n\t-> indices i j (x<+>y) = (indices i j x)<+>(indices i j y)\nmatrixAddEntrywise [] [] i j = FinZElim i\nmatrixAddEntrywise (x::xs) (y::ys) FZ j = lemma_VectAddEntrywise j x y\nmatrixAddEntrywise (x::xs) (y::ys) (FS preli) j = matrixAddEntrywise xs ys preli j\n\n{-\nDISPLACED TO BE DEPENDED ON SOONER:\n\n* lemma_VectAddHead\n* matrixAddHead\n* lemma_VectAddTail\n* matrixAddTail\n\nRelated:\n* headOfSumIsSumOfHeads\n* tailOfSumIsSumOfTails\n-}\n\nmatrixAddMapHead : (x, y : Matrix n (S predm) ZZ) -> map Vect.head $ x<+>y = (map Vect.head x)<+>(map Vect.head y)\nmatrixAddMapHead [] [] = Refl\nmatrixAddMapHead (x::xs) (y::ys) = vecHeadtailsEq (lemma_VectAddHead x y) $ matrixAddMapHead xs ys\n\nmatrixAddMapTail : (x, y : Matrix n (S predm) ZZ) -> map Vect.tail $ x<+>y = (map Vect.tail x)<+>(map Vect.tail y)\nmatrixAddMapTail [] [] = Refl\nmatrixAddMapTail (x::xs) (y::ys) = vecHeadtailsEq (lemma_VectAddTail x y) $ matrixAddMapTail xs ys\n\nmatrixTransposeEndoMatrixPlus : (x, y : Matrix n m ZZ) -> transpose (x<+>y) = (transpose x)<+>(transpose y)\nmatrixTransposeEndoMatrixPlus x y = vecIndexwiseEq\n\t$ \\i => vecIndexwiseEq\n\t\t$ \\j => trans (transposeIndicesChariz j i)\n\t\t\t$ trans (matrixAddEntrywise x y j i)\n\t\t\t$ trans (cong {f=(<+>(indices j i y))}\n\t\t\t\t$ sym $ transposeIndicesChariz j i)\n\t\t\t$ trans (cong {f=((indices i j $ transpose x)<+>)}\n\t\t\t\t$ sym $ transposeIndicesChariz j i)\n\t\t\t$ sym $ matrixAddEntrywise (transpose x) (transpose y) i j\n\nvectorTimesLeftDistributesOverMatrixPlus : (l : Vect n ZZ) -> (c, r : Matrix n m ZZ)\n\t-> l<\\>(c<+>r) = (l<\\>c)<+>(l<\\>r)\nvectorTimesLeftDistributesOverMatrixPlus {m=Z} l c r = zeroVecEq\nvectorTimesLeftDistributesOverMatrixPlus {m=S predm} l c r =\n\ttrans (timesVectMatAsHeadTail_ByTransposeElimination {scals=l} {vects=c<+>r})\n\t$ trans (vecHeadtailsEq (cong {f=(l<:>)} $ matrixAddMapHead c r) $ cong {f=(l<\\>)} $ matrixAddMapTail c r)\n\t$ trans (vecHeadtailsEq (dotProductLeftDistributesOverVectorPlus l (map head c) (map head r)) $ vectorTimesLeftDistributesOverMatrixPlus l (map tail c) (map tail r))\n\t$ trans (cong $ sym $ timesVectMatAsHeadTail_ByTransposeElimination {scals=l} {vects=r})\n\t$ cong {f=(<+>(l<\\>r))} $ sym $ timesVectMatAsHeadTail_ByTransposeElimination {scals=l} {vects=c}\n\n{-\n-- Equational reasoning vrsn\n\tl<\\>(c<+>r) ={ timesVectMatAsHeadTail_ByTransposeElimination {scals=l} {vects=c<+>r} }=\n\t(l <:> map head (c<+>r))::(l<\\>map tail (c<+>r)) ={ vecHeadtailsEq (cong {f=(l<:>)} $ matrixAddMapHead c r) (cong {f=(l<\\>)} $ matrixAddMapTail c r) }=\n\t(l <:> ((map head c)<+>(map head r)))::(l<\\>((map tail c)<+>(map tail r))) ={ vecHeadtailsEq (dotProductLeftDistributesOverVectorPlus l (map head c) ( map head r)) $ vectorTimesLeftDistributesOverMatrixPlus l (map tail c) (map tail r) }=\n\t( (l<:>(map head c))::(l<\\>(map tail c)) ) <+> ( (l<:>(map head r)) :: (l<\\>(map tail r)) ) ={ cong $ sym $ timesVectMatAsHeadTail_ByTransposeElimination {scals=l} {vects=r} }=\n\t( (l<:>(map head c))::(l<\\>(map tail c)) ) <+> ( l<\\>r ) ={ cong {f=(<+>(l<\\>r))} $ sym $ timesVectMatAsHeadTail_ByTransposeElimination {scals=l} {vects=c} }=\n\t(l<\\>c)<+>(l<\\>r)\n\tqed\n-}\n\nmatrixMultRightDistributesOverMatrixPlus : (l, c : Matrix n k ZZ) -> (r : Matrix k m ZZ) -> (l<+>c)<>r = (l<>r)<+>(c<>r)\nmatrixMultRightDistributesOverMatrixPlus [] [] r = zeroVecEq\nmatrixMultRightDistributesOverMatrixPlus (l::ls) (c::cs) r = vecHeadtailsEq\n\t(matrixMultRightDistributesOverVectorPlus l c r)\n\t$ matrixMultRightDistributesOverMatrixPlus ls cs r\n\n{-\nCould use (matrixTransposeAntiendoMatrixMult) to avoid repeating the proof, but\nthat assumes the ring is commutative, so that prevents future full generality.\n-}\nmatrixMultLeftDistributesOverMatrixPlus : (l : Matrix n k ZZ) -> (c, r : Matrix k m ZZ) -> l<>(c<+>r) = (l<>c)<+>(l<>r)\nmatrixMultLeftDistributesOverMatrixPlus [] c r = Refl\nmatrixMultLeftDistributesOverMatrixPlus (l::ls) c r = vecHeadtailsEq (vectorTimesLeftDistributesOverMatrixPlus l c r) $ matrixMultLeftDistributesOverMatrixPlus ls c r\n\n\n\n-- Further interactions with the transpose\n-- The below are true if and only if the ring is commutative.\n\ndotProductCommutative : (x, y : Vect n ZZ) -> x<:>y = y<:>x\ndotProductCommutative [] [] = Refl\ndotProductCommutative (x::xs) (y::ys) = trans monoidrec1D\n\t$ trans (cong {f=(<+>(xs<:>ys))} $ ringOpIsCommutative_ZZ x y)\n\t$ trans (cong {f=((y<.>x)<+>)} $ dotProductCommutative xs ys)\n\t$ sym $ monoidrec1D\n\nmatrixTransposeAntiendoMatrixMult : (x : Matrix n k ZZ) -> (y : Matrix k m ZZ) -> transpose (x<>y) = (transpose y)<>(transpose x)\nmatrixTransposeAntiendoMatrixMult x y = vecIndexwiseEq\n\t$ \\i => vecIndexwiseEq\n\t\t$ \\j => trans (transposeIndicesChariz j i)\n\t\t\t$ trans (cong {f=index i} $ indexMapChariz {k=j} {xs=x} {f=((transpose y))})\n\t\t\t$ trans indexMapChariz\n\t\t\t$ trans (dotProductCommutative _ _)\n\t\t\t$ trans (sym $ indexMapChariz {k=j} {f=((index i (transpose y))<:>)} {xs=x})\n\t\t\t$ trans (cong {f=index j} $ matVecMultIsVecTransposeMult (index i $ transpose y) x)\n\t\t\t$ cong {f=index j} $ sym $ indexMapChariz {k=i} {f=(<\\>(transpose x))} {xs=transpose y}\n\n{-\n-- Equational reasoning vrsn (not formatted in the syntax for that, though)\nmatrixTransposeAntiendoMatrixMult x y = vecIndexwiseEq\n\t$ \\i => vecIndexwiseEq\n\t\t$ \\j => trans (transposeIndicesChariz j i)\n\t\t\t$ trans (cong {f=index i} indexMapChariz) -- ((x!j)<\\>y)!i\n\t\t\t\t-- === ((transpose y)(x!j))!i\n\t\t\t$ trans indexMapChariz\n\t\t\t\t-- (index j x)<:>(index i $ transpose y)\n\t\t\t$ trans (dotProductCommutative _ _)\n\t\t\t\t-- (index i $ transpose y)<:>(index j x)\n\t\t\t$ trans (sym $ indexMapChariz {k=j} {f=((index i $ transpose y)<:>)} {xs=x})\n\t\t\t\t-- index j $ map ((index i $ transpose y)<:>) x\n\t\t\t\t-- === index j $ x(index i $ transpose y)\n\t\t\t$ trans (cong {f=index j} $ matVecMultIsVecTransposeMult (index i $ transpose y) x)\n\t\t\t\t-- index j $ (index i $ transpose y)<\\>(transpose x)\n\t\t\t$ trans (cong {f=index j} $ sym $ indexMapChariz {k=i} {f=(<\\>(transpose x))} {xs=transpose y})\n\t\t\t\t-- index j $ index i $ map (<\\> (transpose x)) (transpose y)\n-}\n\n\n\n{-\ndotCancelsHeadWithLeadingZeroL : VerifiedRing a => (x, y : Vect n a) -> (Algebra.neutral::x)<:>(r::y) = x<:>y\ndotCancelsHeadWithLeadingZeroL x y {r} = trans (monoidrec (Algebra.neutral<.>r) $ zipWith (<.>) x y)\n\t$ trans (cong {f=((Algebra.neutral<.>r)<+>)} ?dotcancelsLpatch) -- something like dotproductRewrite, up to sym\n\t$ trans (cong {f=(<+> (x<:>y))} $ ringNeutralIsMultZeroL r)\n\t$ monoidNeutralIsNeutralR $ x<:>y\n\ndotCancelsHeadWithLeadingZeroR : VerifiedRing a => (x, y : Vect n a) -> (r::x)<:>(Algebra.neutral::y) = x<:>y\n-}\n\ndotCancelsHeadWithLeadingZeroL : (x, y : Vect n ZZ) -> (Algebra.neutral::x)<:>(r::y) = x<:>y\ndotCancelsHeadWithLeadingZeroL x y {r} = trans monoidrec1D\n\t$ trans (cong {f=(<+> (x<:>y))} $ ringNeutralIsMultZeroL r)\n\t$ monoidNeutralIsNeutralR $ x<:>y\n\ndotCancelsHeadWithLeadingZeroR : (x, y : Vect n ZZ) -> (r::x)<:>(Algebra.neutral::y) = x<:>y\ndotCancelsHeadWithLeadingZeroR x y {r} = trans monoidrec1D\n\t$ trans (cong {f=(<+> (x<:>y))} $ ringNeutralIsMultZeroR r)\n\t$ monoidNeutralIsNeutralR $ x<:>y\n\nneutralVectIsDotProductZero_L : (x : Vect nu ZZ) -> Algebra.neutral <:> x = Algebra.neutral\nneutralVectIsDotProductZero_L [] = Refl\nneutralVectIsDotProductZero_L (x::xs) = trans (dotCancelsHeadWithLeadingZeroL Algebra.neutral xs) $ neutralVectIsDotProductZero_L xs\n\n{-\n-- Mixture of instance problems and problem generalizing (dotCancelsHeadWithLeadingZeroR).\n\nneutralVectIsDotProductZero_R : VerifiedRing a => (x : Vect n a) -> x<:>Algebra.neutral = Algebra.neutral {a=a}\nneutralVectIsDotProductZero_R [] = ?neutralVectIsDotProductZero_R_ReflCase\nneutralVectIsDotProductZero_R (x::xs) = trans (dotCancelsHeadWithLeadingZeroR xs Algebra.neutral) $ neutralVectIsDotProductZero_R xs\n-}\n\nneutralVectIsDotProductZero_R : (x : Vect nu ZZ) -> x <:> Algebra.neutral = Algebra.neutral\nneutralVectIsDotProductZero_R [] = Refl\nneutralVectIsDotProductZero_R (x::xs) = trans (dotCancelsHeadWithLeadingZeroR xs Algebra.neutral) $ neutralVectIsDotProductZero_R xs\n\nneutralVectIsVectTimesZero : (x : Matrix nu mu ZZ) -> Algebra.neutral <\\> x = Algebra.neutral\nneutralVectIsVectTimesZero xs {mu=Z} = zeroVecEq\nneutralVectIsVectTimesZero xs {mu=S predmu} = trans timesVectMatAsHeadTail_ByTransposeElimination\n\t$ vecHeadtailsEq\n\t\t(neutralVectIsDotProductZero_L $ map head xs)\n\t\t$ neutralVectIsVectTimesZero $ map tail xs\n\nemptyVectIsTimesVectZero : (x : Matrix nu Z ZZ) -> x[] = Algebra.neutral\nemptyVectIsTimesVectZero [] = Refl\nemptyVectIsTimesVectZero (x::xs) = vecHeadtailsEq (neutralVectIsDotProductZero_L x)\n\t$ emptyVectIsTimesVectZero xs\n\nneutralMatIsMultZeroL : (x : Matrix nu mu ZZ) -> Algebra.neutral <> x = Algebra.neutral\nneutralMatIsMultZeroL x = vecIndexwiseEq $ \\i => trans indexMapChariz $ trans (cong {f=(<\\>x)} indexReplicateChariz) $ trans (neutralVectIsVectTimesZero x) $ sym $ indexReplicateChariz\n\nmatMultCancelsHeadWithZeroColExtensionL : (map ((Pos 0)::) xs)<>(z::ys) = xs<>ys\nmatMultCancelsHeadWithZeroColExtensionL {xs} {ys} {z} = vecIndexwiseEq\n\t$ \\i => vecIndexwiseEq\n\t\t$ \\j => trans (matMultIndicesChariz {l=map ((Pos 0)::) xs} {r=z::ys})\n\t\t\t$ trans (cong {f=(<:>(getCol j $ z::ys))} indexMapChariz)\n\t\t\t$ trans (dotCancelsHeadWithLeadingZeroL {r=index j z} (index i xs) (getCol j ys))\n\t\t\t$ sym $ matMultIndicesChariz {l=xs} {r=ys}\n\ntimesPreservesLeadingZeroExtensionR : xs<>(map ((Pos 0)::) ys) = map ((Pos 0)::) $ xs<>ys\ntimesPreservesLeadingZeroExtensionR {xs} {ys} = vecIndexwiseEq $ \\i => vecIndexwiseEq $ \\j => filmy i j\n\twhere\n\t\tfilmy : (i : _) -> (j : _) -> indices i j $ xs<>(map ((Pos 0)::) ys) = indices i j $ map ((Pos 0)::) $ xs<>ys\n\t\tfilmy i FZ = trans matMultIndicesChariz\n\t\t\t$ trans (cong {f=((index i xs)<:>)} $ leadingElemExtensionFirstColReplicate $ Pos 0)\n\t\t\t$ trans (neutralVectIsDotProductZero_R $ index i xs)\n\t\t\t$ sym $ cong {f=index FZ} $ indexMapChariz {f=((Pos 0)::)}\n\t\tfilmy i (FS prelj) = trans matMultIndicesChariz\n\t\t\t$ trans (cong {f=((index i xs)<:>)} leadingElemExtensionColFSId)\n\t\t\t$ trans (sym $ matMultIndicesChariz)\n\t\t\t$ sym $ cong {f=index $ FS prelj} $ indexMapChariz {f=((Pos 0)::)}\n\n\n\n{-\n-- Type mismatch due to instance mismatch b-n\n-- (<.>) {{(@@constructor of Classes.Verified.VerifiedRing#Ring a) constrarg}}\n-- and\n-- (<.>) {{(@@constructor of Control.Algebra.RingWithUnity#Ring a) constrarg1}}\n-- Also tried (VerifiedRingWithUnity a =>)\nscaledNeutralIsNeutral : (VerifiedRing a, RingWithUnity a) =>\n\t{m : Nat}\n\t-> (z : a)\n\t-> z<#>(the (Vect m a) Algebra.neutral) = Algebra.neutral\nscaledNeutralIsNeutral _ {m=Z} = Refl\nscaledNeutralIsNeutral z {m=S predm} = vecHeadtailsEq (ringNeutralIsMultZeroR z)\n\t$ scaledNeutralIsNeutral z {m=predm}\n-}\n\nscaledNeutralIsNeutral_zz : {m : Nat}\n\t-> (z : ZZ)\n\t-> z<#>(the (Vect m ZZ) Algebra.neutral) = Algebra.neutral\nscaledNeutralIsNeutral_zz _ {m=Z} = Refl\nscaledNeutralIsNeutral_zz z {m=S predm} = vecHeadtailsEq (ringNeutralIsMultZeroR z)\n\t$ scaledNeutralIsNeutral_zz z {m=predm}\n\nvectVectLScalingCompatibility : {z : ZZ} -> (z<#>l)<:>r = z<.>(l<:>r)\nvectVectLScalingCompatibility {z} {l=[]} {r=[]} = sym $ ringNeutralIsMultZeroR z\nvectVectLScalingCompatibility {z} {l=l::ls} {r=r::rs} =\n\ttrans (dotproductRewrite {v=z<#>(l::ls)} {w=r::rs})\n\t$ trans (cong {f=monoidsum} $ vecHeadtailsEq (sym $ ringOpIsAssociative z l r) Refl)\n\t$ trans monoidrec1D\n\t$ trans (cong {f=((z<.>(l<.>r))<+>)}\n\t\t$ trans (sym $ dotproductRewrite {v=z<#>ls} {w=rs})\n\t\t$ (vectVectLScalingCompatibility {z=z} {l=ls} {r=rs}))\n\t$ trans (sym $ ringOpIsDistributiveL z (l<.>r) (ls<:>rs))\n\t-- z<.>(l<.>r <+> ls<:>rs)\n\t$ cong {f=(z<.>)}\n\t$ trans (cong {f=((l<.>r)<+>)} $ dotproductRewrite {v=ls} {w=rs})\n\t-- (l<.>r)<+>(monoidsum $ zipWith (<.>) ls rs)\n\t$ trans (sym monoidrec1D)\n\t$ sym $ dotproductRewrite {v=l::ls} {w=r::rs}\n\n-- Note the relationship to bilinearity of matrix multiplication\nvectMatLScalingCompatibility : {z : ZZ} -> {rs : Matrix k m ZZ} -> (z <#> la) <\\> rs = z <#> (la <\\> rs)\nvectMatLScalingCompatibility {z} {la=[]} {rs=[]} =\n\ttrans zippyLemA\n\t$ sym $ trans (cong {f=(z<#>)} zippyLemA)\n\t$ scaledNeutralIsNeutral_zz z\nvectMatLScalingCompatibility {z} {la=l::la} {rs=r::rs} {m=Z} = zeroVecEq\n-- vectMatLScalingCompatibility {z} {la=l::la} {rs=r::rs} {m=S predm} = ?vMLSC_rhs_2\nvectMatLScalingCompatibility {z} {la=l::la} {rs=r::rs} {m=S predm} =\n\ttrans (timesVectMatAsHeadTail_ByTransposeElimination\n\t\t{scals=z<#>(l::la)} {vects=r::rs})\n\t$ trans ( vecHeadtailsEq\n\t\t\t(vectVectLScalingCompatibility {z=z} {l=l::la} {r=map head $ r::rs})\n\t\t\t$ vectMatLScalingCompatibility {z=z}\n\t\t\t\t{la=l::la} {rs=map tail $ r::rs} )\n\t$ sym $ cong {f=(z<#>)} $ timesVectMatAsHeadTail_ByTransposeElimination\n\t\t{scals=l::la} {vects=r::rs}\n\nmatMatLScalingCompatibility :\n\t(scal : ZZ)\n\t-> (xs : Matrix n k ZZ)\n\t-> (ys : Matrix k m ZZ)\n\t-> (scal <#> xs) <> ys = scal <#> (xs <> ys)\nmatMatLScalingCompatibility _ [] _ = zeroVecEq\nmatMatLScalingCompatibility scal (x::xs) ys = vecHeadtailsEq\n\tvectMatLScalingCompatibility\n\t$ matMatLScalingCompatibility scal xs ys\n\n\n\n{-\nType mismatch between\n\n\t(<.>) {{(@@constructor of Classes.Verified.VerifiedRing#Ring a)\n\t\t(@@constructor of Classes.Verified.VerifiedRingWithUnity#VerifiedRing a)}}\n\t\tneutral\n\t\tx =\n\tneutral (Type of ringNeutralIsMultZeroL x)\n\nand\n\n\t(<.>) {{(@@constructor of Control.Algebra.RingWithUnity#Ring a)\n\t\t(@@constructor of Classes.Verified.VerifiedRingWithUnity#RingWithUnity a)}}\n\t\tneutral\n\t\tx =\n\tneutral (Expected type)\n\n---\n\nneutralScalarIsScalarMultNeutral_Vect : VerifiedRingWithUnity a => (xs : Vect n a)\n\t-> (the a Algebra.neutral)<#>xs = Algebra.neutral\nneutralScalarIsScalarMultNeutral_Vect [] = Refl\nneutralScalarIsScalarMultNeutral_Vect (x::xs) = vecHeadtailsEq\n\t(ringNeutralIsMultZeroL x)\n\t$ neutralScalarIsScalarMultNeutral_Vect xs\n-}\n\nneutralScalarIsScalarMultNeutral_zzVect : (xs : Vect n ZZ)\n\t-> (the ZZ Algebra.neutral)<#>xs = Algebra.neutral\nneutralScalarIsScalarMultNeutral_zzVect [] = Refl\nneutralScalarIsScalarMultNeutral_zzVect (x::xs) = vecHeadtailsEq\n\t(ringNeutralIsMultZeroL x)\n\t$ neutralScalarIsScalarMultNeutral_zzVect xs\n\n-- Can prove for arbitrary module by showing the LHS is its own double by distributivity\n-- groupElemOwnDoubleImpliesNeut\nneutralScalarIsScalarMultNeutral_zzMat : (xs : Matrix n m ZZ)\n\t-> (the ZZ Algebra.neutral)<#>xs = Algebra.neutral\nneutralScalarIsScalarMultNeutral_zzMat [] = Refl\nneutralScalarIsScalarMultNeutral_zzMat (x::xs) = vecHeadtailsEq\n\t(neutralScalarIsScalarMultNeutral_zzVect x)\n\t$ neutralScalarIsScalarMultNeutral_zzMat xs\n\nvectTimesNegOneIsNeg_zz : (xs : Vect n ZZ)\n\t-> (Algebra.inverse $ the ZZ $ Algebra.unity) <#> xs = Algebra.inverse xs\nvectTimesNegOneIsNeg_zz xs = groupOpIsCancellativeR_Vect _ _ xs\n\t$ trans (cong {f=(((Algebra.inverse $ Algebra.unity {a=ZZ}) <#> xs)<+>)}\n\t\t$ sym $ moduleScalarUnityIsUnity_Vect {ok=Refl} xs)\n\t$ trans (sym $ moduleScalarMultDistributiveWRTModuleAddition_Vect {ok=Refl}\n\t\t(Algebra.inverse $ Algebra.unity {a=ZZ}) (Algebra.unity {a=ZZ}) xs)\n\t$ trans (cong {f=(<#>xs)} $ groupInverseIsInverseR $ Algebra.unity {a=ZZ})\n\t$ trans (neutralScalarIsScalarMultNeutral_zzVect xs)\n\t$ sym $ groupInverseIsInverseR_Vect xs\n\nmatTimesNegOneIsNeg_zz : (xs : Matrix n m ZZ)\n\t-> (Algebra.inverse $ the ZZ $ Algebra.unity) <#> xs = Algebra.inverse xs\nmatTimesNegOneIsNeg_zz xs = groupOpIsCancellativeR _ _ xs\n\t$ trans (cong {f=(((Algebra.inverse $ Algebra.unity {a=ZZ}) <#> xs)<+>)}\n\t\t$ sym $ moduleScalarUnityIsUnity_Mat {a=ZZ} xs)\n\t$ trans (sym $ moduleScalarMultDistributiveWRTModuleAddition_Mat\n\t\t(Algebra.inverse $ Algebra.unity {a=ZZ}) (Algebra.unity {a=ZZ}) xs)\n\t$ trans (cong {f=(<#>xs)} $ groupInverseIsInverseR $ Algebra.unity {a=ZZ})\n\t$ trans (neutralScalarIsScalarMultNeutral_zzMat xs)\n\t$ sym $ groupInverseIsInverseR xs\n\n{-\nWhen checking type of ZZModuleSpan.negScalarToScaledNeg:\nWhen checking an application of function Control.Algebra.VectorSpace.<#>:\n Can't resolve type class Group r\n\n---\n\nnegScalarToScaledNeg : (VerifiedRingWithUnity r, VerifiedModule r a) -> (s : r) -> (x : a) -> (inverse s) <#> x = s <#> (inverse x)\n\n-----\n\nWe require generalizations to other rings for:\n\n\tneutralScalarIsScalarMultNeutral_zzVect\n\tneutralScalarIsScalarMultNeutral_zzMat\n\n\tvectTimesNegOneIsNeg_zz\n\tmatTimesNegOneIsNeg_zz\n\n---\n\nnegScalarToScaledNegVect : VerifiedRingWithUnity r => (s : r) -> (x : Vect _ r) -> (inverse s) <#> x = s <#> (inverse x)\n\nnegScalarToScaledNegMat : VerifiedRingWithUnity r => (s : r) -> (x : Matrix _ _ r) -> (inverse s) <#> x = s <#> (inverse x)\n-}\n\nnegScalarToScaledNegVect_zz : (s : ZZ)\n\t-> (x : Vect _ ZZ)\n\t-> (inverse s) <#> x = s <#> (inverse x)\nnegScalarToScaledNegVect_zz s x =\n\ttrans (cong {f=(<#>x)}\n\t\t$ trans (negativeIsNegOneTimesRight s) $ ringOpIsCommutative_ZZ _ s)\n\t$ trans (sym $ moduleScalarMultiplyComposition_Vect s _ x)\n\t$ cong {f=(s<#>)} $ vectTimesNegOneIsNeg_zz x\n\nnegScalarToScaledNegMat_zz : (s : ZZ)\n\t-> (x : Matrix _ _ ZZ)\n\t-> (inverse s) <#> x = s <#> (inverse x)\nnegScalarToScaledNegMat_zz s x =\n\ttrans (cong {f=(<#>x)}\n\t\t$ trans (negativeIsNegOneTimesRight s) $ ringOpIsCommutative_ZZ _ s)\n\t$ trans (sym $ moduleScalarMultiplyComposition_Mat s _ x)\n\t$ cong {f=(s<#>)} $ matTimesNegOneIsNeg_zz x\n", "meta": {"hexsha": "773888dff1ad8a48cb1caab6124792fbb38eb30d", "size": 38913, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Matrix/LinearCombinations.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": "Data/Matrix/LinearCombinations.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": "Data/Matrix/LinearCombinations.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": 47.9224137931, "max_line_length": 339, "alphanum_fraction": 0.6950633464, "num_tokens": 13637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.6490184116207157}} {"text": "> module LinCombHeadtailsEq\n\n> import Data.Matrix.LinearCombinations\n> import Data.Matrix.ZZModuleSpan\n\n> import Control.Algebra\n> import Control.Algebra.VectorSpace -- definition of module\n> import Classes.Verified -- definition of verified algebras other than modules\n> import Data.Matrix\n> import Data.Matrix.Algebraic -- module instances; from Idris 0.9.20\n\n> import Data.ZZ\n\n\n\n# Contents\n* Introduction\n* vecSingletonReplicateEq\n* reduceMultUnderHeadTo1D\n* rewriteZipWithUnderTail\n* References\n\n\n\n# Introduction\n\nSuppose we have\n\n< vecHeadtailsEq : {xs,ys : Vect _ _} -> ( headeq : x = y ) -> ( taileq : xs = ys ) -> x::xs = y::ys\n\nThen we can replace efforts in proofs with this expression.\n\nThese are proofs of equality of two Vects expressed in (x::xs) form, mainly inductive proofs:\n\n< vecSingletonReplicateEq : ((u : a) -> v=u) -> (xs : Vect n a) -> (xs = replicate n v)\n\n< reduceMultUnderHeadTo1D : {xxs : Matrix n (S m) ZZ} -> map Data.Vect.head (zipWith (<#>) (vv::vvs) (xx::xxs)) = zipWith (the (ZZ -> ZZ -> ZZ) (*)) (vv::vvs) (map Data.Vect.head (xx::xxs))\n< reduceMultUnderHeadTo1D_triv\n< reduceMultUnderHeadTo1D'\n\n< rewriteZipWithUnderTail : {scals : Vect n ZZ} -> {vects : Matrix n (S predw) ZZ} -> map Data.Vect.tail $ Data.Vect.zipWith (<#>) scals vects = Data.Vect.zipWith (<#>) scals (map Data.Vect.tail vects)\n< rewriteZipWithUnderTail'\n\n\n\n# vecSingletonReplicateEq\n\nOut of these, `vecSingletonReplicateEq` is the simplest to analyze the replacement.\n\nLet us write\n\n> vecSingletonReplicateEq_2 : ((u : a) -> v=u) -> (xs : Vect n a) -> (xs = replicate n v)\n> vecSingletonReplicateEq_2 f [] = Refl\n> vecSingletonReplicateEq_2 f (x::xs) = vecHeadtailsEq (sym $ f x) (vecSingletonReplicateEq_2 f xs)\n\nthis improves the clarity of\n\n< vecSingletonReplicateEq : ((u : a) -> v=u) -> (xs : Vect n a) -> (xs = replicate n v)\n< vecSingletonReplicateEq f [] = Refl\n< vecSingletonReplicateEq f (x::xs) {v} = rewrite sym (f x) in cong {f=(v::)} (vecSingletonReplicateEq f xs)\n\n\n\n# reduceMultUnderHeadTo1D\n\nThe ones in `reduceMultUnderHeadTo1D` are most aggregious. Let us write\n\n> reduceMultUnderHeadTo1D_2 : {xxs : Matrix n (S m) ZZ} -> map Data.Vect.head (zipWith (<#>) (vv::vvs) (xx::xxs)) = zipWith (the (ZZ -> ZZ -> ZZ) (*)) (vv::vvs) (map Data.Vect.head (xx::xxs))\n> reduceMultUnderHeadTo1D_2 {n=Z} {xxs=[]} {vvs=[]} = vecHeadtailsEq headMapChariz Refl\n> reduceMultUnderHeadTo1D_2 {n=S predn} {xxs=xxx::xxxs} {vvs=vvv::vvvs} = vecHeadtailsEq headMapChariz reduceMultUnderHeadTo1D_2\n> \n\nNote the greater improvement of the proof for the case {n=Z} by pattern matching on the variables `xxs` and `vvs` rather than applying `zeroVecEq` to prove they're both [].\n\nFurther, the corresponding finer-grained pattern matching in the longer-tailed cases eliminates the need for the second `vecHeadtailsEq` argument to be given by the proof\n\n< mapheads_eq_zipwith = proof\n< intros\n< rewrite sym $ headtails vvs\n< rewrite sym $ headtails xxs\n< exact reduceMultUnderHeadTo1D_2 {vv=head vvs} {vvs=tail vvs} {xx=head xxs} {xxs=tail xxs}\n\nas in\n\n< reduceMultUnderHeadTo1D_2 {n=S predn} {vv} {xx} = vecHeadtailsEq headMapChariz ?mapheads_eq_zipwith\n\nThe original, however, is comparatively illegible\n\n< reduceMultUnderHeadTo1D : {xxs : Matrix n (S m) ZZ} -> map Data.Vect.head (zipWith (<#>) (vv::vvs) (xx::xxs)) = zipWith (the (ZZ -> ZZ -> ZZ) (*)) (vv::vvs) (map Data.Vect.head (xx::xxs))\n< reduceMultUnderHeadTo1D {n=Z} {vv} {xx} = ?reduceMultUnderHeadTo1D_triv\n< reduceMultUnderHeadTo1D {n=S predn} {vv} {xx} = ?reduceMultUnderHeadTo1D'\n< \n< reduceMultUnderHeadTo1D_triv = proof\n< intros\n< rewrite sym (the (xxs = []) zeroVecEq)\n< rewrite sym (the (vvs = []) zeroVecEq)\n< compute\n< exact cong {f=(::[])} _\n< exact headMapChariz {xs=xx}\n< \n< reduceMultUnderHeadTo1D' = proof\n< intros\n< -- Not required in the REPL: {f=multZ vv}\n< exact trans (cong {f=(::(map head $ zipWith (<#>) vvs xxs))} $ headMapChariz {f=multZ vv} {xs=xx}) _\n< compute\n< exact cong {f=(::) (multZ vv (head xx))} _\n< rewrite sym $ headtails vvs\n< rewrite sym $ headtails xxs\n< exact reduceMultUnderHeadTo1D {vv=head vvs} {vvs=tail vvs} {xx=head xxs} {xxs=tail xxs}\n\n\n\n# rewriteZipWithUnderTail\n\nFinally, `rewriteZipWithUnderTail` plays a full mind game with Idris to discuss one of these problems. We may write\n\n> rewriteZipWithUnderTail_2 : {scals : Vect n ZZ} -> {vects : Matrix n (S predw) ZZ} -> map Data.Vect.tail $ Data.Vect.zipWith (<#>) scals vects = Data.Vect.zipWith (<#>) scals (map Data.Vect.tail vects)\n> rewriteZipWithUnderTail_2 {scals=[]} {vects=[]} = Refl\n> rewriteZipWithUnderTail_2 {scals=z::zs} {vects=v::vs} = vecHeadtailsEq (rewrite sym $ sym $ headtails v in Refl) rewriteZipWithUnderTail_2\n\nwhereas originally we had to write\n\n< rewriteZipWithUnderTail {scals=z::zs} {vects=v::vs} = ?rewriteZipWithUnderTail'\n< \n< rewriteZipWithUnderTail' = proof\n< intros\n< let headv = map (z <.>) (tail v)\n< exact trans _ (cong {f=(headv::)} $ rewriteZipWithUnderTail {scals=zs} {vects=vs})\n< claim headeq tail (map (z<.>) v) = headv\n< compute -- reduce the headv in the proposition to its value for prepping substitution\n< unfocus\n< rewrite sym headeq\n< compute -- apply the (\\x => headv::x) from the earlier cong\n< exact Refl\n< rewrite sym $ headtails v\n< exact Refl\n\n\n\n# References\n\n* Idris 0.9.20 src: /test/regex007/A.lidr\n\nNotes\n\n* Idris 0.9.20 src: /samples/misc/reflection.idr\n* modules.rst\n", "meta": {"hexsha": "124969d05754034fdd805b35640964e56da03a44", "size": 5439, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "_Technique/LinCombHeadtailsEq.lidr", "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": "_Technique/LinCombHeadtailsEq.lidr", "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": "_Technique/LinCombHeadtailsEq.lidr", "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": 36.75, "max_line_length": 203, "alphanum_fraction": 0.6993932708, "num_tokens": 1817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6489730489267699}} {"text": "import Data.Vect\nimport Python\nimport Python.Lib.Numpy.Matrix\n\n%default total\n\nf : Nat -> Maybe (List Bool)\nf Z = Just [True, False]\nf (S n) = f n\n\nxs : Matrix 3 4 DDouble\nxs = array _\n [[1.0,-2.1, 3.3, -0.1]\n ,[3.5, 7.0, 0.0, -5.2]\n ,[0.5, 7.2,-1.1, 0.0]\n ]\n\nys : Matrix 6 2 DDouble\nys = reshape xs\n\nzs : Matrix 4 3 DDouble\nzs = reshape ys\n\nmain : PIO ()\nmain = do\n printLn' $ f 4\n printLn' xs\n printLn' ys\n printLn' zs\n -- printLn (ys `dot` zs) -- won't work!\n printLn' (xs `dot` zs)\n printLn' (xs `dot` transpose xs)\n printLn' (transpose xs `dot` xs)\n printLn' $ 2 * transpose (zs `dot` xs) + fromDouble 0.2\n", "meta": {"hexsha": "ae5c01a4048e4a74051626c6b52e1377063802be", "size": 626, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples/np.idr", "max_stars_repo_name": "ziman/idris-py", "max_stars_repo_head_hexsha": "934fddd877afa1c082445c8ee598cd760910709c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 140, "max_stars_repo_stars_event_min_datetime": "2015-04-27T09:16:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T08:39:36.000Z", "max_issues_repo_path": "examples/np.idr", "max_issues_repo_name": "ziman/idris-py", "max_issues_repo_head_hexsha": "934fddd877afa1c082445c8ee598cd760910709c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-01-01T20:02:32.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-03T21:19:36.000Z", "max_forks_repo_path": "examples/np.idr", "max_forks_repo_name": "ziman/idris-py", "max_forks_repo_head_hexsha": "934fddd877afa1c082445c8ee598cd760910709c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2015-05-01T10:59:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T00:55:53.000Z", "avg_line_length": 17.8857142857, "max_line_length": 57, "alphanum_fraction": 0.5958466454, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6489715202495117}} {"text": "module Sub02LTE72t45\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\n\n%default total\n\n\n-- 6(12t+7)+3 --E[2,-4]--> 6t+3\nexport\nlte72t45 : (l : Nat) -> LTE (S l)\n (S (((S (l+l))+(S (l+l))) + ((S (l+l))+(S (l+l))) + ((S (l+l))+(S (l+l)))))\nlte72t45 Z = (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc) LTEZero\nlte72t45 (S l) =\n let lemma = lte72t45 l in\n rewrite (sym (plusSuccRightSucc l l)) in\n\n rewrite (sym (plusSuccRightSucc (plus l l) (S (S (plus l l))))) in\n rewrite (sym (plusSuccRightSucc (plus l l) (S (plus l l)))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (S (plus l l))) \n (S (S (S (S (plus (plus l l) (S (plus l l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (S (plus l l))) \n (S (S (S (plus (plus l l) (S (plus l l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (S (plus l l))) \n (S (S (plus (plus l l) (S (plus l l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (S (plus l l))) \n (S (plus (plus l l) (S (plus l l)))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (S (plus l l))) (S (plus (plus l l) (S (plus l l)))))\n (S (S (S (S (plus (plus l l) (S (plus l l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (S (plus l l))) (S (plus (plus l l) (S (plus l l)))))\n (S (S (S (plus (plus l l) (S (plus l l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (S (plus l l))) (S (plus (plus l l) (S (plus l l)))))\n (S (S (plus (plus l l) (S (plus l l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (S (plus l l))) (S (plus (plus l l) (S (plus l l)))))\n (S (plus (plus l l) (S (plus l l)))))) in\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "89aa8258bd9076ad5fc9a226b58d2d23ac4bb843", "size": 2197, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program3/Sub02LTE72t45.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program3/Sub02LTE72t45.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program3/Sub02LTE72t45.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.3095238095, "max_line_length": 184, "alphanum_fraction": 0.5161583978, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6489347432590666}} {"text": "> module Exists.Operations\n\n\n> import Pairs.Operations\n\n\n> %default total\n\n> %access public export\n\n\n> |||\n> outl : {A : Type} -> {P : A -> Type} -> Exists {a = A} P -> A\n> outl = getWitness\n\n\n> |||\n> outr : {A : Type} -> {P : A -> Type} -> (s : Exists {a = A} P) -> P (outl s)\n> outr = getProof\n\n\n", "meta": {"hexsha": "79362810f80b5234c2bc296b43199c588aa773ea", "size": 298, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Exists/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": "Exists/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": "Exists/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": 13.5454545455, "max_line_length": 78, "alphanum_fraction": 0.5201342282, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199471193039, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6488064889250722}} {"text": "data 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 : Stream labelType -> Tree a ->\n (Stream labelType, Tree (labelType, a))\ntreeLabelWith labels Empty = (labels, Empty)\ntreeLabelWith labels (Node left val right) =\n let\n (labelThis :: labelsLeft, leftLabelled) = treeLabelWith labels left\n (labelsRight, rightLabelled) = treeLabelWith labelsLeft right\n in\n (labelsRight, Node leftLabelled (labelThis, val) rightLabelled)\n\ntreeLabel : Tree a -> Tree (Integer, a)\ntreeLabel tree = snd (treeLabelWith [1..] tree)\n", "meta": {"hexsha": "8066368129ba5e0c494cdfb2b5c33059dc4b5429", "size": 849, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/TreeLabel.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/TreeLabel.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/TreeLabel.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.96, "max_line_length": 75, "alphanum_fraction": 0.6725559482, "num_tokens": 231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6487793200533433}} {"text": "-- | ISO 8601 Ordinal Date format\nmodule Data.Time.Calendar.OrdinalDate\n\nimport Data.Time.Calendar.Days\nimport Data.Time.Calendar.Private\n\n||| Is this year a leap year according to the proleptic Gregorian calendar?\nexport\nisLeapYear : Integer -> Bool\nisLeapYear year = (mod year 4 == 0) && ((mod year 400 == 0) || not (mod year 100 == 0))\n\n-- | Convert to ISO 8601 Ordinal Date format. First element of result is year (proleptic Gregoran calendar),\n-- second is the day of the year, with 1 for Jan 1, and 365 (or 366 in leap years) for Dec 31.\nexport\ntoOrdinalDate : Day -> (Integer, Int)\ntoOrdinalDate (MkModifiedJulianDay mjd) =\n let\n a = mjd + 678575\n quadcent = div a 146097\n b = mod a 146097\n cent = min (div b 36524) 3\n c = b - (cent * 36524)\n quad = div c 1461\n d = mod c 1461\n y = min (div d 365) 3\n yd = fromInteger (d - (y * 365) + 1)\n year = quadcent * 400 + cent * 100 + quad * 4 + y + 1\n in\n (year, yd)\n\n-- | Convert from ISO 8601 Ordinal Date format.\n-- Invalid day numbers will be clipped to the correct range (1 to 365 or 366).\nexport\nfromOrdinalDate : Integer -> Int -> Day\nfromOrdinalDate year day =\n let\n y = year - 1\n clipped_day = (clip\n 1\n (if isLeapYear year\n then 366\n else 365)\n (cast day))\n a = (365 * y)\n b = (div y (the Integer 4))\n c = (div y (the Integer 100))\n d = (div y (the Integer 400))\n e = (the Integer 678576)\n mjd = (fromInteger clipped_day) + a + b - c + d - e\n in\n MkModifiedJulianDay mjd\n\n||| Convert from ISO 8601 Ordinal Date format.\n||| Invalid day numbers return 'Nothing'\nexport\nfromOrdinalDateValid: Integer -> Int -> Maybe Day\nfromOrdinalDateValid year day = do\n day' <-\n clipValid\n 1\n (if isLeapYear year\n then 366\n else 365)\n day\n let y = year - 1\n let mjd = (cast day') + (365 * y) + (div y 4) - (div y 100) + (div y 400) - 678576\n pure (MkModifiedJulianDay mjd)\n\n||| Show in ISO 8601 Ordinal Date format (yyyy-ddd)\nexport\nshowOrdinalDate : Day -> String\nshowOrdinalDate date =\n let (y, d) = toOrdinalDate date\n in\n (show y) ++ \"-\" ++ (show d)\n\n||| Get the number of the Monday-starting week in the year and the day of the week.\n||| The first Monday is the first day of week 1, any earlier days in the year are week 0 (as @%W@ in 'Data.Time.Format.formatTime').\n|||Monday is 1, Sunday is 7 (as @%u@ in 'Data.Time.Format.formatTime').\nexport\nmondayStartWeek : Day -> (Int, Int)\nmondayStartWeek date@(MkModifiedJulianDay dateint) =\n let\n yd = snd (toOrdinalDate date)\n d = dateint + 2\n k = d - (cast yd)\n in\n (fromInteger ((div d 7) - (div k 7)), fromInteger (mod d 7) + 1)\n\n||| Get the number of the Sunday-starting week in the year and the day of the week.\n||| The first Sunday is the first day of week 1, any earlier days in the year are week 0 (as @%U@ in 'Data.Time.Format.formatTime').\n||| Sunday is 0, Saturday is 6 (as @%w@ in 'Data.Time.Format.formatTime').\nexport\nsundayStartWeek : Day -> (Int, Int)\nsundayStartWeek date@(MkModifiedJulianDay dateint) =\n let\n yd = snd (toOrdinalDate date)\n d = dateint + 3\n k = d - (cast yd)\n in\n (fromInteger ((div d 7) - (div k 7)), fromInteger (mod d 7))\n\n\n||| The inverse of 'mondayStartWeek'. Get a 'Day' given the year,\n||| the number of the Monday-starting week, and the day of the week.\n||| The first Monday is the first day of week 1, any earlier days in the year\n||| are week 0 (as @%W@ in 'Data.Time.Format.formatTime').\nexport\nfromMondayStartWeek:\n Integer -- ^ Year.\n -> Int -- ^ Monday-starting week number (as @%W@ in 'Data.Time.Format.formatTime').\n -> Int -- ^ Day of week.\n-- Monday is 1, Sunday is 7 (as @%u@ in 'Data.Time.Format.formatTime').\n -> Day\nfromMondayStartWeek year w d = let\n -- first day of the year\n firstDay = fromOrdinalDate year 1\n -- 0-based year day of first monday of the year\n zbFirstMonday = (5 - toInteger firstDay) `mod` 7\n -- 0-based week of year\n zbWeek = w - 1\n -- 0-based day of week\n zbDay = d - 1\n -- 0-based day in year\n zbYearDay = zbFirstMonday + 7 * cast zbWeek + cast zbDay\n in\n addDays zbYearDay firstDay\n\nexport\nfromMondayStartWeekValid :\n Integer -- ^ Year.\n -> Int -- ^ Monday-starting week number (as @%W@ in 'Data.Time.Format.formatTime').\n -> Int -- ^ Day of week.\n -- Monday is 1, Sunday is 7 (as @%u@ in 'Data.Time.Format.formatTime').\n -> Maybe Day\nfromMondayStartWeekValid year w d = do\n d' <- clipValid 1 7 d\n -- first day of the year\n let firstDay = fromOrdinalDate year 1\n -- 0-based week of year\n let zbFirstMonday = (5 - toInteger firstDay) `mod` 7\n -- 0-based week number\n let zbWeek = w - 1\n -- 0-based day of week\n let zbDay = d' - 1\n -- 0-based day in year\n let zbYearDay = zbFirstMonday + 7 * cast zbWeek + cast zbDay\n zbYearDay' <-\n clipValid\n 0\n (if isLeapYear year\n then 365\n else 364)\n zbYearDay\n pure $ addDays zbYearDay' firstDay\n\n||| The inverse of 'sundayStartWeek'. Get a 'Day' given the year and\n||| the number of the day of a Sunday-starting week.\n||| The first Sunday is the first day of week 1, any earlier days in the\n||| year are week 0 (as @%U@ in 'Data.Time.Format.formatTime').\nexport\nfromSundayStartWeek:\n Integer -- ^ Year.\n -> Int -- ^ Sunday-starting week number (as @%U@ in 'Data.Time.Format.formatTime').\n -> Int -- ^ Day of week\n-- Sunday is 0, Saturday is 6 (as @%w@ in 'Data.Time.Format.formatTime').\n -> Day\nfromSundayStartWeek year w d = let\n -- first day of the year\n firstDay = fromOrdinalDate year 1\n -- 0-based year day of first monday of the year\n zbFirstSunday = (4 - toInteger firstDay) `mod` 7\n -- 0-based week of year\n zbWeek = w - 1\n -- 0-based day of week\n zbDay = d\n -- 0-based day in year\n zbYearDay = zbFirstSunday + 7 * cast zbWeek + cast zbDay\n in addDays zbYearDay firstDay\n\nexport\nfromSundayStartWeekValid:\n Integer -- ^ Year.\n -> Int -- ^ Sunday-starting week number (as @%U@ in 'Data.Time.Format.formatTime').\n -> Int -- ^ Day of week.\n-- Sunday is 0, Saturday is 6 (as @%w@ in 'Data.Time.Format.formatTime').\n -> Maybe Day\nfromSundayStartWeekValid year w d = do\n d' <- clipValid 0 6 d\n -- first day of the year\n let firstDay = fromOrdinalDate year 1\n -- 0-based week of year\n let zbFirstSunday = (4 - toInteger firstDay) `mod` 7\n -- 0-based week number\n let zbWeek = w - 1\n -- 0-based day of week\n let zbDay = d'\n -- 0-based day in year\n let zbYearDay = zbFirstSunday + 7 * cast zbWeek + cast zbDay\n zbYearDay' <-\n clipValid\n 0\n (if isLeapYear year\n then 365\n else 364)\n zbYearDay\n pure $ addDays zbYearDay' firstDay\n", "meta": {"hexsha": "55d080b91d8ca2933d346856334b7da795b276a7", "size": 6986, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Time/Calendar/OrdinalDate.idr", "max_stars_repo_name": "gdevanla/idris-time", "max_stars_repo_head_hexsha": "96a488057863d6c3049f62a1ac70734090e50b66", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-18T11:02:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-18T11:02:58.000Z", "max_issues_repo_path": "src/Data/Time/Calendar/OrdinalDate.idr", "max_issues_repo_name": "gdevanla/idris-time", "max_issues_repo_head_hexsha": "96a488057863d6c3049f62a1ac70734090e50b66", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-28T21:13:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T19:56:41.000Z", "max_forks_repo_path": "src/Data/Time/Calendar/OrdinalDate.idr", "max_forks_repo_name": "gdevanla/idris-time", "max_forks_repo_head_hexsha": "96a488057863d6c3049f62a1ac70734090e50b66", "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.5865384615, "max_line_length": 132, "alphanum_fraction": 0.6162324649, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856561, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6486062706762121}} {"text": "\ndata Natural : Type where\n S : Natural -> Natural\n Z : Natural\n\n%builtin Natural Natural\n\nplus : Natural -> Natural -> Natural\nplus Z y = y\nplus (S x) y = S (plus x y)\n\nmain : IO Natural\nmain = pure $ plus (S Z) (S $ S Z)\n", "meta": {"hexsha": "b581a49382aa70ba507bb776583792a136b5238f", "size": 229, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/codegen/builtin001/Main.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/codegen/builtin001/Main.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/codegen/builtin001/Main.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 16.3571428571, "max_line_length": 36, "alphanum_fraction": 0.6113537118, "num_tokens": 71, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045996818985, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6485985232003141}} {"text": "module Sub08LTE108t99\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\n\n%default total\n\n\n-- 6(18t+16)+3 --EF[2,1,-2]--> 6(8t+3)+3\nexport\nlte108t99 : (l : Nat) -> LTE (S (S (S (S ((l+l)+(l+l))))))\n (S ((S ((S (S (l+l+l)))+(S (S (l+l+l))))) + (S ((S (S (l+l+l)))+(S (S (l+l+l))))) + (S ((S (S (l+l+l)))+(S (S (l+l+l)))))))\nlte108t99 Z = (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc) LTEZero\nlte108t99 (S l) =\n let lemma = lte108t99 l in\n\n rewrite (sym (plusSuccRightSucc l l)) in\n\n rewrite (sym (plusSuccRightSucc (plus l l) l)) in\n\n rewrite (sym (plusSuccRightSucc (plus l l) (S (plus l l)))) in\n rewrite (sym (plusSuccRightSucc (plus l l) (plus l l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l)\n (S (S (S (S (plus (plus l l) l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l)\n (S (S (S (plus (plus l l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l)\n (S (S (plus (plus l l) l))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (S (S (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l)\n l)))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (S (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l)\n l))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l)\n l)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l)\n l))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l)\n l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l)\n l))))))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))))))\n (S (S (S (S (S (S (S (S (plus (plus (plus l l) l)\n (S (S (plus (plus l l) l)))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))))))\n (S (S (S (S (S (S (S (plus (plus (plus l l) l)\n (S (S (plus (plus l l) l))))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))))))\n (S (S (S (S (S (S (plus (plus (plus l l) l)\n (S (S (plus (plus l l) l)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))))))\n (S (S (S (S (S (plus (plus (plus l l) l)\n (S (S (plus (plus l l) l))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))))))\n (S (S (S (S (plus (plus (plus l l) l)\n (S (S (plus (plus l l) l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (S (S (plus (plus l l) l))))))))\n (S (S (S (plus (plus (plus l l) l)\n (S (S (plus (plus l l) l))))))))) in\n\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "632e98a0c67dfeec21a1bd2c9eb11c507465a30f", "size": 5042, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program3/Sub08LTE108t99.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program3/Sub08LTE108t99.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program3/Sub08LTE108t99.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.8227848101, "max_line_length": 259, "alphanum_fraction": 0.4353431178, "num_tokens": 1699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868805, "lm_q2_score": 0.7025300511670689, "lm_q1q2_score": 0.6484627498403576}} {"text": "data Tree a = Empty\n | Node (Tree a) a (Tree a)\n\ntestTree : Tree String\ntestTree = 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\ndata 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) ->\n State stateType b\n\n{-\n(>>=) : State stateType a -> (a -> State stateType b) ->\n State stateType b\n(>>=) = Bind\n-}\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 x = Pure x\n (<*>) f a = do func <- f\n arg <- a\n pure (func arg)\n\n Monad (State stateType) where\n (>>=) = Bind\n\nrunState : State stateType a -> (st : stateType) -> (a, stateType)\nrunState Get st = (st, st)\nrunState (Put newState) st = ((), newState)\n\nrunState (Pure x) st = (x, st)\nrunState (Bind cmd prog) st = let (val, nextState) = runState cmd st in\n runState (prog val) nextState\n\ntreeLabelWith : Tree a -> State (Stream labelType) (Tree (labelType, a))\ntreeLabelWith Empty = Pure Empty\ntreeLabelWith (Node left val right)\n = do left_labelled <- treeLabelWith left\n (this :: rest) <- Get\n Put rest\n right_labelled <- treeLabelWith right\n Pure (Node left_labelled (this, val) right_labelled)\n\ntreeLabel : Tree a -> Tree (Integer, a)\ntreeLabel tree = fst (runState (treeLabelWith tree) [1..])\n\n", "meta": {"hexsha": "3217b8c1618d765d43736a176546862b889c0e68", "size": 1821, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter12/TreeLabelType.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/typedd-book/chapter12/TreeLabelType.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/typedd-book/chapter12/TreeLabelType.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": 29.8524590164, "max_line_length": 72, "alphanum_fraction": 0.580450302, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6480384484815506}} {"text": "module HetVect\n\n%default total\n%access public export\n\ninfixr 7 ::\n\n||| Heterogeneous list\ndata Vect : List Type -> Type where\n Nil : Vect []\n (::) : t -> Vect ts -> Vect (t::ts)\n\n-- Name hints for interactive editing\n%name Vect vs, ws, xs, ys, zs\n\ncurried : (ts : List Type) -> (result : Type) -> Type\ncurried [] result = result\ncurried (t :: ts) result = t -> curried ts result\n\ncurryV : (f : Vect ts -> result) -> curried ts result\ncurryV f {ts = []} = f []\ncurryV f {ts = (t :: ts)} = \\x => curryV (f . (x::))\n\nuncurryV : (f : curried ts result) -> Vect ts -> result\nuncurryV f [] = f\nuncurryV f (x :: xs) = uncurryV (f x) xs\n\ninfixr 7 ++\n\n(++) : Vect xs -> Vect ys -> Vect (xs++ys)\n[] ++ ws = ws\n(v::vs) ++ ws = v :: vs ++ ws\n\nusing (x:a, y:a, xs:List a)\n data Elem : a -> List a -> Type where\n Here : Elem x (x :: xs)\n There : Elem x xs -> Elem x (y :: xs)\n\n||| Nothing can be in an empty Vect\nnoEmptyElem : {x : a} -> Elem x [] -> Void\nnoEmptyElem Here impossible\n\ndata Subset : List a -> List a -> Type where\n EmptySet : Subset [] ys\n WithElem : (later : Subset xs ys) -> (elem : Elem x ys) -> Subset (x::xs) ys\n\nsplit : {xs, ys : List Type} -> Vect (xs++ys) -> (Vect xs, Vect ys)\nsplit {xs = []} vs = ([], vs)\nsplit {xs = (x :: xs)} (y :: ys)\n = let (lhs,rhs) = split ys\n in (y :: lhs, rhs)\n\nuncurryLong\n : {xs, ys : List Type}\n -> (Vect xs -> Vect ys -> a)\n -> Vect (xs++ys)\n -> a\nuncurryLong f = uncurry f . split\n\nlengthen\n : {xs, ys : List Type}\n -> (Vect ys -> a)\n -> Vect (xs++ys)\n -> a\nlengthen {xs=_::xs} f (_::vs) = lengthen {xs} f vs\nlengthen {xs=[]} f vs = f vs\n\n\nremove : (x : a) -> (xs : List a) -> (prf : Elem x xs) -> List a\nremove x (x :: ys) Here = ys\nremove x (y :: ys) (There z) = y :: remove x ys z\n\naddBack : {xs : List Type} -> {x : Type} -> {auto prf : Elem x xs } -> (val : x) -> (vec : Vect (remove x xs prf)) -> Vect xs\naddBack {prf = Here} val vec = val :: vec\naddBack {prf = (There x)} val (v::vs) = v :: addBack val vs\n", "meta": {"hexsha": "1aeabf7b5a557b856cbad99dee8f3cd06a4e7d92", "size": 1984, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "HetVect.idr", "max_stars_repo_name": "oisdk/belief-propagation-idris", "max_stars_repo_head_hexsha": "f8d958384d19ef550bd26464287f4d0da7951114", "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": "HetVect.idr", "max_issues_repo_name": "oisdk/belief-propagation-idris", "max_issues_repo_head_hexsha": "f8d958384d19ef550bd26464287f4d0da7951114", "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": "HetVect.idr", "max_forks_repo_name": "oisdk/belief-propagation-idris", "max_forks_repo_head_hexsha": "f8d958384d19ef550bd26464287f4d0da7951114", "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.1052631579, "max_line_length": 125, "alphanum_fraction": 0.548891129, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6480384399038214}} {"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(Integral ty, Neg ty, Eq ty ) => Eq (Expr ty) where\n (==) x y = eval x == eval y\n\nShow ty => Show (Expr ty) where\n show (Val x) = show x\n show (Add x y) = \"(\" ++ show x ++ \" + \" ++ show y ++ \")\"\n show (Sub x y) = \"(\" ++ show x ++ \" - \" ++ show y ++ \")\"\n show (Mul x y) = \"(\" ++ show x ++ \" * \" ++ show y ++ \")\"\n show (Div x y) = \"(\" ++ show x ++ \" / \" ++ show y ++ \")\"\n show (Abs x) = \"|\" ++ show x ++ \"|\"\n\n--https://github.com/idris-lang/Idris-dev/issues/3479\nCast ty ty where\n cast = id \n\n(Integral ty, Neg ty, Cast ty num) => Cast (Expr ty) num where\n cast expr = cast (eval expr)\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", "meta": {"hexsha": "c8b6f9cbb58be9ea7d6a7a6dbf49157318dc3fa8", "size": 1514, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "expr2.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": "expr2.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": "expr2.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": 29.6862745098, "max_line_length": 62, "alphanum_fraction": 0.5198150594, "num_tokens": 517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913356558485, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6478875619664846}} {"text": "import Interfaces\n\n-- State Definition\n\ndata State : Type -> Type -> Type where\n stateFunc : (s -> (a, s)) -> State s a\n\ngetStateFunc : (state : State s a) -> (s -> (a, s))\ngetStateFunc (stateFunc f) = f\n\n\n-- Define state equality\n\n\ndata StateEq : state1 -> state2 -> Type where\n stateEq : {u : State s a} -> {v : State s a} -> (getStateFunc u `FuncEqType` getStateFunc v) -> StateEq u v\n\nstateEqTransitiveLemma : {f : a -> b} -> {g : a -> b} -> {h : a -> b} -> FuncEqType f g -> FuncEqType g h -> (x : a) -> f x = h x\nstateEqTransitiveLemma (funcEqType f g f_eq_g) (funcEqType g h g_eq_h) x = rewrite f_eq_g x in g_eq_h x\n\nstateEqTransitive : {f : State s a} -> {g : State s a} -> {h : State s a} -> StateEq f g -> StateEq g h -> StateEq f h\nstateEqTransitive (stateEq x) (stateEq y) = stateEq (funcEqType (getStateFunc f) (getStateFunc h) (stateEqTransitiveLemma x y))\n\nstateEqReflexive : {f : State s a} -> StateEq f f\nstateEqReflexive = stateEq (funcEqType (getStateFunc f) (getStateFunc f) (\\x => Refl))\n\nstateEqSymmetryLemma : {f : a -> b} -> {g : a -> b} -> FuncEqType f g -> (x : a) -> g x = f x\nstateEqSymmetryLemma (funcEqType f g f_eq_g) x = sym (f_eq_g x)\n\nstateEqSymmetry : {f : State s a} -> {g : State s a} -> StateEq f g -> StateEq g f\nstateEqSymmetry (stateEq x) = stateEq (funcEqType (getStateFunc g) (getStateFunc f) (stateEqSymmetryLemma x))\n\n\n-- map for State\n\nmapFirst : (f : a -> c) -> (a, b) -> (c, b)\nmapFirst f (x, y) = (f x, y)\n\nmapState : (f : a -> b) -> (state : State s a) -> State s b\nmapState f (stateFunc g) = stateFunc (mapFirst f . g)\n\n\n-- Verify that State is Functor\n\n\nmapFirstIdLemma : (x : (a, b)) -> mapFirst Prelude.id x = x\nmapFirstIdLemma (p, q) = Refl\n\nstateFunctorLawIdentityLemma : (state : State s a) -> (x : s) -> getStateFunc (mapState Prelude.id state) x = getStateFunc state x\nstateFunctorLawIdentityLemma (stateFunc f) x = mapFirstIdLemma (f x)\n\nstateFunctorLawIdentity : (state : State s a) -> mapState Prelude.id state `StateEq` state\nstateFunctorLawIdentity state = stateEq $ funcEqType (getStateFunc $ mapState Prelude.id state) (getStateFunc state) (stateFunctorLawIdentityLemma state)\n\nmapFirstCompositionLemma : (g : b -> c) -> (h : a -> b) -> (x : (a, s)) -> mapFirst (g . h) x = mapFirst g (mapFirst h x)\nmapFirstCompositionLemma g h (p, q) = Refl\n\nstateFunctorLawCompositionLemma : (state : State s a) -> (g : (b -> c)) -> (h : (a -> b)) -> (x : s) -> getStateFunc (mapState (g . h) state) x = getStateFunc (mapState g (mapState h state)) x\nstateFunctorLawCompositionLemma (stateFunc f) g h x = rewrite mapFirstCompositionLemma g h (f x)in Refl\n\nstateFunctorLawComposition : (g : (b -> c)) -> (h : (a -> b)) -> (state : State s a) -> mapState (g . h) state `StateEq` mapState g (mapState h state)\nstateFunctorLawComposition g h state = stateEq $ funcEqType (getStateFunc $ mapState (g . h) state) (getStateFunc $ mapState g $ mapState h state) (stateFunctorLawCompositionLemma state g h)\n\nMyFunctor (State s) where\n equalsTo = StateEq\n eqReflexive = stateEqReflexive\n eqSymmetry = stateEqSymmetry\n eqTransitive = stateEqTransitive\n myMap = mapState\n functorLawIdentity = stateFunctorLawIdentity\n functorLawComposition = stateFunctorLawComposition\n\n\n-- Applicative functions\n\n\npureState : (s : Type) -> (x : a) -> State s a\npureState s x = stateFunc (\\state => (x, state))\n\ninfixl 3 <<**>>\n\n(<<**>>) : State s (a -> b) -> State s a -> State s b\n(<<**>>) (stateFunc ff) (stateFunc gg) = stateFunc newStateFunc\nwhere\n newStateFunc : (ss : s) -> (b, s)\n newStateFunc ss = mapFirst (fst $ ff ss) (gg $ snd (ff ss))\n\n\n-- Applicative laws\n\n\nstateApplicativeLawIdentityLemma : (u : State s a) -> (x : s) -> getStateFunc (stateFunc (\\s => (Prelude.id, s)) <<**>> u) x = getStateFunc u x\nstateApplicativeLawIdentityLemma (stateFunc f) x = mapFirstIdLemma (f x)\n\nstateApplicativeLawIdentity : (s : Type) -> (u : State s a) -> (pureState s Prelude.id <<**>> u) `StateEq` u\nstateApplicativeLawIdentity s u = stateEq $ funcEqType (getStateFunc $ pureState s Prelude.id <<**>> u) (getStateFunc u) (stateApplicativeLawIdentityLemma u)\n\n\nstateApplicativeLawHomomorphism : (s : Type) -> (x : a) -> (func : a -> b) ->\n (pureState s func <<**>> pureState s x) `StateEq` (pureState s (func x))\nstateApplicativeLawHomomorphism s x func = stateEq $ funcEqType (getStateFunc $ pureState s func <<**>> pureState s x)\n (getStateFunc $ pureState s (func x))\n (\\z => Refl)\n\nmapFirstAppLemma : (f : (a -> b, s)) -> (x : a) -> (fst f x, snd f) = mapFirst ($ x) f\nmapFirstAppLemma (func, state) x = Refl\n\nstateApplicativeLawInterchangeLemma : (f : (s -> (a -> b, s))) -> (x : a) -> (state : s) -> (fst (f state) x, snd (f state)) = mapFirst ($ x) (f state)\nstateApplicativeLawInterchangeLemma f x state = rewrite mapFirstAppLemma (f state) x in Refl\n\nstateApplicativeLawInterchange : (s : Type) -> (u : State s (a -> b)) -> (x : a) ->\n (u <<**>> pureState s x) `StateEq` (pureState s ($ x) <<**>> u)\nstateApplicativeLawInterchange s (stateFunc f) x = stateEq $ funcEqType (getStateFunc $ (stateFunc f) <<**>> pureState s x)\n (getStateFunc $ pureState s ($ x) <<**>> (stateFunc f))\n (stateApplicativeLawInterchangeLemma f x)\n\ncomposeStateFunc : (u : State s (b -> c)) -> (v : State s (a -> b)) -> State s (a -> c)\ncomposeStateFunc (stateFunc f) (stateFunc g) = stateFunc h\n where\n h : s -> ((a -> c), s)\n h s = let p = (f s)\n q = g (snd p)\n in (fst p . fst q, snd q)\n\n-- proof of Applicative is incomplete\n(s : Type) => MyApplicative (State s) where\n myPure = pureState s\n (<<*>>) = (<<**>>)\n\n applicativeLawIdentity = stateApplicativeLawIdentity s\n applicativeLawHomomorphism = stateApplicativeLawHomomorphism s\n applicativeLawInterchange = stateApplicativeLawInterchange s\n applicativeLawComposition = ?stateApplicativeLawComposition\n\n\n-- Monad\n\ninfixl 1 >>>==\n\n(>>>==) : (n : State s a) -> (f : a -> State s b) -> State s b\n(>>>==) (stateFunc g) f = stateFunc (\\state => let x = g state in getStateFunc (f $ fst x) (snd x))\n\nstateReturn : (x : a) -> State s a\nstateReturn x = stateFunc (\\state => (x, state))\n\nstateMonadLawIdentityLeft : (x : a) -> (f : a -> State s b) -> (stateReturn x >>>== f) `equalsTo` (f x)\nstateMonadLawIdentityLeft x f = stateEq $ funcEqType (getStateFunc $ stateReturn x >>>== f) (getStateFunc (f x)) (\\z => Refl)\n\nstateMonadLawIdentityRightLemma2 : (z : (a, s)) -> (fst z, snd z) = z\nstateMonadLawIdentityRightLemma2 (x, y) = Refl\n\nstateMonadLawIdentityRightLemma : (f : (s -> (a, s))) -> (x : s) -> (fst (f x), snd (f x)) = f x\nstateMonadLawIdentityRightLemma f x = stateMonadLawIdentityRightLemma2 (f x)\n\nstateMonadLawIdentityRight : (n : State s a) -> (n >>>== (\\x => stateFunc \\state => (x, state))) `equalsTo` n\nstateMonadLawIdentityRight (stateFunc f) = stateEq $ funcEqType (\\state => (fst (f state), snd (f state)))\n f\n (stateMonadLawIdentityRightLemma f)\n\nstateMonadLawCompositionLemma3 : (z : State s b) -> (y : s) -> (g : (b -> State s c)) -> getStateFunc (g (fst (getStateFunc z y))) (snd (getStateFunc z y)) = getStateFunc (z >>>== g) y\nstateMonadLawCompositionLemma3 (stateFunc f) y g = Refl\n\nstateMonadLawCompositionLemma2 : (result : (a, s)) -> (g : (b -> State s c)) -> (f : (a -> State s b)) -> getStateFunc (g (fst (getStateFunc (f (fst result)) (snd result)))) (snd (getStateFunc (f (fst result)) (snd result))) = getStateFunc (f (fst result) >>>== g) (snd result)\nstateMonadLawCompositionLemma2 (x, y) g f = stateMonadLawCompositionLemma3 (f x) y g\n\nstateMonadLawCompositionLemma : (e : (s -> (a, s))) -> (g : (b -> State s c)) -> (f : (a -> State s b)) -> (x : s) -> getStateFunc (g (fst (getStateFunc (f (fst (e x))) (snd (e x))))) (snd (getStateFunc (f (fst (e x))) (snd (e x)))) = getStateFunc (f (fst (e x)) >>>== g) (snd (e x))\nstateMonadLawCompositionLemma e g f x = stateMonadLawCompositionLemma2 (e x) g f\n\nstateMonadLawComposition : (n : State s a) -> (f : a -> State s b) -> (g : b -> State s c) ->\n ((n >>>== f) >>>== g) `equalsTo` (n >>>== \\x => f x >>>== g)\nstateMonadLawComposition (stateFunc e) f g = stateEq $ funcEqType (getStateFunc $ (stateFunc e >>>== f) >>>== g)\n (getStateFunc $ stateFunc e >>>== \\x => f x >>>== g)\n (stateMonadLawCompositionLemma e g f)\n\n(s : Type) => MyMonad (State s) where\n myReturn = stateReturn\n (>>>=) = (>>>==)\n monadLawIdentityLeft = stateMonadLawIdentityLeft\n monadLawIdentityRight = stateMonadLawIdentityRight\n monadLawComposition = stateMonadLawComposition\n", "meta": {"hexsha": "acd2613845bc46d731ccefe785fc07a7801ed0a3", "size": 9049, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "MyState.idr", "max_stars_repo_name": "yutaro-sakamoto/prove-monad", "max_stars_repo_head_hexsha": "ea2649ce7b6a6ea8f2ebd2f485127c4e3015d63d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-24T19:45:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T07:44:49.000Z", "max_issues_repo_path": "MyState.idr", "max_issues_repo_name": "yutaro-sakamoto/prove-monad", "max_issues_repo_head_hexsha": "ea2649ce7b6a6ea8f2ebd2f485127c4e3015d63d", "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": "MyState.idr", "max_forks_repo_name": "yutaro-sakamoto/prove-monad", "max_forks_repo_head_hexsha": "ea2649ce7b6a6ea8f2ebd2f485127c4e3015d63d", "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": 49.9944751381, "max_line_length": 283, "alphanum_fraction": 0.6061443253, "num_tokens": 2780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6478875561313676}} {"text": "\nmodule PCF\n\n-- Re-export modules that define expressions and\n-- evaluation in the simply-typed lambda calculus.\n--\n-- Also introduce simplified syntax for lambda calculus\n-- expressions and utility functions for converting\n-- between Idris' built-in natural numbers and natural\n-- numbers in the lambda calculus.\n\n\nimport public BigStep\nimport public Determinism\nimport public Equivalence\nimport public Eval\nimport public Term\nimport public Step\n\n\n%access export\n\n\n------------------------------------------------------------------\n-- Begin: SIMPLIFIED SYNTAX FOR EXPRESSIONS IN THE LAMBDA CALCULUS\n\n-- Simplified syntax for abstraction (viz. \"Lambda\"):\nL : Term (s::ctx) t -> Term ctx (s :->: t)\nL = TAbs\n\n\n-- Simplified syntac for application:\ninfixl 10 @.\n(@.) : Term ctx (s :->: t) -> Term ctx s -> Term ctx t\n(@.) = TApp\n\n\n-- More natural syntax for 'Ifz':\nsyntax \"ifz\" [e1] \"then\" [e2] \"else\" [e3] = TIfz e1 e2 e3;\n\n\n-- Constants for the variables with the lowest\n-- the de-Bruijn indices (i.e. indices 0--2):\nv0 : {ctx : Context (S n)} ->\n {auto p : index 0 ctx = t} -> Term ctx t\nv0 = TVar 0\n\nv1 : {ctx : Context (S (S n))} ->\n {auto p : index 1 ctx = t} -> Term ctx t\nv1 = TVar 1\n\nv2 : {ctx : Context (S (S (S n)))} ->\n {auto p : index 2 ctx = t} -> Term ctx t\nv2 = TVar 2\n\nv3 : {ctx : Context (S (S (S (S n))))} ->\n {auto p : index 3 ctx = t} -> Term ctx t\nv3 = TVar 3\n\n-- End: SIMPLIFIED SYNTAX FOR EXPRESSIONS IN THE LAMBDA CALCULUS\n----------------------------------------------------------------\n\n\n\n---------------------------------\n-- Begin: EXAMPLES OF EXPRESSIONS \n \nadd : Term ctx (TyNat :->: TyNat :->: TyNat)\nadd = (L (L (TRec v0 \n v1\n (TSucc v0) )))\n\nmul : Term ctx (TyNat :->: TyNat :->: TyNat)\nmul = (L (L (TRec v0\n TZero\n (add @.v0 @.v3 ) )))\n\n\nfact : Term ctx (TyNat :->: TyNat)\nfact = (L (TRec v0\n (TSucc TZero)\n (mul @.v0 @.(TSucc v1)) ))\n \nid : Term ctx (t :->: t)\nid = L v0\n \nfirst : Term ctx (t :->: t :->: t)\nfirst = L (L v1)\n \nsecond : Term ctx (t :->: t :->: t)\nsecond = L (L v0)\n\ntwo : Term ctx TyNat\ntwo = TSucc $ TSucc TZero\n\ndouble : Term ctx (TyNat :->: TyNat)\ndouble = mul @.two\n\n-- End: EXAMPLES OF EXPRESSIONS \n-------------------------------\n\n\n\n----------------------------------------\n-- Begin: CONVERSIONS FOR NATURAL NUMBER\n\nnatToTerm : Nat -> Term ctx TyNat\nnatToTerm Z = TZero\nnatToTerm (S n) = TSucc (natToTerm n)\n\n \ntermToNat : Term ctx TyNat -> Nat\ntermToNat TZero = Z\ntermToNat (TSucc n) = S (termToNat n)\n\n-- End: CONVERSIONS FOR NATURAL NUMBER\n--------------------------------------\n\n\n", "meta": {"hexsha": "486340a0b29cc10112d69d51f9da71f8f7437573", "size": 2696, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "total/src/PCF.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": "total/src/PCF.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": "total/src/PCF.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": 22.4666666667, "max_line_length": 66, "alphanum_fraction": 0.5318991098, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6477431008206057}} {"text": "import Providers\nimport Data.HVect\nimport Data.Fin\n\n%default total\n%language TypeProviders\n\n-- Playing with reasoning about black boxes here. The goal is not to\n-- reconstruct their algorithms (which won't be possible in many\n-- cases), but to experiment, make statements about their behaviour,\n-- confirm or refute those, and reason using those statements as\n-- premises.\n\n-- Confirmations are commented out, because they take a bit too much\n-- time and memory to typecheck, but they are fine\n\n-- Not using Dec here, mostly because of laziness, but in some cases\n-- it might be much more convenient. Also would be nice to add type\n-- aliases for common things.\n\n\npostulate blackbox : (Bool, Nat, Nat) -> Nat\n\n-- there should be a nicer way to do this, without an additonal type\ndata MTL : Nat -> Type where\n Nil : MTL Z\n (::) : {ib:Bool} -> {in1, in2, out: Nat} -> (t:Type) ->\n {auto eq: t = (blackbox (ib, in1, in2) = out)} -> {n: Nat} -> MTL n -> MTL (S n)\n\n(++) : MTL m -> MTL n -> MTL (m + n)\n(++) [] ys = ys\n(++) ((::) x {eq} xs) ys = (::) x {eq} $ xs ++ ys\n\nindex : Fin n -> MTL n -> Type\nindex FZ (x::xs) = x\nindex (FS k) (x::xs) = index k xs\nindex FZ [] impossible\n\n-- simply turns (f: bb -> Type) into ((x:bb) -> f x)\nh : ({ib: Bool} -> {in1, in2, o: Nat} -> blackbox (ib, in1, in2) = o -> Type) -> Type\nh f = {ib: Bool} -> {in1, in2, o: Nat} -> (x:(blackbox (ib, in1, in2) = o)) -> f x\n\n-- applies a model to an observation\nmt : {ib:Bool} -> {in1, in2, out: Nat} ->\n ({ib: Bool} -> {in1, in2, o: Nat} -> (blackbox (ib, in1, in2) = o) -> Type) ->\n (t:Type) -> {auto eq: t = (blackbox (ib, in1, in2) = out)} -> Type\nmt {ib} {in1} {in2} {out} f t = (x:(blackbox (ib, in1, in2) = out)) -> f x\n\n-- same, but for a bunch of observations\nconfirm : ({ib: Bool} -> {in1, in2, o: Nat} -> (blackbox (ib, in1, in2) = o) -> Type) -> MTL n -> Vect n Type\nconfirm f [] = []\nconfirm f ((::) x xs {eq}) = mt f x {eq} :: confirm f xs\n\n\n\n-- only one kind of experiment here, in two versions: for single and\n-- multiple tests\nexperiment : (Bool, Nat, Nat) -> IO (Provider Type)\nexperiment inp@(o, a1, a2) = do\n out <- return $ if o then a1 + a2 else (if lte a2 a1 then a1 - a2 else a1 * a2)\n return (Provide (blackbox inp = out))\n\nexperiment' : Vect n (Bool, Nat, Nat) -> IO (MTL n)\nexperiment' [] = return []\nexperiment' (inp@(o, a1, a2)::xs) = do\n out <- return $ if o then a1 + a2 else (if lte a2 a1 then a1 - a2 else a1 * a2)\n next <- experiment' xs\n return $ (blackbox inp = out) :: next\n\nexperimentV : Vect n (Bool, Nat, Nat) -> IO (Provider (MTL n))\nexperimentV v = do\n types <- experiment' v\n return (Provide types)\n\n\n-- beginning to poke the box\n%provide (initialTests : MTL 8) with (experimentV [\n (True, 0, 0), -- 0\n (True, 0, 1), -- 1\n (True, 1, 0), -- 1\n (True, 1, 1), -- 2\n (False, 0, 0), -- 0\n (False, 0, 1), -- 0\n (False, 1, 0), -- 1\n (False, 1, 1) -- 0\n ])\n\n-- the first guess\ntPlusFMinus : {ib: Bool} -> {in1, in2, o: Nat} -> (blackbox (ib, in1, in2) = o) -> Type\ntPlusFMinus {ib} {in1} {in2} {o} ob = if ib then o = in1 + in2 else o = in1 - in2\n\n-- confirmTPlusFMinus : HVect (confirm tPlusFMinus initialTests)\n-- confirmTPlusFMinus = [\\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl]\n\n%provide (furtherTests : MTL 4) with (experimentV [\n (True, 42, 23), -- 65\n (True, 23, 42), -- 65\n (False, 42, 23), -- 19\n (False, 23, 42) -- 966\n ])\n\n-- confirmTPlusFMinus2 : HVect (confirm tPlusFMinus furtherTests)\n-- confirmTPlusFMinus2 = ?mv -- uh oh, 966 = 0!\n\nrefuteTPlusFMinus2 : index 3 furtherTests -> HVect (confirm tPlusFMinus furtherTests) -> Void\nrefuteTPlusFMinus2 f [_,_,_,d] = uninhabited (sym (d f))\n\n-- is it multiplication? why it happened?\n\n%provide (moreTests : MTL 4) with (experimentV [\n (False, 3, 5), -- 15\n (False, 5, 3), -- 2\n (False, 7, 13), -- 91\n (False, 13, 7) -- 6\n ])\n \n-- ok, it happens when the first Nat is lower\n\ntPlusFMinusMult : {ib: Bool} -> {in1, in2, o: Nat} -> (blackbox (ib, in1, in2) = o) -> Type\ntPlusFMinusMult {ib} {in1} {in2} {o} ob =\n o = if ib then in1 + in2 else (if lte in2 in1 then in1 - in2 else in1 * in2)\n\n-- confirmTPlusFMinusMult : HVect (confirm tPlusFMinusMult $ initialTests ++ furtherTests ++ moreTests)\n-- confirmTPlusFMinusMult = confirmTPlusFMinus ++ [\\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl, \\x => Refl]\n\n-- now we could reason using this model\n\ntCommutative : {in1, in2, o1, o2: Nat} ->\n -- for any two black box runs with their Nat arguments swapped, and Bool arg = True…\n (blackbox (True, in1, in2) = o1) -> (blackbox (True, in2, in1) = o2) ->\n -- according to tPlusFMinusMult…\n (h tPlusFMinusMult) ->\n -- outputs are equal\n o1 = o2\ntCommutative {in1} {in2} {o1} {o2} b1 b2 f with (f b1, f b2)\n | (r1, r2) = rewrite r1 in rewrite r2 in plusCommutative in1 in2\n\n", "meta": {"hexsha": "86e5546782d9e65e959410ba0f7395923b7130f3", "size": 5081, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Simple.idr", "max_stars_repo_name": "defanor/black-box-reasoning", "max_stars_repo_head_hexsha": "48bd9f2a383fb0fcf5fbe5f9e866137c35cd54e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-10T20:58:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-10T20:58:10.000Z", "max_issues_repo_path": "Simple.idr", "max_issues_repo_name": "defanor/black-box-reasoning", "max_issues_repo_head_hexsha": "48bd9f2a383fb0fcf5fbe5f9e866137c35cd54e2", "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": "defanor/black-box-reasoning", "max_forks_repo_head_hexsha": "48bd9f2a383fb0fcf5fbe5f9e866137c35cd54e2", "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.8188405797, "max_line_length": 146, "alphanum_fraction": 0.5802007479, "num_tokens": 1843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6477430901134632}} {"text": "> module Isomorphism.Operations\n\n> import Data.Fin\n> import Control.Isomorphism\n\n\n> %default total\n\n> %access public export\n\n\n> to : {A, B : Type} -> Iso A B -> (A -> B)\n> to (MkIso to from toFrom fromTo) = to\n\n\n> from : {A, B : Type} -> Iso A B -> (B -> A)\n> from (MkIso to from toFrom fromTo) = from\n\n\n> toFrom : {A, B : Type} -> (iso : Iso A B) -> (b : B) -> Isomorphism.Operations.to iso (Isomorphism.Operations.from iso b) = b\n> toFrom (MkIso to from toFrom fromTo) = toFrom\n\n\n> fromTo : {A, B : Type} -> (iso : Iso A B) -> (a : A) -> Isomorphism.Operations.from iso (Isomorphism.Operations.to iso a) = a\n> fromTo (MkIso to from toFrom fromTo) = fromTo\n", "meta": {"hexsha": "6989c56c9fc264628220f0f12e0a8747bd3efcb1", "size": 658, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Isomorphism/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": "Isomorphism/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": "Isomorphism/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": 25.3076923077, "max_line_length": 127, "alphanum_fraction": 0.623100304, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6475419867347645}} {"text": "import Data.List.Views\nimport Data.Vect\nimport Data.Vect.Views\nimport Data.Nat.Views\n\ntotal equalSuffixHelper: Eq a => List a -> List a -> List a\nequalSuffixHelper input1 input2 with (snocList input1)\n equalSuffixHelper [] input2 | Empty = []\n equalSuffixHelper (xs ++ [x]) input2 | (Snoc xs_rec) with (snocList input2)\n equalSuffixHelper (xs ++ [x]) [] | (Snoc xs_rec) | Empty = []\n equalSuffixHelper (xs ++ [x]) (ys ++ [y]) | (Snoc xs_rec) | (Snoc ys_rec) =\n if x == y\n then x :: (equalSuffixHelper xs ys | xs_rec | ys_rec)\n else []\n\ntotal equalSuffix: Eq a => List a -> List a -> List a\nequalSuffix xs ys = reverse (equalSuffixHelper xs ys)\n\ntotal mergeSort: Ord a => Vect n a -> Vect n a\nmergeSort input with (splitRec input)\n mergeSort [] | SplitRecNil = []\n mergeSort [x] | SplitRecOne = [x]\n mergeSort (lefts ++ rights) | (SplitRecPair lrec rrec) =\n merge (mergeSort lefts | lrec)\n (mergeSort rights | rrec)\n\ntotal toBinary: Nat -> String\ntoBinary input with (halfRec input)\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\ntotal palindrome: Eq a => List a -> Bool\npalindrome input with (vList input)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (first :: (mid ++ [last])) | (VCons rec) =\n if first == last\n then palindrome mid | rec\n else False\n\nlist : List Int\nlist = [1..5]\n\ntest1 : List Int\ntest1 = [1,2,4,5]\n\nvect1 : Vect 10 Integer\nvect1 = [1,2,3,4,5,6,7,8,9,0]\n", "meta": {"hexsha": "aeca2b438485cd07b9543f766fb4511883244e68", "size": 1619, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Exercise_10_2.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": "Exercise_10_2.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": "Exercise_10_2.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": 32.38, "max_line_length": 79, "alphanum_fraction": 0.6182828907, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.754914975839675, "lm_q1q2_score": 0.647541982764993}} {"text": "-- module Main\n\ndata N = Zero | Suc N\n\n-- data Q : N -> N -> Type where\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\ntest : (n : N) -> Type\ntest Zero = N\ntest (Suc n) = N -> N\n\nfoo : (n : N) -> test n\nfoo Zero = Three\nfoo (Suc n) = add n\n\nhej : Char\nhej = 'h'\n\nbar : {n : N} -> test n\nbar = ?haj\n", "meta": {"hexsha": "3f4836663502dcdf497c18df26435451e330ffd3", "size": 529, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "patrik.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": "patrik.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": "patrik.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": 13.225, "max_line_length": 32, "alphanum_fraction": 0.550094518, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6472086987988048}} {"text": "data ListLast : List a -> Type where\n Empty : ListLast []\n NonEmpty : (xs : List a) -> (x : a) -> ListLast (xs ++ [x])\n\nlistLast : (xs : List a) -> ListLast xs\nlistLast [] = Empty\nlistLast (x :: xs) = case listLast xs of\n Empty => NonEmpty [] x\n NonEmpty xs y => NonEmpty (x :: xs) y\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", "meta": {"hexsha": "efdb72ab1055d6f75e9f4b0a602fd869af073aaa", "size": 628, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter10/DescribeList.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": "Chapter10/DescribeList.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": "Chapter10/DescribeList.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": 34.8888888889, "max_line_length": 64, "alphanum_fraction": 0.5812101911, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6471516675820689}} {"text": "module Conat\n\n%default total\n\nnamespace R\n\n record Conat where\n constructor C\n pred : Maybe $ Inf Conat\n\n Z : Conat\n Z = C {pred = Nothing}\n\n S : Conat -> Conat\n S n = C {pred = Just n}\n\n -- Infinity value\n I : Conat\n I = C {pred = Just I}\n\n coind : (p : Conat -> Type) -> p Z -> ({n : Conat} -> p (S n) -> p n) -> (n : Conat) -> Inf (p n)\n coind p base _ (C Nothing) = base\n coind p base prev n@(C $ Just _) = prev {n} $ coind p base prev $ S n\n\nnamespace D\n\n %hide Prelude.Z\n %hide Prelude.S\n\n %hide Conat.R.Conat\n %hide Conat.R.Z\n %hide Conat.R.S\n\n data Conat : Type where\n Z : Conat\n S : Inf Conat -> Conat\n\n I : Conat\n I = S I\n\n coind : (p : Conat -> Type) -> p Z -> ({n : Conat} -> p (S n) -> p n) -> (n : Conat) -> Inf (p n)\n coind p base _ Z = base\n coind p base prev n@(S _) = prev {n} $ coind p base prev $ S n\n", "meta": {"hexsha": "2daa5794bc8f0d556189fb35eab587dfadcc06f2", "size": 870, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Conat.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": "Conat.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": "Conat.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": 19.7727272727, "max_line_length": 99, "alphanum_fraction": 0.5344827586, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6469695623389246}} {"text": "> module PNat.Operations\n\n> import PNat.PNat\n> import Nat.Positive\n> import Nat.Operations\n> import Nat.OperationsProperties\n> import Pairs.Operations\n\n> %default total\n> %access public export\n\n\n> ||| The predecessor of a PNat\n> pred : PNat -> Nat\n> pred (Element _ (MkPositive {n})) = n\n\n\n> ||| \n> fromNat : (m : Nat) -> Z `LT` m -> PNat\n> {-\n> fromNat Z zLTz = absurd zLTz\n> fromNat (S m) _ = Element (S m) (MkPositive {n = m})\n> ----}\n> --{-\n> fromNat m prf = Element m pm where\n> pm : Positive m\n> pm = fromSucc (pred m prf) m (predLemma m prf)\n> ---}\n\n\n> |||\n> toNat : PNat -> Nat\n> toNat = getWitness\n\n\n> |||\n> plus : PNat -> PNat -> PNat\n> plus (Element m pm) (Element n pn) = Element (m + n) (plusPreservesPositivity pm pn)\n\n\n> |||\n> (+) : PNat -> PNat -> PNat\n> (+) = plus\n\n\n> |||\n> mult : PNat -> PNat -> PNat\n> mult (Element m pm) (Element n pn) = Element (m * n) (multPreservesPositivity pm pn)\n\n\n> |||\n> (*) : PNat -> PNat -> PNat\n> (*) = mult\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "b633bdc71d7b4b59a6cd6c7f9205951bddbbf024", "size": 977, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "PNat/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": "PNat/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": "PNat/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": 16.5593220339, "max_line_length": 86, "alphanum_fraction": 0.571136131, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.646882422698988}} {"text": "module Symmetry.Abelian\n\nimport Specifications.TranslationInvariance\n\n%default total\n%access export\n\nabelianTranslationInvariantLR : isAbelian op -> \n isTranslationInvariantL op rel -> \n isTranslationInvariantR op rel\nabelianTranslationInvariantLR abel left x y a given =\n rewrite abel x a in \n rewrite abel y a in\n left x y a given \n", "meta": {"hexsha": "2c57a94ee35dd62cb0c752736f6ee19ab7eddecd", "size": 339, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Symmetry/Abelian.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/Symmetry/Abelian.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/Symmetry/Abelian.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": 22.6, "max_line_length": 53, "alphanum_fraction": 0.7935103245, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6468391814763168}} {"text": "-- ReadVect.idr\n\n-- Demonstrates reading of dependent types from stdin\n-- e.g., reading Data.Vect of defined length\n\nmodule ReadVect\n\nimport Data.Vect\n\n||| Reads a Vect with given length\n||| @len Length of Vect to be read\nexport\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\n-- alternative implementation without DPairs\n\npublic export\ndata VectUnknown : Type -> Type where\n MkVect : (len : Nat) -> Vect len a -> VectUnknown a\n\n||| Reads a Vect of unknown length\nexport\nreadVect2 : IO (VectUnknown String)\nreadVect2 = do x <- getLine\n if (x == \"\")\n then pure (MkVect _ [])\n else do MkVect _ xs <- readVect2\n pure (MkVect _ (x :: xs))\n\n\n||| Prints a vector of unknown length\nexport\nprintVect : Show a => VectUnknown a -> IO ()\nprintVect (MkVect len xs) =\n putStrLn (show xs ++ \" (length: \" ++ (show len) ++ \")\\n\")\n\n\n\n", "meta": {"hexsha": "f8c340bf9115e891d5cb851e56c79b425d9bcfeb", "size": 1033, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_5/ReadVect.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_5/ReadVect.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_5/ReadVect.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.023255814, "max_line_length": 59, "alphanum_fraction": 0.5953533398, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6466714585359242}} {"text": "module Examples.FourPointLattice\n\nimport public DepSec.Lattice\n\n%access public export\n\ndata FourPoint = H | M1 | M2 | L\n\nimplementation JoinSemilattice FourPoint where\n join H _ = H\n join _ H = H\n join L x = x\n join x L = x\n join M1 M1 = M1\n join M1 M2 = H\n join M2 M1 = H\n join M2 M2 = M2\n\n associative H x y = Refl\n associative M1 H H = Refl\n associative M1 H M1 = Refl\n associative M1 H M2 = Refl\n associative M1 H L = Refl\n associative M1 M1 H = Refl\n associative M1 M1 M1 = Refl\n associative M1 M1 M2 = Refl\n associative M1 M1 L = Refl\n associative M1 M2 H = Refl\n associative M1 M2 M1 = Refl\n associative M1 M2 M2 = Refl\n associative M1 M2 L = Refl\n associative M1 L H = Refl\n associative M1 L M1 = Refl\n associative M1 L M2 = Refl\n associative M1 L L = Refl\n associative M2 H H = Refl\n associative M2 H M1 = Refl\n associative M2 H M2 = Refl\n associative M2 H L = Refl\n associative M2 M1 H = Refl\n associative M2 M1 M1 = Refl\n associative M2 M1 M2 = Refl\n associative M2 M1 L = Refl\n associative M2 M2 H = Refl\n associative M2 M2 M1 = Refl\n associative M2 M2 M2 = Refl\n associative M2 M2 L = Refl\n associative M2 L H = Refl\n associative M2 L M1 = Refl\n associative M2 L M2 = Refl\n associative M2 L L = Refl\n associative L H H = Refl\n associative L H M1 = Refl\n associative L H M2 = Refl\n associative L H L = Refl\n associative L M1 H = Refl\n associative L M1 M1 = Refl\n associative L M1 M2 = Refl\n associative L M1 L = Refl\n associative L M2 H = Refl\n associative L M2 M1 = Refl\n associative L M2 M2 = Refl\n associative L M2 L = Refl\n associative L L H = Refl\n associative L L M1 = Refl\n associative L L M2 = Refl\n associative L L L = Refl\n\n commutative H H = Refl\n commutative H M1 = Refl\n commutative H M2 = Refl\n commutative H L = Refl\n commutative M1 H = Refl\n commutative M1 M1 = Refl\n commutative M1 M2 = Refl\n commutative M1 L = Refl\n commutative M2 H = Refl\n commutative M2 M1 = Refl\n commutative M2 M2 = Refl\n commutative M2 L = Refl\n commutative L H = Refl\n commutative L M1 = Refl\n commutative L M2 = Refl\n commutative L L = Refl\n\n idempotent H = Refl\n idempotent M1 = Refl\n idempotent M2 = Refl\n idempotent L = Refl\n\nimplementation BoundedJoinSemilattice FourPoint where\n Bottom = L\n unitary H = Refl\n unitary L = Refl\n unitary M1 = Refl\n unitary M2 = Refl\n", "meta": {"hexsha": "ec18d1764e35f0e45c8bc34954ad7c9a2a406581", "size": 2356, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Examples/FourPointLattice.idr", "max_stars_repo_name": "simongregersen/DepSec", "max_stars_repo_head_hexsha": "10e0419acbe690c460df509d0cb9f4690867422c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-08-25T15:16:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T11:10:20.000Z", "max_issues_repo_path": "Examples/FourPointLattice.idr", "max_issues_repo_name": "simongregersen/DepSec", "max_issues_repo_head_hexsha": "10e0419acbe690c460df509d0cb9f4690867422c", "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/FourPointLattice.idr", "max_forks_repo_name": "simongregersen/DepSec", "max_forks_repo_head_hexsha": "10e0419acbe690c460df509d0cb9f4690867422c", "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.2886597938, "max_line_length": 53, "alphanum_fraction": 0.6876061121, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109622750986, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6465764555950585}} {"text": "module Data.Bool.Xor\n\nimport Data.Bool\n\n%default total\n\npublic export\nxor : Bool -> Bool -> Bool\nxor True True = False\nxor False False = False\nxor _ _ = True\n\nexport\nxorSameFalse : (b : Bool) -> xor b b = False\nxorSameFalse False = Refl\nxorSameFalse True = Refl\n\nexport\nxorFalseNeutral : (b : Bool) -> xor False b = b\nxorFalseNeutral False = Refl\nxorFalseNeutral True = Refl\n\nexport\nxorTrueNot : (b : Bool) -> xor True b = not b\nxorTrueNot False = Refl\nxorTrueNot True = Refl\n\nexport\nnotXor : (a, b : Bool) -> not (xor a b) = xor (not a) b\nnotXor True b = rewrite xorFalseNeutral b in\n rewrite xorTrueNot b in\n notInvolutive b\nnotXor False b = rewrite xorFalseNeutral b in\n sym $ xorTrueNot b\n\nexport\nnotXorCancel : (a, b : Bool) -> xor (not a) (not b) = xor a b\nnotXorCancel True b = rewrite xorFalseNeutral (not b) in\n sym $ xorTrueNot b\nnotXorCancel False b = rewrite xorFalseNeutral b in\n rewrite xorTrueNot (not b) in\n notInvolutive b\n\nexport\nxorAssociative : (a, b, c : Bool) -> xor a (xor b c) = xor (xor a b) c\nxorAssociative False b c =\n rewrite xorFalseNeutral b in\n xorFalseNeutral $ xor b c\nxorAssociative True b c =\n rewrite xorTrueNot b in\n rewrite xorTrueNot (xor b c) in\n notXor b c\n\nexport\nxorCommutative : (a, b : Bool) -> xor a b = xor b a\nxorCommutative False False = Refl\nxorCommutative False True = Refl\nxorCommutative True False = Refl\nxorCommutative True True = Refl\n\nexport\nxorNotTrue : (a : Bool) -> a `xor` (not a) = True\nxorNotTrue False = Refl\nxorNotTrue True = Refl\n", "meta": {"hexsha": "3663c55899c28a0c68d1c4468af0ae42c1bee7f8", "size": 1624, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/Bool/Xor.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/base/Data/Bool/Xor.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/base/Data/Bool/Xor.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": 24.9846153846, "max_line_length": 70, "alphanum_fraction": 0.6594827586, "num_tokens": 510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583169, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6460473671409706}} {"text": "module Fibonacci\n\nfibpair: Nat -> (Nat, Nat)\nfibpair Z = (1, 1)\nfibpair (S k) = case (fibpair k) of\n (a, b) => (b, a + b)\n\nappend : List a -> a -> List a\nappend [] x = x :: []\nappend (y :: xs) x = y :: (append xs x)\n\nfiblist: Nat -> List (Nat)\nfiblist Z = []\nfiblist (S k) = case (fibpair k) of\n (a, b) => append (fiblist k) a\n\ntuple: Nat -> Type\ntuple Z = Unit\ntuple (S k) = (Nat, tuple k)\n\nfibtup: (n: Nat) -> tuple n\nfibtup Z = ()\nfibtup (S k) = case (fibpair k) of\n (a, b) => (a, fibtup k)\n\n\napptup: (n: Nat) -> tuple n -> Nat -> tuple (succ n)\napptup Z () k = (k, ())\napptup (S j) (a, b) k = (a, tail) where\n tail = apptup j b k\n\nrev: (n: Nat) -> tuple n -> tuple n\nrev Z () = ()\nrev (S k) (a, b) = apptup k (rev k b) a\n\nrevv: {n: Nat} -> tuple n -> tuple n\nrevv {n = Z} () = ()\nrevv {n = (S k)} (a, b) = apptup k (revv b) a\n\ntotal ack : Nat -> Nat -> Nat\nack Z n = n + 1\nack (S k) Z = ack k 1\nack (S k) (S j) = ack k (ack (S k) j)\n\n\nrec : (a : Type) -> a -> (Nat -> a -> a) -> (Nat -> a)\nrec a x f Z = x\nrec a x f (S k) = f k (rec a x f k)\n\nbase : Nat -> Nat\nbase k = k + 1\n\ns : (m : Nat) -> (ackm : Nat -> Nat) -> Nat -> Nat -> Nat\ns m ackm k j = ackm j\n\nstep : Nat -> (Nat -> Nat) -> Nat -> Nat\nstep m ackm = rec Nat (ackm 1)(s m ackm)\n\nackrec : Nat -> Nat -> Nat\nackrec = rec (Nat -> Nat) base step\n", "meta": {"hexsha": "6c63c212e685a06ebe77aaf77e1e4f8e794acf23", "size": 1368, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/code/fib.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/fib.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/fib.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": 22.4262295082, "max_line_length": 57, "alphanum_fraction": 0.4875730994, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6458082148956152}} {"text": "module Parity\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)) 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\nparity_lemma_2 = proof {\n intro;\n intro;\n rewrite sym (plusSuccRightSucc j j);\n trivial;\n}\n\nparity_lemma_1 = proof {\n intro j;\n intro;\n rewrite sym (plusSuccRightSucc j j);\n trivial;\n}\n\n", "meta": {"hexsha": "98e8b7224b35ee938355d21900c4bcd11988b5ba", "size": 534, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Binary/Parity.idr", "max_stars_repo_name": "silky/idris-demos", "max_stars_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-27T11:33:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T11:33:51.000Z", "max_issues_repo_path": "Binary/Parity.idr", "max_issues_repo_name": "silky/idris-demos", "max_issues_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Binary/Parity.idr", "max_forks_repo_name": "silky/idris-demos", "max_forks_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4137931034, "max_line_length": 53, "alphanum_fraction": 0.5486891386, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6458082141762778}} {"text": "> module NonNegRational.BasicOperations\n\n\n> import NonNegRational.NonNegRational\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.BasicProperties\n> import Fraction.Normalize\n> import Fraction.NormalizeProperties\n> import Pairs.Operations\n> import Sigma.Sigma\n\n> %default total\n> %access public export\n\n\n> ||| \n> toFraction : NonNegRational -> Fraction\n> toFraction = getWitness -- PairsOperations.Subset.getWitness\n> -- %freeze toFraction\n\n\n> ||| \n> fromFraction : Fraction -> NonNegRational\n> fromFraction x = Element (normalize x) (normalNormalize x)\n> %freeze fromFraction\n\n\n> ||| The numerator of a non-negative rational\n> num : NonNegRational -> Nat\n> num = num . toFraction\n> -- %freeze num\n\n\n> ||| The denominator of a non-negative rational\n> den : NonNegRational -> Nat\n> den = den . toFraction \n> -- %freeze den\n\n\n> ||| Every natural number is a non-negative rational\n> fromNat : (n : Nat) -> NonNegRational\n> fromNat = fromFraction . fromNat\n> -- %freeze fromNat\n\n\n> ||| Addition of non-negative rational numbers\n> plus : NonNegRational -> NonNegRational -> NonNegRational\n> plus x y = fromFraction (toFraction x + toFraction y)\n> -- %freeze plus\n\n\n> ||| Multiplication of non-negative rational numbers\n> mult : NonNegRational -> NonNegRational -> NonNegRational\n> mult x y = fromFraction (toFraction x * toFraction y)\n> -- %freeze mult\n\n\n", "meta": {"hexsha": "d45b2de311e58c009203a21604a6356ec2624d6b", "size": 1379, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegRational/BasicOperations.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/BasicOperations.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/BasicOperations.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.3728813559, "max_line_length": 62, "alphanum_fraction": 0.7273386512, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6456891590724301}} {"text": "module Algebra.Solver.CommutativeMonoid\n\nimport public Algebra.Monoid\nimport public Algebra.Solver.Prod\nimport Syntax.PreorderReasoning\n\n%default total\n\npublic export\ntimes : CommutativeMonoid a => Nat -> a -> a\ntimes 0 x = neutral\ntimes (S k) x = x <+> times k x\n\npublic export\ndata Expr : (a : Type) -> (as : List a) -> Type where\n Lit : (x : a) -> Expr a as\n Var : (x : a) -> Elem x as -> Expr a as\n Neutral : Expr a as\n Append : Expr a as -> Expr a as -> Expr a as\n\npublic export\nFromString a => FromString (Expr a as) where\n fromString = Lit . fromString\n\npublic export\nSemigroup (Expr a as) where\n (<+>) = Append\n\npublic export\nMonoid (Expr a as) where\n neutral = Neutral\n\n--------------------------------------------------------------------------------\n-- Normalization\n--------------------------------------------------------------------------------\n\npublic export\nrecord Term (a : Type) (as : List a) where\n constructor T\n factor : a\n prod : Prod a as\n\npublic export\nappend : CommutativeMonoid a => Term a as -> Term a as -> Term a as\nappend (T f1 p1) (T f2 p2) = T (f1 <+> f2) (mult p1 p2)\n\npublic export\nnormalize : CommutativeMonoid a => {as : List a} -> Expr a as -> Term a as\nnormalize (Lit x) = T x one\nnormalize (Var x y) = T neutral (fromVar y)\nnormalize Neutral = T neutral one\nnormalize (Append x y) = append (normalize x) (normalize y)\n\n--------------------------------------------------------------------------------\n-- Evaluation\n--------------------------------------------------------------------------------\n\npublic export\neval : CommutativeMonoid a => Expr a as -> a\neval (Lit x) = x\neval (Var x y) = x\neval Neutral = neutral\neval (Append x y) = eval x <+> eval y\n\npublic export\neprod : CommutativeMonoid a => {as : List a} -> Prod a as -> a\neprod [] = neutral\neprod {as = v :: vs} (exp :: x) = times exp v <+> eprod x\n\npublic export\neterm : CommutativeMonoid a => {as : List a} -> Term a as -> a\neterm (T f p) = f <+> eprod p\n\n--------------------------------------------------------------------------------\n-- Proofs\n--------------------------------------------------------------------------------\n\n0 p1324 : CommutativeMonoid a\n => {k,l,m,n : a}\n -> (k <+> l) <+> (m <+> n) === (k <+> m) <+> (l <+> n)\np1324 = Calc $\n |~ (k <+> l) <+> (m <+> n)\n ~~ ((k <+> l) <+> m) <+> n ... appendAssociative\n ~~ (k <+> (l <+> m)) <+> n ..< cong (<+>n) appendAssociative\n ~~ (k <+> (m <+> l)) <+> n ... cong (\\x => (k <+> x) <+> n) appendCommutative\n ~~ ((k <+> m) <+> l) <+> n ... cong (<+>n) appendAssociative\n ~~ (k <+> m) <+> (l <+> n) ..< appendAssociative\n\n0 pone : CommutativeMonoid a\n => (as : List a)\n -> eprod {as} Prod.one === Prelude.neutral\npone [] = Refl\npone (v :: vs) = Calc $\n |~ neutral <+> eprod {as = vs} one\n ~~ neutral <+> neutral ... cong (neutral <+>) (pone vs)\n ~~ neutral ... appendLeftNeutral\n\nexport\n0 pvar : CommutativeMonoid a\n => (as : List a)\n -> (e : Elem x as)\n -> eprod (fromVar {as} e) === x\npvar (x :: vs) Here = Calc $\n |~ (x <+> neutral) <+> eprod {as = vs} one\n ~~ (x <+> neutral) <+> neutral ... cong ((x <+> neutral) <+>) (pone vs)\n ~~ x <+> neutral ... appendRightNeutral\n ~~ x ... appendRightNeutral\n\npvar (v :: vs) (There y) = Calc $\n |~ neutral <+> eprod (fromVar y)\n ~~ eprod (fromVar y) ... appendLeftNeutral\n ~~ x ... pvar vs y\n\npvar [] Here impossible\npvar [] (There y) impossible\n\n0 ptimes : CommutativeMonoid a\n => (m,n : Nat)\n -> (x : a)\n -> times m x <+> times n x === times (m + n) x\nptimes 0 n x = appendLeftNeutral\nptimes (S k) n x = Calc $\n |~ (x <+> times k x) <+> times n x\n ~~ x <+> (times k x <+> times n x) ..< appendAssociative\n ~~ x <+> times (k + n) x ... cong (x <+>) (ptimes k n x)\n\n\n0 ppm : CommutativeMonoid a\n => (e1,e2 : Prod a as)\n -> eprod e1 <+> eprod e2 === eprod (mult e1 e2)\nppm [] [] = appendRightNeutral\nppm {as = v :: vs} (m :: xs) (n :: ys) = Calc $\n |~ (times m v <+> eprod xs) <+> (times n v <+> eprod ys)\n ~~ (times m v <+> times n v) <+> (eprod xs <+> eprod ys)\n ... p1324\n ~~ (times m v <+> times n v) <+> eprod (mult xs ys)\n ... cong ((times m v <+> times n v) <+>) (ppm xs ys)\n ~~ times (m + n) v <+> eprod (mult xs ys)\n ... cong (<+> eprod (mult xs ys)) (ptimes m n v)\n\n\n0 pappend : CommutativeMonoid a\n => (e1,e2 : Term a as)\n -> eterm e1 <+> eterm e2 === eterm (append e1 e2)\npappend (T f p) (T g q) = Calc $\n |~ (f <+> eprod p) <+> (g <+> eprod q)\n ~~ (f <+> g) <+> (eprod p <+> eprod q) ... p1324\n ~~ (f <+> g) <+> eprod (mult p q) ... cong ((f <+> g) <+>) (ppm p q)\n\n0 pnorm : CommutativeMonoid a\n => (e : Expr a as)\n -> eval e === eterm (normalize e)\npnorm (Lit x) = Calc $\n |~ x\n ~~ x <+> neutral ..< appendRightNeutral\n ~~ x <+> eprod {as} one ..< cong (x <+>) (pone as)\n\npnorm (Var x y) = Calc $\n |~ x\n ~~ eprod (fromVar y) ..< pvar as y\n ~~ neutral <+> eprod (fromVar y) ..< appendLeftNeutral\n\npnorm Neutral = Calc $\n |~ neutral\n ~~ neutral <+> neutral ..< appendRightNeutral\n ~~ neutral <+> eprod {as} one ..< cong (neutral <+>) (pone as)\n\npnorm (Append x y) = Calc $\n |~ eval x <+> eval y\n ~~ eterm (normalize x) <+> eval y\n ... cong (<+> eval y) (pnorm x)\n ~~ eterm (normalize x) <+> eterm (normalize y)\n ... cong (eterm (normalize x) <+>) (pnorm y)\n ~~ eterm (append (normalize x) (normalize y))\n ... pappend (normalize x) (normalize y)\n\n--------------------------------------------------------------------------------\n-- Solver\n--------------------------------------------------------------------------------\n\nexport\n0 solve : CommutativeMonoid a\n => (as : List a)\n -> (e1,e2 : Expr a as)\n -> (prf : normalize e1 === normalize e2)\n => eval e1 === eval e2\nsolve _ e1 e2 = Calc $\n |~ eval e1\n ~~ eterm (normalize e1) ... pnorm e1\n ~~ eterm (normalize e2) ... cong eterm prf\n ~~ eval e2 ..< pnorm e2\n", "meta": {"hexsha": "97e39e0274c0cb453980f5c0fd6fd7d1176e5145", "size": 6238, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Solver/CommutativeMonoid.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/Solver/CommutativeMonoid.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/Solver/CommutativeMonoid.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": 32.4895833333, "max_line_length": 80, "alphanum_fraction": 0.4620070535, "num_tokens": 1954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6456842624958667}} {"text": "module Algebra.Solver.Semiring.SolvableSemiring\n\nimport Algebra.Semiring\n\n%default total\n\n||| When normalizing arithmetic expressions, we must\n||| make sure that factors that evaluate to zero must\n||| be removed from the sum of products.\n|||\n||| For instance, the following example only works,\n||| if the term `0 * x * y` gets removed before comparing\n||| the normalized sums:\n|||\n||| ```idris example\n||| 0 binom3 : {x,y : Bits8} -> (x + y) * (x - y) === x * x - y * y\n||| binom3 = solve [x,y] ((x .+. y) * (x .-. y)) (x .*. x - y .*. y)\n||| ```\n|||\n||| Because we cannot directly use a (primitive) pattern match\n||| without having a concrete type, we need this interface.\n||| (We *could* use `DecEq`, but this is not publicly exported\n||| for the primitives; probably for good reasons since it is\n||| implemented using `believe_me`).\npublic export\ninterface Semiring a => SolvableSemiring a where\n\n ||| Checks if a value is propositionally equal to zero.\n isZero : (v : a) -> Maybe (v === 0)\n\npublic export\nSolvableSemiring Nat where\n isZero Z = Just Refl\n isZero _ = Nothing\n", "meta": {"hexsha": "ef0f05a9ac6462f3fc8fadf652f9d68581d0da43", "size": 1082, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Solver/Semiring/SolvableSemiring.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/Solver/Semiring/SolvableSemiring.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/Solver/Semiring/SolvableSemiring.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": 30.9142857143, "max_line_length": 68, "alphanum_fraction": 0.6654343808, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.6456050286029151}} {"text": "module Main\n\nimport Data.Vect\n\n-- check that all functions are total\n %default total\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--noWhere : (contra: Elem value xs -> Void) -> Elem value (x::xs) -> Void\n\nnoWhere : (notThere: Elem value xs -> Void) -> (notHere: value = x -> Void) -> Elem value (x::xs) -> Void\nnoWhere notThere notHere Here = notHere Refl\nnoWhere notThere notHere (There later) = notThere later\n\nnotInNil1: Elem value [] -> Void\nnotInNil1 Here impossible\nnotInNil1 (There _) impossible\n\n\nisElem1 : DecEq a => (value: a) -> (xs: Vect n a) -> Dec (Elem value xs)\nisElem1 value [] = No notInNil1\nisElem1 value (x :: xs) = case decEq value x of\n Yes Refl => Yes Here\n No contra => case isElem1 value xs of\n Yes prof => Yes (There prof)\n No contra1 => No (noWhere contra1 contra)\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\ndata Elem1 : a -> List a -> Type where\n Here : Elem1 x (x::xs)\n There: (later: Elem1 x xs) -> Elem1 x (y :: ys)\n\ndata Last : List a -> a -> Type where\n LastOne : Last [value] value\n LastCons : (prf : Last xs value) -> Last (x :: xs) value\n\nnotInEmptyList : Last [] value -> Void\nnotInEmptyList LastOne impossible\nnotInEmptyList (LastCons _) impossible\n\nnotInLast : (contra: value = x -> Void) -> (Last [x] value) -> Void\nnotInLast contra LastOne = contra Refl\nnotInLast contra (LastCons prf) impossible\n\nanotherContra : (contra : Last [] value) -> Void\nanotherContra LastOne impossible\nanotherContra (LastCons _) impossible\n\nUninhabited (Last [] a) where\n uninhabited LastOne impossible\n\nnotAnywhere : (contra: Last (x::xs) value -> Void) -> (Last (y::x::xs) value) -> Void\nnotAnywhere contra (LastCons prf) = contra prf\n\n\n--notAnywhere contra LastOne = contra ?hole\n--notAnywhere contra (LastCons prf) = contra prf\n\n--notAnywhere contra LastOne = contra ?hole_2\n--notAnywhere contra (LastCons prf) = contra prf\n\nisLast : DecEq a => (xs : List a) -> (value : a) -> Dec (Last xs value)\nisLast [] value = No notInEmptyList\nisLast [x] value = case decEq value x of\n Yes Refl => Yes LastOne\n No contra => No (notInLast contra)\nisLast (x :: y :: xs) value = case isLast (y :: xs) value of\n Yes prf => Yes (LastCons prf)\n No contra => No (notAnywhere contra)\n\n\n\n-- game functions\nremoveElem_auto : (value: a) -> (xs: Vect (S n) a) -> {auto prf: Elem 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\n\ndata WordState : (guesses_remaing: Nat) -> (letters: Nat) -> Type where\n MkWordState: (word: String) -> (missing: Vect letters Char) -> WordState guessess_remaining letters\n\ndata Finished: Type where\n Lost: (game: WordState 0 (S letters)) -> Finished\n Won: (game: WordState (S guesses) 0) -> Finished\n\n\ndata ValidInput : List Char -> Type where\n Letter: (c: Char) -> ValidInput [c]\n\nisValidNil : ValidInput [] -> Void\nisValidNil (Letter _) impossible\n\nisMoreChar : (ValidInput (c1::c2::cs)) -> Void\nisMoreChar (Letter _) impossible\n\n\nisValidInput : (cs: List Char) -> Dec (ValidInput cs)\nisValidInput [] = No isValidNil\nisValidInput (c::[]) = Yes (Letter c)\nisValidInput (c1::c2::cs) = No isMoreChar\n\n\nisValidString : (s: String) -> Dec (ValidInput (unpack s))\nisValidString s = isValidInput (unpack s)\n\nreadGuess: IO (x**ValidInput x)\nreadGuess = do putStr \"Guess\"\n x <- getLine\n case isValidString (toUpper x) of\n Yes prf => pure (_ ** prf)\n No contra => do putStrLn \"Invalid guess\"\n readGuess\nprocessGuess : (letter: Char) ->\n WordState (S guesses) (S letters) ->\n Either (WordState guesses (S letters)) (WordState (S guesses) letters)\nprocessGuess letter (MkWordState word missing) = case isElem letter missing of\n Yes prf => Right (MkWordState word (removeElem_auto letter missing))\n No contra => Left (MkWordState word missing)\n\n\ngame : WordState (S guesses) (S letters) -> IO Finished\ngame {guesses} {letters} st = do\n (_ ** Letter letter) <- readGuess\n case processGuess letter st of\n Left l => do putStrLn \"Wrong\"\n case guesses of\n Z => pure (Lost l)\n S k => game l\n Right r => do putStrLn \"Right!\"\n case letters of\n Z => pure (Won r)\n S k => game r\n", "meta": {"hexsha": "3101a25caaa2c7ed74f8b7703f132c5868644c35", "size": 4940, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter81.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": "Chapter81.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": "Chapter81.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": 31.8709677419, "max_line_length": 105, "alphanum_fraction": 0.6441295547, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6455935394541912}} {"text": "module Specifications.OrderedRing\n\nimport public Specifications.Ring\nimport public Specifications.TranslationInvariance\nimport public Specifications.DiscreteOrderedGroup\n\n%default total\n%access public export\n\n||| composed specification\n||| todo: multiplication of positive elements is positive\ndata PartiallyOrderedRingSpec :\n Binop s -> s -> (s -> s) -> Binop s -> Binrel s -> Type\n where MkPartiallyOrderedRing :\n RingSpec add zero neg mul ->\n PartiallyOrderedMagmaSpec add leq ->\n PartiallyOrderedRingSpec add zero neg mul leq\n\n||| forget\nring : PartiallyOrderedRingSpec add zero neg mul _ -> RingSpec add zero neg mul\nring (MkPartiallyOrderedRing r _) = r\n\n||| forget\npartiallyOrderedGroup : PartiallyOrderedRingSpec add zero neg _ leq ->\n PartiallyOrderedGroupSpec add zero neg leq\npartiallyOrderedGroup (MkPartiallyOrderedRing r o) =\n MkPartiallyOrderedGroup (group (abelianGroup r)) o\n\n||| composed specification\ndata OrderedRingSpec :\n Binop s -> s -> (s -> s) -> Binop s -> Binrel s -> Type\n where MkOrderedRing :\n PartiallyOrderedRingSpec add zero neg mul leq ->\n isTotalOrder leq ->\n OrderedRingSpec add zero neg mul leq\n\nnamespace ForgetOrder\n ring : OrderedRingSpec add zero neg mul _ -> RingSpec add zero neg mul\n ring (MkOrderedRing r _) = ring r\n\n||| forget\norderedGroup : OrderedRingSpec add zero neg _ leq ->\n OrderedGroupSpec add zero neg leq\norderedGroup (MkOrderedRing r t) = MkOrderedGroup (partiallyOrderedGroup r) t\n\n||| composed specification\ndata DiscreteOrderedRingSpec :\n Binop s -> s -> (s -> s) -> Binop s -> Binrel s -> s -> Type\n where MkDiscreteOrderedRing :\n OrderedRingSpec add zero neg mul leq ->\n isDiscreteOrder add leq zero one ->\n isNeutralL mul one ->\n isNeutralR mul one ->\n (onePositive : leq zero one) ->\n DiscreteOrderedRingSpec add zero neg mul leq one\n\n\n||| forget\ndiscreteOrderedGroup : DiscreteOrderedRingSpec add zero neg _ leq one ->\n DiscreteOrderedGroupSpec add zero neg leq one\ndiscreteOrderedGroup (MkDiscreteOrderedRing r d _ _ _) =\n MkDiscreteOrderedGroup (orderedGroup r) (abelian (abelianGroup (ring r))) d\n\n||| forget\nunitalRing : DiscreteOrderedRingSpec add zero neg mul _ one ->\n UnitalRingSpec add zero neg mul one\nunitalRing (MkDiscreteOrderedRing or _ l r _) = MkUnitalRing (ring or) l r\n\n||| forget\nonePositive : DiscreteOrderedRingSpec _ zero _ _ leq one -> leq zero one\nonePositive (MkDiscreteOrderedRing _ _ _ _ pos) = pos\n", "meta": {"hexsha": "a9e6096c7c82b2d859e45a01ad5f23bc6645c293", "size": 2442, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Specifications/OrderedRing.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/OrderedRing.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/OrderedRing.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": 33.9166666667, "max_line_length": 79, "alphanum_fraction": 0.7514332514, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.645398809039921}} {"text": "-- Axiom of (constructive) choice\n\nch : {0 r : a -> b -> Type} -> ((x : a) -> (y : b ** r x y)) -> (f : a -> b ** (x : a) -> r x (f x))\nch f = (\\x => fst (f x) ** \\x => let _ = True in snd (f x))\n\n-- The dummy `let` above is needed for typecheck success in idris-0.3.0, to be removed when fixed.\n", "meta": {"hexsha": "af9cce5ce08ec7c4c4139addcc4cc2642c8136ec", "size": 296, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ChoiceAxiom.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": "ChoiceAxiom.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": "ChoiceAxiom.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": 42.2857142857, "max_line_length": 100, "alphanum_fraction": 0.5033783784, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.645367255293992}} {"text": "|||\n|||\n||| foldr is the unique solution to the equation:\n|||\n||| h f e [] = e\n||| h f e (x :: xs) = x `h` (foldr f e xs)\n|||\n||| (This fact is called 'the universal property of foldr'.)\n|||\n||| Since the prelude defines foldr tail-recursively, this fact isn't immediate\n||| and we need some lemmata to prove it.\nmodule Data.Vect.Properties.Foldr\n\nimport Data.Vect\nimport Data.Vect.Elem\nimport Data.Fin\nimport Data.Nat\nimport Data.Nat.Order\n\nimport Syntax.PreorderReasoning\nimport Syntax.PreorderReasoning.Generic\n\nimport Control.Order\n\n||| Sum implemented with foldr\npublic export\nsumR : (Foldable f, Num a) => f a -> a\nsumR = foldr (+) 0\n\n%transform \"sumR/sum\" sumR = sum\n\n||| A function H : forall n. Vect n A -> B preserving the structure of vectors over A\npublic export\nrecord VectHomomorphismProperty {0 A, B : Type} (F : A -> B -> B) (E : B) (H : forall n . Vect n A -> B) where\n constructor ShowVectHomomorphismProperty\n nil : H [] = E\n cons : {0 n : Nat} -> (x : A) -> (xs : Vect n A) -> H (x :: xs) = x `F` (H xs)\n\n||| There is an extensionally unique function preserving the vector structure\nexport\nnilConsInitiality :\n (f : a -> b -> b) -> (e : b)\n -> (h1, h2 : forall n . Vect n a -> b)\n -> (prf1 : VectHomomorphismProperty f e h1)\n -> (prf2 : VectHomomorphismProperty f e h2)\n -> (xs : Vect n a) -> h1 xs = h2 xs\nnilConsInitiality f e h1 h2 prf1 prf2 [] = Calc $\n |~ h1 []\n ~~ e ...(prf1.nil)\n ~~ h2 [] ...(sym prf2.nil)\n\nnilConsInitiality f e h1 h2 prf1 prf2 (x :: xs) = Calc $\n |~ h1 (x :: xs)\n ~~ (x `f` (h1 xs)) ...(prf1.cons _ _)\n ~~ (x `f` (h2 xs)) ...(cong (x `f`) $ nilConsInitiality f e h1 h2 prf1 prf2 xs)\n ~~ h2 (x :: xs) ...(sym $ prf2.cons _ _)\n\n||| extensionality is a congruence with respect to Data.Vect.foldrImpl\nfoldrImplExtensional :\n (f : a -> b -> b) -> (e : b)\n -> (go1, go2 : b -> b)\n -> ((y : b) -> go1 y = go2 y)\n -> (xs : Vect n a)\n -> foldrImpl f e go1 xs = foldrImpl f e go2 xs\nfoldrImplExtensional f e go1 go2 ext [] = ext e\nfoldrImplExtensional f e go1 go2 ext (x :: xs) =\n foldrImplExtensional f e _ _\n (\\y => ext (f x y))\n xs\n\n||| foldrImpl f e x : (b -> -) -> - is natural\nfoldrImplNaturality : (f : a -> b -> b) -> (e : b) -> (xs : Vect n a) -> (go1, go2 : b -> b)\n -> foldrImpl f e (go1 . go2) xs = go1 (foldrImpl f e go2 xs)\nfoldrImplNaturality f e [] go1 go2 = Refl\nfoldrImplNaturality f e (x :: xs) go1 go2 = foldrImplNaturality f e xs go1 (go2 . (f x))\n\n||| Our tail-recursive foldr preserves the vector structure\nexport\nfoldrVectHomomorphism : VectHomomorphismProperty f e (foldr f e)\nfoldrVectHomomorphism = ShowVectHomomorphismProperty\n { nil = Refl\n , cons = \\x, xs => Calc $\n |~ foldr f e (x :: xs)\n ~~ foldrImpl f e (id . (f x)) xs ...(Refl)\n ~~ foldrImpl f e ((f x) . id) xs ...(foldrImplExtensional f e _ _ (\\y => Refl) xs)\n ~~ f x (foldrImpl f e id xs) ...(foldrImplNaturality f e xs (f x) _)\n ~~ f x (foldr f e xs) ...(Refl)\n }\n\n||| foldr is the unique function preserving the vector structure\nexport\nfoldrUniqueness : (h : forall n . Vect n a -> b) -> VectHomomorphismProperty f e h -> (xs : Vect n a) -> h xs = foldr f e xs\nfoldrUniqueness {f} h prf xs = irrelevantEq $\n nilConsInitiality f e h (foldr f e) prf foldrVectHomomorphism xs\n\n\n||| Each summand is `LTE` the sum\nexport\nsumIsGTEtoParts : {x : Nat} -> (xs : Vect n Nat) -> (x `Elem` xs) -> sumR xs `GTE` x\nsumIsGTEtoParts (x :: xs) Here\n = CalcWith $\n |~ x\n ~~ x + 0 ...(sym $ plusZeroRightNeutral _)\n <~ x + (sumR xs) ...(plusLteMonotoneLeft x 0 _ LTEZero)\n ~~ sumR (x :: xs) ...(sym $ (foldrVectHomomorphism {f = plus} {e = 0}).cons _ _)\n\nsumIsGTEtoParts {x} (y :: xs) (There later)\n = CalcWith $\n |~ x\n <~ sumR xs ...(sumIsGTEtoParts {x} xs later)\n ~~ 0 + sumR xs ...(Refl)\n <~ y + (sumR xs) ...(plusLteMonotoneRight (sumR xs) 0 y LTEZero)\n ~~ sumR (y :: xs) ...(sym $ (foldrVectHomomorphism {f = plus} {e = 0}).cons _ _)\n\n||| `sumR : Vect n Nat -> Nat` is monotone\nexport\nsumMonotone : {n : Nat} -> (xs, ys : Vect n Nat)\n -> (prf : (i : Fin n) -> index i xs `LTE` index i ys)\n -> (sumR xs `LTE` sumR ys)\nsumMonotone [] [] prf = LTEZero\nsumMonotone (x :: xs) (y :: ys) prf =\n let prf' = sumMonotone xs ys (\\i => prf (FS i))\n in CalcWith $\n |~ sumR (x :: xs)\n ~~ x + sumR xs ...((foldrVectHomomorphism {f = plus} {e = 0}).cons x xs)\n <~ y + sumR ys ...(plusLteMonotone (prf 0) prf')\n ~~ sumR (y :: ys) ...(sym $ (foldrVectHomomorphism {f = plus} {e = 0}).cons y ys)\n", "meta": {"hexsha": "3c28e8c7fa824528ee505e6a6ddc9f7dc6c7ae92", "size": 4516, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Vect/Properties/Foldr.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/Vect/Properties/Foldr.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/Vect/Properties/Foldr.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": 35.28125, "max_line_length": 124, "alphanum_fraction": 0.5963241807, "num_tokens": 1688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.645275417672089}} {"text": "{-\ncd collatzProof_DivSeq/program2\nchcp 65001\nidris\n-}\nmodule ProofColDivSeqBase\n\n%default total\n-- %language ElabReflection\n%access export\n\n\n-- mod2\npublic export\ndata Parity : Nat -> Type where\n Even : Parity (n + n)\n Odd : Parity (S (n + n))\nhelpEven : (j : Nat) -> Parity (S j + S j) -> Parity (S (S (plus j j)))\nhelpEven j p = rewrite plusSuccRightSucc j j in p\nhelpOdd : (j : Nat) -> Parity (S (S (j + S j))) -> Parity (S (S (S (j + j))))\nhelpOdd j p = rewrite plusSuccRightSucc j j in p\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 = helpEven j (Even {n = S j})\n parity (S (S (S (j + j)))) | Odd = helpOdd j (Odd {n = S j})\n\n-- mod3\npublic export\ndata Mod3 : Nat -> Type where\n ThreeZero : Mod3 (n + n + n)\n ThreeOne : Mod3 (S (n + n + n))\n ThreeTwo : Mod3 (S (S (n + n + n)))\nhelpThreeZero : (j:Nat) -> (plus (plus (S j) (S j)) (S j)) = S (S (S (plus (plus j j) j)))\nhelpThreeZero j = rewrite sym $ plusSuccRightSucc j j in\n rewrite sym $ plusSuccRightSucc (plus j j) j in Refl\nhelpThreeOne : (j:Nat) -> S (plus (plus (S j) (S j)) (S j)) = S (S (S (S (plus (plus j j) j))))\nhelpThreeOne j = cong {f=S} $ helpThreeZero j\nhelpThreeTwo : (j:Nat) -> S (S (plus (plus (S j) (S j)) (S j))) = S (S (S (S (S (plus (plus j j) j)))))\nhelpThreeTwo j = cong {f=S} $ helpThreeOne j\nmod3 : (n:Nat) -> Mod3 n\nmod3 Z = ThreeZero {n=Z}\nmod3 (S Z) = ThreeOne {n=Z}\nmod3 (S (S Z)) = ThreeTwo {n=Z}\nmod3 (S (S (S k))) with (mod3 k)\n mod3 (S (S (S (j + j + j)))) | ThreeZero =\n rewrite sym $ helpThreeZero j in ThreeZero {n=S j}\n mod3 (S (S (S (S (j + j + j))))) | ThreeOne =\n rewrite sym $ helpThreeOne j in ThreeOne {n=S j}\n mod3 (S (S (S (S (S (j + j + j)))))) | ThreeTwo =\n rewrite sym $ helpThreeTwo j in ThreeTwo {n=S j}\n-- ---------------------------------\n\n\n-- divSeqの実装に必要な関数\n -- ----- from libs/contrib/Data/CoList.idr -----\npublic export\ncodata CoList : Type -> Type where\n Nil : CoList a\n (::) : a -> CoList a -> CoList a\n\nimplementation Functor CoList where\n map f [] = []\n map f (x::xs) = f x :: map f xs\n\nimplementation Show a => Show (CoList a) where\n show xs = \"[\" ++ show' \"\" 20 xs ++ \"]\" where\n show' : String -> (n : Nat) -> (xs : CoList a) -> String\n show' acc Z _ = acc ++ \"...\"\n show' acc (S n) [] = acc\n show' acc (S n) [x] = acc ++ show x\n show' acc (S n) (x :: xs) = show' (acc ++ (show x) ++ \", \") n xs\n\nunfoldr : (a -> Maybe (b, a)) -> a -> CoList b\nunfoldr f x =\n case f x of\n Just (y, new_x) => y :: (unfoldr f new_x)\n _ => []\n -- ----- from libs/contrib/Data/CoList.idr -----\n\ncountEven : Nat -> Nat -> Nat -> (Nat, Nat)\ncountEven n Z acc = (acc, n)\ncountEven n (S nn) acc =\n if (modNatNZ n 2 SIsNotZ) == 1\n then (acc, n)\n else countEven (divNatNZ n 2 SIsNotZ) nn (acc+1)\n\n-- divSeqの実装\ndivSeq : Nat -> CoList Integer\ndivSeq n = divSeq' n n\n where\n divSeq' : Nat -> Nat -> CoList Integer\n divSeq' n Z = []\n divSeq' Z (S k) = []\n divSeq' (S n) (S k) with (parity n)\n divSeq' (S (S (j + j))) (S k) | Odd = divSeq' (S j) k\n divSeq' (S (j + j) ) (S k) | Even =\n map toIntegerNat\n (unfoldr (\\b => if b <= 1 then Nothing\n else Just (countEven (b*3+1) (b*3+1) 0) ) (S (j + j)))\ndefiniDivSeq0 : divSeq Z = []\ndefiniDivSeq0 = Refl\n-- ---------------------------------\n\n\n-- その他関数\nlimitedNStep : CoList Integer -> Nat -> Bool\nlimitedNStep [] _ = True\nlimitedNStep (_ :: _) Z = False\nlimitedNStep (_ :: xs) (S n) = limitedNStep xs n\ndefiniLimited0 : limitedNStep [] Z = True\ndefiniLimited0 = Refl\n-- ---------------------------------\n\n\n\n", "meta": {"hexsha": "cf2ec748b4f5f900dc8b0e28aae34ea03669fad9", "size": 3804, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program2/ProofColDivSeqBase.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program2/ProofColDivSeqBase.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program2/ProofColDivSeqBase.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2372881356, "max_line_length": 103, "alphanum_fraction": 0.5247108307, "num_tokens": 1399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6451064566231488}} {"text": "> module Subset.Properties\n\n> import Data.Fin\n> import Data.Vect\n> import Control.Isomorphism\n\n> import Decidable.Predicates\n> import Finite.Predicates\n> import Unique.Predicates\n> import Sigma.Sigma\n> import Pairs.Operations\n> import Subset.Operations\n> import Vect.Operations\n> import Vect.Properties\n> import Finite.Operations\n> import Finite.Properties\n> import Fin.Operations\n> -- import Isomorphism.Operations\n> import Isomorphism.Properties\n> import Basic.Operations\n> import Basic.Properties\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\nEquality of projections:\n\n> ||| Equality of first projections\n> getWitnessPreservesEq : {A : Type} ->\n> {P : A -> Type} ->\n> {s1 : Subset A P} ->\n> {s2 : Subset A P} ->\n> (s1 = s2) -> (getWitness s1 = getWitness s2)\n> getWitnessPreservesEq {s1 = (Element a p)} {s2 = (Element a p)} Refl = Refl\n> %freeze getWitnessPreservesEq\n\n\n> ||| Equality of second projections\n> getProofPreservesEq : {A : Type} ->\n> {P : A -> Type} ->\n> {s1 : Subset A P} ->\n> {s2 : Subset A P} ->\n> (s1 = s2) -> (getProof s1 = getProof s2)\n> getProofPreservesEq {s1 = (Element a p)} {s2 = (Element a p)} Refl = Refl\n> %freeze getProofPreservesEq\n\n\nEquality of Subset types:\n\n> ||| Introduction\n> subsetEqLemma2 : {A : Type} ->\n> {P : A -> Type} ->\n> {s1: Subset A P} ->\n> {s2: Subset A P} ->\n> (getWitness s1 = getWitness s2) ->\n> (getProof s1 = getProof s2) ->\n> s1 = s2\n> subsetEqLemma2 {A} {P} {s1 = (Element a p)} {s2 = (Element a p)} Refl Refl = Refl\n> %freeze subsetEqLemma2\n\n\n> ||| Elimination and formation\n> subsetEqLemma0 : {A : Type} ->\n> {P : A -> Type} ->\n> (s : Subset A P) ->\n> s = (Element (getWitness s) (getProof s))\n> subsetEqLemma0 (Element a p) = Refl\n> %freeze subsetEqLemma0\n\n\n> ||| Equality for singleton predicates\n> subsetEqLemma1 : {A : Type} ->\n> {P : A -> Type} ->\n> (s1 : Subset A P) ->\n> (s2 : Subset A P) ->\n> getWitness s1 = getWitness s2 ->\n> Unique0 (P (getWitness s1)) ->\n> s1 = s2\n> subsetEqLemma1 (Element a p) (Element a q) Refl uP = cong (uP p q)\n> %freeze subsetEqLemma1\n\n\nDecidability of Subset equality:\n\n> ||| Decidability of equality 1\n> subsetDecEqLemma1 : {A : Type} ->\n> {P : A -> Type} ->\n> (DecEq0 A) ->\n> (DecEq1 P) ->\n> (s1 : Subset A P) ->\n> (s2 : Subset A P) ->\n> Dec (s1 = s2)\n> subsetDecEqLemma1 da d1p (Element a1 pa1) (Element a2 pa2) with (da a1 a2)\n> subsetDecEqLemma1 da d1p (Element a1 pa1) (Element a1 pa2) | (Yes Refl) with ((d1p a1) pa1 pa2)\n> subsetDecEqLemma1 da d1p (Element a1 pa1) (Element a1 pa1) | (Yes Refl) | (Yes Refl) = Yes Refl\n> subsetDecEqLemma1 da d1p (Element a1 pa1) (Element a1 pa2) | (Yes Refl) | (No contra) = No (\\ eq => contra (getProofPreservesEq eq))\n> subsetDecEqLemma1 da d1p (Element a1 pa1) (Element a2 pa2) | (No contra) = No (\\ eq => contra (getWitnessPreservesEq eq))\n> %freeze subsetDecEqLemma1\n\n\n> ||| Decidability of equality 2\n> subsetDecEqLemma2 : {A : Type} ->\n> {P : A -> Type} ->\n> (DecEq A) ->\n> (Unique1 P) ->\n> (s1 : Subset A P) ->\n> (s2 : Subset A P) ->\n> Dec (s1 = s2)\n> subsetDecEqLemma2 da p1P s1 s2 with (decEq (getWitness s1) (getWitness s2))\n> | (Yes prf) = Yes (subsetEqLemma1 s1 s2 prf (p1P (getWitness s1)))\n> | (No contra) = No (\\ eq => contra (getWitnessPreservesEq eq))\n> %freeze subsetDecEqLemma2\n\nWe want to show that |toVect| is complete\n\n< toVectSubsetComplete : {A : Type} ->\n< {P : A -> Type} ->\n< (fA : Finite A) ->\n< (d1P : Dec1 P) ->\n< (Unique1 {t0 = A} P) ->\n< (s : Subset A P) ->\n< Elem s (getProof (toVectSubset fA d1P))\n\nWe start by deriving two auxiliary results. The first one is\n\n> toVectSubsetLemma : {A : Type} ->\n> {P : A -> Type} ->\n> (fA : Finite A) ->\n> (d1P : Dec1 P) ->\n> (a : A) ->\n> (p : P a) ->\n> Elem a (map Subset.getWitness (Sigma.getProof (toVectSubset fA d1P)))\n> toVectSubsetLemma {A} {P} fA d1P a p =\n> filterTagSubsetLemma d1P a (toVect fA) (toVectComplete fA a) p\n> %freeze toVectSubsetLemma\n\nThe proof is computed by applying |VectProperties.filterTagSubsetLemma|:\n\n< filterTagSubsetLemma : {A : Type} -> {P : A -> Type} ->\n< (d1P : Dec1 P) ->\n< (a : A) ->\n< (as : Vect n A) ->\n< (Elem a as) ->\n< (p : P a) ->\n< Elem a (map getWitness (getProof (filterTagSubset d1P as)))\n\nto |d1P|, |a|, to the vector-based representation of |A| associated to\n|fA| provided by |FiniteOperations.toVect fA| and to a proof that |a| is\nan element of |FiniteOperations.toVect fA|. The latter follows from\ncompleteness of |toVect|, see |FiniteProperties.toVectComplete|. In this\nform, |toVectLemma| does not type check.\n\nThe second result is\n\n> subsetUniqueLemma1 : {A : Type} ->\n> {P : A -> Type} ->\n> (Unique1 P) ->\n> (a : A) ->\n> (p : P a) ->\n> (ss : Vect n (Subset A P)) ->\n> (Elem a (map Subset.getWitness ss)) ->\n> Elem (Element a p) ss\n> subsetUniqueLemma1 u1P a p Nil prf = absurd prf\n> subsetUniqueLemma1 u1P a p ((Element a q) :: ss) (Here {x = a}) with (u1P a p q)\n> subsetUniqueLemma1 u1P a p ((Element a p) :: ss) (Here {x = a}) | Refl =\n> Here {x = (Element a p)} {xs = ss}\n> subsetUniqueLemma1 u1P a1 p1 ((Element a2 p2) :: ss) (There prf) =\n> There (subsetUniqueLemma1 u1P a1 p1 ss prf)\n> %freeze subsetUniqueLemma1\n\nWith |toVectLemma| and |subsetUniqueLemma1|, it is easy to show that\n|toVect| is complete:\n\n> toVectSubsetComplete : {A : Type} ->\n> {P : A -> Type} ->\n> (fA : Finite A) ->\n> (d1P : Dec1 P) ->\n> (Unique1 P) ->\n> (s : Subset A P) ->\n> Elem s (getProof (toVectSubset fA d1P))\n> toVectSubsetComplete fA d1P u1P (Element a p) = s1 where\n> s0 : Elem a (map Subset.getWitness (getProof (toVectSubset fA d1P)))\n> s0 = toVectSubsetLemma fA d1P a p\n> s1 : Elem (Element a p) (getProof (toVectSubset fA d1P))\n> s1 = subsetUniqueLemma1 u1P a p (getProof (toVectSubset fA d1P)) s0\n> %freeze toVectSubsetComplete\n\n> {-\n> toVectSubsetInjective1 : {A : Type} ->\n> {P : A -> Type} ->\n> (fA : Finite A) ->\n> (d1P : Dec1 P) ->\n> (Unique1 {t0 = A} P) ->\n> Injective1 (getProof (toVectSubset fA d1P))\n> toVectSubsetInjective1 fA dP uP =\n> injectiveFilterTagSubsetLemma dP (toVect fA) (toVectInjective1 fA)\n> -}\n\n\nSubset Fin properties:\n\n> using (P : Fin Z -> Type)\n> implementation Uninhabited (Subset (Fin Z) P) where\n> uninhabited (Element k _) = absurd k\n\n\n> |||\n> isoReplaceLemma1 : {A, A' : Type} -> {B : A -> Type} -> {B' : A' -> Type} ->\n> (isoA : Iso A A') ->\n> (isoBa : (a : A) -> Iso (B a) (B' (to isoA a)) ) ->\n> (a' : A') -> (b' : B' a') ->\n> to (isoBa (from isoA a')) (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b'))\n> =\n> b'\n> isoReplaceLemma1 isoA isoBa a' b' = trans s1 s2 where\n> s1 : to (isoBa (from isoA a')) (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b'))\n> =\n> (replace (sym (toFrom isoA a')) b')\n> s1 = toFrom (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')\n> s2 : replace (sym (toFrom isoA a')) b' = b'\n> s2 = replaceLemma (sym (toFrom isoA a')) b'\n> %freeze isoReplaceLemma1\n\n\n> |||\n> isoReplaceLemma2 : {A, A' : Type} -> {B : A -> Type} -> {B' : A' -> Type} ->\n> (isoA : Iso A A') ->\n> (isoBa : (a : A) -> Iso (B a) (B' (to isoA a)) ) ->\n> (a : A) -> (b : B a) ->\n> from (isoBa (from isoA (to isoA a))) (replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b))\n> =\n> b\n> isoReplaceLemma2 {A} {A'} {B} {B'} isoA isoBa a b = trans s2 s3 where\n> s1 : replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b)\n> =\n> to (isoBa a) b\n> s1 = replaceLemma (sym (toFrom isoA (to isoA a))) (to (isoBa a) b)\n> s2 : from (isoBa (from isoA (to isoA a))) (replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b))\n> =\n> from (isoBa a) (to (isoBa a) b)\n> s2 = depCong2' {alpha = A}\n> {P = \\ a => B' (to isoA a)}\n> {Q = \\ a => \\ pa => B a}\n> {a1 = from isoA (to isoA a)}\n> {a2 = a}\n> {Pa1 = replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b)}\n> {Pa2 = to (isoBa a) b}\n> {f = \\ x => \\ y => from (isoBa x) y}\n> (fromTo isoA a)\n> s1\n> s3 : from (isoBa a) (to (isoBa a) b) = b\n> s3 = fromTo (isoBa a) b\n> %freeze isoReplaceLemma2\n\n\n> |||\n> subsetIsoLemma : (A : Type) -> (A' : Type) -> (B : A -> Type) -> (B' : A' -> Type) ->\n> (isoA : Iso A A') ->\n> (isoBa : (a : A) -> Iso (B a) (B' (to isoA a)) ) ->\n> Iso (Subset A B) (Subset A' B')\n> subsetIsoLemma A A' B B' isoA isoBa = MkIso toQ fromQ toFromQ fromToQ\n> where toQ : Subset A B -> Subset A' B'\n> toQ (Element a b) = (Element (to isoA a) (to (isoBa a) b))\n>\n> fromQ : Subset A' B' -> Subset A B\n> fromQ (Element a' b') = (Element a b) where\n> a : A\n> a = from isoA a'\n> b : B a\n> b = from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')\n>\n> toFromQ : (ab' : Subset A' B') -> toQ (fromQ ab') = ab'\n> toFromQ (Element a' b') = trans s1 (trans s2 s3) where\n> s1 : toQ (fromQ (Element a' b'))\n> =\n> toQ (Element (from isoA a') (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')))\n> s1 = Refl\n> s2 : toQ (Element (from isoA a') (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')))\n> =\n> Element (to isoA (from isoA a'))\n> (to (isoBa (from isoA a')) (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')))\n> s2 = Refl\n> s3 : Element (to isoA (from isoA a'))\n> (to (isoBa (from isoA a')) (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')))\n> =\n> (Element a' b')\n> s3 = subsetEqLemma2 {s1 = Element (to isoA (from isoA a'))\n> (to (isoBa (from isoA a')) (from (isoBa (from isoA a')) (replace (sym (toFrom isoA a')) b')))}\n> {s2 = (Element a' b')}\n> (toFrom isoA a')\n> (isoReplaceLemma1 isoA isoBa a' b')\n>\n> fromToQ : (ab : Subset A B) -> fromQ (toQ ab) = ab\n> fromToQ (Element a b) = trans s1 (trans s2 s3) where\n> s1 : fromQ (toQ (Element a b))\n> =\n> fromQ (Element (to isoA a) (to (isoBa a) b))\n> s1 = Refl\n> s2 : fromQ (Element (to isoA a) (to (isoBa a) b))\n> =\n> Element (from isoA (to isoA a))\n> (from (isoBa (from isoA (to isoA a))) (replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b)))\n> s2 = Refl\n> s3 : Element (from isoA (to isoA a))\n> (from (isoBa (from isoA (to isoA a))) (replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b)))\n> =\n> (Element a b)\n> s3 = subsetEqLemma2 {s1 = Element (from isoA (to isoA a))\n> (from (isoBa (from isoA (to isoA a))) (replace (sym (toFrom isoA (to isoA a))) (to (isoBa a) b)))}\n> {s2 = (Element a b)}\n> (fromTo isoA a)\n> (isoReplaceLemma2 isoA isoBa a b)\n> %freeze subsetIsoLemma\n\n\n> ||| |Subset (Fin Z) P| are void\n> voidSubsetFinZ : {P : Fin Z -> Type} -> Iso (Subset (Fin Z) P) Void\n> voidSubsetFinZ = MkIso (\\x => void (uninhabited x))\n> (\\x => void x)\n> (\\x => void x)\n> (\\x => void (uninhabited x))\n> %freeze voidSubsetFinZ\n\n\n> ||| Decomposition lemma\n> subsetEitherLemma : {n : Nat} ->\n> {P : Fin (S n) -> Type} ->\n> Iso (Subset (Fin (S n)) P) (Either (P FZ) (Subset (Fin n) (tail P)))\n> subsetEitherLemma {n} {P} = MkIso to from toFrom fromTo where\n> to : Subset (Fin (S n)) P -> Either (P FZ) (Subset (Fin n) (tail P))\n> to (Element FZ j) = Left j\n> to (Element (FS k) j) = Right (Element k j)\n> from : Either (P FZ) (Subset (Fin n) (tail P)) -> Subset (Fin (S n)) P\n> from (Left j) = (Element FZ j)\n> from (Right (Element k j)) = (Element (FS k) j)\n> toFrom : (e : Either (P FZ) (Subset (Fin n) (tail P))) -> to (from e) = e\n> toFrom (Left j) = Refl\n> toFrom (Right (Element k j)) = Refl\n> fromTo : (s : Subset (Fin (S n)) P) -> from (to s) = s\n> fromTo (Element FZ j) = Refl\n> fromTo (Element (FS k) j) = Refl\n> %freeze subsetEitherLemma\n\n\n> |||\n> subsetFinEitherLemma : {n : Nat} -> {f : Fin (S n) -> Nat} ->\n> Iso\n> (Subset (Fin (S n)) (Fin . f))\n> (Either (Fin (f FZ)) (Subset (Fin n) (Fin . (tail f))))\n> subsetFinEitherLemma {n} {f} =\n> ( Subset (Fin (S n)) (Fin . f) )\n> ={ subsetEitherLemma {n = n} {P = Fin . f} }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (tail (Fin . f))) )\n> -- ={ isoCong {P = \\ X => Either (Fin (f FZ)) (Subset (Fin n) X)} (sym (lambdaLemma1 (tail (Fin . f)))) }=\n> ={ isoRefl }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (\\ k => (tail (Fin . f)) k)) )\n> ={ isoRefl }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (\\ k => (Fin . f) (FS k))) )\n> ={ isoRefl }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (\\ k => Fin (f (FS k)))) )\n> ={ isoRefl }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (\\ k => Fin ((tail f) k))) )\n> ={ isoRefl }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (\\ k => (Fin . (tail f)) k)) )\n> -- ={ isoCong {P = \\ X => Either (Fin (f FZ)) (Subset (Fin n) X)} (lambdaLemma1 (Fin . (tail f))) }=\n> ={ isoRefl }=\n> ( Either (Fin (f FZ)) (Subset (Fin n) (Fin . (tail f))) )\n> QED\n> %freeze subsetFinEitherLemma\n\n\n> ||| |finDepPairTimes| for dependent pairs\n> finDepPairTimes : {n : Nat} -> {f : Fin n -> Nat} ->\n> Iso (Subset (Fin n) (Fin . f))\n> (Fin (sum f))\n> finDepPairTimes {n = Z} {f} =\n> ( Subset (Fin Z) (Fin . f) )\n> ={ voidSubsetFinZ }=\n> ( Void )\n> ={ isoSym finZeroBot }=\n> ( Fin Z )\n> QED\n> finDepPairTimes {n = S m} {f} =\n> ( Subset (Fin (S m)) (Fin . f) )\n> ={ subsetFinEitherLemma }=\n> ( Either (Fin (f FZ)) (Subset (Fin m) (Fin . (tail f))) )\n> ={ eitherCongRight (finDepPairTimes {n = m} {f = tail f}) }=\n> ( Either (Fin (f FZ)) (Fin (sum (tail f))) )\n> ={ eitherFinPlus }=\n> ( Fin (f FZ + sum (tail f)) )\n> ={ isoRefl }=\n> ( Fin (sum f) )\n> QED\n> %freeze finDepPairTimes\n\n\nSubset Exists properties\n\n> |||\n> subsetExistsLemma : {A : Type} -> {P : A -> Type} ->\n> Iso (Subset A P) (Exists P)\n> subsetExistsLemma {A} {P} = MkIso to from toFrom fromTo where\n> to : Subset A P -> Exists P\n> to (Element _ p) = Evidence _ p\n> from : Exists P -> Subset A P\n> from (Evidence _ p) = Element _ p\n> toFrom : (e : Exists P) -> to (from e) = e\n> toFrom (Evidence _ _) = Refl\n> fromTo : (s : Subset A P) -> from (to s) = s\n> fromTo (Element _ _) = Refl\n> %freeze subsetExistsLemma\n\n\nFinitess properties\n\n> ||| For finite predicates, Subset types of finite types are finite\n> finiteSubsetLemma0 : {A : Type} -> {P : A -> Type} ->\n> Finite A -> Finite1 P -> Finite (Subset A P)\n> finiteSubsetLemma0 {A} {P} (MkSigma n isoA) f1P = MkSigma sumf (isoTrans step1 step2)\n> where f' : A -> Nat\n> f' a = card (f1P a)\n> f : Fin n -> Nat\n> f = f' . from isoA\n> sumf : Nat\n> sumf = sum f\n> step1 : Iso (Subset A P) (Subset (Fin n) (Fin . f))\n> step1 = subsetIsoLemma A (Fin n) P (Fin . f) isoA s5 where -- s6 where\n> s1 : (a : A) -> Iso (P a) (Fin (f' a))\n> s1 a = iso (f1P a)\n> s2 : (a : A) -> Iso (P a) (Fin (f' (from isoA (to isoA a))))\n> s2 a = replace {P = \\ x => Iso (P a) (Fin (f' x))} prf (s1 a) where\n> prf : a = from isoA (to isoA a)\n> prf = sym (fromTo isoA a)\n> s3 : (a : A) -> Iso (P a) (Fin ((f' . (from isoA)) (to isoA a)))\n> s3 = s2\n> s4 : (a : A) -> Iso (P a) (Fin (f (to isoA a)))\n> s4 = s3\n> s5 : (a : A) -> Iso (P a) ((Fin . f) (to isoA a))\n> s5 = s4\n> -- s6 : (k : Fin n) -> Iso (P (from isoA k)) ((Fin . f) k)\n> -- s6 k = iso (f1P (from isoA k))\n> step2 : Iso (Subset (Fin n) (Fin . f)) (Fin sumf)\n> step2 = finDepPairTimes {n} {f}\n> %freeze finiteSubsetLemma0\n\n\n> |||\n> finiteExistsLemma : {A : Type} -> {P : A -> Type} ->\n> Finite A -> Finite1 P -> Finite (Exists {a = A} P)\n> finiteExistsLemma {A} {P} fA f1P = MkSigma n iE where\n> fS : Finite (Subset A P)\n> fS = finiteSubsetLemma0 fA f1P\n> n : Nat\n> n = card fS\n> iS : Iso (Subset A P) (Fin n)\n> iS = iso fS\n> iE : Iso (Exists {a = A} P) (Fin n)\n> iE = isoTrans (isoSym (subsetExistsLemma {A} {P})) iS\n> %freeze finiteExistsLemma\n\n\nFinite A ~= (n ** Iso A (Fin n))\nFinite1 P ~= (a : A) -> (na ** Iso (P a) (Fin na))\nFinite (Subset A P) ~= (sum na ** Iso (Subset A P) (Fin (sum na)))\n", "meta": {"hexsha": "8fe23cf6f3b6cbbf5e2fd71a2330eedeccebb644", "size": 19120, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Subset/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": "Subset/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": "Subset/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": 40.9421841542, "max_line_length": 144, "alphanum_fraction": 0.4702405858, "num_tokens": 6206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6450856270077474}} {"text": "data Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\nnoFinZ : Fin Z -> Void\nnoFinZ FZ impossible\nnoFinZ (FS k) impossible\n\nnoFinZ' : Fin Z -> Void\nnoFinZ' x impossible\n\nnoEmpty : Void -> Fin Z\nnoEmpty t impossible\n", "meta": {"hexsha": "58a14811b1cfdb2fc3e638102c88f7a2b7885a64", "size": 240, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/total002/Total.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/total002/Total.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/total002/Total.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.1428571429, "max_line_length": 28, "alphanum_fraction": 0.6333333333, "num_tokens": 83, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6450787992120117}} {"text": "module Sub12LTE108t39\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\n\n%default total\n\n\n-- 6(18t+6)+3 --DB[3,-1,-2]--> 6(2t)+3\nexport\nlte108t39 : (l : Nat) -> LTE (S (plus l l)) (S (S (S ((S ((l+l+l)+(l+l+l))) + (S ((l+l+l)+(l+l+l))) + (S ((l+l+l)+(l+l+l)))))))\nlte108t39 Z = (lteSuccRight . LTESucc) LTEZero\nlte108t39 (S l) =\n let lemma = lte108t39 l in\n rewrite (sym (plusSuccRightSucc l l)) in\n rewrite (sym (plusSuccRightSucc (plus l l) l)) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) (S (S (plus (plus l l) l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) (S (plus (plus l l) l)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) (plus (plus l l) l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l)) (S (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l)) (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l)) (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l)) (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l)) (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (plus (plus (plus l l) l) (plus (plus l l) l))))) in\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "625326d8c8948c4f1d2e73fc92861dfd48f60f49", "size": 3201, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program3/Sub12LTE108t39.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program3/Sub12LTE108t39.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program3/Sub12LTE108t39.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 82.0769230769, "max_line_length": 269, "alphanum_fraction": 0.5791940019, "num_tokens": 1294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6448592211428669}} {"text": "> module SequentialDecisionProblems.TabBackwardsInduction\n\n> import Data.Vect\n> import Control.Isomorphism\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.Utils\n\n> import Nat.Operations\n> import Nat.OperationsProperties\n> import Nat.LTEProperties\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Decidable.Properties\n> import Sigma.Sigma\n> import Sigma.Operations\n> import Pairs.Operations\n> import Vect.Operations\n> import Vect.Properties\n> import Decidable.Predicates\n> import Fin.Operations\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Preliminaries\n\nThe major disadvantage of the generic backwards induction implementation\nof the core theory\n\n< bi : (t : Nat) -> (n : Nat) -> PolicySeq t n\n< bi t Z = Nil\n< bi t (S n) = optExt ps :: ps where\n< ps : PolicySeq (S t) n\n< ps = bi (S t) n\n\nis that its computational cost is exponential in the number of decidion\nsteps. Consider, for example, |bi 0 3|\n\n< bi 0 3\n< = { def. |bi| }\n< (optExt (bi 1 2)) :: (bi 1 2)\n< = { def. |bi| }\n< (optExt ((optExt (bi 2 1)) :: (bi 2 1))) :: (optExt (bi 2 1)) :: (bi 2 1)\n< = { def. |bi| }\n< (optExt ((optExt ((optExt (bi 3 0)) :: (bi 3 0))) :: (optExt (bi 3 0)) :: (bi 3 0))) :: \n< (optExt ((optExt (bi 3 0)) :: (bi 3 0))) :: \n< (optExt (bi 3 0)) :: \n< (bi 3 0)\n< = { def. |bi| }\n< (optExt ((optExt ((optExt Nil) :: Nil)) :: (optExt Nil) :: Nil)) :: \n< (optExt ((optExt Nil) :: Nil)) :: \n< (optExt Nil) :: \n< Nil\n\nresulting in\n\n- 4 computations of |optExt Nil|\n- 2 computations of |optExt ((optExt Nil) :: Nil)|\n- 1 computation of |optExt ((optExt ((optExt Nil) :: Nil)) :: ((optExt Nil) :: Nil))|\n\nor 7 calls to |optExt|. One more decision step implies 15 calls to\n|optExt| suggesting that the number of calls to |optExt| for |n|\ndecision steps is |sum_{i = 0}^{n - 1} 2^j = (1 - 2^n) / (1 - 2)|.\n\n\n* Towards a tail-recursive implementation\n\nWe can make the number of calls to |optExt| linear in |n| by rewriting\n|bi| in tail-recursive form. The first step is to replace the recursive\ncall to |bi| with an iteration. Instead of pattern matching on the\nnumber of steps, we delegate the computation of the policy sequence to\nan auxiliary function |ibi| which implements backwards induction\niteratively:\n\n> ||| Iterative backwards induction\n> ibi : (t : Nat) -> (n : Nat) -> (c : Nat) -> LTE c n ->\n> PolicySeq (n - c + t) c -> PolicySeq t n\n> ibi t n c prf ps with (n - c) proof itsEqual\n> | Z = replace {P = \\ x => PolicySeq (Z + t) x} ceqn\n> ps where\n> ceqn : c = n\n> ceqn = minusLemma3 prf itsEqual\n> | (S m) = assert_total (ibi t n (S c) prf' ps') where\n> prf' : LTE (S c) n\n> prf' = minusLemma2 prf (sym itsEqual)\n> ps' : PolicySeq (n - (S c) + t) (S c)\n> ps' = replace {P = \\ x => PolicySeq (x + t) (S c)} (minusLemma1 (sym itsEqual))\n> ((optExt ps) :: ps)\n\n> ||| Tail-recursive backwardsinduction\n> trbi : (t : Nat) -> (n : Nat) -> PolicySeq t n\n> trbi t n = ibi t n Z LTEZero Nil\n\nWe can check that |trbi 0 3| and |bi 0 3| reduce to the same expression\n\n< trbi 0 3\n< = { def. |trbi| }\n< ibi 0 3 0 LTEZero Nil\n< = { def. |ibi| }\n< ibi 0 3 1 (...) (optExt Nil) :: \n< Nil\n< = {def. |ibi|}\n< ibi 0 3 2 (...) (optExt ((optExt Nil) :: Nil)) :: \n< (optExt Nil) :: \n< Nil\n< = {def. |ibi|}\n< ibi 0 3 3 (...) (optExt ((optExt ((optExt Nil) :: Nil)) :: (optExt Nil) :: Nil)) :: \n< (optExt ((optExt Nil) :: Nil)) :: \n< (optExt Nil) :: \n< Nil\n< = {def. |ibi|}\n< (optExt ((optExt ((optExt Nil) :: Nil)) :: (optExt Nil) :: Nil)) :: \n< (optExt ((optExt Nil) :: Nil)) :: \n< (optExt Nil) :: \n< Nil\n\n\n* Tabulation\n\nIf the state space is finite\n\n> finiteState : (t : Nat) -> Finite (State t)\n\n, we can compute the number of values of type |State t| and collect them\nin a vector\n\n> cardState : (t : Nat) -> Nat\n> cardState t = card (finiteState t)\n\n> vectState : (t : Nat) -> Vect (cardState t) (State t)\n> vectState t = toVect (finiteState t)\n\nIf |Reachable| and |Viable n| are also decidable\n\n> decidableReachable : {t' : Nat} -> (x' : State t') -> Dec (Reachable x')\n\n< decidableViable : {t : Nat} -> (n : Nat) -> (x : State t) -> Dec (Viable n x)\n\nthen their conjunction\n\n> ReachableAndViable : {t : Nat} -> (n : Nat) -> (x : State t) -> Type\n> ReachableAndViable n x = (Reachable x , Viable n x)\n\nis decidable\n\n> decidableReachableAndViable : {t : Nat} -> (n : Nat) -> (x : State t) -> Dec (ReachableAndViable n x)\n> decidableReachableAndViable n x = decPair (decidableReachable x) (decidableViable n x)\n\nand we can collect all states which are reachable and viable in a vector:\n\n> cardReachableAndViableState : (t : Nat) -> (n : Nat) -> Nat\n> cardReachableAndViableState t n = outl (f t n) where\n> f : (t : Nat) -> (n : Nat) -> Sigma Nat (\\ m => Vect m (Sigma (State t) (ReachableAndViable n)))\n> f t n = filterTagSigma (decidableReachableAndViable n) (vectState t)\n\n> vectReachableAndViableState : (t : Nat) -> (n : Nat) -> \n> Vect (cardReachableAndViableState t n) (Sigma (State t) (ReachableAndViable n))\n> vectReachableAndViableState t n = outr (f t n) where\n> f : (t : Nat) -> (n : Nat) -> Sigma Nat (\\ m => Vect m (Sigma (State t) (ReachableAndViable n)))\n> f t n = filterTagSigma (decidableReachableAndViable n) (vectState t)\n\nIn this case, we can implement a \"tabulated\" versions of |bi| which is\nlinear in the number of decidion steps. Remember that |optExt| takes a\npolicy sequence for |n| steps and computes a policy sequence for |n + 1|\nsteps:\n\n< optExt : {t, n : Nat} -> \n< (ps : PolicySeq (S t) n) -> Policy t (S n)\n\nThe idea is to replace the |ps| argument of |optExt| with a \"value\ntable\" |vt : Vect (cardReachableAndViableState t n) Val| storing the\nvalue, for every state in |vectReachableAndViableState (S t) n|, of\ntaking |n| decision steps with |ps| starting from that state:\n\n> toptExt : {t, n : Nat} -> \n> (vt : Vect (cardReachableAndViableState (S t) n) Val) -> Policy t (S n)\n\nWe implement |toptExt| on the basis of the implementation of |optExt|\nof the core theory. We start with a tabulated version of |sval|:\n\n> tsval : {t,n : Nat} -> \n> (x : State t) -> .(r : Reachable x) -> .(v : Viable (S n) x) ->\n> (gy : GoodCtrl t x n) -> \n> (vt : Vect (cardReachableAndViableState (S t) n) Val) ->\n> PossibleNextState x (ctrl gy) -> Val\n> {-\n> tsval {t} {n} x r v gy vt (MkSigma x' x'emx') = reward t x y x' `plus` index k vt where\n> y : Ctrl t x\n> y = ctrl gy\n> mx' : M (State (S t))\n> mx' = nexts t x y\n> ar' : All Reachable mx'\n> ar' = reachableSpec1 x r y\n> av' : All (Viable n) mx'\n> av' = allViable gy\n> r' : Reachable x'\n> r' = allElemSpec0 x' mx' ar' x'emx'\n> v' : Viable n x'\n> v' = allElemSpec0 x' mx' av' x'emx'\n> rvxs : Vect (cardReachableAndViableState (S t) n) (State (S t))\n> rvxs = map outl (vectReachableAndViableState (S t) n)\n> k : Fin (cardReachableAndViableState (S t) n)\n> k = lookup x' rvxs prf' where\n> dRV : (x' : State (S t)) -> Dec (ReachableAndViable n x')\n> dRV = decidableReachableAndViable n\n> prf : Elem x' (vectState (S t))\n> prf = toVectComplete (finiteState (S t)) x'\n> prf' : Elem x' rvxs\n> prf' = filterTagSigmaLemma {P = ReachableAndViable n} dRV x' (vectState (S t)) prf (r',v')\n> -}\n> tsval {t} {n} x r v gy vt (MkSigma x' x'emx') =\n> let y : Ctrl t x\n> = ctrl gy in\n> let mx' : M (State (S t))\n> = nexts t x y in\n> let ar' : All Reachable mx'\n> = reachableSpec1 x r y in\n> let av' : All (Viable n) mx'\n> = allViable gy in\n> let r' : Reachable x'\n> = allElemSpec0 x' mx' ar' x'emx' in\n> let v' : Viable n x'\n> = allElemSpec0 x' mx' av' x'emx' in\n> let rvxs : Vect (cardReachableAndViableState (S t) n) (State (S t))\n> = map outl (vectReachableAndViableState (S t) n) in\n> let dRV : ((x' : State (S t)) -> Dec (ReachableAndViable n x'))\n> = decidableReachableAndViable n in\n> let prf : Elem x' (vectState (S t))\n> = toVectComplete (finiteState (S t)) x' in\n> let prf' : Elem x' rvxs\n> = filterTagSigmaLemma {P = ReachableAndViable n} dRV x' (vectState (S t)) prf (r',v') in\n> let k : Fin (cardReachableAndViableState (S t) n)\n> = lookup x' rvxs prf' in\n> reward t x y x' `plus` index k vt\n\nNext, we implement a tabulated version of |cval|:\n\n> tcval : {t, n : Nat} -> \n> (x : State t) -> .(r : Reachable x) -> .(v : Viable (S n) x) ->\n> (vt : Vect (cardReachableAndViableState (S t) n) Val) -> \n> GoodCtrl t x n -> Val\n> {-\n> tcval {t} x r v vt gy = meas (fmap (tsval x r v gy vt) (tagElem mx')) where\n> y : Ctrl t x\n> y = ctrl gy\n> mx' : M (State (S t))\n> mx' = nexts t x y\n> -}\n> tcval {t} x r v vt gy = let y : Ctrl t x\n> = ctrl gy in\n> let mx' : M (State (S t))\n> = nexts t x y in\n> meas (fmap (tsval x r v gy vt) (tagElem mx'))\n\nAnd finally\n\n> tcvalargmax : {t, n : Nat} -> \n> (x : State t) -> .(r : Reachable x) -> .(v : Viable (S n) x) ->\n> (vt : Vect (cardReachableAndViableState (S t) n) Val) -> GoodCtrl t x n\n\n> toptExt {t} {n} vt = p where\n> p : Policy t (S n)\n> p x r v = tcvalargmax x r v vt\n\n\n* Tabulated tail-recursive backwards induction\n\nWith |toptExt| in place, it is easy to implement a tabulated version of\n|trbi|:\n\n> ||| A table of the result of calling |flip val| (roughly) on a policy sequence\n> ValueTable : Nat -> Nat -> Type\n> ValueTable t n = Vect (cardReachableAndViableState t n) Val\n\n> |||\n> PolicySeqAndTab : Nat -> Nat -> Type\n> PolicySeqAndTab t n = (PolicySeq t n, ValueTable t n)\n\n> |||\n> zeroVec : (n : Nat) -> Vect n Val\n> zeroVec Z = Nil\n> zeroVec (S n) = zero :: zeroVec n\n\n\n> ||| Tabulated tail-recursive backwards induction iteration\n> ttrbii : (t : Nat) -> (n : Nat) -> (c : Nat) -> (LTE c n) ->\n> PolicySeq (c + t) (n - c) ->\n> (vt : Vect (cardReachableAndViableState (c + t) (n - c)) Val) ->\n> PolicySeq t n\n>\n> ttrbii t n Z prf ps vt = replace {P = \\ z => PolicySeq t z} (minusZeroRight n) ps\n>\n> {-\n> ttrbii t n (S c') prf ps vt = ttrbii t n c' prf' ps' vt'' where\n> bic : S (n - S c') = n - c'\n> bic = minusLemma4 prf\n> prf' : LTE c' n\n> prf' = lteLemma1 c' n prf\n> p : Policy (c' + t) (S (n - S c'))\n> p = toptExt vt\n> ps' : PolicySeq (c' + t) (n - c')\n> ps' = replace {P = \\ z => PolicySeq (c' + t) z} bic (p :: ps)\n> vt' : Vect (cardReachableAndViableState (c' + t) (S (n - S c'))) Val\n> vt' = toVect vt'f where\n> vt'f : Fin (cardReachableAndViableState (c' + t) (S (n - S c'))) -> Val\n> vt'f k = tcval x r v vt (p x r v) where\n> xrv : Sigma (State (c' + t)) (ReachableAndViable (S (n - S c')))\n> xrv = index k (vectReachableAndViableState (c' + t) (S (n - S c')))\n> x : State (c' + t)\n> x = outl xrv\n> r : Reachable {t' = c' + t} x\n> r = fst (outr xrv)\n> v : Viable {t = c' + t} (S (n - S c')) x\n> v = snd (outr xrv)\n> vt'' : Vect (cardReachableAndViableState (c' + t) (n - c')) Val\n> vt'' = replace {P = \\z => Vect (cardReachableAndViableState (c' + t) z) Val} bic vt'\n> -}\n> ttrbii t n (S c') prf ps vt = \n> let bic : (S (n - S c') = n - c')\n> = minusLemma4 prf in\n> let prf' : LTE c' n\n> = lteLemma1 c' n prf in\n> let p : Policy (c' + t) (S (n - S c'))\n> = toptExt vt in\n> let ps' : PolicySeq (c' + t) (n - c')\n> = replace {P = \\ z => PolicySeq (c' + t) z} bic (p :: ps) in\n> let xrv -- : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> Sigma (State (c' + t)) (ReachableAndViable (S (n - S c'))))\n> = \\ k => index k (vectReachableAndViableState (c' + t) (S (n - S c'))) in\n> let x : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> State (c' + t))\n> = \\ k => outl (xrv k) in\n> let r : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> Reachable {t' = c' + t} (x k))\n> = \\ k => fst (outr (xrv k)) in\n> let v : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> Viable {t = c' + t} (S (n - S c')) (x k))\n> = \\ k => snd (outr (xrv k)) in\n> let vt'f : (Fin (cardReachableAndViableState (c' + t) (S (n - S c'))) -> Val)\n> = \\ k => tcval (x k) (r k) (v k) vt (p (x k) (r k) (v k)) in\n> let vt' : Vect (cardReachableAndViableState (c' + t) (S (n - S c'))) Val\n> = toVect vt'f in\n> let vt'' : Vect (cardReachableAndViableState (c' + t) (n - c')) Val\n> = replace {P = \\z => Vect (cardReachableAndViableState (c' + t) z) Val} bic vt' in\n> ttrbii t n c' prf' ps' vt'' \n\n\n> ||| Tabulated tail-recursive backwards induction\n> tabTailRecursiveBackwardsInduction : (t : Nat) -> (n : Nat) -> PolicySeq t n\n> tabTailRecursiveBackwardsInduction t n = ttrbii t n n (reflexiveLTE n) zps (zeroVec _) where\n> zps : PolicySeq (n + t) (n - n)\n> zps = replace {P = \\ z => PolicySeq (n + t) z} (minusZeroN n) Nil\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "7cdb1db8c7961e84d46ab45ee4f026d4d7cfdfce", "size": 13389, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/TabBackwardsInduction.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/TabBackwardsInduction.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/TabBackwardsInduction.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": 37.3994413408, "max_line_length": 145, "alphanum_fraction": 0.5610575846, "num_tokens": 4864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6448293282663851}} {"text": "module ShapeExercises\n\nimport Shape\n\narea : Shape -> Double\narea s with (shapeView s)\n area (triangle x y) | STriangle = 0.5 * x * y\n area (rectangle x y) | SRectangle = x * y\n area (circle x) | SCircle = pi * x * x\n", "meta": {"hexsha": "e65d0ed9b280b1f6dbe8aca568cdac82ac9cadde", "size": 229, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch10/shape_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/ch10/shape_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/ch10/shape_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": 22.9, "max_line_length": 49, "alphanum_fraction": 0.615720524, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.6825737344123242, "lm_q1q2_score": 0.6444703234292651}} {"text": "> data 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\n> my_cong : forall f . (x : a) -> (y : a) -> x = y -> f x = f y\n\n> my_curry : ((a, b) -> c) -> a -> b -> c\n\n> my_uncurry : (a -> b -> c) -> (a, b) -> c\n\n> append : Vect n a -> Vect m a -> Vect (n + m) a\n\n> lappend : (1 xs : List a) -> (1 ys : List a) -> List a\n\n> zipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\n\n> data Env : Vect n Type -> Type where\n> ENil : Env []\n> ECons : a -> Env xs -> Env (a :: xs)\n\n> %name Env es\n\n> data Elem : a -> Vect n a -> Type where\n> Here : Elem x (x :: xs)\n> There : (p : Elem x xs) -> Elem x (y :: xs)\n\n> lookup : Elem ty vs -> Env vs -> ty\n", "meta": {"hexsha": "6ea4247886da9c6ca08818e434760bf9c9184082", "size": 741, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/literate003/IEdit.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/literate003/IEdit.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/literate003/IEdit.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": 24.7, "max_line_length": 63, "alphanum_fraction": 0.4480431849, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6443331739281043}} {"text": "module Verified.Algebra.Nat\n\nimport Classes.Verified\n\n%default total\n\nfromAdditive : Additive -> Nat\nfromAdditive (getAdditive n) = n\n\nnatAndAdditive1 : fromAdditive (getAdditive n) = n\nnatAndAdditive1 = Refl\n\nnatAndAdditive2 : getAdditive (fromAdditive n) = n\nnatAndAdditive2 {n=getAdditive n'}= Refl\n\nnatAndAdditiveOp1 : fromAdditive (getAdditive n <+> getAdditive m) = n + m\nnatAndAdditiveOp1 = Refl\n\nnatAndAdditiveOp2 : getAdditive (fromAdditive n + fromAdditive m) = n <+> m\nnatAndAdditiveOp2 {n=getAdditive n'} {m=getAdditive m'} = Refl\n\nfromMultiplicative : Multiplicative -> Nat\nfromMultiplicative (getMultiplicative n) = n\n\nnatAndMultiplicative1 : fromMultiplicative (getMultiplicative n) = n\nnatAndMultiplicative1 = Refl\n\nnatAndMultiplicative2 : getMultiplicative (fromMultiplicative n) = n\nnatAndMultiplicative2 {n=getMultiplicative n'} = Refl\n\nnatAndMultiplicativeOp1 : fromMultiplicative (getMultiplicative n <+> getMultiplicative m) = n * m\nnatAndMultiplicativeOp1 = Refl\n\nnatAndMultiplicativeOp2 : getMultiplicative (fromMultiplicative n * fromMultiplicative m) = n <+> m\nnatAndMultiplicativeOp2 {n=getMultiplicative n'} {m=getMultiplicative m'} = Refl\n\ninstance VerifiedSemigroup Additive where\n semigroupOpIsAssociative (getAdditive l) (getAdditive c) (getAdditive r) =\n ?lemmaAdditiveAssoc\n\ninstance VerifiedMonoid Additive where\n monoidNeutralIsNeutralL (getAdditive l) = ?lemmaAdditiveNeutralL\n monoidNeutralIsNeutralR (getAdditive r) = ?lemmaAdditiveNeutralR\n\ninstance VerifiedSemigroup Multiplicative where\n semigroupOpIsAssociative (getMultiplicative l) (getMultiplicative c) (getMultiplicative r) =\n ?lemmaMultiplicativeAssoc\n\ninstance VerifiedMonoid Multiplicative where\n monoidNeutralIsNeutralL (getMultiplicative l) = ?lemmaMultiplicativeNeutralL\n monoidNeutralIsNeutralR (getMultiplicative r) = ?lemmaMultiplicativeNeutralR\n\n---------- Proofs ----------\n\nVerified.Algebra.Nat.lemmaMultiplicativeNeutralL = proof\n intros\n rewrite multOneRightNeutral l\n exact Refl \n\n\nVerified.Algebra.Nat.lemmaMultiplicativeNeutralR = proof\n intros\n rewrite multOneLeftNeutral r\n exact Refl \n\n\nVerified.Algebra.Nat.lemmaMultiplicativeAssoc = proof\n intros\n rewrite multAssociative l c r\n exact Refl\n\n\nVerified.Algebra.Nat.lemmaAdditiveNeutralL = proof\n intros\n rewrite (plusZeroRightNeutral l)\n exact Refl\n\n\nVerified.Algebra.Nat.lemmaAdditiveNeutralR = proof\n intros\n exact Refl\n\n\nVerified.Algebra.Nat.lemmaAdditiveAssoc = proof\n intros\n rewrite (plusAssociative l c r)\n exact Refl\n\n\n", "meta": {"hexsha": "21986449ac79f1ad02dcc7550e70ccd5d0b22fda", "size": 2523, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Verified/Algebra/Nat.idr", "max_stars_repo_name": "yurrriq/idris-verified", "max_stars_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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/Verified/Algebra/Nat.idr", "max_issues_repo_name": "yurrriq/idris-verified", "max_issues_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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/Verified/Algebra/Nat.idr", "max_forks_repo_name": "yurrriq/idris-verified", "max_forks_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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.0333333333, "max_line_length": 99, "alphanum_fraction": 0.7974633373, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6441033564899944}} {"text": "module xquant.Spinor.BKS\n\nimport Data.Vect\nimport xquant.Spinor.Sigmas\nimport xquant.Spinor.SigKets\n\n%default total\n\n-----------------------------------------------------------------------\n-- Commutation\n-----------------------------------------------------------------------\n\n||| Individual Pauli operators commute iff they are identical up to a phase,\n||| or if one of them is the identity\ndata PauliComm : Pauli -> Pauli -> Type where\n PSame : (p : Pauli) -> PauliComm p p\n PIdRight : (p : Pauli) -> PauliComm p SI\n PIdLeft : (p : Pauli) -> PauliComm SI p\n\n||| Pauli operators do not commute iff they are not identical up to a phase,\n||| and one of them isn't the identity\ndata PauliNonComm : Pauli -> Pauli -> Type where\n NonCommXY : PauliNonComm SX SY\n NonCommYZ : PauliNonComm SY SZ\n NonCommZX : PauliNonComm SZ SX\n NonCommSwap : PauliNonComm q w -> PauliNonComm w q\n\n||| Decide whether two Pauli operators commute or not\ndecCommPauli : (x : Pauli) -> (y : Pauli) -> Either (PauliComm x y) (PauliNonComm x y)\ndecCommPauli SI p = Left $ PIdLeft p\ndecCommPauli p SI = Left $ PIdRight p\ndecCommPauli SX SX = Left $ PSame SX\ndecCommPauli SY SY = Left $ PSame SY\ndecCommPauli SZ SZ = Left $ PSame SZ\ndecCommPauli SX SY = Right $ NonCommXY\ndecCommPauli SY SX = Right $ NonCommSwap NonCommXY\ndecCommPauli SY SZ = Right $ NonCommYZ\ndecCommPauli SZ SY = Right $ NonCommSwap NonCommYZ\ndecCommPauli SZ SX = Right $ NonCommZX\ndecCommPauli SX SZ = Right $ NonCommSwap NonCommZX\n\nmutual\n ||| A pair of commuting Sigma operators is formed by prepending a pair of commuting Paulis\n ||| onto a pair of commuting Sigmas, or by prepending a pair of non-commuting Paulis onto\n ||| a pair of non-commuting Sigmas. Sigmas of level zero (pure numbers) trivially commute.\n data Commuting : Sigma n -> Sigma n -> Type where\n CommPhase : {s1,s2 : Sigma Z} -> Commuting s1 s2\n CommSame : PauliComm j k -> Commuting g h -> Commuting (Sig j g) (Sig k h)\n CommDiff : PauliNonComm j k -> NonCommuting g h -> Commuting (Sig j g) (Sig k h)\n\n ||| A pair of non-commuting Sigma operators is formed by prepending a pair of commuting Paulis\n ||| onto a pair of non-commuting Sigmas, or by prepending a pair of non-commuting Paulis onto\n ||| a pair of commuting Sigmas.\n data NonCommuting : Sigma n -> Sigma n -> Type where\n NoCommSame : PauliNonComm j k -> Commuting g h -> NonCommuting (Sig j g) (Sig k h)\n NoCommDiff : PauliComm j k -> NonCommuting g h -> NonCommuting (Sig j g) (Sig k h)\n\n||| Decide whether two Sigma operators commute or not\ndecComm : (x : Sigma n) -> (y : Sigma n) -> Either (Commuting x y) (NonCommuting x y)\ndecComm (sPhase p1) (sPhase p2) = Left CommPhase\ndecComm (Sig p1 s1) (Sig p2 s2) with (decComm s1 s2)\n decComm (Sig p1 s1) (Sig p2 s2) | commPrf with (decCommPauli p1 p2)\n decComm (Sig p1 s1) (Sig p2 s2) | Left cm | Left cmp = Left $ CommSame cmp cm\n decComm (Sig p1 s1) (Sig p2 s2) | Left cm | Right ncp = Right $ NoCommSame ncp cm\n decComm (Sig p1 s1) (Sig p2 s2) | Right nc | Left cmp = Right $ NoCommDiff cmp nc\n decComm (Sig p1 s1) (Sig p2 s2) | Right nc | Right ncp = Left $ CommDiff ncp nc\n\ncommTest : Vect n (Sigma m) -> Bool\ncommTest [] = True\ncommTest (x :: xs) = all (commute x) xs && (commTest xs)\n\ndata MutuallyCommuting : Vect n (Sigma m) -> Type where\n IsMutuallyCommuting : (v : Vect n $ Sigma m) ->\n commTest v = True ->\n MutuallyCommuting v\n\ndata CommStatus : (x : Sigma n) -> (y : Sigma n) -> Type where\n Status_Comm : Commuting x y -> CommStatus x y\n Status_NoComm : NonCommuting x y -> CommStatus x y\n\n\n-----------------------------------------------------------------------\n-- Even Parity (for each subspace & generator) datatype\n-----------------------------------------------------------------------\n\ndata Parity = Even | Odd\n\ndata PauliParity = PParity Parity Parity Parity\n\nswap : Parity -> Parity\nswap Even = Odd\nswap Odd = Even\n\nupdateP : Pauli -> PauliParity -> PauliParity\nupdateP SX (PParity x y z) = PParity (swap x) y z\nupdateP SY (PParity x y z) = PParity x (swap y) z\nupdateP SZ (PParity x y z) = PParity x y (swap z)\nupdateP SI p = p\n\nupdateParity : Sigma n -> Vect n PauliParity -> Vect n PauliParity\nupdateParity (sPhase ph) [] = []\nupdateParity (Sig pl s) (p::ps) = (updateP pl p) :: (updateParity s ps)\n\n||| Sets of Sigma n operators can be classified by whether each Sigma occurs\n||| an even or odd number of times in each single-qubit Hilbert Space\ndata SigmaParity : Vect n (Sigma m) -> Vect m PauliParity -> Type where\n ParityZero : {m : Nat} -> SigmaParity [] (replicate m $ PParity Even Even Even)\n ParityNext : {v : Vect n (Sigma m)} ->\n (s : Sigma m) ->\n SigmaParity v p ->\n SigmaParity (s::v) (updateParity s p)\n\ndata EvenParity : Vect n (Sigma m) -> Type where\n IsEven : {v : Vect n (Sigma m)} ->\n SigmaParity v (replicate m $ PParity Even Even Even) ->\n EvenParity v\n\nevenParity : (n : Nat) -> Vect n PauliParity\nevenParity n = replicate n $ PParity Even Even Even\n\n\n-----------------------------------------------------------------------\n-- Multiply-to-Negative-Identity datatype\n-----------------------------------------------------------------------\n\ndata NegId : Vect n (Sigma m) -> Type where\n IsNegId : (v : Vect (S n) (Sigma m)) ->\n foldr1 (<>) v = negId m ->\n NegId v\n\n\n-----------------------------------------------------------------------\n-- BKS Theorem datatype\n-----------------------------------------------------------------------\n\ndata BKS : Vect n (Sigma m) -> Type where\n MkBKS : MutuallyCommuting v ->\n NegId v ->\n EvenParity v ->\n BKS v\n\n\n-----------------------------------------------------------------------\n-- 5-qubit BKS proof of David DiVincenzo & Asher Peres\n-----------------------------------------------------------------------\n\nzzzzz : Sigma 5\nzzzzz = sZ <&> sZ <&> sZ <&> sZ <&> sZ\n\nzxIIx : Sigma 5\nzxIIx = sZ <&> sX <&> sI <&> sI <&> sX\n\nxzxII : Sigma 5\nxzxII = sX <&> sZ <&> sX <&> sI <&> sI\n\nIxzxI : Sigma 5\nIxzxI = sI <&> sX <&> sZ <&> sX <&> sI\n\nIIxzx : Sigma 5\nIIxzx = sI <&> sI <&> sX <&> sZ <&> sX\n\nxIIxz : Sigma 5\nxIIxz = sX <&> sI <&> sI <&> sX <&> sZ\n\n\nAsher_David : Vect 6 (Sigma 5)\nAsher_David = [zzzzz,\n zxIIx,\n xzxII,\n IxzxI,\n IIxzx,\n xIIxz]\n\n\nAsher_David_Commuting : MutuallyCommuting Asher_David\nAsher_David_Commuting = IsMutuallyCommuting Asher_David Refl\n\nAsher_David_NegId : NegId Asher_David\nAsher_David_NegId = IsNegId Asher_David Refl\n\nAsher_David_Parity : SigmaParity Asher_David $ evenParity 5\nAsher_David_Parity = ParityNext zzzzz $\n ParityNext zxIIx $\n ParityNext xzxII $\n ParityNext IxzxI $\n ParityNext IIxzx $\n ParityNext xIIxz ParityZero\n\nAsher_David_EvenParity : EvenParity Asher_David\nAsher_David_EvenParity = IsEven Asher_David_Parity\n\nAsher_David_BKS : BKS Asher_David\nAsher_David_BKS = MkBKS Asher_David_Commuting Asher_David_NegId Asher_David_EvenParity\n\n\n-----------------------------------------------------------------------\n-- 4-qubit BKS proof of Aravind-Chryssanthacopoulos-Harvey\n-----------------------------------------------------------------------\n\nxxxx : Sigma 4\nxxxx = sX <&> sX <&> sX <&> sX\n\nxxzz : Sigma 4\nxxzz = sX <&> sX <&> sZ <&> sZ\n\nzxxz : Sigma 4\nzxxz = sZ <&> sX <&> sX <&> sZ\n\nzxzx : Sigma 4\nzxzx = sZ <&> sX <&> sZ <&> sX\n\n\nAravind : Vect 4 (Sigma 4)\nAravind = [xxxx,\n xxzz,\n zxxz,\n zxzx]\n\nAravind_Commuting : MutuallyCommuting Aravind\nAravind_Commuting = IsMutuallyCommuting Aravind Refl\n\nAravind_NegId : NegId Aravind\nAravind_NegId = IsNegId Aravind Refl\n\nAravind_Parity : SigmaParity Aravind $ evenParity 4\nAravind_Parity = ParityNext xxxx $\n ParityNext xxzz $\n ParityNext zxxz $\n ParityNext zxzx ParityZero\n\nAravind_Even_Parity : EvenParity Aravind\nAravind_Even_Parity = IsEven Aravind_Parity\n\nAravind_BKS : BKS Aravind\nAravind_BKS = MkBKS Aravind_Commuting Aravind_NegId Aravind_Even_Parity\n", "meta": {"hexsha": "88e4a5f2766e307cdbf9b79541e94db70b4f2237", "size": 8337, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/xquant/Spinor/BKS.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/Spinor/BKS.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/Spinor/BKS.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.3262711864, "max_line_length": 96, "alphanum_fraction": 0.5818639798, "num_tokens": 2583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6436108182562568}} {"text": "> %default total\n> %auto_implicits off\n\n> X : Type\n> H : Type\n> fulfils : X -> H -> Bool\n\n> LTE : H -> H -> Type\n> LTE h1 h2 = (x : X) -> fulfils x h1 = True -> fulfils x h2 = True\n\n> antisymmetricLTE : (h1 : H) -> (h2 : H) -> h1 `LTE` h2 -> h2 `LTE` h1 -> \n> (x : X) -> fulfils x h1 = fulfils x h2 \n> antisymmetricLTE h1 h2 p q y with (fulfils y h1)\n> | True = ?kika\n> | False = ?kiko\n", "meta": {"hexsha": "27ca0d695ee4aff44dc3ec03a6dc9601bda1e264", "size": 410, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Testing/name_matter.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": "Testing/name_matter.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": "Testing/name_matter.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": 25.625, "max_line_length": 75, "alphanum_fraction": 0.512195122, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.7025300511670689, "lm_q1q2_score": 0.6435945369277567}} {"text": "Symmetric : {c : Type} -> (c -> c -> Type) -> Type\nSymmetric {c} rel = {a : c} -> {b : c} -> rel a b -> rel b a\n\nrecord Symmetry (t : Type) (rel : t -> t -> Type) where\n constructor MkSymmetry\n is_symmetric : Symmetric {c=t} rel\n\nsymmetry : {ty : Type} -> Symmetry ty (=)\nsymmetry = MkSymmetry sym\n\n", "meta": {"hexsha": "ebaefe6997c0da9096670876706e34f5a816a676", "size": 301, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/idris-dev/basic012/basic012a.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/basic012/basic012a.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/basic012/basic012a.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": 27.3636363636, "max_line_length": 60, "alphanum_fraction": 0.584717608, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6433017161290875}} {"text": "data 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 f (value :: xs) = (f value) :: map f xs\n", "meta": {"hexsha": "7167d43a797f46c476ca7d0928c343deaebc89fc", "size": 406, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/InfList.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/InfList.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/InfList.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.0666666667, "max_line_length": 63, "alphanum_fraction": 0.618226601, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.7154240018510025, "lm_q1q2_score": 0.6432530158101348}} {"text": "-- -------------------------------------------------------------- [ Lens.idr ]\n-- Description : Idris port of Control.Lens\n-- Copyright : (c) Huw Campbell\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Control.Lens.Examples\nimport Control.Lens\n\n--\n-- Examples of interactions available with these Lenses\n--\n\nEx1 : Maybe Int\nEx1 = over mapped (+1) (Just 2)\n\nEx1Proof : Ex1 = Just 3\nEx1Proof = Refl\n\nEx2 : (Int, Int)\nEx2 = (2,3) & over both (+1)\n\nEx2Proof : Ex2 = (3, 4)\nEx2Proof = Refl\n\nEx3 : (String, String)\nEx3 = (\"Hello\",2) & _2 .~ \"World!\"\n\nEx3Proof : Ex3 = (\"Hello\",\"World!\")\nEx3Proof = Refl\n\nEx4 : Either String Int\nEx4 = f (Left \"hi\")\n where f : Either String Int -> Either String Int\n f = over _Right (+1)\n\nEx4Proof : Ex4 = (Left \"hi\")\nEx4Proof = Refl\n\nEx5 : Either String Int\nEx5 = f (Right 4)\n where f : Either String Int -> Either String Int\n f = over _Right (+1)\n\nEx5Proof : Ex5 = (Right 5)\nEx5Proof = Refl\n\nEx6 : Either (String, Int) Int\nEx6 = f (Left (\"hi\", 2))\n where f : Either (String,Int) Int -> Either (String,Int) Int\n f = over (_Left . _2) (+1)\n\nEx6Proof : Ex6 = Left (\"hi\", 3)\nEx6Proof = Refl\n\nEx7 : Additive\nEx7 = f (Left (\"hi\", GetAdditive 2)) where\n f : Either (String, Additive) Int -> Additive\n f = view (_Left . _2)\n\nEx7Proof : Ex7 = (GetAdditive 2)\nEx7Proof = Refl\n\nEx8 : Additive\nEx8 = f (Right 2) where\n f : Either (String, Additive) Int -> Additive\n f = view (_Left . _2)\n\nEx8Proof : Ex8 = (GetAdditive 0)\nEx8Proof = Refl\n\nEx9 : Maybe String\nEx9 = g ^? _Right . _1 where\n g : Either String (String, Int)\n g = Right (\"x\",2)\n\nEx9Proof : Ex9 = Just \"x\"\nEx9Proof = Refl\n\nEx10 : Maybe ()\nEx10 = Just \"x\" ^? _Nothing\n\nEx10Proof : Ex10 = Nothing\nEx10Proof = Refl\n\nEx11 : Maybe ()\nEx11 = n ^? _Nothing where\n n : Maybe String\n n = Nothing\n\nEx11Proof : Ex11 = Just ()\nEx11Proof = Refl\n\nEx12 : Int\nEx12 = view (to fst) (1,2)\n\nEx12Proof : Ex12 = 1\nEx12Proof = Refl\n\nEx13 : Either Int String\nEx13 = the (Either Int String) $ _Left # 4\n\nEx13Proof : Ex13 = Left 4\nEx13Proof = Refl\n\nEx14 : Either Int String\nEx14 = the (Either Int String) $ 5 ^.re _Left\n\nEx14Proof : Ex14 = Left 5\nEx14Proof = Refl\n\nsansExample : Maybe Int\nsansExample = sans () (Just 4)\n\nfusingExample : Maybe (Int, Int)\nfusingExample = Just (2,3) & over ( fusing (_Just . both)) (+1)\n\nconfusingExample : Maybe (Int, Int)\nconfusingExample = Just (2,3) & over ( confusing (_Just . both)) (+1)\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "10855e1e61daf23743633a729521b0a6b98d03a8", "size": 2531, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Control/Lens/Examples.idr", "max_stars_repo_name": "andrevidela/idris-lens", "max_stars_repo_head_hexsha": "0f8389baead6fd4344f37a58295b5edf0d76e1fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-06-09T21:43:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-04T11:31:38.000Z", "max_issues_repo_path": "Control/Lens/Examples.idr", "max_issues_repo_name": "andrevidela/idris-lens", "max_issues_repo_head_hexsha": "0f8389baead6fd4344f37a58295b5edf0d76e1fc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-06-03T15:45:49.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-15T22:02:32.000Z", "max_forks_repo_path": "Control/Lens/Examples.idr", "max_forks_repo_name": "andrevidela/idris-lens", "max_forks_repo_head_hexsha": "0f8389baead6fd4344f37a58295b5edf0d76e1fc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-06-03T14:26:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-13T02:09:39.000Z", "avg_line_length": 21.0916666667, "max_line_length": 80, "alphanum_fraction": 0.584749111, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325345, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6431519316566612}} {"text": "import Data.List.Views\n\ntotal\nequalSuffix : Eq a => List a -> List a -> List a\nequalSuffix xs ys with (snocList xs)\n equalSuffix [] ys | Empty = []\n equalSuffix (zs ++ [x]) ys | (Snoc rec) with (snocList ys)\n equalSuffix (xs' ++ [x]) [] | (Snoc rec) | Empty = []\n equalSuffix (xs' ++ [x]) (ys' ++ [y]) | (Snoc rec_xs) | (Snoc rec_ys)\n = if x == y\n then (equalSuffix xs' ys' | rec_xs | rec_ys) ++ [x]\n else []\n", "meta": {"hexsha": "b6492c03712338e3776f367d8e6a2841f53b942f", "size": 436, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/equal_suffix.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/equal_suffix.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/equal_suffix.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": 33.5384615385, "max_line_length": 73, "alphanum_fraction": 0.5504587156, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6430832898372327}} {"text": "module Transversals\n\nimport Group\nimport GroupCosets\nimport GroupCosetRep\n%access public export\n\n--Proof that the definitional equality for Transversal multiplication holds\nMulTransDefPf: (h: Type) -> ((+) : h -> h -> h) -> (pf1: IsGroup h (+)) ->\n (g: Type) -> ((*) : g -> g -> g) -> (pf2: IsGroup g (*)) ->\n (sbgrp: Subgroup h (MkGroup h (+) pf1) g (MkGroup g (*) pf2)) -> (trav: Type) ->\n (pftrav: IsTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav) -> (y: trav) -> (z: trav) ->\n (MulTrans trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) y z) =\n ((DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) (((DPair.fst pftrav) y)*((DPair.fst pftrav) z))) )))\nMulTransDefPf h (+) pf1 g (*) pf2 sbgrp trav pftrav y z = Refl\n\n--Proof that the function from g to trav recovered from CosetAll is in some sense a magma homorphism\nMulTransHomPf: (h: Type) -> ((+) : h -> h -> h) -> (pf1: IsGroup h (+)) ->\n (g: Type) -> ((*) : g -> g -> g) -> (pf2: IsGroup g (*)) ->\n (sbgrp: Subgroup h (MkGroup h (+) pf1) g (MkGroup g (*) pf2)) -> (trav: Type) ->\n (pftrav: IsTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav) -> (y: trav) -> (z: trav) ->\n ((DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) (((DPair.fst pftrav) y)*((DPair.fst pftrav) z))) ))) = (MulTrans trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) ((DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) (((DPair.fst pftrav) y))) ))) ((DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) (((DPair.fst pftrav) z))) ))))\nMulTransHomPf h (+) pf1 g (*) pf2 sbgrp trav pftrav y z = trans (sym (MulTravDefProof)) (trans (cong {f = f1} (sym CorepFInverseY)) (cong {f = f2} (sym CorepFInverseZ))) where\n\n MulTravDefProof: (MulTrans trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) y z) = ((fst (snd ((snd (snd pftrav)) (((fst pftrav) y)*((fst pftrav) z))) )))\n MulTravDefProof = (MulTransDefPf h (+) pf1 g (*) pf2 sbgrp trav pftrav y z )\n\n f1: trav -> trav\n f1 x = MulTrans trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) x z\n\n f2: trav -> trav\n f2 x = MulTrans trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) ((DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) (((DPair.fst pftrav) y) ) )) )) x\n\n CorepFInverseY: (((fst (snd ((snd (snd pftrav)) ((fst pftrav) y) ) )) ) = y)\n CorepFInverseY = CorepFinv trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) y\n\n CorepFInverseZ: (((fst (snd ((snd (snd pftrav)) ((fst pftrav) z) ) )) ) = z)\n CorepFInverseZ = CorepFinv trav (MkTransversal h (MkGroup h (+) pf1) g (MkGroup g (*) pf2) sbgrp trav pftrav) z\n", "meta": {"hexsha": "02aa5af85d882c2be1d1315742ee6f97101b34ae", "size": 2889, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/GroupTransversals.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/GroupTransversals.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/GroupTransversals.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": 74.0769230769, "max_line_length": 392, "alphanum_fraction": 0.5922464521, "num_tokens": 1111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.6992544210587586, "lm_q1q2_score": 0.643064107259774}} {"text": "isSingleton : Bool -> Type\nisSingleton True = Nat\nisSingleton False = List Nat \n\nmkSingle : (x:Bool) -> isSingleton x\nmkSingle True = 0\nmkSingle False = []\n\nsum : (single : Bool) -> isSingleton single -> Nat\nsum True x = x\nsum False [] = 0\nsum False (x::xs) = x + sum False xs\n\n", "meta": {"hexsha": "e4cbed5e26e9c946145fa29abf6352b2aae41066", "size": 278, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "deptype.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": "deptype.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": "deptype.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": 19.8571428571, "max_line_length": 50, "alphanum_fraction": 0.6618705036, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6427077811113262}} {"text": "||| Primitive operations for the Felt data type.\nmodule Primitives.Felt\n\nimport Core.Context\nimport CairoCode.CairoCode\nimport Data.SortedSet\nimport Data.SortedMap\nimport Primitives.Common\nimport CommonDef\nimport CodeGen.CodeGenHelper\n\n\n-- https://github.com/starkware-libs/cairo-lang/blob/cf8266fd5d1ff66962579ff7967ac5cdcf699f77/src/starkware/cairo/lang/cairo_constants.py\n-- 2^251 + 17 * 2^192 + 1\npublic export\nPRIME : Integer\nPRIME = 3618502788666131213697322783095070105623107215331596699973092056135872020481\n\npublic export\nHALF_PRIME : Integer\nHALF_PRIME = PRIME `div` 2\n-- 1809251394333065606848661391547535052811553607665798349986546028067936010240\n\n-- Converts i to an integer in the range (-prime/2, prime/2) which is equivalent to val modulo prime.\n-- https://github.com/starkware-libs/cairo-lang/blob/3d33c4e829a87bc3d88cf04ed6a489e788918b8b/src/starkware/cairo/lang/compiler/expression_simplifier.py#L147\nexport\nintegerToFelt : Integer -> Integer \nintegerToFelt i = (i + HALF_PRIME) `mod` PRIME - HALF_PRIME\n\n-- Extended Euclidian Algorithm\n-- extendedEu a PRIME computes (a^(-1),_)\nextendedEu : Integer -> Integer -> (Integer, Integer)\nextendedEu a 0 = (1, 0)\nextendedEu a b = \n let q = a `div` b\n r = a `mod` b\n (s, t) = extendedEu b r\n in (t, s - q * t)\n\n-- a / b\nexport\nfeltDiv : Integer -> Integer -> Integer\nfeltDiv a b = let (invB, _) = extendedEu b PRIME -- computes b^(-1)\n res = (a * invB) `mod` PRIME\n in integerToFelt res\n\n---------------------------------------------------------------------\n\nfeltBinOp : (op: String) -> CairoReg -> List CairoReg -> LinearImplicitArgs -> PrimFnCode\nfeltBinOp op r [a,b] impls = \n if impls == empty\n then Raw \"\\{ compileRegDecl r } = \\{ compileReg a } \\{op} \\{ compileReg b }\\n\"\n else assert_total $ idris_crash \"no implicits expected for generateCodeBinOp: \\{op}\"\nfeltBinOp op _ _ _ = assert_total $ idris_crash \"Bad arguments to feltBinOp: \\{op}\"\n\n\nexport\n[add_felt] PrimFn where\n eval [_, ConstValue (F 0)] = Just $ ArgValue 0\n eval [ConstValue (F 0), _] = Just $ ArgValue 1\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (a+b)\n eval _ = Nothing\n\n generateCode = feltBinOp \"+\"\n\nexport\n[sub_felt] PrimFn where\n eval [_, ConstValue (F 0)] = Just $ ArgValue 0\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (a-b)\n eval _ = Nothing\n\n generateCode = feltBinOp \"-\"\n\nexport\n[mul_felt] PrimFn where\n eval [_, ConstValue (F 1)] = Just $ ArgValue 0\n eval [ConstValue (F 1), _] = Just $ ArgValue 1\n eval [_, ConstValue (F 0)] = Just $ NewValue $ ConstValue $ F 0\n eval [ConstValue (F 0), _] = Just $ NewValue $ ConstValue $ F 0\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (a*b)\n eval _ = Nothing\n\n generateCode = feltBinOp \"*\"\n\nexport\n[div_felt] PrimFn where\n eval [_, ConstValue (F 0)] = Just $ Failure \"Division by zero is not defined\"\n eval [_, ConstValue (F 1)] = Just $ ArgValue 0\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F (feltDiv a b)\n eval _ = Nothing\n\n generateCode = feltBinOp \"/\"\n\nexport\n[neg_felt] PrimFn where\n eval [ConstValue (F a)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (-a)\n eval _ = Nothing\n\n generateCode r [a] _ = Raw \"\\{ compileRegDecl r } = -\\{ compileReg a }\\n\"\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode neg_felt\"\n\n--Todo: should we even allow this (should we have shifts in general)\nexport\n[shl_felt] PrimFn where\n eval [_, ConstValue(F 0)] = Just $ ArgValue 0\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (prim__shl_Integer (cast a) (cast b))\n eval _ = Nothing\n\n generateCode = generateMissingCodeError \"shl_felt\"\n\n\n--Todo: should we even allow this (should we have shifts in general)\nexport\n[shr_felt] PrimFn where\n eval [_, ConstValue(F 0)] = Just $ ArgValue 0\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (prim__shr_Integer (cast a) (cast b))\n eval _ = Nothing\n\n generateCode = generateMissingCodeError \"shr_felt\"\n\n-- Duplicate of UInt.and_uintX_code\nand_felt_code : CairoReg -> CairoReg -> CairoReg -> CairoReg -> CairoReg -> String\nand_felt_code r bitwise_ptr_in bitwise_ptr_out x y = \"\"\"\n assert [\\{compileReg bitwise_ptr_in}] = \\{compileReg x} \n assert [\\{compileReg bitwise_ptr_in}+1] = \\{compileReg y}\n \\{ compileRegDecl bitwise_ptr_out} = \\{compileReg bitwise_ptr_in} + BitwiseBuiltin.SIZE\n \\{ compileRegDecl r } = [\\{compileReg bitwise_ptr_in}+2]\n\n\"\"\"\nexport\n[and_felt] PrimFn where\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (prim__and_Integer (cast a) (cast b))\n eval _ = Nothing\n\n generateCode res [a,b] implicits = \n case lookup bitwise_builtin implicits of\n Just (bw_in, bw_out) => Raw $ and_felt_code res bw_in bw_out a b\n Nothing => assert_total $ idris_crash \"bitwise_ptr not found\"\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode and_felt\"\n\n\n-- Duplicate of UInt.or_uintX_code\nor_felt_code : CairoReg -> CairoReg -> CairoReg -> CairoReg -> CairoReg -> String\nor_felt_code r bitwise_ptr_in bitwise_ptr_out x y = \"\"\"\n assert [\\{compileReg bitwise_ptr_in}] = \\{compileReg x} \n assert [\\{compileReg bitwise_ptr_in}+1] = \\{compileReg y}\n \\{ compileRegDecl bitwise_ptr_out} = \\{compileReg bitwise_ptr_in} + BitwiseBuiltin.SIZE\n \\{ compileRegDecl r } = [\\{compileReg bitwise_ptr_in}+4]\n\n\"\"\"\n\nexport\n[or_felt] PrimFn where\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a),ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (prim__or_Integer (cast a) (cast b))\n eval _ = Nothing\n\n generateCode res [a,b] implicits = \n case lookup bitwise_builtin implicits of\n Just (bw_in, bw_out) => Raw $ or_felt_code res bw_in bw_out a b\n Nothing => assert_total $ idris_crash \"bitwise_ptr not found\"\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode or_felt_code\"\n\n\n-- Duplicate of UInt.xor_uintX_code\nxor_felt_code : CairoReg -> CairoReg -> CairoReg -> CairoReg -> CairoReg -> String\nxor_felt_code r bitwise_ptr_in bitwise_ptr_out x y = \"\"\"\n assert [\\{compileReg bitwise_ptr_in}] = \\{compileReg x} \n assert [\\{compileReg bitwise_ptr_in}+1] = \\{compileReg y}\n \\{ compileRegDecl bitwise_ptr_out} = \\{compileReg bitwise_ptr_in} + BitwiseBuiltin.SIZE\n \\{ compileRegDecl r } = [\\{compileReg bitwise_ptr_in}+3]\n\n\"\"\"\n\nexport\n[xor_felt] PrimFn where\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ F $ integerToFelt (prim__xor_Integer (cast a) (cast b))\n eval _ = Nothing\n\n generateCode res [a,b] implicits = \n case lookup bitwise_builtin implicits of\n Just (bw_in, bw_out) => Raw $ xor_felt_code res bw_in bw_out a b\n Nothing => assert_total $ idris_crash \"bitwise_ptr not found\"\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode xor_felt\"\n\n\n---------------------------------------------------------------------------------------------------\n-- Felt LT\n---------------------------------------------------------------------------------------------------\nlt_felt_name : Name\nlt_felt_name = makeBuiltinName \"is_lt_felt\"\n\nlt_felt_code : String\nlt_felt_code = \"\"\"\n# Checks if the unsigned integer lift (as a number in the range [0, PRIME)) of a is lower than\n# that of b.\n# See split_felt() for more details.\n# Returns 1 if true, 0 otherwise.\nfunc \\{cairoName lt_felt_name}(range_check_ptr,a, b) -> (res, range_check_ptr):\n %{ memory[ap] = 0 if (ids.a % PRIME) < (ids.b % PRIME) else 1 %}\n jmp not_lt if [ap] != 0; ap++\n assert_lt_felt{range_check_ptr=range_check_ptr}(a, b)\n return (1, range_check_ptr)\n\n not_lt:\n assert_le_felt{range_check_ptr=range_check_ptr}(b, a)\n return (0, range_check_ptr)\nend\n\n\"\"\"\n\n\nexport\n[lt_felt] PrimFn where\n apStable = False\n\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ toInt (a (res, range_check_ptr):\n %{ memory[ap] = 0 if (ids.a % PRIME) <= (ids.b % PRIME) else 1 %}\n jmp not_le if [ap] != 0; ap++\n assert_le_felt{range_check_ptr=range_check_ptr}(a, b)\n return (1, range_check_ptr)\n\n not_le:\n assert_lt_felt{range_check_ptr=range_check_ptr}(b, a)\n return (0, range_check_ptr)\n end\n\n\"\"\"\n\nexport\n[lte_felt] PrimFn where\n apStable = False\n\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ toInt (a<=b)\n eval _ = Nothing\n\n imports = fromList [\n MkImport \"starkware.cairo.common.math_cmp\" \"assert_lt_felt\",\n MkImport \"starkware.cairo.common.math_cmp\" \"assert_le_felt\"]\n implicits = singleton range_check_builtin\n dependencies = fromList [(lte_felt_name, ForeignDef (MkForeignInfo True Nothing [range_check_builtin] empty lte_felt_code) 2 1)]\n generateCode res args implicits = Instructions [CALL [res] implicits lte_felt_name args]\n\n\n---------------------------------------------------------------------------------------------------\n-- Felt EQ\n---------------------------------------------------------------------------------------------------\nexport\n[eq_felt] PrimFn where\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ toInt (a==b)\n eval _ = Nothing\n\n generateCode r a i = Raw $ compileEqOp \"eq_felt\" r a i\n\n---------------------------------------------------------------------------------------------------\n-- Felt GTE \n-- Implementation uses flipped arguments to lte\n---------------------------------------------------------------------------------------------------\nexport\n[gte_felt] PrimFn where\n apStable = False\n\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ toInt (a>=b)\n eval _ = Nothing\n\n imports = fromList [\n MkImport \"starkware.cairo.common.math_cmp\" \"assert_lt_felt\",\n MkImport \"starkware.cairo.common.math_cmp\" \"assert_le_felt\"]\n implicits = singleton range_check_builtin\n dependencies = fromList [(lte_felt_name, ForeignDef (MkForeignInfo True Nothing [range_check_builtin] empty lte_felt_code) 2 1)]\n generateCode res [a,b] implicits = Instructions [CALL [res] implicits lte_felt_name [b,a]] -- Flipped arguments\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode gte_felt\"\n\n\n---------------------------------------------------------------------------------------------------\n-- Felt GT\n-- Implementation uses flipped arguments to lt\n---------------------------------------------------------------------------------------------------\nexport\n[gt_felt] PrimFn where\n apStable = False\n\n -- Todo: Just an incorrect quick hack add real felt impl in idris2\n eval [ConstValue (F a), ConstValue (F b)] = Just $ NewValue $ ConstValue $ toInt (a>b)\n eval _ = Nothing\n\n imports = fromList [\n MkImport \"starkware.cairo.common.math_cmp\" \"assert_lt_felt\",\n MkImport \"starkware.cairo.common.math_cmp\" \"assert_le_felt\"]\n implicits = singleton range_check_builtin\n dependencies = fromList [(lt_felt_name, ForeignDef (MkForeignInfo True Nothing [range_check_builtin] empty lt_felt_code) 2 1)]\n generateCode res [a,b] implicits = Instructions [CALL [res] implicits lt_felt_name [b,a]] -- Flipped arguments\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode gt_felt\"\n\n-- Todo: How to treat Integers which are larger or smaller than Felt\nexport\n[cast_to_felt] PrimFn where\n eval [ConstValue c] = map (\\i => NewValue $ ConstValue $ F $ integerToFelt i) (constToInteger c)\n eval _ = Nothing\n\n generateCode r [a] _ = Raw \"\\{ compileRegDecl r } = \\{ compileReg a } #Cast to felt\\n\"\n generateCode _ _ _ = assert_total $ idris_crash \"Bad arguments to generateCode cast_to_felt\"\n", "meta": {"hexsha": "7c656ba2c53683bc53faa049af356cdc59e5a0ce", "size": 13623, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Primitives/Felt.idr", "max_stars_repo_name": "skyro-compiler/skyro", "max_stars_repo_head_hexsha": "9ae15463ff46d8b6a3cd3ec8061ba81174614cf0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2022-03-10T13:35:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T13:05:54.000Z", "max_issues_repo_path": "src/Primitives/Felt.idr", "max_issues_repo_name": "skyro-compiler/skyro", "max_issues_repo_head_hexsha": "9ae15463ff46d8b6a3cd3ec8061ba81174614cf0", "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/Primitives/Felt.idr", "max_forks_repo_name": "skyro-compiler/skyro", "max_forks_repo_head_hexsha": "9ae15463ff46d8b6a3cd3ec8061ba81174614cf0", "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.1570996979, "max_line_length": 157, "alphanum_fraction": 0.6425163327, "num_tokens": 3747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6423769353325652}} {"text": "module Main\n\nfactorial : Nat -> Nat\nfactorial Z = 1\nfactorial x@(S k) = x * factorial k\n\nmain : IO ()\nmain =\n for_ [0..9] $ \\i =>\n putStrLn $ show i <+> \"! = \" <+> show (factorial i)\n", "meta": {"hexsha": "15c072941a47ec452fc3bd2874e1009c4a80fbd0", "size": 187, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "code/factorial.idr", "max_stars_repo_name": "pharpend/artint", "max_stars_repo_head_hexsha": "3e74e3978d6b6d6178f8722644250ede33b99be4", "max_stars_repo_licenses": ["CC-BY-4.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": "code/factorial.idr", "max_issues_repo_name": "pharpend/artint", "max_issues_repo_head_hexsha": "3e74e3978d6b6d6178f8722644250ede33b99be4", "max_issues_repo_licenses": ["CC-BY-4.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": "code/factorial.idr", "max_forks_repo_name": "pharpend/artint", "max_forks_repo_head_hexsha": "3e74e3978d6b6d6178f8722644250ede33b99be4", "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": 17.0, "max_line_length": 55, "alphanum_fraction": 0.550802139, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6422513770462507}} {"text": "module Main\n\nsum : Nat -> Nat\nsum n = go 0 n where\n go : Nat -> Nat -> Nat\n go acc Z = acc\n go acc n@(S k) = go (acc + n) k\n\nmain : IO ()\nmain = printLn (sum 50000)\n", "meta": {"hexsha": "784518e84c0fb4ee79535bd2f48f10a8644a0363", "size": 168, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-jvm-integration-test/src/test/idris/tailrec/tailrec.idr", "max_stars_repo_name": "gzoom13/idris-jvm", "max_stars_repo_head_hexsha": "3f63d279231c3d137fab3c311888c77935faad4a", "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": "idris-jvm-integration-test/src/test/idris/tailrec/tailrec.idr", "max_issues_repo_name": "gzoom13/idris-jvm", "max_issues_repo_head_hexsha": "3f63d279231c3d137fab3c311888c77935faad4a", "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": "idris-jvm-integration-test/src/test/idris/tailrec/tailrec.idr", "max_forks_repo_name": "gzoom13/idris-jvm", "max_forks_repo_head_hexsha": "3f63d279231c3d137fab3c311888c77935faad4a", "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": 15.2727272727, "max_line_length": 33, "alphanum_fraction": 0.5476190476, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6420822317287098}} {"text": "> module Pair.Properties\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n> pairLemma : {A, B : Type} -> (ab : (A, B)) -> ab = (fst ab, snd ab)\n> pairLemma (a, b) = Refl\n\n> pairEqElimFst : {A, B : Type} -> {a, a' : A} -> {b, b' : B} -> (a, b) = (a', b') -> a = a' \n> pairEqElimFst Refl = Refl\n\n> pairEqElimSnd : {A, B : Type} -> {a, a' : A} -> {b, b' : B} -> (a, b) = (a', b') -> b = b' \n> pairEqElimSnd Refl = Refl\n", "meta": {"hexsha": "52013349c071482ecadf9b00045121a992d11eef", "size": 433, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Pair/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": "Pair/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": "Pair/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": 27.0625, "max_line_length": 93, "alphanum_fraction": 0.5011547344, "num_tokens": 190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.641967941545116}} {"text": "module Main\n\ntarai : Int -> Int -> Int -> Int\ntarai x y z = if x <= y\n\tthen y\n\telse tarai (tarai (x - 1) y z) (tarai (y - 1) z x) (tarai (z - 1) x y)\n\nmain : JS_IO ()\nmain = do\n\tputStr' $ show (tarai 11 5 0)\n", "meta": {"hexsha": "9e8284f7625b13eb30b74dd96bb3eda996e7d550", "size": 208, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/tarai.idr", "max_stars_repo_name": "be5invis/idris-codegen-es", "max_stars_repo_head_hexsha": "d36d095d7409ee1c8fcc53bdcdd4cd4b28b868a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2017-04-28T12:10:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T05:05:27.000Z", "max_issues_repo_path": "tests/tarai.idr", "max_issues_repo_name": "be5invis/idris-codegen-js", "max_issues_repo_head_hexsha": "d36d095d7409ee1c8fcc53bdcdd4cd4b28b868a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-07-30T02:42:03.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-07T14:04:25.000Z", "max_forks_repo_path": "tests/tarai.idr", "max_forks_repo_name": "be5invis/idris-codegen-js", "max_forks_repo_head_hexsha": "d36d095d7409ee1c8fcc53bdcdd4cd4b28b868a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-05-02T08:31:10.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-12T12:48:41.000Z", "avg_line_length": 18.9090909091, "max_line_length": 71, "alphanum_fraction": 0.5480769231, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.72487026428967, "lm_q1q2_score": 0.6419679248660676}} {"text": "module Verified.Applicative.Vect\n\nimport Data.Vect\nimport Verified.Applicative\nimport Verified.Functor\nimport Verified.Functor.Vect\n\n\napplicativeMap_Vect : (vs : Vect n a) -> (g : a -> b) -> map g vs = pure g <*> vs\napplicativeMap_Vect [] g = Refl\napplicativeMap_Vect (v :: vs) g = rewrite (applicativeMap_Vect vs g) in Refl\n\n\napplicativeIdentity_Vect : (vs : Vect n a) -> pure id <*> vs = vs\napplicativeIdentity_Vect [] = Refl\napplicativeIdentity_Vect (x :: xs) = rewrite (applicativeIdentity_Vect xs) in Refl\n\n\napplicativeInterchange_Vect : (x : a) -> (g : Vect n (a -> b)) -> g <*> pure x = pure (\\g' => g' x) <*> g\napplicativeInterchange_Vect x [] = Refl\napplicativeInterchange_Vect x (f :: fs) = rewrite (applicativeInterchange_Vect x fs) in Refl\n\n\napplicativeComposition_Vect : (xs : Vect n a) -> (g1 : Vect n (a -> b)) -> (g2 : Vect n (b -> c))\n -> pure (.) <*> g2 <*> g1 <*> xs = g2 <*> (g1 <*> xs)\napplicativeComposition_Vect [] [] [] = Refl\napplicativeComposition_Vect (v :: vs) (g1 :: g1s) (g2 :: g2s) = rewrite (applicativeComposition_Vect vs g1s g2s) in Refl\n\n\napplicativeHomomorphism_Vect : {n : Nat} -> (x : a) -> (g : a -> b)\n -- pure g <*> pure x = pure (g x)\n -> Vect.zipWith apply (Vect.replicate n g) (Vect.replicate n x) = Vect.replicate n (g x)\napplicativeHomomorphism_Vect {n = Z } x g = Refl\napplicativeHomomorphism_Vect {n = (S k)} x g = rewrite (applicativeHomomorphism_Vect x g {n=k}) in Refl\n\n\ninstance VerifiedApplicative (Vect vlen) where\n applicativeMap = applicativeMap_Vect\n applicativeIdentity = applicativeIdentity_Vect\n applicativeInterchange = applicativeInterchange_Vect\n applicativeComposition = applicativeComposition_Vect\n applicativeHomomorphism = applicativeHomomorphism_Vect\n\n", "meta": {"hexsha": "33fabe1ec0dae638f814114635b41082a3317970", "size": 1854, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Verified/Applicative/Vect.idr", "max_stars_repo_name": "yurrriq/idris-verified", "max_stars_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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/Verified/Applicative/Vect.idr", "max_issues_repo_name": "yurrriq/idris-verified", "max_issues_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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/Verified/Applicative/Vect.idr", "max_forks_repo_name": "yurrriq/idris-verified", "max_forks_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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.1363636364, "max_line_length": 120, "alphanum_fraction": 0.6548004315, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6419271259392787}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 4\n\n-- check that all functions are total\n%default total\n\n--\n-- Expressions\n--\n\n||| An integer arithmetic expression\ndata Expr = ||| A single integer\n Value Int\n | ||| Addition of an expression to an expression\n Addition Expr Expr\n | ||| Subtraction of an expression from an expression\n Subtraction Expr Expr\n | ||| Multiplication of an expression with an expression\n Multiplication Expr Expr\n\n||| Evaluate an expression\nevaluate : Expr -> Int\nevaluate (Value x) = x\nevaluate (Addition x y) = evaluate x + evaluate y\nevaluate (Subtraction x y) = evaluate x - evaluate y\nevaluate (Multiplication x y) = evaluate x * evaluate y\n", "meta": {"hexsha": "0fb3b8bc7fd8183eea2215ff5814d1fc7bda7faa", "size": 760, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter4/Expr.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/Expr.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/Expr.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": 28.1481481481, "max_line_length": 66, "alphanum_fraction": 0.6644736842, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6417576555182022}} {"text": "module Decidable.Equality\n\nimport Data.Maybe\nimport Data.Either\nimport Data.Nat\nimport Data.List\nimport Data.List1\n\nimport public Decidable.Equality.Core as Decidable.Equality\n\n%default total\n\n--------------------------------------------------------------------------------\n--- Unit\n--------------------------------------------------------------------------------\n\npublic export\nDecEq () where\n decEq () () = Yes Refl\n\n--------------------------------------------------------------------------------\n-- Booleans\n--------------------------------------------------------------------------------\n\npublic export\nDecEq Bool where\n decEq True True = Yes Refl\n decEq False False = Yes Refl\n decEq False True = No absurd\n decEq True False = No absurd\n\n--------------------------------------------------------------------------------\n-- Nat\n--------------------------------------------------------------------------------\n\npublic export\nDecEq Nat where\n decEq Z Z = Yes Refl\n decEq Z (S _) = No absurd\n decEq (S _) Z = No absurd\n decEq (S n) (S m) with (decEq n m)\n decEq (S n) (S m) | Yes p = Yes $ cong S p\n decEq (S n) (S m) | No p = No $ \\h : (S n = S m) => p $ succInjective n m h\n\n--------------------------------------------------------------------------------\n-- Maybe\n--------------------------------------------------------------------------------\n\npublic export\nDecEq t => DecEq (Maybe t) where\n decEq Nothing Nothing = Yes Refl\n decEq Nothing (Just _) = No absurd\n decEq (Just _) Nothing = No absurd\n decEq (Just x') (Just y') with (decEq x' y')\n decEq (Just x') (Just y') | Yes p = Yes $ cong Just p\n decEq (Just x') (Just y') | No p\n = No $ \\h : Just x' = Just y' => p $ justInjective h\n\n--------------------------------------------------------------------------------\n-- Either\n--------------------------------------------------------------------------------\n\npublic export\n(DecEq t, DecEq s) => DecEq (Either t s) where\n decEq (Left x) (Left y) with (decEq x y)\n decEq (Left x) (Left x) | Yes Refl = Yes Refl\n decEq (Left x) (Left y) | No contra = No (contra . leftInjective)\n decEq (Left x) (Right y) = No absurd\n decEq (Right x) (Left y) = No absurd\n decEq (Right x) (Right y) with (decEq x y)\n decEq (Right x) (Right x) | Yes Refl = Yes Refl\n decEq (Right x) (Right y) | No contra = No (contra . rightInjective)\n\n--------------------------------------------------------------------------------\n-- Tuple\n--------------------------------------------------------------------------------\n\npairInjective : (a, b) = (c, d) -> (a = c, b = d)\npairInjective Refl = (Refl, Refl)\n\npublic export\n(DecEq a, DecEq b) => DecEq (a, b) where\n decEq (a, b) (a', b') with (decEq a a')\n decEq (a, b) (a', b') | (No contra) =\n No $ contra . fst . pairInjective\n decEq (a, b) (a, b') | (Yes Refl) with (decEq b b')\n decEq (a, b) (a, b) | (Yes Refl) | (Yes Refl) = Yes Refl\n decEq (a, b) (a, b') | (Yes Refl) | (No contra) =\n No $ contra . snd . pairInjective\n\n--------------------------------------------------------------------------------\n-- List\n--------------------------------------------------------------------------------\n\npublic export\nDecEq a => DecEq (List a) where\n decEq [] [] = Yes Refl\n decEq (x :: xs) [] = No absurd\n decEq [] (x :: xs) = No absurd\n decEq (x :: xs) (y :: ys) with (decEq x y)\n decEq (x :: xs) (y :: ys) | No contra =\n No $ contra . fst . consInjective\n decEq (x :: xs) (x :: ys) | Yes Refl with (decEq xs ys)\n decEq (x :: xs) (x :: xs) | (Yes Refl) | (Yes Refl) = Yes Refl\n decEq (x :: xs) (x :: ys) | (Yes Refl) | (No contra) =\n No $ contra . snd . consInjective\n\n\n--------------------------------------------------------------------------------\n-- List1\n--------------------------------------------------------------------------------\n\npublic export\nDecEq a => DecEq (List1 a) where\n\n decEq (x ::: xs) (y ::: ys) with (decEq x y)\n decEq (x ::: xs) (y ::: ys) | No contra = No (contra . fst . consInjective)\n decEq (x ::: xs) (y ::: ys) | Yes eqxy with (decEq xs ys)\n decEq (x ::: xs) (y ::: ys) | Yes eqxy | No contra = No (contra . snd . consInjective)\n decEq (x ::: xs) (y ::: ys) | Yes eqxy | Yes eqxsys = Yes (cong2 (:::) eqxy eqxsys)\n\n-- TODO: Other prelude data types\n\n-- For the primitives, we have to cheat because we don't have access to their\n-- internal implementations. We use believe_me for the inequality proofs\n-- because we don't them to reduce (and they should never be needed anyway...)\n-- A postulate would be better, but erasure analysis may think they're needed\n-- for computation in a higher order setting.\n\n\n--------------------------------------------------------------------------------\n-- Int\n--------------------------------------------------------------------------------\npublic export\nimplementation DecEq Int where\n decEq x y = case x == y of -- Blocks if x or y not concrete\n True => Yes primitiveEq\n False => No primitiveNotEq\n where primitiveEq : forall x, y . x = y\n primitiveEq = believe_me (Refl {x})\n primitiveNotEq : forall x, y . Not (x = y)\n primitiveNotEq prf = believe_me {b = Void} ()\n\n--------------------------------------------------------------------------------\n-- Char\n--------------------------------------------------------------------------------\npublic export\nimplementation DecEq Char where\n decEq x y = case x == y of -- Blocks if x or y not concrete\n True => Yes primitiveEq\n False => No primitiveNotEq\n where primitiveEq : forall x, y . x = y\n primitiveEq = believe_me (Refl {x})\n primitiveNotEq : forall x, y . Not (x = y)\n primitiveNotEq prf = believe_me {b = Void} ()\n\n--------------------------------------------------------------------------------\n-- Integer\n--------------------------------------------------------------------------------\npublic export\nimplementation DecEq Integer where\n decEq x y = case x == y of -- Blocks if x or y not concrete\n True => Yes primitiveEq\n False => No primitiveNotEq\n where primitiveEq : forall x, y . x = y\n primitiveEq = believe_me (Refl {x})\n primitiveNotEq : forall x, y . Not (x = y)\n primitiveNotEq prf = believe_me {b = Void} ()\n\n--------------------------------------------------------------------------------\n-- String\n--------------------------------------------------------------------------------\npublic export\nimplementation DecEq String where\n decEq x y = case x == y of -- Blocks if x or y not concrete\n True => Yes primitiveEq\n False => No primitiveNotEq\n where primitiveEq : forall x, y . x = y\n primitiveEq = believe_me (Refl {x})\n primitiveNotEq : forall x, y . Not (x = y)\n primitiveNotEq prf = believe_me {b = Void} ()\n", "meta": {"hexsha": "2376aa7fcf36783e317218f1be68078b874aa351", "size": 7040, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Decidable/Equality.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/Decidable/Equality.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/Decidable/Equality.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": 38.6813186813, "max_line_length": 92, "alphanum_fraction": 0.4210227273, "num_tokens": 1651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6416559674334925}} {"text": "module Rationals\n\nimport ZZ\n\n%access public export\n\nPair : Type\nPair = (Integer, Integer)\n\nZZPair : Type\nZZPair = (ZZ, ZZ)\n\nZZtoDb : ZZ -> Double\nZZtoDb x = cast{from=Integer}{to=Double} (cast{from=ZZ}{to=Integer} x)\n\nDbtoZZ : Double -> ZZ\nDbtoZZ x = cast{from=Integer}{to=ZZ} (cast{from=Double}{to=Integer} x)\n\napZZ : (f: ZZ -> ZZ) -> (n: ZZ) -> (m: ZZ) -> n = m -> f n = f m\napZZ f m m Refl = Refl\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\n--Integer implemetation of gcd\nCalcGCD : (Integer, Integer) -> Integer\nCalcGCD (a, b) = if (isNotZero (toNat b)) then next else a where\n next = CalcGCD (b, toIntegerNat (modNat (toNat a) (toNat b)))\n\nOnlyPositive : (x: Pair) -> Pair\nOnlyPositive x = (if (fst x)>0 then fst x else (-1)*(fst x), if(snd x)>0 then (snd x) else (-1)*(snd x))\n\n--Integer implemetation of gcd\ngccd : (Integer, Integer) -> Integer\ngccd x = CalcGCD (OnlyPositive x)\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\ndata ZZNotZero : ZZ -> Type where\n ZZOneNotZero : ZZNotZero 1\n ZZNegativeNotZero : ( n: ZZ ) -> ZZNotZero n -> ZZNotZero (-n)\n ZZPositiveNotZero : ( m: ZZ ) -> LTE 1 (fromIntegerNat (cast(m))) -> ZZNotZero m\n\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: ZZPair) -> ZZNotZero (snd x) -> (y: ZZPair) -> ZZNotZero (snd y) -> ZZPair\nAddRationals x a y b = ((fst x)*(snd y) + (snd x)*(fst y), (snd x)*(snd y))\n\nMultiplyRationals : (x: ZZPair) -> ZZNotZero (snd x) -> (y: ZZPair) -> ZZNotZero (snd y) -> ZZPair\nMultiplyRationals x a y b =((fst x)*(fst y), (snd x)*(snd y))\n\nMultInverse : (x: ZZPair) -> ZZNotZero (fst x) -> ZZNotZero (snd x) -> ZZPair\nMultInverse x y z = ((snd x), (fst x))\n\nAddInverse : (x: ZZPair) -> ZZNotZero (snd x) -> ZZPair\nAddInverse x a = (-(fst x), (snd x))\n\nSubtraction : (x: ZZPair) -> ZZNotZero (snd x) -> (y: ZZPair) -> ZZNotZero (snd y) -> ZZPair\nSubtraction x a y b = AddRationals x a (AddInverse y b) b\n\nDivision : (x: ZZPair) -> ZZNotZero (snd x) -> (y: ZZPair) -> ZZNotZero (fst y) -> ZZNotZero (snd y) -> ZZPair\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\n\nsimplifyRational : (x : ZZPair) -> ZZPair\nsimplifyRational (a, b) = (sa, sb) where\n sa = DbtoZZ (da / g) where\n da = ZZtoDb a\n g = cast {from=Integer} {to=Double}\n (gccd (cast {from=ZZ} {to=Integer}a,cast {from=ZZ} {to=Integer}b))\n sb = DbtoZZ (db / g) where\n db = ZZtoDb b\n g = cast {from=Integer} {to=Double}\n (gccd (cast {from=ZZ} {to=Integer}a,cast {from=ZZ} {to=Integer}b))\n\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\nxAndInverseNotZero : (x: ZZPair) -> (k: ZZNotZero (snd x)) -> ZZNotZero (snd (AddInverse x k))\nxAndInverseNotZero x (ZZPositiveNotZero (snd x) y) = (ZZPositiveNotZero (snd x) y)\n\nFirstIsInverted : (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (a: ZZ) -> (a = (fst x)) -> ((-a) = fst (AddInverse x k))\nFirstIsInverted x k a prf = (apZZ (\\x => -x) a (fst x) prf)\n\nSecondStaysSame : (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (b: ZZ) -> (b = (snd x)) -> (b = (snd (AddInverse x k)))\nSecondStaysSame x k b prf = (apZZ (\\x => x) b (snd x) prf)\n\nxplusinverse: (x: ZZPair) -> (k: ZZNotZero (snd x)) -> ZZPair\nxplusinverse x k = AddRationals x k (AddInverse x k) (xAndInverseNotZero x k)\n\naddinverselemma: (a: ZZ) -> (b: ZZ) -> ((-a)=b) -> (a + b = ((-a) + a)) -> ((-a)+a =0 ) -> (a + b = 0)\naddinverselemma a b prf prf1 prf2 = trans prf1 prf2\n\naddinverseFST: (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (a: ZZ) -> (a = (fst x)) -> (fst (AddInverse x k) = b) -> ((-a) = b)\naddinverseFST x k a prf prf1 = trans (FirstIsInverted x k a prf) (prf1)\n\naddinverseSND: (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (c: ZZ) -> (c = (snd x)) -> (snd (AddInverse x k) = b) -> (c = b)\naddinverseSND x k c prf prf1 = trans (SecondStaysSame x k c prf) (prf1)\n", "meta": {"hexsha": "bbd6d8456b51f5d43318277562d176d8e997617c", "size": 5028, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/Rationals.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/Rationals.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/Rationals.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": 40.5483870968, "max_line_length": 177, "alphanum_fraction": 0.6304693715, "num_tokens": 1834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6413863077436631}} {"text": "module Sub13LTE108t75\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\n\n%default total\n\n\n-- 6(18t+12)+3 --AB[6,-3,-2]--> 6(4t+1)+3\nexport\nlte108t75 : (l : Nat) -> LTE (S (S (plus (plus l l) (plus l l)))) (S (S (S ((S ((S (l+l+l))+(S (l+l+l)))) + (S ((S (l+l+l))+(S (l+l+l)))) + (S ((S (l+l+l))+(S (l+l+l))))))))\nlte108t75 Z = (lteSuccRight . LTESucc . LTESucc) LTEZero\nlte108t75 (S l) =\n let lemma = lte108t75 l in\n rewrite (sym (plusSuccRightSucc l l)) in\n rewrite (sym (plusSuccRightSucc (plus l l) l)) in\n\n rewrite (sym (plusSuccRightSucc (plus l l) (S (plus l l)))) in\n rewrite (sym (plusSuccRightSucc (plus l l) (plus l l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) (S (S (S (plus (plus l l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) (S (S (plus (plus l l) l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) (S (plus (plus l l) l)))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (S (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l))))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))) (S (S (S (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))) (S (S (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l))))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))) (S (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))) (S (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))) (S (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (S (plus (plus l l) l))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l)))))) (S (S (plus (plus (plus l l) l) (S (plus (plus l l) l))))))) in\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "df9820e3e0e6a0ea2f59d60f0b96dc0a96e72d80", "size": 3584, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program3/Sub13LTE108t75.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program3/Sub13LTE108t75.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program3/Sub13LTE108t75.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 85.3333333333, "max_line_length": 259, "alphanum_fraction": 0.5591517857, "num_tokens": 1482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6412889202888916}} {"text": "= Basics\n\n**REMINDER**:\n\n #####################################################\n ### PLEASE DO NOT DISTRIBUTE SOLUTIONS PUBLICLY ###\n #####################################################\n\n (See the Preface for why.)\n\n> ||| Basics: Functional Programming in Idris\n> module Basics\n>\n> %access public export\n>\n\n\\idr{postulate} is Idris's \"escape hatch\" that says accept this definition\nwithout proof. Instead of using it to mark the holes, similar to Coq's\n\\mintinline[]{Coq}{Admitted}, we use Idris's holes directly. In practice, holes\n(and \\idr{postulate}) are useful when you're incrementally developing large\nproofs.\n\n\n== Introduction\n\nThe functional programming style brings programming closer to simple, everyday\nmathematics: If a procedure or method has no side effects, then (ignoring\nefficiency) all we need to understand about it is how it maps inputs to outputs\n-- that is, we can think of it as just a concrete method for computing a\nmathematical function. This is one sense of the word \"functional\" in \"functional\nprogramming.\" The direct connection between programs and simple mathematical\nobjects supports both formal correctness proofs and sound informal reasoning\nabout program behavior.\n\nThe other sense in which functional programming is \"functional\" is that it\nemphasizes the use of functions (or methods) as \\gls{first-class} values --\ni.e., values that can be passed as arguments to other functions, returned as\nresults, included in data structures, etc. The recognition that functions can be\ntreated as data in this way enables a host of useful and powerful idioms.\n\nOther common features of functional languages include \\glspl{algebraic data\ntype} and \\gls{pattern matching}, which make it easy to construct and manipulate\nrich data structures, and sophisticated \\glspl{polymorphic type system}\nsupporting abstraction and code reuse. Idris shares all of these features.\n\nThe first half of this chapter introduces the most essential elements of Idris's\nfunctional programming language. The second half introduces some basic\n\\glspl{tactic} that can be used to prove simple properties of Idris programs.\n\n\n== Enumerated Types\n\nOne unusual aspect of Idris, similar to Coq, is that its set of built-in\nfeatures (see the \\idr{base} package in the Idris distribution) is _extremely_\nsmall. For example, instead of providing the usual palette of atomic data types\n(booleans, integers, strings, etc.), Idris offers a powerful mechanism for\ndefining new data types from scratch, from which all these familiar types arise\nas instances.\n\nNaturally, the Idris distribution comes with extensive standard libraries\nproviding definitions of booleans, numbers, and many common data structures like\nlists and hash tables (see the \\idr{prelude} and \\idr{contrib} packages), as\nwell as the means to write type-safe effectful code (see the \\idr{effects}\npackage) and \\idr{pruvlioj}, a toolkit for proof automation and program\nconstruction. But there is nothing magic or primitive about these library\ndefinitions. To illustrate this, we will explicitly recapitulate all the\ndefinitions we need in this course, rather than just getting them implicitly\nfrom the library.\n\nTo see how this definition mechanism works, let's start with a very simple\nexample.\n\n\n=== Days of the Week\n\nThe following declaration tells Idris that we are defining a new set of data\nvalues -- a \\gls{type}.\n\n> namespace Days\n>\n> ||| Days of the week.\n> data Day = ||| `Monday` is a `Day`.\n> Monday\n> | ||| `Tuesday` is a `Day`.\n> Tuesday\n> | ||| `Wednesday` is a `Day`.\n> Wednesday\n> | ||| `Thursday` is a `Day`.\n> Thursday\n> | ||| `Friday` is a `Day`.\n> Friday\n> | ||| `Saturday` is a `Day`.\n> Saturday\n> | ||| `Sunday` is a `Day`.\n> Sunday\n>\n\nThe type is called \\idr{Day}, and its members are \\idr{Monday}, \\idr{Tuesday},\netc. The right hand side of the definition can be read \"\\idr{Monday} is a\n\\idr{Day}, \\idr{Tuesday} is a \\idr{Day}, etc.\"\n\nUsing the \\idr{%name} directive, we can tell Idris how to choose default\nvariable names for a particular \\gls{type}.\n\n> %name Day day, day1, day2\n>\n\nNow, if Idris needs to choose a name for a variable of type \\idr{Day}, it will\nchoose \\idr{day} by default, followed by \\idr{day1} and \\idr{day2} if any of its\npredecessors are already in scope.\n\nHaving defined \\idr{Day}, we can write functions that operate on days.\n\nType the following:\n\n```idris\n nextWeekday : Day -> Day\n```\n\nThen with the point on \\idr{nextWeekday}, call \\gls{idris-add-clause}.\n\n```idris\n nextWeekday : Day -> Day\n nextWeekday day = ?nextWeekday_rhs\n```\n\nWith the point on \\idr{day}, call \\gls{idris-case-split}.\n\n```idris\n nextWeekday : Day -> Day\n nextWeekday Monday = ?nextWeekday_rhs_1\n nextWeekday Tuesday = ?nextWeekday_rhs_2\n nextWeekday Wednesday = ?nextWeekday_rhs_3\n nextWeekday Thursday = ?nextWeekday_rhs_4\n nextWeekday Friday = ?nextWeekday_rhs_5\n nextWeekday Saturday = ?nextWeekday_rhs_6\n nextWeekday Sunday = ?nextWeekday_rhs_7\n```\n\nFill in the proper \\idr{Day} constructors and align whitespace as you like.\n\n> ||| Determine the next weekday after a day.\n> nextWeekday : Day -> Day\n> nextWeekday Monday = Tuesday\n> nextWeekday Tuesday = Wednesday\n> nextWeekday Wednesday = Thursday\n> nextWeekday Thursday = Friday\n> nextWeekday Friday = Monday\n> nextWeekday Saturday = Monday\n> nextWeekday Sunday = Monday\n>\n\nCall \\gls{idris-load-file} to load the \\idr{Basics} module with the finished\n\\idr{nextWeekday} definition.\n\nHaving defined a function, we should check that it works on some examples. There\nare actually three different ways to do this in Idris.\n\nFirst, we can evaluate an expression involving \\idr{nextWeekday} in a REPL.\n\n```idris\nλΠ> nextWeekday Friday\nMonday : Day\n```\n\n```idris\nλΠ> nextWeekday (nextWeekday Saturday)\nTuesday : Day\n```\n\n\\todo[inline]{Mention other editors? Discuss idris-mode?}\n\nWe show Idris's responses in comments, but, if you have a computer handy, this\nwould be an excellent moment to fire up the Idris interpreter under your\nfavorite Idris-friendly text editor -- such as Emacs or Vim -- and try this for\nand try this for yourself. Load this file, `Basics.lidr` from the book's\naccompanying Idris sources, find the above example, submit it to the Idris REPL,\nand observe the result.\n\nSecond, we can record what we _expect_ the result to be in the form of a proof.\n\n> ||| The second weekday after `Saturday` is `Tuesday`.\n> testNextWeekday :\n> (nextWeekday (nextWeekday Saturday)) = Tuesday\n\nThis declaration does two things: it makes an assertion (that the second weekday\nafter \\idr{Saturday} is \\idr{Tuesday}) and it gives the assertion a name that\ncan be used to refer to it later.\n\nHaving made the assertion, we can also ask Idris to verify it, like this:\n\n> testNextWeekday = Refl\n>\n\n\\todo[inline]{Edit this}\n\nThe details are not important for now (we'll come back to them in a bit), but\nessentially this can be read as \"The assertion we've just made can be proved by\nobserving that both sides of the equality evaluate to the same thing, after some\nsimplification.\"\n\n(For simple proofs like this, you can call \\gls{idris-add-clause} with the point\non the name (\\idr{testNextWeekday}) in the type signature and then call\n\\gls{idris-proof-search} with the point on the resultant hole to have Idris\nsolve the proof for you.)\n\n\\todo[inline]{Verify the \"main uses\" claim.}\n\nThird, we can ask Idris to _generate_, from our definition, a program in some\nother, more conventional, programming (C, JavaScript and Node are bundled with\nIdris) with a high-performance compiler. This facility is very interesting,\nsince it gives us a way to construct \\gls{fully certified} programs in\nmainstream languages. Indeed, this is one of the main uses for which Idris was\ndeveloped. We'll come back to this topic in later chapters.\n\n\n== Booleans\n\n> namespace Booleans\n>\n\nIn a similar way, we can define the standard type \\idr{Bool} of booleans, with\nmembers \\idr{False} and \\idr{True}.\n\n```idris\n ||| Boolean Data Type\n data Bool = True | False\n```\n\nThis definition is written in the simplified style, similar to \\idr{Day}. It can\nalso be written in the verbose style:\n\n```idris\n data Bool : Type where\n True : Bool\n False : Bool\n```\n\nThe verbose style is more powerful because it allows us to assign precise\ntypes to individual constructors. This will become very useful later on.\n\nAlthough we are rolling our own booleans here for the sake of building up\neverything from scratch, Idris does, of course, provide a default implementation\nof the booleans in its standard library, together with a multitude of useful\nfunctions and lemmas. (Take a look at \\idr{Prelude} in the Idris library\ndocumentation if you're interested.) Whenever possible, we'll name our own\ndefinitions and theorems so that they exactly coincide with the ones in the\nstandard library.\n\nFunctions over booleans can be defined in the same way as above:\n\n```idris\n not : (b : Bool) -> Bool\n not True = False\n not False = True\n```\n\n> andb : (b1 : Bool) -> (b2 : Bool) -> Bool\n> andb True b2 = b2\n> andb False b2 = False\n>\n> orb : (b1 : Bool) -> (b2 : Bool) -> Bool\n> orb True b2 = True\n> orb False b2 = b2\n>\n\nThe last two illustrate Idris's syntax for multi-argument function definitions.\nThe corresponding multi-argument application syntax is illustrated by the\nfollowing four \"unit tests,\" which constitute a complete specification -- a\ntruth table -- for the \\idr{orb} function:\n\n> testOrb1 : (orb True False) = True\n> testOrb1 = Refl\n>\n> testOrb2 : (orb False False) = False\n> testOrb2 = Refl\n>\n> testOrb3 : (orb False True) = True\n> testOrb3 = Refl\n>\n> testOrb4 : (orb True True) = True\n> testOrb4 = Refl\n>\n\n\\todo[inline]{Edit this.}\n\nWe can also introduce some familiar syntax for the boolean operations we have\njust defined. The \\idr{syntax} command defines a new symbolic notation for an\nexisting definition, and \\idr{infixl} specifies left-associative fixity.\n\n```idris\n infixl 4 &&, ||\n\n (&&) : Bool -> Bool -> Bool\n (&&) = andb\n\n (||) : Bool -> Bool -> Bool\n (||) = orb\n```\n\n> testOrb5 : False || False || True = True\n> testOrb5 = Refl\n>\n\n\n==== Exercise: 1 star (nandb)\n\nFill in the hole \\idr{?nandb_rhs} and complete the following function; then make\nsure that the assertions below can each be verified by Idris. (Fill in each of\nthe holes, following the model of the \\idr{orb} tests above.) The function\nshould return \\idr{True} if either or both of its inputs are \\idr{False}.\n\n> nandb : (b1 : Bool) -> (b2 : Bool) -> Bool\n> nandb b1 b2 = ?nandb_rhs\n>\n> test_nandb1 : (nandb True False) = True\n> test_nandb1 = ?test_nandb1_rhs\n>\n> test_nandb2 : (nandb False False) = True\n> test_nandb2 = ?test_nandb2_rhs\n>\n> test_nandb3 : (nandb False True) = True\n> test_nandb3 = ?test_nandb3_rhs\n>\n> test_nandb4 : (nandb True True) = False\n> test_nandb4 = ?test_nandb4_rhs\n>\n\n$\\square$\n\n\n==== Exercise: 1 star (andb3)\n\nDo the same for the \\idr{andb3} function below. This function should return\n\\idr{True} when all of its inputs are \\idr{True}, and \\idr{False} otherwise.\n\n> andb3 : (b1 : Bool) -> (b2 : Bool) -> (b3 : Bool) -> Bool\n> andb3 b1 b2 b3 = ?andb3_rhs\n>\n> test_andb31 : (andb3 True True True) = True\n> test_andb31 = ?test_andb31_rhs\n>\n> test_andb32 : (andb3 False True True) = False\n> test_andb32 = ?test_andb32_rhs\n>\n> test_andb33 : (andb3 True False True) = False\n> test_andb33 = ?test_andb33_rhs\n>\n> test_andb34 : (andb3 True True False) = False\n> test_andb34 = ?test_andb34_rhs\n>\n\n$\\square$\n\n\n== Function Types\n\nEvery expression in Idris has a type, describing what sort of thing it computes.\nThe \\idr{:type} (or \\idr{:t}) REPL command asks Idris to print the type of an\nexpression.\n\nFor example, the type of \\idr{not True} is \\idr{Bool}.\n\n```idris\nλΠ> :type True\nTrue : Bool\nλΠ> :t not True\nnot True : Bool\n```\n\n\\todo[inline]{Confirm the \"function types\" wording.}\n\nFunctions like \\idr{not} itself are also data values, just like \\idr{True} and\n\\idr{False}. Their types are called \\glspl{function type}, and they are written\nwith arrows.\n\n```idris\nλΠ> :t not\nnot : Bool -> Bool\n```\n\nThe type of \\idr{not}, written \\idr{Bool -> Bool} and pronounced \"\\idr{Bool}\narrow \\idr{Bool},\" can be read, \"Given an input of type \\idr{Bool}, this\nfunction produces an output of type \\idr{Bool}.\" Similarly, the type of\n\\idr{andb}, written \\idr{Bool -> Bool -> Bool}, can be read, \"Given two inputs,\nboth of type \\idr{Bool}, this function produces an output of type \\idr{Bool}.\"\n\n\n== Modules\n\n\\todo[inline]{Flesh this out and discuss namespaces}\n\nIdris provides a \\gls{module system}, to aid in organizing large developments.\n\n\n== Numbers\n\n> namespace Numbers\n>\n\nThe types we have defined so far are examples of \"enumerated types\": their\ndefinitions explicitly enumerate a finite set of elements. A More interesting\nway of defining a type is to give a collection of \\glspl{inductive rule}\ndescribing its elements. For example, we can define the natural numbers as\nfollows:\n\n```idris\n data Nat : Type where\n Z : Nat\n S : Nat -> Nat\n```\n\nThe clauses of this definition can be read:\n\n- \\idr{Z} is a natural number.\n- \\idr{S} is a \"constructor\" that takes a natural number and yields another one\n -- that is, if \\idr{n} is a natural number, then \\idr{S n} is too.\n\nLet's look at this in a little more detail.\n\nEvery inductively defined set (\\idr{Day}, \\idr{Nat}, \\idr{Bool}, etc.) is\nactually a set of \\glspl{expression}. The definition of \\idr{Nat} says how\nexpressions in the set \\idr{Nat} can be constructed:\n\n- the expression \\idr{Z} belongs to the set \\idr{Nat};\n- if \\idr{n} is an expression belonging to the set \\idr{Nat}, then \\idr{S n} is\n also an expression belonging to the set \\idr{Nat}; and\n- expression formed in these two ways are the only ones belonging to the set\n \\idr{Nat}.\n\nThe same rules apply for our definitions of \\idr{Day} and \\idr{Bool}. The\nannotations we used for their constructors are analogous to the one for the\n\\idr{Z} constructor, indicating that they don't take any arguments.\n\nThese three conditions are the precise force of inductive declarations. They\nimply that the expression \\idr{Z}, the expression \\idr{S Z}, the expression\n\\idr{S (S Z)}, the expression \\idr{S (S (S Z))} and so on all belong to the set\n\\idr{Nat}, while other expressions like \\idr{True}, \\idr{andb True False}, and\n\\idr{S (S False)} do not.\n\nWe can write simple functions that pattern match on natural numbers just as we\ndid above -- for example, the predecessor function:\n\n> pred : (n : Nat) -> Nat\n> pred Z = Z\n> pred (S k) = k\n>\n\nThe second branch can be read: \"if \\idr{n} has the form \\idr{S k} for some\n\\idr{k}, then return \\idr{k}.\"\n\n> minusTwo : (n : Nat) -> Nat\n> minusTwo Z = Z\n> minusTwo (S Z) = Z\n> minusTwo (S (S k)) = k\n>\n\nBecause natural numbers are such a pervasive form of data, Idris provides a tiny\nbit of built-in magic for parsing and printing them: ordinary Arabic numerals\ncan be used as an alternative to the \"unary\" notation defined by the\nconstructors \\idr{S} and \\idr{Z}. Idris prints numbers in Arabic form by\ndefault:\n\n```idris\nλΠ> S (S (S (S Z)))\n4 : Nat\nλΠ> minusTwo 4\n2 : Nat\n```\n\nThe constructor \\idr{S} has the type \\idr{Nat -> Nat}, just like the functions\n\\idr{minusTwo} and \\idr{pred}:\n\n```idris\nλΠ> :t S\nλΠ> :t pred\nλΠ> :t minusTwo\n```\n\nThese are all things that can be applied to a number to yield a number. However,\nthere is a fundamental difference between the first one and the other two:\nfunctions like \\idr{pred} and \\idr{minusTwo} come with \\glspl{computation rule}\n-- e.g., the definition of \\idr{pred} says that \\idr{pred 2} can be simplified\nto \\idr{1} -- while the definition of \\idr{S} has no such behavior attached.\nAlthough it is like a function in the sense that it can be applied to an\nargument, it does not _do_ anything at all!\n\nFor most function definitions over numbers, just pattern matching is not enough:\nwe also need recursion. For example, to check that a number \\idr{n} is even, we\nmay need to recursively check whether \\idr{n-2} is even.\n\n> ||| Determine whether a number is even.\n> ||| @n a number\n> evenb : (n : Nat) -> Bool\n> evenb Z = True\n> evenb (S Z) = False\n> evenb (S (S k)) = evenb k\n>\n\nWe can define \\idr{oddb} by a similar recursive declaration, but here is a\nsimpler definition that is a bit easier to work with:\n\n> ||| Determine whether a number is odd.\n> ||| @n a number\n> oddb : (n : Nat) -> Bool\n> oddb n = not (evenb n)\n>\n> testOddb1 : oddb 1 = True\n> testOddb1 = Refl\n>\n> testOddb2 : oddb 4 = False\n> testOddb2 = Refl\n>\n\nNaturally, we can also define multi-argument functions by recursion.\n\n> namespace Playground2\n>\n> plus : (n : Nat) -> (m : Nat) -> Nat\n> plus Z m = m\n> plus (S k) m = S (Playground2.plus k m)\n>\n\nAdding three to two now gives us five, as we'd expect.\n\n```idris\nλΠ> plus 3 2\n```\n\nThe simplification that Idris performs to reach this conclusion can be\nvisualized as follows:\n\n\\idr{plus (S (S (S Z))) (S (S Z))}\n\n$\\hookrightarrow$ \\idr{S (plus (S (S Z)) (S (S Z)))}\n by the second clause of \\idr{plus}\n\n$\\hookrightarrow$ \\idr{S (S (plus (S Z) (S (S Z))))}\n by the second clause of \\idr{plus}\n\n$\\hookrightarrow$ \\idr{S (S (S (plus Z (S (S Z)))))}\n by the second clause of \\idr{plus}\n\n$\\hookrightarrow$ \\idr{S (S (S (S (S Z))))}\n by the first clause of \\idr{plus}\n\nAs a notational convenience, if two or more arguments have the same type, they\ncan be written together. In the following definition, \\idr{(n, m : Nat)} means\njust the same as if we had written \\idr{(n : Nat) -> (m : Nat)}.\n\n```idris\n mult : (n, m : Nat) -> Nat\n mult Z = Z\n mult (S k) = plus m (mult k m)\n```\n\n> testMult1 : (mult 3 3) = 9\n> testMult1 = Refl\n>\n\nYou can match two expressions at once:\n\n```idris\n minus : (n, m : Nat) -> Nat\n minus Z _ = Z\n minus n Z = n\n minus (S k) (S j) = minus k j\n```\n\n\\todo[inline]{Verify this.}\n\nThe \\idr{_} in the first line is a \\gls{wildcard pattern}. Writing \\idr{_} in a\npattern is the same as writing some variable that doesn't get used on the\nright-hand side. This avoids the need to invent a bogus variable name.\n\n\n> exp : (base, power : Nat) -> Nat\n> exp base Z = S Z\n> exp base (S p) = mult base (exp base p)\n>\n\n\n==== Exercise: 1 star (factorial)\n\nRecall the standard mathematical factorial function:\n\n\\[\n factorial(n)=\n\\begin{cases}\n 1, & \\text{if } n = 0 \\\\\n n \\times factorial(n-1),& \\text{otherwise}\n\\end{cases}\n\\]\n\nTranslate this into Idris.\n\n> factorial : (n : Nat) -> Nat\n> factorial n = ?factorial_rhs\n>\n> testFactorial1 : factorial 3 = 6\n> testFactorial1 = ?testFactorial1_rhs\n>\n> testFactorial2 : factorial 5 = mult 10 12\n> testFactorial2 = ?testFactorial2_rhs\n>\n\n$\\square$\n\nWe can make numerical expressions a little easier to read and write by\nintroducing \\gls{syntax} for addition, multiplication, and subtraction.\n\n```idris\n syntax [x] \"+\" [y] = plus x y\n syntax [x] \"-\" [y] = minus x y\n syntax [x] \"*\" [y] = mult x y\n```\n\n```idris\nλΠ> :t (0 + 1) + 1\n```\n\n(The details are not important, but interested readers can refer to the optional\n\"More on Syntax\" section at the end of this chapter.)\n\nNote that these do not change the definitions we've already made: they are\nsimply instructions to the Idris parser to accept \\idr{x + y} in place of\n\\idr{plus x y} and, conversely, to the Idris pretty-printer to display \\idr{plus\nx y} as \\idr{x + y}.\n\n\\todo[inline]{Mention interfaces here? Say this is infix}\n\nThe \\idr{(==)} function tests \\idr{Nat}ural numbers for equality, yielding a\n\\idr{Bool}ean.\n\n```idris\n ||| Test natural numbers for equality.\n (==) : (n, m : Nat) -> Bool\n (==) Z Z = True\n (==) Z (S j) = False\n (==) (S k) Z = False\n (==) (S k) (S j) = (==) k j\n```\n\nThe \\idr{lte} function tests whether its first argument is less than or equal to\nits second argument, yielding a boolean.\n\n```idris\n||| Test whether a number is less than or equal to another.\nlte : (n, m : Nat) -> Bool\nlte Z m = True\nlte n Z = False\nlte (S k) (S j) = lte k j\n```\n\n> testLte1 : lte 2 2 = True\n> testLte1 = Refl\n>\n> testLte2 : lte 2 4 = True\n> testLte2 = Refl\n>\n> testLte3 : lte 4 2 = False\n> testLte3 = Refl\n>\n\n\n==== Exercise: 1 star (blt_nat)\n\nThe \\idr{blt_nat} function tests \\idr{Nat}ural numbers for\n\\idr{l}ess-\\idr{t}han, yielding a \\idr{b}oolean. Instead of making up a new\nrecursive function for this one, define it in terms of a previously defined\nfunction.\n\n> blt_nat : (n, m : Nat) -> Bool\n> blt_nat n m = ?blt_nat_rhs\n>\n> test_blt_nat_1 : blt_nat 2 2 = False\n> test_blt_nat_1 = ?test_blt_nat_1_rhs\n>\n> test_blt_nat_2 : blt_nat 2 4 = True\n> test_blt_nat_2 = ?test_blt_nat_2_rhs\n>\n> test_blt_nat_3 : blt_nat 4 2 = False\n> test_blt_nat_3 = ?test_blt_nat_3_rhs\n>\n\n$\\square$\n\n\n== Proof by Simplification\n\nNow that we've defined a few datatypes and functions, let's turn to stating and\nproving properties of their behavior. Actually, we've already started doing\nthis: each of the functions beginning with \\idr{test} in the previous sections\nmakes a precise claim about the behavior of some function on some particular\ninputs. The proofs of these claims were always the same: use \\idr{Refl} to check\nthat both sides contain identical values.\n\nThe same sort of \"proof by simplification\" can be used to prove more interesting\nproperties as well. For example, the fact that \\idr{0} is a \"neutral element\"\nfor \\idr{+} on the left can be proved just by observing that \\idr{0 + n} reduces\nto \\idr{n} no matter what \\idr{n} is, a fact that can be read directly off the\ndefinition of \\idr{plus}.\n\n> plus_Z_n : (n : Nat) -> 0 + n = n\n> plus_Z_n n = Refl\n>\n\nIt will be useful later to know that [reflexivity] does some simplification --\nfor example, it tries \"unfolding\" defined terms, replacing them with their\nright-hand sides. The reason for this is that, if reflexivity succeeds, the\nwhole goal is finished and we don't need to look at whatever expanded\nexpressions \\idr{Refl} has created by all this simplification and unfolding.\n\nOther similar theorems can be proved with the same pattern.\n\n> plus_1_l : (n : Nat) -> 1 + n = S n\n> plus_1_l n = Refl\n>\n> mult_0_l : (n : Nat) -> 0 * n = 0\n> mult_0_l n = Refl\n>\n\nThe \\idr{_l} suffix in the names of these theorems is pronounced \"on the left.\"\n\nAlthough simplification is powerful enough to prove some fairly general facts,\nthere are many statements that cannot be handled by simplification alone. For\ninstance, we cannot use it to prove that \\idr{0} is also a neutral element for\n\\idr{+} _on the right_.\n\n\n```idris\nplus_n_Z : (n : Nat) -> n = n + 0\nplus_n_Z n = Refl\n```\n\n```\nWhen checking right hand side of plus_n_Z with expected type\n n = n + 0\n\n Type mismatch between\n plus n 0 = plus n 0 (Type of Refl)\n and\n n = plus n 0 (Expected type)\n\n Specifically:\n Type mismatch between\n plus n 0\n and\n n\n```\n\n(Can you explain why this happens?)\n\nThe next chapter will introduce \\gls{induction}, a powerful technique that can\nbe used for proving this goal. For the moment, though, let's look at a few more\nsimple tactics.\n\n\n== Proof by Rewriting\n\nThis theorem is a bit more interesting than the others we've seen:\n\n> plus_id_example : (n, m : Nat) -> (n = m) -> n + n = m + m\n\nInstead of making a universal claim about all numbers \\idr{n} and \\idr{m}, it\ntalks about a more specialized property that only holds when \\idr{n = m}. The\narrow symbol is pronounced \"implies.\"\n\nAs before, we need to be able to reason by assuming the existence of some\nnumbers \\idr{n} and \\idr{m}. We also need to assume the hypothesis \\idr{n = m}.\n\n\\todo[inline]{Edit, mention the \"generate initial pattern match\" editor command}\n\nThe \\idr{intros} tactic will serve to move all three of these from the goal into\nassumptions in the current context.\n\nSince \\idr{n} and \\idr{m} are arbitrary numbers, we can't just use\nsimplification to prove this theorem. Instead, we prove it by observing that, if\nwe are assuming \\idr{n = m}, then we can replace \\idr{n} with \\idr{m} in the\ngoal statement and obtain an equality with the same expression on both sides.\nThe tactic that tells Idris to perform this replacement is called \\idr{rewrite}.\n\n> plus_id_example n m prf = rewrite prf in Refl\n>\n\nThe first two variables on the left side move the universally quantified\nvariables \\idr{n} and \\idr{m} into the context. The third moves the hypothesis\n\\idr{n = m} into the context and gives it the name \\idr{prf}. The right side\ntells Idris to rewrite the current goal (\\idr{n + n = m + m}) by replacing the\nleft side of the equality hypothesis \\idr{prf} with the right side.\n\n\n==== Exercise: 1 star (plus_id_exercise)\n\nFill in the proof.\n\n> plus_id_exercise : (n, m, o : Nat) -> (n = m) -> (m = o) -> n + m = m + o\n> plus_id_exercise n m o prf prf1 = ?plus_id_exercise_rhs\n>\n\n$\\square$\n\nThe prefix \\idr{?} on the right-hand side of an equation tells Idris that we\nwant to skip trying to prove this theorem and just leave a hole. This can be\nuseful for developing longer proofs, since we can state subsidiary lemmas that\nwe believe will be useful for making some larger argument, use holes to delay\ndefining them for the moment, and continue working on the main argument until we\nare sure it makes sense; then we can go back and fill in the proofs we skipped.\n\n\\todo[inline]{Decide whether to discuss \\idr{postulate}.}\n\n> -- Be careful, though: every time you say `postulate` you are leaving a door\n> -- open for total nonsense to enter Idris's nice, rigorous, formally checked\n> -- world!\n\nWe can also use the \\idr{rewrite} tactic with a previously proved theorem\ninstead of a hypothesis from the context. If the statement of the previously\nproved theorem involves quantified variables, as in the example below, Idris\ntries to instantiate them by matching with the current goal.\n\n> mult_0_plus : (n, m : Nat) -> (0 + n) * m = n * (0 + m)\n> mult_0_plus n m = Refl\n>\n\nUnlike in Coq, we don't need to perform such a rewrite for \\idr{mult_0_plus} in\nIdris and can just use \\idr{Refl} instead.\n\n\n==== Exercise: 2 starts (mult_S_1)\n\n> mult_S_1 : (n, m : Nat) -> (m = S n) -> m * (1 + n) = m * m\n> mult_S_1 n m prf = ?mult_S_1_rhs\n>\n\n$\\square$\n\n\n== Proof by Case Analysis\n\nOf course, not everything can be proved by simple calculation and rewriting: In\ngeneral, unknown, hypothetical values (arbitrary numbers, booleans, lists, etc.)\ncan block simplification. For example, if we try to prove the following fact\nusing the \\idr{Refl} tactic as above, we get stuck.\n\n```idris\nplus_1_neq_0_firsttry : (n : Nat) -> (n + 1) == 0 = False\nplus_1_neq_0_firsttry n = Refl -- does nothing!\n```\n\nThe reason for this is that the definitions of both \\idr{(==)} and \\idr{+}\nbegin by performing a \\idr{match} on their first argument. But here, the first\nargument to \\idr{+} is the unknown number \\idr{n} and the argument to\n\\idr{(==)} is the compound expression \\idr{n + 1}; neither can be simplified.\n\nTo make progress, we need to consider the possible forms of \\idr{n} separately.\nIf \\idr{n} is \\idr{Z}, then we can calculate the final result of \\idr{(n + 1) ==\n0} and check that it is, indeed, \\idr{False}. And if \\idr{n = S k} for some\n\\idr{k}, then, although we don't know exactly what number \\idr{n + 1} yields, we\ncan calculate that, at least, it will begin with one \\idr{S}, and this is enough\nto calculate that, again, \\idr{(n + 1) == 0} will yield \\idr{False}.\n\nTo tell Idris to consider, separately, the cases where \\idr{n = Z} and where\n\\idr{n = S k}, simply case split on \\idr{n}.\n\n\\todo[inline]{Mention case splitting interactively in Emacs, Atom, etc.}\n\n> plus_1_neq_0 : (n : Nat) -> (n + 1) == 0 = False\n> plus_1_neq_0 Z = Refl\n> plus_1_neq_0 (S k) = Refl\n>\n\nCase splitting on \\idr{n} generates _two_ holes, which we must then prove,\nseparately, in order to get Idris to accept the theorem.\n\nIn this example, each of the holes is easily filled by a single use of\n\\idr{Refl}, which itself performs some simplification -- e.g., the first one\nsimplifies \\idr{(S k + 1) == 0} to \\idr{False} by first rewriting \\idr{(S k +\n1)} to \\idr{S (k + 1)}, then unfolding \\idr{(==)}, simplifying its pattern\nmatching.\n\nThere are no hard and fast rules for how proofs should be formatted in Idris.\nHowever, if the places where multiple holes are generated are lifted to lemmas,\nthen the proof will be readable almost no matter what choices are made about\nother aspects of layout.\n\nThis is also a good place to mention one other piece of somewhat obvious advice\nabout line lengths. Beginning Idris users sometimes tend to the extremes, either\nwriting each tactic on its own line or writing entire proofs on one line. Good\nstyle lies somewhere in the middle. One reasonable convention is to limit\nyourself to 80-character lines.\n\nThe case splitting strategy can be used with any inductively defined datatype.\nFor example, we use it next to prove that boolean negation is involutive --\ni.e., that negation is its own inverse.\n\n> ||| A proof that boolean negation is involutive.\n> not_involutive : (b : Bool) -> not (not b) = b\n> not_involutive True = Refl\n> not_involutive False = Refl\n>\n\nNote that the case splitting here doesn't introduce any variables because none\nof the subcases of the patterns need to bind any, so there is no need to specify\nany names.\n\nIt is sometimes useful to case split on more than one parameter, generating yet\nmore proof obligations. For example:\n\n> andb_commutative : (b, c : Bool) -> b && c = c && b\n> andb_commutative True True = Refl\n> andb_commutative True False = Refl\n> andb_commutative False True = Refl\n> andb_commutative False False = Refl\n>\n\nIn more complex proofs, it is often better to lift subgoals to lemmas:\n\n\n> andb_commutative'_rhs_1 : (c : Bool) -> c = c && True\n> andb_commutative'_rhs_1 True = Refl\n> andb_commutative'_rhs_1 False = Refl\n>\n> andb_commutative'_rhs_2 : (c : Bool) -> False = c && False\n> andb_commutative'_rhs_2 True = Refl\n> andb_commutative'_rhs_2 False = Refl\n>\n> andb_commutative' : (b, c : Bool) -> b && c = c && b\n> andb_commutative' True = andb_commutative'_rhs_1\n> andb_commutative' False = andb_commutative'_rhs_2\n>\n\n\n==== Exercise: 2 stars (andb_true_elim2)\n\nProve the following claim, lift cases (and subcases) to lemmas when case split.\n\n> andb_true_elim_2 : (b, c : Bool) -> (b && c = True) -> c = True\n> andb_true_elim_2 b c prf = ?andb_true_elim_2_rhs\n>\n\n$\\square$\n\n\n==== Exercise: 1 star (zero_nbeq_plus_1)\n\n> zero_nbeq_plus_1 : (n : Nat) -> 0 == (n + 1) = False\n> zero_nbeq_plus_1 n = ?zero_nbeq_plus_1_rhs\n>\n\n$\\square$\n\n\n\\todo[inline]{Discuss associativity.}\n\n\n== Structural Recursion (Optional)\n\nHere is a copy of the definition of addition:\n\n```idris\nplus' : Nat -> Nat -> Nat\nplus' Z right = right\nplus' (S left) right = S (plus' left right)\n```\n\nWhen Idris checks this definition, it notes that \\idr{plus'} is \"decreasing on\n1st argument.\" What this means is that we are performing a \\gls{structural\nrecursion} over the argument \\idr{left} -- i.e., that we make recursive calls\nonly on strictly smaller values of \\idr{left}. This implies that all calls to\n\\idr{plus'} will eventually terminate. Idris demands that some argument of\n_every_ recursive definition is \"decreasing.\"\n\nThis requirement is a fundamental feature of Idris's design: In particular, it\nguarantees that every function that can be defined in Idris will terminate on\nall inputs. However, because Idris's \"decreasing analysis\" is not very\nsophisticated, it is sometimes necessary to write functions in slightly\nunnatural ways.\n\n\\todo[inline]{Verify the previous claims.}\n\n\\todo[inline]{Add decreasing exercise.}\n\n\n== More Exercises\n\n\n==== Exercise: 2 stars (boolean_functions)\n\nUse the tactics you have learned so far to prove the following theorem about\nboolean functions.\n\n> identity_fn_applied_twice : (f : Bool -> Bool) ->\n> ((x : Bool) -> f x = x) ->\n> (b : Bool) -> f (f b) = b\n> identity_fn_applied_twice f g b = ?identity_fn_applied_twice_rhs\n\nNow state and prove a theorem \\idr{negation_fn_applied_twice} similar to the\nprevious one but where the second hypothesis says that the function \\idr{f} has\nthe property that \\idr{f x = not x}.\n\n>\n> -- FILL IN HERE\n>\n\n$\\square$\n\n\n==== Exercise: 2 start (andb_eq_orb)\n\nProve the following theorem. (You may want to first prove a subsidiary lemma or\ntwo. Alternatively, remember that you do not have to introduce all hypotheses at\nthe same time.)\n\n> andb_eq_orb : (b, c : Bool) -> (b && c = b || c) -> b = c\n> andb_eq_orb b c prf = ?andb_eq_orb_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars (binary)\n\nConsider a different, more efficient representation of natural numbers using a\nbinary rather than unary system. That is, instead of saying that each natural\nnumber is either zero or the successor of a natural number, we can say that each\nbinary number is either\n\n- zero,\n- twice a binary number, or\n- one more than twice a binary number.\n\n(a) First, write an inductive definition of the type \\idr{Bin} corresponding to\n this description of binary numbers.\n\n(Hint: Recall that the definition of \\idr{Nat} from class,\n\n```idris\ndata Nat : Type where\n Z : Nat\n S : Nat -> Nat\n```\n\nsays nothing about what \\idr{Z} and \\idr{S} \"mean.\" It just says \"\\idr{Z} is in\nthe set called \\idr{Nat}, and if \\idr{n} is in the set then so is \\idr{S n}.\"\nThe interpretation of \\idr{Z} as zero and \\idr{S} as successor/plus one comes\nfrom the way that we _use_ \\idr{Nat} values, by writing functions to do things\nwith them, proving things about them, and so on. Your definition of \\idr{Bin}\nshould be correspondingly simple; it is the functions you will write next that\nwill give it mathematical meaning.)\n\n(b) Next, write an increment function \\idr{incr} for binary numbers, and a\n function \\idr{bin_to_nat} to convert binary numbers to unary numbers.\n\n(c) Write five unit tests \\idr{test_bin_incr_1}, \\idr{test_bin_incr_2}, etc. for\n your increment and binary-to-unary functions. Notice that incrementing a\n binary number and then converting it to unary should yield the same result\n as first converting it to unary and then incrementing.\n\n>\n> -- FILL IN HERE\n>\n\n$\\square$\n", "meta": {"hexsha": "b1fa17589a70d7c0866ce909ea87d7c775472ff0", "size": 34782, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Basics.lidr", "max_stars_repo_name": "MarcelineVQ/software-foundations", "max_stars_repo_head_hexsha": "41b6038e7e3a007ca57f42b50794775633e1c5bd", "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/Basics.lidr", "max_issues_repo_name": "MarcelineVQ/software-foundations", "max_issues_repo_head_hexsha": "41b6038e7e3a007ca57f42b50794775633e1c5bd", "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/Basics.lidr", "max_forks_repo_name": "MarcelineVQ/software-foundations", "max_forks_repo_head_hexsha": "41b6038e7e3a007ca57f42b50794775633e1c5bd", "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.7206020696, "max_line_length": 80, "alphanum_fraction": 0.6990684837, "num_tokens": 10201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.6404835113328818}} {"text": "||| Simple GADTs for F#\r\nmodule TypeTheory\r\n\r\n%default total\r\n%access public export\r\n\r\n||| A term in the language\r\n||| universe 0 - values\r\n||| universe 1 - types\r\n||| universe 2 - kinds\r\n||| universe 2 - sorts\r\ndata Term : (universe : Nat) -> Type where\r\n ||| A named term or variable\r\n Var : String -> Term u\r\n ||| An explicit type annotation\r\n Ann : Term u -> Term (S u) -> Term u\r\n ||| Function application\r\n Appl : Term u -> Term u -> Term u\r\n ||| Type constructor operator. Its terms cannot be values.\r\n Arrow : Term (S u) -> Term (S u) -> Term (S u)\r\n ||| The name of Type in any universe starting with 2 (since the lowest Type\r\n ||| has as its type Kind).\r\n Tau : Term (S (S n))\r\n\r\n||| A primitive type or type constructor in universe one, opaque to the\r\n||| source language because taken for granted as existing in the target\r\n||| language. Syntax:\r\n||| primitive string : Type\r\n||| primitive Maybe : Type -> Type\r\n||| primitive Either : Type -> Type -> Type\r\n||| The term in universe two is the type of the primitive: all primitives\r\n||| have a type of Type or of some type constructor, which are kinds, so it\r\n||| is in universe two.\r\nprimType : String -> Term 2 -> Term 1\r\nprimType name type = Ann (Var name) type\r\n\r\n||| With full dependent types, equality is a problem that needs gamma, and\r\n||| requires evaluation. We do not yet need this.\r\nequal : Term u -> Term u -> Bool\r\nequal (Var a) (Var c) = a == c\r\nequal (Ann a b) (Ann c d) = equal a c && equal b d\r\nequal (Appl a b) (Appl c d) = equal a c && equal b d\r\nequal (Arrow a b) (Arrow c d) = equal a c && equal b d\r\nequal Tau Tau = True\r\nequal _ _ = False\r\n\r\nequal' : Term u -> Term v -> Bool\r\nequal' {u} {v} x y =\r\n case decEq u v of\r\n Yes prf => equal x (rewrite prf in y)\r\n No _ => False\r\n\r\n||| Typing environment, where its universe is one larger than the universe of\r\n||| the biggest terms for which it contains typing information: or said another\r\n||| way, perhaps more lucidly, the universe off the typing environment is equal\r\n||| to the universe of the types of the biggest terms it contains.\r\ndata Gamma : (universe : Nat) -> Type where\r\n ||| To ensure that the typing information is always cumulative from its\r\n ||| biggest universe all the way down to values, we must ground the empty\r\n ||| universe as size zero. This also makes sense with the definition of its\r\n ||| universe being one larger than the universe of its biggest terms: there is\r\n ||| no universe below Z and therefore if Z is one larger than the biggest\r\n ||| terms in Nil there are no terms in Nil.\r\n Nil : Gamma Z\r\n -- List (u : Nat ** List (Term u, Term (S u)))\r\n (::) : List (Term u, Term (S u)) -> Gamma u -> Gamma (S u)\r\n\r\ntypeInEnv : Gamma v -> Term u -> Maybe (Term (S u))\r\n-- The empty type environment contains no judgements, by definition.\r\ntypeInEnv {v=Z} {u=_} [] _ = Nothing\r\n-- u is at least as big as v if not bigger in this case. That means the typing\r\n-- environment is insufficiently large to contain information on this term.\r\ntypeInEnv {v=S Z} {u = (S _)} (_ :: _) _ = Nothing\r\ntypeInEnv {v=S j} {u = k} (x :: xs) t =\r\n case decEq k j of\r\n Yes prf => lookupBy equal t (rewrite prf in x)\r\n No _ => typeInEnv xs t\r\n\r\ncheckTypeInEnv : Gamma v -> Term u -> Term (S u) -> Bool\r\ncheckTypeInEnv gamma x t =\r\n let maybeT = typeInEnv gamma x\r\n in case maybeT of\r\n Just t' => equal t t'\r\n Nothing => False\r\n\r\nmutual\r\n check : Gamma v -> Term u -> Term (S u) -> Bool\r\n check gamma x@(Var _) t = checkTypeInEnv gamma x t\r\n check _ (Ann _ t) t' = equal t t'\r\n check gamma (Appl f a) t =\r\n case synthesize gamma f of\r\n Just (Arrow at bt) => check gamma a at && equal t bt\r\n -- The first term in an application must be a function, i.e. must have an\r\n -- arrow type, else it is bogus and we can't synthesize a type for that\r\n _ => False\r\n check _ (Arrow _ _) Tau = True\r\n check _ (Arrow _ _) _ = False\r\n check _ Tau Tau = True\r\n check _ Tau _ = False\r\n\r\n synthesize : Gamma v -> Term u -> Maybe (Term (S u))\r\n synthesize gamma x@(Var _) = typeInEnv gamma x\r\n synthesize _ (Ann _ t) = Just t\r\n synthesize gamma (Appl f a) =\r\n case synthesize gamma f of\r\n Just (Arrow at bt) => if check gamma a at then Just bt else Nothing\r\n -- The first term in an application must be a function, i.e. must have an\r\n -- arrow type, else it is bogus and we can't synthesize a type for that\r\n _ => Nothing\r\n synthesize _ (Arrow _ _) = Just Tau\r\n synthesize _ Tau = Just Tau\r\n", "meta": {"hexsha": "5efb360788ea03add59a05b349e9f6b1e35ad80c", "size": 4517, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeTheory.idr", "max_stars_repo_name": "Kazark/fspp", "max_stars_repo_head_hexsha": "32ad3478beb13047ff6c87369b2443297ee4310b", "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": "TypeTheory.idr", "max_issues_repo_name": "Kazark/fspp", "max_issues_repo_head_hexsha": "32ad3478beb13047ff6c87369b2443297ee4310b", "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": "TypeTheory.idr", "max_forks_repo_name": "Kazark/fspp", "max_forks_repo_head_hexsha": "32ad3478beb13047ff6c87369b2443297ee4310b", "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": 40.3303571429, "max_line_length": 81, "alphanum_fraction": 0.6422404251, "num_tokens": 1280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782012, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6404166886725294}} {"text": "module Data.Time.Calendar.MonthDay\n\nimport Data.Vect\n\nimport Data.Time.Calendar.Private\n\nexport\nmonthLengths: Bool -> Vect 12 Nat\nmonthLengths False = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\nmonthLengths True = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\nexport\nmonthSum: Bool -> Vect 12 Nat\nmonthSum False = [31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]\nmonthSum True = [31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]\n\n\nexport\nYearBound : (isLeap: Bool) -> Type\nYearBound False = Fin 365\nYearBound True = Fin 366\n\nexport\ndayLengthBounds : Fin 12 -> Vect 12 Nat -> Type\ndayLengthBounds x xs = Fin $ succ $ index x xs\n\nexport\nDayBounds : Fin 12 -> Bool -> Type\nDayBounds n isLeap = (dayLengthBounds n (monthLengths isLeap))\n\n\n-- defDayLengthBounds : (n: Fin 12) -> (dayLengthBounds n (monthLengths isLeap))\n-- defDayLengthBounds x = Vect.index x (monthLengths True)\n\n-- hole : (n : Integer) -> ((n1 : Nat) -> Maybe (Fin n1)) -> Fin 32\n-- hole n f = ?hole_rhs\n\n||| Used to clip the days value to a typed bounded value based on the provided month and isLeap value\nexport\nboundedDay: (n: Int) -> (month: Fin 12) -> (isLeap: Bool) -> Maybe (DayBounds month isLeap)\nboundedDay x m isLeap = integerToFin (cast x) (S (Vect.index m (monthLengths isLeap)))\n\nexport\nboundedDay': (n: Int) -> (month: Fin 12) -> (isLeap: Bool) -> Nat\nboundedDay' x m isLeap = Vect.index m (monthLengths isLeap)\n\n\n-- construct_prf : (n: Nat) -> (xs: List a) -> (prf: NonEmpty xs) -> InBounds n xs\n-- construct_prf _ [] IsNonEmpty impossible\n-- construct_prf Z (x :: xs) prf = InFirst\n-- construct_prf (S k) (x :: y :: xs) prf = InLater (construct_prf k (y::xs) prf)\n\n\n-- -- construct_prf Z [] = ?construct_prf_rhs_4\n-- -- construct_prf Z (x :: xs) = InFirst\n-- -- construct_prf (S k) (x::xs) = InLater (construct_prf k xs)\n\n-- | The length of a given month in the Gregorian or Julian calendars.\n-- First arg is leap year flag.\nexport\nmonthLength: Bool -> Fin 12 -> Nat\nmonthLength isLeap month' =\n let\n --inBounds = InBounds (cast (month' - 1)) (monthLengths isLeap)\n monthLengths' = (monthLengths isLeap)\n in\n index month' monthLengths'\n\n-- --Prelude.List.index (cast (month' - 1)) (monthLengths isLeap) {inBounds}\n\n-- ||| Convert month and day in the Gregorian or Julian calendars to day of year.\n-- ||| First arg is leap year flag.\nexport\nmonthAndDayToDayOfYear : (isLeap: Bool) -> Int -> Int -> Int\nmonthAndDayToDayOfYear isLeap month day' =\n let\n day' = day'\n k =\n if month <= 2\n then 0\n else if isLeap\n then -1\n else -2\n res = (div (367 * month - 362) 12) + k + day'\n in\n res\n\nexport\nfindMonthDay: Vect n Nat -> Int -> (Int, Int)\nfindMonthDay (y :: xs) yd =\n if yd > cast y\n then (\\(m, d) => (m + 1, d)) (findMonthDay xs (yd - cast y))\n else (1, yd)\n\nexport\nfindDay: Vect n Nat -> Int -> Int\nfindDay (y :: xs) yd =\n if yd > cast y\n then findDay xs (yd - cast y)\n else yd\n\nexport\nfindMonth : (m: Fin 12) -> (isLeap: Bool) -> Int -> Fin 12\nfindMonth FZ isLeap x = if x > cast (Vect.index FZ (monthSum isLeap)) then (FS FZ) else FZ\nfindMonth (FS y) isLeap x = if x > cast (Vect.index (FS y) (monthSum isLeap)) then succ (FS y) else findMonth (pred (FS y)) isLeap x\n\n-- export\n-- findMonth' : (m: Fin 12) -> (in_m: Fin 12) (isLeap: Bool) -> (x: YearBound True) -> (x ** DayBounds x isLeap)\n-- findMonth' FZ in_m isLeap x = if (finToInteger x) > cast (Vect.index FZ (monthSum isLeap)) then ((FS FZ), else FZ\n-- findMonth' (FS y) in_m isLeap x = if (finToInteger x) > cast (Vect.index (FS y) (monthSum isLeap)) then succ (FS y) else findMonth (pred (FS y)) isLeap x\n\n\n\n-- ||| Convert day of year in the Gregorian or Julian calendars to month and day.\n-- ||| First arg is leap year flag.\nexport\ndayOfYearToMonthAndDay : Bool -> Int -> (Int, Int)\ndayOfYearToMonthAndDay isLeap yd =\n let\n clipped = (clip 1 (if isLeap then 366 else 365) yd)\n in\n findMonthDay (monthLengths isLeap) clipped\n", "meta": {"hexsha": "24c48df65c25dd1dac235e75c791de340ba072a3", "size": 3991, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Time/Calendar/MonthDay.idr", "max_stars_repo_name": "gdevanla/idris-time", "max_stars_repo_head_hexsha": "96a488057863d6c3049f62a1ac70734090e50b66", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-18T11:02:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-18T11:02:58.000Z", "max_issues_repo_path": "src/Data/Time/Calendar/MonthDay.idr", "max_issues_repo_name": "gdevanla/idris-time", "max_issues_repo_head_hexsha": "96a488057863d6c3049f62a1ac70734090e50b66", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-28T21:13:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T19:56:41.000Z", "max_forks_repo_path": "src/Data/Time/Calendar/MonthDay.idr", "max_forks_repo_name": "gdevanla/idris-time", "max_forks_repo_head_hexsha": "96a488057863d6c3049f62a1ac70734090e50b66", "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.4471544715, "max_line_length": 156, "alphanum_fraction": 0.6497118517, "num_tokens": 1379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6404166732386081}} {"text": "module PLFI.Part1.Negation\n\nimport Control.Function.FunExt\nimport Data.DPair\n\nimport PLFI.Part1.Relations\nimport PLFI.Part1.Naturals\n\n\n-- ¬_ : Set → Set\n-- ¬ A = A → ⊥\n\n%default total\n\n%hide Prelude.Not\n\nNot : Type -> Type\nNot a = a -> Void\n\n-- ¬-elim : ∀ {A : Set}\n-- → ¬ A\n-- → A\n-- ---\n-- → ⊥\n-- ¬-elim ¬x x = ¬x x\n\nnotElim : (Not a) -> a -> Void\nnotElim = ($)\n-- notElim not_x x = not_x $ x\n-- notElim not_x x = not_x x\n\n-- ¬¬-intro : ∀ {A : Set}\n-- → A\n-- -----\n-- → ¬ ¬ A\n-- ¬¬-intro x = λ{¬x → ¬x x}\n\nnotNotIntro : a -> (Not (Not a))\nnotNotIntro = flip ($)\n-- notNotIntro x = \\notX => notX x\n-- notNotIntro x notX = notX x\n\n-- ¬¬¬-elim : ∀ {A : Set}\n-- → ¬ ¬ ¬ A\n-- -------\n-- → ¬ A\n-- ¬¬¬-elim ¬¬¬x = λ x → ¬¬¬x (¬¬-intro x)\n\nnotNotNotElim : (Not (Not (Not a))) -> Not a\nnotNotNotElim = flip (.) notNotIntro\n-- notNotNotElim nnnx = nnnx . notNotIntro\n-- notNotNotElim nnnx x = nnnx (notNotIntro x) -- (\\f => f x)\n\nnnnnElim : (Not (Not (Not (Not a)))) -> (Not (Not a))\nnnnnElim = notNotNotElim\n\n-- contraposition : ∀ {A B : Set}\n-- → (A → B)\n-- -----------\n-- → (¬ B → ¬ A)\n-- contraposition f ¬y x = ¬y (f x)\n\ncontraposition : (a -> b) -> (Not b -> Not a)\ncontraposition = flip (.)\n-- contraposition f ny = ny (f x)\n\n-- _≢_ : ∀ {A : Set} → A → A → Set\n-- x ≢ y = ¬ (x ≡ y)\n\n-- inequality\n-- unequality\nNeq : a -> a -> Type\nNeq x y = Not (x === y)\n-- Neq = (Not .) . (===)\n\n-- _ : 1 ≢ 2\n-- _ = λ()\n\n-- PLFI.Part1.Negation.h1 : 1 = 2 -> Void\nex1 : Neq (S Z) (S (S Z))\n-- ex1 = ?h1 -- x impossible\n-- ex1 Refl impossible\nex1 x impossible\n\n-- PLFI.Part1.Negation.h2 : () = Nat -> Void\nex2 : Neq Unit Nat\n-- ex2 = ?h2 -- Refl impossible -- wat?\nex2 Refl impossible\n-- ex2 x impossible -- ex2 x is not a valid impossible case.\n\nNeq2 : a -> b -> Type\nNeq2 x y = Not (x ~=~ y)\n\n-- PLFI.Part1.Negation.h3 : () = 0 -> Void\nex3 : Neq2 Unit Z\nex3 x impossible\n\n-- peano : ∀ {m : ℕ} → zero ≢ suc m\n-- peano = λ()\n\npeano : {m : Nat} -> Neq Z (S m)\npeano Refl impossible\n\n-- id : ⊥ → ⊥\n-- id x = x\n-- \n-- id′ : ⊥ → ⊥\n-- id′ ()\n\nid1 : Void -> Void\nid1 x = x\n\nid2 : Void -> Void\nid2 x impossible\n\n0\nid1_id2 : FunExt => Negation.id1 === Negation.id2\n-- id1_id2 = funExt (\\x => case x of {})\nid1_id2 = funExt (\\x => absurd x)\n-- id1_id2 = funExt absurd\n\n0\nh : FunExt => (f : Void -> a) -> (g : Void -> a) -> f === g\nh f g = funExt (\\x => absurd x)\n\n-- assimilation : ∀ {A : Set} (¬x ¬x′ : ¬ A) → ¬x ≡ ¬x′\n-- assimilation ¬x ¬x′ = extensionality (λ x → ⊥-elim (¬x x))\n\n0\nassimilation : FunExt => (f, g : Not a) -> f === g\nassimilation f g = funExt (\\x => absurd (g x))\n\n-- <-irreflexive\n-- Using negation, show that strict inequality is irreflexive, that is, n < n holds for no n.\n\ntotal\nltIrreflexive0 : (n : N) -> Not (n < n)\nltIrreflexive0 (Suc _) (SucLT x) = ltIrreflexive0 _ x\n\nltIrreflexive1 : (n : N) -> Not (n < n)\nltIrreflexive1 Zero ZeroLT impossible\nltIrreflexive1 Zero (SucLT x) impossible\nltIrreflexive1 (Suc m) (SucLT x) = ltIrreflexive1 m x\n\n-- Exercise trichotomy (practice)\n-- Show that strict inequality satisfies trichotomy, that is, for any naturals m and n exactly one of the following holds:\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\nuniquenessOfEq : {a : Type} -> (n,m : a) -> (x,y : n === m) -> x === y\nuniquenessOfEq n n Refl Refl = Refl\n\nuniquenessOfLT : (n,m : N) -> (x,y : n < m) -> x === y\nuniquenessOfLT Zero (Suc n) ZeroLT ZeroLT = Refl\nuniquenessOfLT (Suc m) (Suc n) (SucLT x) (SucLT y) = cong SucLT (uniquenessOfLT m n x y)\n\nlessNotEqualLemma : (m < n) -> (m = n) -> Void\nlessNotEqualLemma ZeroLT Refl impossible\nlessNotEqualLemma (SucLT x) Refl = lessNotEqualLemma x Refl\n\nlessNotGreaterLemma : (m < n) -> (n < m) -> Void\nlessNotGreaterLemma ZeroLT ZeroLT impossible\nlessNotGreaterLemma ZeroLT (SucLT x) impossible\nlessNotGreaterLemma (SucLT x) (SucLT y) = lessNotGreaterLemma x y\n\ntrichotomy : (m, n : N) -> (t1, t2 : Trichotomy m n) -> t1 === t2\ntrichotomy m n (LT x) (LT y) = cong LT (uniquenessOfLT m n x y)\ntrichotomy m n (LT x) (EQ p) = absurd (lessNotEqualLemma x p)\ntrichotomy m n (LT x) (GT y) = absurd (lessNotGreaterLemma x y)\ntrichotomy m n (EQ p) (LT x) = absurd (lessNotEqualLemma x p)\ntrichotomy m n (EQ p) (EQ q) = cong EQ (uniquenessOfEq m n p q)\ntrichotomy m n (EQ p) (GT x) = absurd (lessNotEqualLemma x (sym p))\ntrichotomy m n (GT x) (LT y) = absurd (lessNotGreaterLemma x y)\ntrichotomy m n (GT x) (EQ p) = absurd (lessNotEqualLemma x (sym p))\ntrichotomy m n (GT x) (GT y) = cong GT (uniquenessOfLT n m x y)\n\ndata Trichotomy1 : N -> N -> Type where\n LT1 : (m < n) -> (Not (m = n)) -> (Not (n < m)) -> Trichotomy1 m n\n EQ1 : (Not (m < n)) -> (m = n) -> (Not (n < m)) -> Trichotomy1 m n\n GT1 : (Not (n < m)) -> (Not (m = n)) -> (n < m) -> Trichotomy1 m n\n\nlemma1 : (n < m) -> (Not (n = m), Not (m < n))\nlemma2 : (m = n) -> (Not (n < m), Not (m < n))\n", "meta": {"hexsha": "13d790aa132461f111206a05b5f87c699bc4c418", "size": 4973, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "PLFI/Part1/Negation.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/Negation.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/Negation.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": 26.5935828877, "max_line_length": 122, "alphanum_fraction": 0.5700784235, "num_tokens": 1946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6403352280223861}} {"text": "module InfList\n\npublic export\ndata InfList : Type -> Type where\n (::) : (value: elem) -> Inf (InfList elem) -> InfList elem\n\n%name InfList xs, ys, zs\n\npublic export\ntotal countFrom : Integer -> InfList Integer\ncountFrom x = x :: countFrom (x + 1)\n\npublic export\ntotal labelFrom : InfList k -> List a -> List (k, a)\nlabelFrom (key :: xs) [] = []\nlabelFrom (key :: xs) (y :: ys) = (key, y) :: labelFrom xs ys\n\npublic export\ntotal labelWith : Stream labelType -> List a -> List (labelType, a)\nlabelWith xs [] = []\nlabelWith (lbl :: lbls) (x :: xs) = (lbl, x) :: labelWith lbls xs\n\npublic export\ntotal label : List a -> List (Integer, a)\nlabel = labelWith (iterate (+1) 0)\n\npublic export\ntotal getPrefix : (count: Nat) -> InfList ty -> List ty\ngetPrefix Z (value :: xs) = []\ngetPrefix (S k) (value :: xs) = value :: (getPrefix k xs)\n", "meta": {"hexsha": "6e15629fa362e78ebbda4e8c4fa89e28bcd73c69", "size": 841, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "InfList.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": "InfList.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": "InfList.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.1290322581, "max_line_length": 67, "alphanum_fraction": 0.6349583829, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6402676346796708}} {"text": "module Algebra.ZeroOneOmega\n\nimport Algebra.Semiring\nimport Algebra.Preorder\n\n%default total\n\nexport\ndata ZeroOneOmega = Rig0 | Rig1 | RigW\n\nexport\nPreorder ZeroOneOmega where\n Rig0 <= _ = True\n Rig1 <= Rig1 = True\n Rig1 <= RigW = True\n RigW <= RigW = True\n _ <= _ = False\n preorderRefl {x = Rig0} = Refl\n preorderRefl {x = Rig1} = Refl\n preorderRefl {x = RigW} = Refl\n preorderTrans {x = Rig0} {y = y} {z = z} a b = Refl\n preorderTrans {x = Rig1} {y = Rig0} {z = Rig0} Refl Refl impossible\n preorderTrans {x = Rig1} {y = Rig1} {z = Rig0} _ Refl impossible\n preorderTrans {x = Rig1} {y = RigW} {z = Rig0} _ Refl impossible\n preorderTrans {x = Rig1} {y = y} {z = Rig1} a b = Refl\n preorderTrans {x = Rig1} {y = y} {z = RigW} a b = Refl\n preorderTrans {x = RigW} {y = Rig0} {z = _} Refl _ impossible\n preorderTrans {x = RigW} {y = Rig1} {z = _} Refl _ impossible\n preorderTrans {x = RigW} {y = RigW} {z = z} a b = b\n\npublic export\nEq ZeroOneOmega where\n (==) Rig0 Rig0 = True\n (==) Rig1 Rig1 = True\n (==) RigW RigW = True\n (==) _ _ = False\n\nexport\nShow ZeroOneOmega where\n show Rig0 = \"Rig0\"\n show Rig1 = \"Rig1\"\n show RigW = \"RigW\"\n\nexport\nrigPlus : ZeroOneOmega -> ZeroOneOmega -> ZeroOneOmega\nrigPlus Rig0 a = a\nrigPlus a Rig0 = a\nrigPlus Rig1 a = RigW\nrigPlus a Rig1 = RigW\nrigPlus RigW RigW = RigW\n\nexport\nrigMult : ZeroOneOmega -> ZeroOneOmega -> ZeroOneOmega\nrigMult Rig0 _ = Rig0\nrigMult _ Rig0 = Rig0\nrigMult Rig1 a = a\nrigMult a Rig1 = a\nrigMult RigW RigW = RigW\n\npublic export\nSemiring ZeroOneOmega where\n (|+|) = rigPlus\n (|*|) = rigMult\n plusNeutral = Rig0\n timesNeutral = Rig1\n\n||| The top value of a lattice\nexport\nTop ZeroOneOmega where\n top = RigW\n topAbs {x = Rig0} = Refl\n topAbs {x = Rig1} = Refl\n topAbs {x = RigW} = Refl\n", "meta": {"hexsha": "29fb001083c6ecb26977aef4bbeae2b159345bba", "size": 1772, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/src/Algebra/ZeroOneOmega.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/src/Algebra/ZeroOneOmega.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/src/Algebra/ZeroOneOmega.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": 23.9459459459, "max_line_length": 69, "alphanum_fraction": 0.6540632054, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338729, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.640014245805007}} {"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\nsumEntries : (Num a) => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos xs ys = let left = tryIndex pos xs\n right = tryIndex pos ys\n in case (left,right) of\n (Just x,Just y) => Just (x+y)\n _ => Nothing\n\n", "meta": {"hexsha": "cd436a7ae2b53acfa28c8d48c7e2779e066c72bb", "size": 570, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tryindex.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": "tryindex.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": "tryindex.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": 38.0, "max_line_length": 74, "alphanum_fraction": 0.4333333333, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6394790241684591}} {"text": "module DepSec.Poset\n\n%access public export\n%default total\n%hide Prelude.Monad.join\n\n||| Verified partial ordering\ninterface Poset a where\n leq : a -> a -> Type\n reflexive : (x : a) -> x `leq` x\n antisymmetric : (x, y : a) -> x `leq` y -> y `leq` x -> x = y\n transitive : (x, y, z : a) -> x `leq` y -> y `leq` z -> x `leq` z\n", "meta": {"hexsha": "d7a1f677966acf75e4822421f0c0784effddfbf3", "size": 345, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "DepSec/Poset.idr", "max_stars_repo_name": "simongregersen/DepSec", "max_stars_repo_head_hexsha": "10e0419acbe690c460df509d0cb9f4690867422c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-08-25T15:16:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T11:10:20.000Z", "max_issues_repo_path": "DepSec/Poset.idr", "max_issues_repo_name": "simongregersen/DepSec", "max_issues_repo_head_hexsha": "10e0419acbe690c460df509d0cb9f4690867422c", "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": "DepSec/Poset.idr", "max_forks_repo_name": "simongregersen/DepSec", "max_forks_repo_head_hexsha": "10e0419acbe690c460df509d0cb9f4690867422c", "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.5384615385, "max_line_length": 70, "alphanum_fraction": 0.5565217391, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6393674692965663}} {"text": "module Prelude.Enum\n\nimport Data.List\nimport Data.Nat\n\nexport\nCast Int Nat where\n cast i = fromInteger (cast i)\n\nexport\nCast Integer Nat where\n cast = fromInteger\n\nexport\nnatRange : Nat -> List Nat\nnatRange n = List.reverse (go n)\n where go : Nat -> List Nat\n go Z = []\n go (S n) = n :: go n\n\n-- predefine Nat versions of Enum, so we can use them in the default impls\nexport\ncountFrom : Num n => n -> n -> Stream n\ncountFrom start diff = start :: countFrom (start + diff) diff\n\nexport total\nnatEnumFromThen : Nat -> Nat -> Stream Nat\nnatEnumFromThen n next = countFrom n (minus next n)\n\nexport total\nnatEnumFromTo : Nat -> Nat -> List Nat\nnatEnumFromTo n m = if n <= m\n then go n m\n else List.reverse $ go m n\n where go : Nat -> Nat -> List Nat\n go n m = map (plus n) (natRange (minus (S m) n))\n\nexport total\nnatEnumFromThenTo' : Nat -> Nat -> Nat -> List Nat\nnatEnumFromThenTo' _ Z _ = []\nnatEnumFromThenTo' n (S inc) m = map (plus n . (* (S inc))) (natRange (S (divNatNZ (minus m n) (S inc) SIsNotZ)))\n\nexport total\nnatEnumFromThenTo : Nat -> Nat -> Nat -> List Nat\nnatEnumFromThenTo n next m = if n == m then [n]\n else if n < m then natEnumFromThenTo' n (minus next n) m\n else case minus n next of\n Z => []\n S step => List.reverse . map (+ (modNatNZ (minus n m) (S step) SIsNotZ)) $ natEnumFromThenTo' m (minus n next) n\n where modNatNZ : Nat -> (m : Nat) -> Not (m = 0) -> Nat\n modNatNZ n m nz = minus n $ mult m $ divNatNZ n m nz\n\npublic export\ninterface Enum a where\n total pred : a -> a\n total succ : a -> a\n succ e = fromNat (S (toNat e))\n total toNat : a -> Nat\n total fromNat : Nat -> a\n total enumFrom : a -> Stream a\n enumFrom n = n :: enumFrom (succ n)\n total enumFromThen : a -> a -> Stream a\n enumFromThen x y = map fromNat (natEnumFromThen (toNat x) (toNat y))\n total enumFromTo : a -> a -> List a\n enumFromTo x y = map fromNat (natEnumFromTo (toNat x) (toNat y))\n total enumFromThenTo : a -> a -> a -> List a\n enumFromThenTo x1 x2 y = map fromNat (natEnumFromThenTo (toNat x1) (toNat x2) (toNat y))\n\npublic export\nEnum Nat where\n pred n = Nat.pred n\n succ n = S n\n toNat x = id x\n fromNat x = id x\n enumFromThen x y = natEnumFromThen x y\n enumFromThenTo x y z = natEnumFromThenTo x y z\n enumFromTo x y = natEnumFromTo x y\n\npublic export\nEnum Integer where\n pred n = n - 1\n succ n = n + 1\n toNat n = cast n\n fromNat n = cast n\n enumFromThen n inc = countFrom n (inc - n)\n enumFromTo n m = if n <= m\n then go n m\n else List.reverse $ go m n\n where go' : Integer -> List Nat -> List Integer\n go' _ [] = []\n go' n (x :: xs) = n + cast x :: go' n xs\n go : Integer -> Integer -> List Integer\n go n m = go' n (natRange (S (cast {to = Nat} (m - n))))\n enumFromThenTo n next m = if n == m then [n]\n else if next - n == 0 || (next - n < 0) /= (m - n < 0) then []\n else go (natRange (S (divNatNZ (fromInteger (abs (m - n))) (S (fromInteger ((abs (next - n)) - 1))) SIsNotZ)))\n where go : List Nat -> List Integer\n go [] = []\n go (x :: xs) = n + (cast x * (next - n)) :: go xs\n\npublic export\nEnum Int where\n pred n = n - 1\n succ n = n + 1\n toNat n = cast n\n fromNat n = cast n\n enumFromTo n m = if n <= m\n then go n m\n else List.reverse $ go m n\n where go' : List Int -> Nat -> Int -> List Int\n go' acc Z m = m :: acc\n go' acc (S k) m = go' (m :: acc) k (m - 1)\n go : Int -> Int -> List Int\n go n m = go' [] (cast {to = Nat} (m - n)) m\n enumFromThen n inc = countFrom n (inc - n)\n\n enumFromThenTo n next m = if n == m then [n]\n else if next - n == 0 || (next - n < 0) /= (m - n < 0) then []\n else go (natRange (S (divNatNZ (cast {to=Nat} (abs (m - n))) (S (cast {to=Nat} ((abs (next - n)) - 1))) SIsNotZ)))\n where go : List Nat -> List Int\n go [] = []\n go (x :: xs) = n + (cast x * (next - n)) :: go xs\n\npublic export\nEnum Char where\n toNat c = toNat (fromInteger $ cast c)\n fromNat n = cast (cast n {to=Int})\n\n pred c = fromNat (pred (toNat c))\n\n-- syntax \"[\" [start] \"..\" [end] \"]\"\n-- = enumFromTo start end\n-- syntax \"[\" [start] \",\" [next] \"..\" [end] \"]\"\n-- = enumFromThenTo start next end\n\n-- syntax \"[\" [start] \"..\" \"]\"\n-- = enumFrom start\n-- syntax \"[\" [start] \",\" [next] \"..\" \"]\"\n-- = enumFromThen start next\n", "meta": {"hexsha": "faef430ce6ca982b4001d1f8c913bdf4844c034a", "size": 4687, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "bautzen1945/idris/Prelude/Enum.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/Prelude/Enum.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/Prelude/Enum.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.4785714286, "max_line_length": 146, "alphanum_fraction": 0.5387241306, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6391984951542565}} {"text": "module Data.Lawful.Eqv\n\n%default total\n\n||| `Eq` enriched with reflexivity, commutativity and transitivity.\npublic export\ninterface Eq a => Eqv a where\n 0 eqvReflexive : (x : a) -> x == x = True\n 0 eqvCommutative : (x, y : a) -> x == y = y == x\n 0 eqvTransitive : (x, y, z : a) -> x == y = True -> y == z = True -> x == z = True\n\nexport\nEqv () where\n eqvReflexive () = Refl\n eqvCommutative () () = Refl\n eqvTransitive () () () Refl Refl = Refl\n\nexport\nEqv Bool where\n eqvReflexive True = Refl\n eqvReflexive False = Refl\n\n eqvCommutative True True = Refl\n eqvCommutative True False = Refl\n eqvCommutative False True = Refl\n eqvCommutative False False = Refl\n\n eqvTransitive True True True Refl Refl = Refl\n eqvTransitive False False False Refl Refl = Refl\n\nexport\nEqv Nat where\n eqvReflexive 0 = Refl\n eqvReflexive (S n) = rewrite eqvReflexive n in Refl\n\n eqvCommutative 0 0 = Refl\n eqvCommutative 0 (S m) = Refl\n eqvCommutative (S n) 0 = Refl\n eqvCommutative (S n) (S m) = rewrite eqvCommutative n m in Refl\n\n eqvTransitive Z Z Z Refl Refl = Refl\n eqvTransitive (S n) (S m) (S k) nm mk = eqvTransitive n m k nm mk\n\nsplit_and : {a, b : Bool} -> a && b = True -> (a = True, b = True)\nsplit_and {a=True} {b=True} Refl = (Refl, Refl)\n\nexport\nEqv a => Eqv (List a) where\n eqvReflexive [] = Refl\n eqvReflexive (x::xs) = rewrite eqvReflexive x in eqvReflexive xs\n\n eqvCommutative [] [] = Refl\n eqvCommutative [] (x::xs) = Refl\n eqvCommutative (x::xs) [] = Refl\n eqvCommutative (x::xs) (y::ys) = rewrite eqvCommutative x y in\n rewrite eqvCommutative xs ys in\n Refl\n\n eqvTransitive [] [] [] Refl Refl = Refl\n eqvTransitive (x::xs) (y::ys) (z::zs) xy yz = rewrite eqvTransitive x y z (fst $ split_and xy) (fst $ split_and yz) in\n rewrite eqvTransitive xs ys zs (snd $ split_and xy) (snd $ split_and yz) in\n Refl\n\nexport\n(Eqv a, Eqv b) => Eqv (a, b) where\n eqvReflexive (a, b) = rewrite eqvReflexive a in\n rewrite eqvReflexive b in\n Refl\n\n eqvCommutative (a, b) (c, d) = rewrite eqvCommutative a c in\n rewrite eqvCommutative b d in\n Refl\n\n eqvTransitive (a, b) (c, d) (e, f) ac ce = rewrite eqvTransitive a c e (fst $ split_and ac) (fst $ split_and ce) in\n rewrite eqvTransitive b d f (snd $ split_and ac) (snd $ split_and ce) in\n Refl\n\nexport\n(Eqv a, Eqv b) => Eqv (Either a b) where\n eqvReflexive (Left x) = rewrite eqvReflexive x in Refl\n eqvReflexive (Right y) = rewrite eqvReflexive y in Refl\n\n eqvCommutative (Left x) (Left y) = rewrite eqvCommutative x y in Refl\n eqvCommutative (Right x) (Right y) = rewrite eqvCommutative x y in Refl\n eqvCommutative (Left x) (Right y) = Refl\n eqvCommutative (Right x) (Left y) = Refl\n\n eqvTransitive (Left x) (Left y) (Left z ) xy yz = eqvTransitive x y z xy yz\n eqvTransitive (Right x) (Right y) (Right z) xy yz = eqvTransitive x y z xy yz\n", "meta": {"hexsha": "efc3bd9eb018c0ccb9a651d47412c03a2696298a", "size": 3210, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Lawful/Eqv.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/Lawful/Eqv.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/Lawful/Eqv.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": 35.6666666667, "max_line_length": 123, "alphanum_fraction": 0.5919003115, "num_tokens": 1127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6391424926357256}} {"text": "-- Minimal implicational modal logic, PHOAS approach, initial encoding\n\nmodule Pi.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\ninfixl 1 :$\ndata Tm : Nat -> Cx -> Ty -> Type where\n var : isTrue a d tc -> Tm d tc a\n lam' : (isTrue a d tc -> Tm d tc b) -> Tm d tc (a :=> b)\n (:$) : Tm d tc (a :=> b) -> Tm d tc a -> Tm d tc b\n box : Tm (succ d) tc a -> Tm d tc (BOX a)\n unbox' : Tm d tc (BOX a) -> (isTrue a gd tc -> Tm d tc b) -> Tm d tc b\n\nlam'' : (Tm d tc a -> Tm d tc b) -> Tm d tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\nunbox'' : Tm d tc (BOX a) -> (Tm gd tc a -> Tm d tc b) -> Tm d tc b\nunbox'' x' f = unbox' x' $ \\x => f (var x)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\nsyntax \"unbox\" [a'] as {a} \":=>\" [b] = unbox'' a' (\\a => b)\n\nThm : Ty -> Type\nThm a = {d : Nat} -> {tc : Cx} -> Tm 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": "3937711268899036abfe19ace6bb3f7923e43ed4", "size": 1548, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pi/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/Pi/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/Pi/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.64, "max_line_length": 74, "alphanum_fraction": 0.4554263566, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6391424902206201}} {"text": "> data 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\n> append : Vect n a -> Vect m a -> Vect (n + m) a\n> append {n} xs ys = ?foo\n\n> vadd : Num a => Vect n a -> Vect n a -> Vect n a\n> vadd [] ys = ?bar\n> vadd (x :: xs) ys = ?baz\n\n> suc : (x : Nat) -> (y : Nat) -> x = y -> S x = S y\n> suc x y prf = ?quux\n\n> suc' : x = y -> S x = S y\n> suc' {x} {y} prf = ?quuz\n", "meta": {"hexsha": "140e7ce2471e558c17377bf678ebf22b557a3e80", "size": 439, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/literate001/IEdit.lidr", "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/literate001/IEdit.lidr", "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/literate001/IEdit.lidr", "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": 23.1052631579, "max_line_length": 52, "alphanum_fraction": 0.4487471526, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.639094975942085}} {"text": "module Resumption\n\n{-\ndata Res a = Done a | Pause (Res a)\n-}\n\ndata Res : Type -> Type where\n Done : a -> Res a\n Pause : (Res a) -> (Res a)\n\n\ninstance Functor Res where\n map f (Done a) = Done (f a)\n map f (Pause r) = Pause (map f r)\n\ninstance Applicative Res where\n pure a = Done a\n (Done f) <$> res = map f res\n (Pause p) <$> res = p <$> res\n\ninstance Monad Res where\n (Done a) >>= f = f a\n (Pause a) >>= f = a >>= f\n\n\n{-\ndata React i o a = Done a | Pause o (i -> o)\n-}\n\n\ndata React : Type -> Type -> Type -> Type where\n D : a -> React i o a\n P : o -> (i -> React i o a) -> React i o a\n\ninstance Functor (React i o) where\n map f (D a) = D (f a)\n map f (P o r) = P o (\\i => map f (r i))\n\ninstance Applicative (React i o) where\n pure a = D a\n (D f) <$> res = map f res\n (P o f) <$> res = P o (\\i => (f i) <$> res)\n\ninstance Monad (React i o) where\n (D a) >>= f = f a\n (P o r) >>= f = P o (\\i => (r i) >>= f)\n\n\npar : React i o a -> React j n a -> React (i,j) (o,n) a\npar (D a) _ = D a\npar _ (D a) = D a\npar (P o r1) (P n r2) = P (o,n) (\\(i1,i2) => par (r1 i1) (r2 i2))\n\nrefold : (o1 -> o2) -> (i2 -> o1 -> i1) -> React i1 o1 a -> React i2 o2 a\nrefold _ _ (D a) = D a\nrefold fo fi (P o ii) = P (fo o) (\\i2 => refold fo fi (ii (fi i2 o)))\n\nparvect : React (Vect k s) (Vect k' t) a -> \n React (Vect n s) (Vect n' t) a ->\n React (Vect (k+n) s) (Vect (k'+n') t) a\nparvect (D a) _ = D a\nparvect _ (D a) = D a\nparvect {k} (P ol r1) (P or r2) = P (ol ++ or) (\\i => let (i1,i2) = splitAt k i\n in parvect (r1 i1) (r2 i2))\n", "meta": {"hexsha": "2eae8d9f26bbc5953d5b2283bd694c9d07bba5cd", "size": 1621, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Resumption.idr", "max_stars_repo_name": "igraves/draconis-resumptions", "max_stars_repo_head_hexsha": "ec49c33fa25e637fc39ab5a8c62e03f7586128fd", "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": "Resumption.idr", "max_issues_repo_name": "igraves/draconis-resumptions", "max_issues_repo_head_hexsha": "ec49c33fa25e637fc39ab5a8c62e03f7586128fd", "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": "Resumption.idr", "max_forks_repo_name": "igraves/draconis-resumptions", "max_forks_repo_head_hexsha": "ec49c33fa25e637fc39ab5a8c62e03f7586128fd", "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.9384615385, "max_line_length": 79, "alphanum_fraction": 0.4836520666, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6386570809913881}} {"text": "module Proofs.SemigroupTheory\n\nimport Specifications.Semigroup\n\n%default total\n%access export\n\nabelianCongruence : isAbelian op -> x = y -> op x a = op a y\nabelianCongruence {a} {x} abel given = abel x a === cong given\n", "meta": {"hexsha": "bfa4e49d7f0966bce3fb88e676beec9096a91828", "size": 219, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Proofs/SemigroupTheory.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/Proofs/SemigroupTheory.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/Proofs/SemigroupTheory.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": 21.9, "max_line_length": 62, "alphanum_fraction": 0.7351598174, "num_tokens": 68, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505248181418, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6384887902430844}} {"text": "module Main\n\n\ndata Vector : Nat -> Type -> Type where\n Nil : Vector Z a\n (::) : a -> Vector k a -> Vector (S k) a\n\n{-\ninterface Functor (f : Type -> Type) where\n fmap : (a -> b) -> (f a -> f b)\n-}\nimplementation Functor (Vector Z) where\n map f = const Nil\n\nimplementation Functor (Vector n) => Functor (Vector (S n)) where\n map f (x :: xs) = f x :: map f xs\n \n \nimplementation Applicative (Vector Z) where\n pure _ = Nil\n (<*>) v = const Nil\n \nimplementation Applicative (Vector n) => Applicative (Vector (S n)) where\n pure a = a :: pure a\n (<*>) (f :: fs) (a :: as) = f a :: (fs <*> as)\n\ntail : Vector n a -> Vector (pred n) a\ntail (x :: xs) = xs\n \nlength : ( xs : Vector n a ) -> Nat\nlength Nil = 0\nlength x = succ . Main.length . Main.tail $ x\n\nmain : IO ()\nmain = print $ Main.length (0::1::2::3::4::5::Nil)\n", "meta": {"hexsha": "2deefeb67ea0cc97e486a83acb833edf7a9bf57e", "size": 850, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "vectors.idr", "max_stars_repo_name": "Crazycolorz5/IdrisExplorations", "max_stars_repo_head_hexsha": "af851f62783a9bad196f9e45764f5ed23805d3a1", "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": "vectors.idr", "max_issues_repo_name": "Crazycolorz5/IdrisExplorations", "max_issues_repo_head_hexsha": "af851f62783a9bad196f9e45764f5ed23805d3a1", "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": "vectors.idr", "max_forks_repo_name": "Crazycolorz5/IdrisExplorations", "max_forks_repo_head_hexsha": "af851f62783a9bad196f9e45764f5ed23805d3a1", "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.6111111111, "max_line_length": 73, "alphanum_fraction": 0.5552941176, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6383390864834546}} {"text": "module Algebra.Semigroup\n\n%default total\n\n||| This interface is a witness that for a\n||| type `a` the axioms of a semigroup hold: `(<+>)` is associative.\n|||\n||| Note: If the type is actually a monoid, use `Data.Algebra.LMonoid` instead.\npublic export\ninterface Semigroup a => LSemigroup a where\n 0 appendAssociative : {x,y,z : a} -> x <+> (y <+> z) === (x <+> y) <+> z\n\n||| This interface is a witness that for a\n||| type `a` the axioms of a commutative semigroup hold:\n||| `(<+>)` is commutative.\npublic export\ninterface LSemigroup a => CommutativeSemigroup a where\n 0 appendCommutative : {x,y : a} -> x <+> y === y <+> x\n", "meta": {"hexsha": "e747ce50a2bd86e2ccdc387569fca3120e5cdadb", "size": 626, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Semigroup.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/Semigroup.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/Semigroup.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": 32.9473684211, "max_line_length": 79, "alphanum_fraction": 0.6533546326, "num_tokens": 202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6380493554016262}} {"text": "> module Unique.Properties\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Unique.Predicates\n> import Decidable.Predicates\n> import Finite.Predicates\n> import Sigma.Sigma\n\n> %default total\n> %access public export\n\n\n> |||\n> uniqueLemma : {A : Type} -> {P : A -> Type} -> ((a : A) -> Unique (P a)) ->\n> (a1 : A) -> (a2 : A) -> (pa1 : P a1) -> (pa2 : P a2) -> \n> (a1 = a2) -> pa1 = pa2\n> uniqueLemma {A} {P} prf a a pa1 pa2 Refl = prf a pa1 pa2\n> %freeze uniqueLemma\n\n\n> ||| Unique properties are finite\n> uniqueFiniteLemma1 : {P : Type} -> P -> Unique P -> Finite P\n> uniqueFiniteLemma1 {P} p uP = MkSigma n (MkIso to from toFrom fromTo) where\n> n : Nat\n> n = S Z\n> to : P -> Fin n\n> to x = FZ\n> from : Fin n -> P\n> from FZ = p\n> from (FS k) = absurd k\n> toFrom : (k : Fin n) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS k) = absurd k\n> fromTo : (x : P) -> from (to x) = x\n> fromTo x = uP p x\n> %freeze uniqueFiniteLemma1\n\n\n> ||| Unique properties are finite\n> uniqueFiniteLemma2 : {P : Type} -> Not P -> Finite P\n> uniqueFiniteLemma2 {P} contra = MkSigma n (MkIso to from toFrom fromTo) where\n> n : Nat\n> n = Z\n> to : P -> Fin n\n> to x = void (contra x)\n> from : Fin n -> P\n> from k = absurd k\n> toFrom : (k : Fin n) -> to (from k) = k\n> toFrom k = absurd k\n> fromTo : (x : P) -> from (to x) = x\n> fromTo x = void (contra x)\n> %freeze uniqueFiniteLemma2\n\n\n> ||| Decidable and unique properties are finite\n> decUniqueFiniteLemma : {P : Type} -> Dec P -> Unique P -> Finite P\n> decUniqueFiniteLemma (Yes p) uP = uniqueFiniteLemma1 p uP\n> decUniqueFiniteLemma (No contra) _ = uniqueFiniteLemma2 contra\n> %freeze decUniqueFiniteLemma\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "25422f1aac7ac5c413d5cf6be2a5cfb82be07c1f", "size": 1736, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Unique/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": "Unique/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": "Unique/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": 25.9104477612, "max_line_length": 79, "alphanum_fraction": 0.5887096774, "num_tokens": 620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6380493496676073}} {"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 i) = absurd $ FinZAbsurd i\neval' (TAbs e) = TAbs e\neval' (TApp e1 e2) = let (TAbs e1v) = eval' e1\n e2v = eval' e2\n in eval' $ subst e2v FZ e1v\neval' (TRec e e0 e1) = case eval' e of\n TZero => eval' e0\n TSucc n => eval' $ (subst n FZ (subst (TRec n e0 e1) FZ e1))\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 i) = absurd $ FinZAbsurd i\nevalBigStep (TAbs x) = (TAbs x ** (VAbs, BStValue VAbs))\nevalBigStep (TApp x y) = case evalBigStep x of\n (ex ** (VZero , bStx)) impossible\n (ex ** (VSucc _, bStx)) impossible\n (TAbs ex ** (VAbs, bStx)) => let (ey ** (_ , bSty)) = evalBigStep y\n (er ** (vr, bStr)) = evalBigStep (subst ey FZ ex)\n in (er ** (vr, BStApp bStx bSty bStr))\nevalBigStep (TRec x y z) = case evalBigStep x of\n (TZero ** (_, bStx)) => let (ey ** (vy, bSty)) = evalBigStep y\n in (ey ** (vy, BStRecZero bStx bSty))\n (TSucc ex ** (_, bStx)) => let (es ** (vs, bSts)) = evalBigStep (subst ex FZ (subst (TRec ex y z) FZ z))\n in (es ** (vs, BStRecSucc bStx bSts))\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))\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\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\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\ndata Env : Context n -> Type where\n ENil : Env []\n ECons : denoteType t -> Env ctx -> Env (t::ctx)\n\n\ntotal lookup : {ctx : Context n} -> \n (i : Fin n) -> Env ctx -> denoteType (index i ctx)\nlookup FZ (ECons x _) = x\nlookup (FS i') (ECons _ env') = lookup i' env'\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 -> Term ctx t -> denoteType t\nevalEnv' env (TVar i {prf}) = rewrite (sym prf) in lookup i env\nevalEnv' env (TAbs e) = \\x => evalEnv' (ECons x env) e \nevalEnv' env (TApp e1 e2) = (evalEnv' env e1) (evalEnv' env e2)\nevalEnv' env (TRec e e0 e1) = let e' = evalEnv' env e\n e0' = evalEnv' env e0\n e1' = \\n => \\x => (evalEnv' (ECons x (ECons n env)) e1)\n in primRec e' e0' e1'\nevalEnv' env TZero = Z\nevalEnv' env (TSucc e) = S (evalEnv' env e)\nevalEnv' env (TPred e) = case evalEnv' env e of\n Z => Z\n S n => n\nevalEnv' env (TIfz e1 e2 e3) = case evalEnv' env e1 of\n Z => evalEnv' env e2\n S _ => evalEnv' env e3\n\n\ntotal evalEnv : Term [] TyNat -> Nat\nevalEnv = evalEnv' ENil\n\n-- End: ENVIRONMENT-BASED/DENOTATIONAL EVALUATOR\n------------------------------------------------\n", "meta": {"hexsha": "e0fd04c163fa7e0017874139d801a6bd6e8bd322", "size": 5747, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "total/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": "total/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": "total/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.8397435897, "max_line_length": 106, "alphanum_fraction": 0.4670262746, "num_tokens": 1777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6376824229794632}} {"text": "import Data.Vect\ndouble : Num ty => ty -> ty\ndouble x = x * x\n\nadd : Int -> Int -> Int\nadd x y = x + y\n\ntwice : (a -> a) -> a -> a\ntwice f x = f (f x)\n\nquadruple : Num a => a -> a\nquadruple = twice double\n\n\nfourInts : Vect 4 Int\nfourInts = [0, 1, 2, 3]\nsixInts : Vect 6 Int\nsixInts = [4, 5, 6, 7, 8, 9]\n\nlet tenInts = fourInts ++ sixInts\n", "meta": {"hexsha": "2630921ad5848f4bd46f6e072a3616bb4e3de411", "size": 339, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tdd.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": "tdd.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": "tdd.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": 16.1428571429, "max_line_length": 34, "alphanum_fraction": 0.5663716814, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6375204661085271}} {"text": "||| Here we present an example not found in the paper.\n|||\n||| We define an *Edge Bounded Graph* as a graph whose nodes are bounded on the number of edges they can contain.\n||| Here we differentiate between bounds for roots, leaf, and other nodes.\n|||\n||| We define a handler to generate a simple adjacency graph representation from our graph language description.\nmodule Examples.EdgeBoundedGraph\n\nimport Data.List\n\nimport Resources\n\n%access public export\n%default total\n\nnamespace TypeLevel\n\n ||| The different node types.\n data Ty = LEAF | ROOT | NODE\n\n namespace State\n ||| Leaf nodes can accept a certain number of connections.\n record LeafState where\n constructor MkLeafState\n max_incoming : Nat\n incoming : Nat\n\n ||| Root nodes can make a certain number of connections.\n record RootState where\n constructor MkRootState\n max_outgoing : Nat\n outgoing : Nat\n\n ||| Nodes that can make, and accept, a certain number of connections.\n record NodeState where\n constructor MkNodeState\n max_incoming : Nat\n max_outgoing : Nat\n incoming : Nat\n outgoing : Nat\n\n ||| Map variable types to concrete abstract states.\n CalcStateType : Ty -> Type\n CalcStateType LEAF = LeafState\n CalcStateType ROOT = RootState\n CalcStateType NODE = NodeState\n\nnamespace Predicates\n data DIRECTION = O | I\n\n ||| Can a node be connected.\n data CanConnect : DIRECTION\n -> Var Ty ty\n -> StateItem Ty CalcStateType ty\n -> Type\n where\n CanNodeIn : CanConnect I lbl (MkStateItem NODE lbl (MkNodeState a b (S n) x))\n CanNodeOut : CanConnect O lbl (MkStateItem NODE lbl (MkNodeState a b x (S n)))\n CanRootOut : CanConnect O lbl (MkStateItem ROOT lbl (MkRootState a (S n)))\n CanLeafIn : CanConnect I lbl (MkStateItem LEAF lbl (MkLeafState a (S n)))\n\n ||| Has the node be used completely.\n data Used : StateItem Ty CalcStateType ty -> Type where\n IsNodeUsed : Used (MkStateItem NODE lbl (MkNodeState a b Z Z))\n IsRootUsed : Used (MkStateItem ROOT lbl (MkRootState a Z))\n IsLeafUsed : Used (MkStateItem LEAF lbl (MkLeafState a Z))\n\n ||| Has the node been used partially.\n data UsedS : StateItem Ty CalcStateType ty -> Type where\n -- All used.\n AllUsedL : UsedS (MkStateItem LEAF lbl (MkLeafState a Z))\n AllUsedR : UsedS (MkStateItem ROOT lbl (MkRootState a Z))\n AllUsedN : UsedS (MkStateItem NODE lbl (MkNodeState a b Z Z))\n\n -- All incoming ports are used.\n IUsedNode : UsedS (MkStateItem NODE lbl (MkNodeState a b Z x))\n IUsedLeaf : UsedS (MkStateItem LEAF lbl (MkLeafState a Z))\n\n -- All outgoing ports are used.\n OUsedNode : UsedS (MkStateItem NODE lbl (MkNodeState a b x Z))\n OUsedRoot : UsedS (MkStateItem ROOT lbl (MkRootState a Z))\n\n ||| Some ports\n SomeNodes : LTE x a\n -> LTE y b\n -> UsedS (MkStateItem NODE lbl (MkNodeState a b x y))\n\n SomeRoot : LTE x a\n -> UsedS (MkStateItem ROOT lbl (MkRootState a x))\n\n SomeLeaf : LTE x a\n -> UsedS (MkStateItem LEAF lbl (MkLeafState a x))\n\nnamespace Update\n\n ||| The type-level function to update a node's usage count.\n Use : (d : DIRECTION)\n -> (item : StateItem Ty CalcStateType ty)\n -> (bewijs : CanConnect d lbl item)\n -> StateItem Ty CalcStateType ty\n Use I (MkStateItem NODE lbl (MkNodeState a b (S n) x)) CanNodeIn {ty = NODE} =\n MkStateItem NODE lbl (MkNodeState a b n x)\n Use O (MkStateItem NODE lbl (MkNodeState a b x (S n))) CanNodeOut {ty = NODE} =\n MkStateItem NODE lbl (MkNodeState a b x n)\n Use O (MkStateItem ROOT lbl (MkRootState a (S n))) CanRootOut {ty = ROOT} =\n MkStateItem ROOT lbl (MkRootState a n)\n Use I (MkStateItem LEAF lbl (MkLeafState a (S n))) CanLeafIn {ty = LEAF} =\n MkStateItem LEAF lbl (MkLeafState a n)\n\nnamespace Declaration\n\n{- [ Language Definition ] -}\n\n data GraphLang : Lang Ty CalcStateType where\n ||| Create a node that can accept `i` connections, and make `o` connections.\n Node : (i,o : Nat) -> GraphLang (Var Ty NODE) old (\\lbl => MkStateItem NODE lbl (MkNodeState i o i o) :: old)\n ||| Create a new root node that can make `o` connections.\n Root : (o : Nat) -> GraphLang (Var Ty ROOT) old (\\lbl => MkStateItem ROOT lbl (MkRootState o o) :: old)\n ||| Create a new leaf node that can accept `i` connections.\n Leaf : (i : Nat) -> GraphLang (Var Ty LEAF) old (\\lbl => MkStateItem LEAF lbl (MkLeafState i i) :: old)\n\n ||| Connect two nodes together if they each have space to allow an edge.\n Stop : GraphLang () old (const Nil)\n\n ||| Connect two nodes together if they each have space to allow an edge.\n Connect : (a : Var Ty tyO)\n -> (b : Var Ty tyI)\n\n -> (prfO : InContext tyO (CanConnect O a) old)\n -> (prfI : InContext tyI (CanConnect I b) (update old prfO (Use O)))\n -> GraphLang () old (const $ update (update old prfO (Use O)) prfI (Use I))\n\n{- [ NOTE ]\n\nA high-level API to embedd language expressions within `LangM`, and calculate language proofs.\n\n\n-}\n ||| The definition of an edge bounded graph.\n MYGRAPH : LANG Ty CalcStateType\n MYGRAPH = MkLang Ty CalcStateType GraphLang\n\n ||| Create a node that can accept `i` connections, and make `o` connections.\n node : (i,o : Nat)\n -> LangM m (Var Ty NODE) MYGRAPH old (\\lbl => (MkStateItem NODE lbl (MkNodeState i o i o)) :: old)\n node i o = Expr $ Node i o\n\n ||| Create a new root node that can make `o` connections.\n root : (o : Nat)\n -> LangM m (Var Ty ROOT) MYGRAPH old (\\lbl => MkStateItem ROOT lbl (MkRootState o o) :: old)\n root o = Expr $ Root o\n\n ||| Create a new leaf node that can accept `i` connections.\n leaf : (i : Nat)\n -> LangM m (Var Ty LEAF) MYGRAPH old (\\lbl => MkStateItem LEAF lbl (MkLeafState i i) :: old)\n leaf i = Expr $ Leaf i\n\n ||| Declare the end of tthe specification.\n stop : LangM m () MYGRAPH old (const Nil)\n stop = Expr Stop\n\n ||| Connect two nodes together if they each have space to allow an edge.\n connect : (a : Var Ty tyO)\n -> (b : Var Ty tyI)\n\n -> {auto prfO : InContext tyO (CanConnect O a) old}\n -> {auto prfI : InContext tyI (CanConnect I b) (update old prfO (Use O))}\n -> LangM m () MYGRAPH old (const $ update (update old prfO (Use O)) prfI (Use I))\n connect a b {prfO} {prfI} = Expr $ Connect a b prfO prfI\n\n ||| A simple graph representation.\n record Graph where\n constructor MkGraph\n nodes : List Nat\n edges : List (Nat, Nat)\n\n||| Nodes are *just* Natural numbers\nRealVar Ty where\n CalcRealType _ = Nat\n\n||| A pure evaluation context to generate the graph instance.\n|||\n||| **note** the accumulator is one that contains the node counter,\n||| and the graph being constructed.\nHandler Ty CalcStateType GraphLang (Nat, Graph) Basics.id where\n handle env Stop (c,g) cont = cont () Nil (c,g)\n handle env (Node i o) (c,g) cont =\n cont MkVar (MkTag c::env) (S c, record {nodes $= (c::)} g)\n handle env (Root o) (c,g) cont =\n cont MkVar (MkTag c::env) (S c, record {nodes $= (c::)} g)\n handle env (Leaf i) (c,g) cont =\n cont MkVar (MkTag c::env) (S c, record {nodes $= (c::)} g)\n handle env (Connect a b prfO prfI) (c,g) cont =\n let (MkTag l) = lookup env prfO in\n let env' = update env prfO (Use O) in\n let (MkTag r) = lookup env' prfI in\n let env'' = update env' prfI (Use I) in\n cont () env'' (c,record {edges $= ((l,r)::)} g)\n\n||| An example program that is closed.\nexample : LangM m () MYGRAPH Nil (const Nil)\nexample = do\n a <- node 2 5\n b <- root 1\n c <- root 3\n\n d <- root 5\n connect c a\n connect b a\n stop\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "a60d265c981d24f6e283e3aa2973a5fadca5b04a", "size": 7929, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Example/EdgeBoundedGraph.idr", "max_stars_repo_name": "border-patrol/resources", "max_stars_repo_head_hexsha": "930a1c4be75ca800340a7dc7c6b4e6a095d95e8d", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-13T05:32:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-13T07:10:09.000Z", "max_issues_repo_path": "Example/EdgeBoundedGraph.idr", "max_issues_repo_name": "border-patrol/resources", "max_issues_repo_head_hexsha": "930a1c4be75ca800340a7dc7c6b4e6a095d95e8d", "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": "Example/EdgeBoundedGraph.idr", "max_forks_repo_name": "border-patrol/resources", "max_forks_repo_head_hexsha": "930a1c4be75ca800340a7dc7c6b4e6a095d95e8d", "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": 37.2253521127, "max_line_length": 115, "alphanum_fraction": 0.6258040106, "num_tokens": 2319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6364576014095231}} {"text": "AdderType: (numargs: Nat) -> Type -> Type\nAdderType Z numType = numType\nAdderType (S k) numType = (next: numType) -> AdderType k numType\n\nadder: Num numType => (numargs: Nat) -> numType -> AdderType numargs numType\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (next + acc)\n----------------------------------------------------------------------------\ndata Format = Number Format\n | Str Format\n | Character Format\n | FNumber Format\n | Lit String Format\n | End\n----------------------------------------------------------------------------\nPrintfType: Format -> Type\nPrintfType (Number fmt) = (i: Int) -> PrintfType fmt\nPrintfType (Str fmt) = (str: String) -> PrintfType fmt\nPrintfType (Character fmt) = (str: Char) -> PrintfType fmt\nPrintfType (FNumber fmt) = (str: Double) -> PrintfType fmt\nPrintfType (Lit str fmt) = PrintfType fmt\nPrintfType End = String\n----------------------------------------------------------------------------\nprintfFmt: (fmt: Format) -> (acc: String) -> PrintfType fmt\nprintfFmt (Number fmt) acc = \\i => printfFmt fmt (acc ++ show i)\nprintfFmt (Str fmt) acc = \\str => printfFmt fmt (acc ++ str)\nprintfFmt (Character fmt) acc = \\char => printfFmt fmt (acc ++ show char)\nprintfFmt (FNumber fmt) acc = \\fnum => printfFmt fmt (acc ++ show fnum)\nprintfFmt (Lit lit fmt) acc = printfFmt fmt (acc ++ lit)\nprintfFmt End acc = acc\n----------------------------------------------------------------------------\ntoFormat: (xs: List Char) -> Format\ntoFormat [] = End\ntoFormat ('%' :: 'd' :: chars) = Number (toFormat chars)\ntoFormat ('%' :: 's' :: chars) = Str (toFormat chars)\ntoFormat ('%' :: 'c' :: chars) = Character (toFormat chars)\ntoFormat ('%' :: 'f' :: chars) = FNumber (toFormat chars)\ntoFormat ('%' :: chars) = Lit \"%\" (toFormat chars)\ntoFormat (c :: chars) = case toFormat chars of\n Lit lit fmt => Lit (strCons c lit) fmt\n fmt => Lit (strCons c \"\") fmt\n----------------------------------------------------------------------------\nprintf: (fmt: String) -> PrintfType (toFormat (unpack fmt))\nprintf fmt = printfFmt _ \"\"\n----------------------------------------------------------------------------\nTupleVect: (len: Nat) -> (elemType: Type) -> Type\nTupleVect Z elemType = ()\nTupleVect (S k) elemType = (elemType, TupleVect k elemType)\n\n", "meta": {"hexsha": "f467b1314fc953ddbae4143be2d51185f73142e9", "size": 2317, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "FirstClassTypes.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": "FirstClassTypes.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": "FirstClassTypes.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": 46.34, "max_line_length": 76, "alphanum_fraction": 0.5192058697, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190226, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6364561905819048}} {"text": "module SqEq0\n\nsqeq0 : (a, b : Nat) -> a*a + b*b = 0 -> (a = 0, b = 0)\nsqeq0 0 0 Refl = (Refl, Refl)\n", "meta": {"hexsha": "552f72166ec1cd2e201aeb686a02aefc63f06e16", "size": 100, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "SqEq0.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": "SqEq0.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": "SqEq0.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": 20.0, "max_line_length": 55, "alphanum_fraction": 0.49, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.6893056295505783, "lm_q1q2_score": 0.6362560980876876}} {"text": "module BaseN\n\nimport Data.Fin\nimport ZZ\nimport GCDZZ\nimport gcd\nimport ZZUtils\nimport NatUtils\nimport NatOrder\n\n%access public export\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)\ntotal\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)\ntotal\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\n--Concatenates two values in Base (S n)\ntotal\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\ntotal\ntonatFin: (n: Nat) -> Fin(S n) -> Nat\ntonatFin Z FZ = Z\ntonatFin (S k) FZ = Z\ntonatFin (S k) (FS x) = S (tonatFin k x)\n\n--Outputs the length of a number in base n\ntotal\nlen: (n: Nat) -> Base (S n) -> Nat\nlen n (Ones (S n) x) = S Z\nlen n (Next (S n) x y) = S(len n y)\n\n--List Fin to Nat\ntotal\ntonat: (n: Nat) -> Base (S n) -> Nat\ntonat Z y = case y of\n (Ones (S Z) x) => case x of\n FZ => Z\n FS x impossible\n (Next (S Z) x z) => case x of\n FZ => Z\n FS x impossible\ntonat (S k) y = case y of\n (Ones (S (S k)) x) => case x of\n FZ => Z\n FS x => S(tonat k (Ones (S k) x))\n (Next (S (S k)) x z) => case x of\n FZ => tonat (S k) z\n FS w => (S(tonat k (Ones (S k) w)))*(pow (S (S k)) (len (S k) z)) + (tonat (S k) z)\n\ntotal\ntonatFindef: tonatFin (S Z) FZ = Z\ntonatFindef = Refl\n\ntotal\ntonatdef: tonat Z (Ones (S Z) FZ) = Z\ntonatdef = Refl\n\n--Nat to Fin (modular values)\ntotal\ntofinNath: (a: Nat) -> (n: Nat) -> (k: Nat) -> Fin (S n)\ntofinNath r Z k = FZ\ntofinNath r (S j) Z = FZ\ntofinNath Z (S j) (S r) = FZ\ntofinNath (S k) (S j) (S r) = f k j r (lte (S k) (S j)) where\n f: (k: Nat) -> (j: Nat) -> (r: Nat) -> (t: Bool) -> Fin (S (S j))\n f k j r True = FS (tofinNath k j r)\n f k j r False = let qrem = eculidDivideAux (S k) (S j) (SIsNotZ) in\n (tofinNath (DPair.fst(DPair.snd(qrem))) (S j) r)\n\n\ntotal\ntofinNat: (a: Nat) -> (n: Nat) -> Fin (S n)\ntofinNat a n = tofinNath a n (n+2)\n\ntotal\ntonatfinlte: (n: Nat) -> (a: Fin (S n)) -> (lte (tonatFin n a) n) = True\ntonatfinlte Z FZ = Refl\ntonatfinlte Z (FS x) impossible\ntonatfinlte (S k) FZ = Refl\ntonatfinlte (S k) (FS x) = (tonatfinlte k x)\n\ntotal\nFinNatop: (n: Nat) -> (a: Fin (S n)) -> (tofinNat (tonatFin n a) n) = a\nFinNatop Z FZ = Refl\nFinNatop Z (FS x) impossible\nFinNatop (S k) FZ = Refl\nFinNatop (S k) (FS x) = trans (cong(tonatfinlte (S k) (FS x))) (cong(FinNatop k x))\n\ntotal\nRemn: (a: Nat) -> (n: Nat) -> (r: Nat ** (lte r (S n) = True))\nRemn a n = let\n qrem = eculidDivideAux a (S n) (SIsNotZ)\n rem = DPair.fst(DPair.snd(qrem))\n in\n MkDPair rem (LTEmeanslteTrue rem (S n) (ltImpliesLTE (Basics.snd(DPair.snd(DPair.snd(qrem))))))\n\ntotal\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)\ntotal\ntofinh: Nat -> (n: Nat) -> (r: Nat) -> Base (S n)\ntofinh Z n r = Ones (S n) FZ\ntofinh k n Z = Ones (S n) FZ\ntofinh (S k) n (S r) = strp(concat n (tofinh q n r) (Ones (S n) rem)) where\n qrem: (q : Nat ** (r : Nat ** (((S k) = r + (q * (S n))), LT r (S n))))\n qrem = eculidDivideAux (S k) (S n) (SIsNotZ)\n rem: Fin (S n)\n rem = tofinNat (DPair.fst(DPair.snd(qrem))) n\n q: Nat\n q = DPair.fst(qrem)\n\ntotal\ntofin: Nat -> (n: Nat) -> Base (S n)\ntofin k n = tofinh k n k\n\n--embedding Fin n in Fin S n vertically\ntotal\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))\ntotal\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\ntotal\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\ntotal\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)\ntotal\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\ntotal\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\ntotal\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\ntotal\naddfinh: (n: Nat) -> (k: Nat) -> Fin (S n) -> Fin (S n) -> (Fin (S n), Fin (S n))\naddfinh k Z x y = (FZ, FZ)\naddfinh Z (S r) x y = (FZ, FZ)\naddfinh (S k) (S r) FZ y = (FZ, y)\naddfinh (S k) (S r) (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(addfinh (S k) r (embn (S k) x) y)\n z = snd(addfinh (S k) r (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\ntotal\naddfin: (n: Nat) -> Fin (S n) -> Fin (S n) -> (Fin (S n), Fin (S n))\naddfin n x y = addfinh n (n+1) x y\n\n--adding two reversed lists as specified\ntotal\naddfinlh: (n: Nat) -> (k: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\naddfinlh n Z a b = (Ones (S n) FZ)\naddfinlh n (S k) (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))\naddfinlh n (S k) (Ones (S n) x) (Next (S n) y z) = Next (S n) (snd (addfin n x y)) (addfinlh n k (Ones (S n) (fst (addfin n x y))) z)\naddfinlh n (S k) (Next (S n) x z) (Ones (S n) y) = Next (S n) (snd (addfin n x y)) (addfinlh n k (Ones (S n) (fst (addfin n x y))) z)\naddfinlh n (S k) (Next (S n) x z) (Next (S n) y w) = Next (S n) (snd (addfin n x y)) (addfinlh n k (Ones (S n) (fst (addfin n x y))) (addfinlh n k z w))\n\ntotal\naddfinl: (n: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\naddfinl n x y = addfinlh n (4*((len n x)+(len n y))) x y\n\n--adding two lists\ntotal\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\ntotal\nmulfinlh: (n: Nat) -> (k: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\nmulfinlh n Z a b = Ones (S n) FZ\nmulfinlh n (S k) (Ones (S n) FZ) y = Ones (S n) FZ\nmulfinlh n (S k) (Ones (S n) (FS x)) y = addfinl n y (mulfinlh n k (Ones (S n) (embn n x)) y)\nmulfinlh n (S k) (Next (S n) FZ z) y = Next (S n) FZ (mulfinlh n k z y)\nmulfinlh n (S k) (Next (S n) (FS x) z) y = addfinl n y (mulfinlh n k (Next (S n) (embn n x) z) y)\n\ntotal\nmulfinl: (n: Nat) -> Base (S n) -> Base (S n) -> Base (S n)\nmulfinl n x y = mulfinlh n (tonat n x) x y\n\n--multiply two lists\ntotal\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\ntotal\nap: (x: Type) -> (y: Type) -> (f: x->y) -> (n = m) -> (f n = f m)\nap x y f Refl = Refl\n", "meta": {"hexsha": "0ef028c1debb540d211816e216595432609fd8a8", "size": 8430, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "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": "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": "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": 33.9919354839, "max_line_length": 152, "alphanum_fraction": 0.5144721234, "num_tokens": 3387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.636159349533012}} {"text": "module CH09\n\n%default total\n\ndata Elem : a -> List a -> Type where\n InCons : Elem value (value :: xs)\n InList : (prf : Elem value xs) -> Elem value (x :: xs)\n\nelemNotInNil : Elem value [] -> Void\nelemNotInNil _ impossible\n\nelemNotInTail : (notInTail : Elem y xs -> Void) -> (notInCons : (x = y) -> Void) -> Elem y (x :: xs) -> Void\nelemNotInTail _ notInCons InCons = notInCons Refl\nelemNotInTail notInTail notInCons (InList prf) = notInTail prf\n\nisElem : DecEq a => (value : a) -> (xs : List a) -> Dec (Elem value xs)\nisElem _ [] = No elemNotInNil\nisElem y (x :: xs) = case decEq x y of\n Yes Refl => Yes InCons\n No notInCons => case isElem y xs of\n Yes prf => Yes (InList prf)\n No notInTail => No (elemNotInTail notInTail notInCons)\n\ndata Last : List a -> a -> Type where\n LastOne : Last [value] value\n LastCons : (prf : Last xs value) -> Last (x :: xs) value\n\nnotInLast : (contra : (x = y) -> Void) -> Last [x] y -> Void\nnotInLast contra LastOne = contra Refl\n\nnotInNil : Last [] value -> Void\nnotInNil _ impossible\n\nnotInTail : (notNil : (xs = []) -> Void) -> (notInList : Last xs y -> Void) -> Last (x :: xs) y -> Void\nnotInTail notNil _ LastOne = notNil Refl\nnotInTail _ notInList (LastCons prf) = notInList prf\n\nisLast : DecEq a => (xs : List a) -> (value : a) -> Dec (Last xs value)\nisLast [] _ = No notInNil\nisLast (x :: xs) y = case decEq xs [] of\n Yes Refl => case decEq x y of\n Yes Refl => Yes LastOne\n No notEq => No (notInLast notEq)\n No notNil => case isLast xs y of\n Yes prf => Yes (LastCons prf)\n No notLast => No (notInTail notNil notLast)\n", "meta": {"hexsha": "7de4e345cf00ddc5b9ed693e0ecf27ab2b116ecb", "size": 1927, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch09/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/ch09/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/ch09/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": 41.0, "max_line_length": 108, "alphanum_fraction": 0.5251686559, "num_tokens": 553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6351765479073657}} {"text": "module RevRev\n\nnamespace Preloaded\n %access public export\n %default total\n\n rev : List x -> List x\n rev [] = []\n rev (y :: xs) = rev xs ++ [y]\n\n%access export\n%default total\n\nlemma : (xs : List x) -> (y : x) -> rev (xs ++ [y]) = y :: rev xs\nlemma [] _ = Refl\nlemma (_::as) y = rewrite lemma as y in Refl\n\nrevrevid : (a : List x) -> (rev (rev a)) = a\nrevrevid [] = Refl\nrevrevid (a::as) = rewrite lemma (rev as) a in\n rewrite revrevid as in\n Refl\n", "meta": {"hexsha": "515a0e1a6a259f0d265ab56b7f412ee06fffee20", "size": 497, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codewars/RevRev.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/RevRev.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/RevRev.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": 21.6086956522, "max_line_length": 65, "alphanum_fraction": 0.5352112676, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6350899284734361}} {"text": "data MyList : (a: Type) -> Type where\n Nil: MyList a\n Cons: (x: a) -> MyList a -> MyList a\n\ninsertList: a -> MyList a -> MyList a\ninsertList = Cons\n\n", "meta": {"hexsha": "74f716c373962277aa64b00c3b620c625fa3ffd1", "size": 151, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-structures/MyList.idr", "max_stars_repo_name": "LucasTornai/pgc-ufabc", "max_stars_repo_head_hexsha": "ae38058644363daa39e6fb44e831d26b27d810ea", "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-structures/MyList.idr", "max_issues_repo_name": "LucasTornai/pgc-ufabc", "max_issues_repo_head_hexsha": "ae38058644363daa39e6fb44e831d26b27d810ea", "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-structures/MyList.idr", "max_forks_repo_name": "LucasTornai/pgc-ufabc", "max_forks_repo_head_hexsha": "ae38058644363daa39e6fb44e831d26b27d810ea", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.875, "max_line_length": 38, "alphanum_fraction": 0.6158940397, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6350474765151992}} {"text": "\nmodule FreshPerm\n\nimport FreshList\nimport Data.Fin\nimport Data.Vect\n\n||| An arrangement is a list of fins of a given length\n||| and range.\npublic export\nArrangement : Nat -> Nat -> Type\nArrangement len range = FreshVect len (Fin range) (/=)\n\n||| A permutation is an arrangement where each fin appears n times\n||| and the fins range from 0 to n\npublic export\nPermutation : Nat -> Type\nPermutation n = Arrangement n n\n\nweakenInj : (x : Fin k) -> (y : Fin k) -> So (not (x == y)) -> So (not (weaken x == weaken y))\nweakenInj FZ FZ z = z\nweakenInj FZ (FS x) z = z\nweakenInj (FS x) FZ z = z\nweakenInj (FS x) (FS y) z = weakenInj x y z\n\neasyNeq : (y : Fin n) -> So ((Fin.last /= (Fin.weaken y)))\neasyNeq FZ = Oh\neasyNeq (FS x) = easyNeq x\n\nfreshWeakend : (fs : Arrangement l r) ->\n So ((Fin.last) ## map Fin.weaken {Bneq=(/=)} weakenInj fs)\nfreshWeakend [] = Oh\nfreshWeakend (x :: xs) = andSo (easyNeq _, freshWeakend xs)\n\nreversePermutation : (n : Nat) -> Permutation n\nnewFresh : (n : Nat) -> So (Fin.last {n}\n ## map Fin.weaken {Bneq = (/=)} FreshPerm.weakenInj (reversePermutation n))\n\nreversePermutation 0 = []\nreversePermutation (S k) =\n (::) (last {n=k})\n (FreshList.map weaken {Bneq = (/=)} weakenInj (reversePermutation k)) {fresh = newFresh k}\n\nnewFresh n = freshWeakend (reversePermutation n)\n\nflip : {a, b : Fin n} -> So (a /= b) -> So (b /= a)\nflip {a = FZ} {b = FZ} x = x\nflip {a = FZ} {b = (FS y)} x = x\nflip {a = (FS y)} {b = FZ} x = x\nflip {a = (FS y)} {b = (FS z)} x = flip x\n\nexport\nappend : (f : Fin n) -> (fs : Arrangement l n) -> {0 notIn : So (f ## fs)} -> Arrangement (S l) n\nfreshlyAppend : {x, f : Fin n} ->\n {xs : Arrangement l n} ->\n {fneq : So (f ## xs)} ->\n (notEq : So (x /= f)) ->\n (fresh : So (x ## xs)) ->\n So (x ## append {notIn = fneq} f xs)\n\nappend f [] = [f]\nappend f ((x :: xs) {fresh}) = let 0 p = soAnd notIn in\n (::) x (append f {notIn = snd p} xs)\n {fresh = freshlyAppend (flip $ fst p) fresh}\n\nfreshlyAppend notEq fresh {xs = []} = andSo (notEq, Oh)\nfreshlyAppend notEq fresh {xs = (y :: xs)} =\n let (a, b) = soAnd fresh in\n andSo (a, freshlyAppend notEq b)\n\nexport\nreverse : Arrangement l n -> Arrangement l n\n\n0 freshlyReversed : (x, xs : _) -> So (x ## xs) -> So (x ## FreshPerm.reverse xs)\n\nreverse [] = []\nreverse ((::) x xs {fresh}) = append x (reverse xs) {notIn = freshlyReversed x xs fresh}\n\nfreshlyReversed x [] y = Oh\nfreshlyReversed x (z :: xs) y with (soAnd y)\n freshlyReversed x (z :: xs) y | (w, v) =\n freshlyAppend {xs= reverse xs} {f=z} w (freshlyReversed ? xs v)\n\nexport\nidentityPermutation : (n : Nat) -> Permutation n\nidentityPermutation n = reverse (reversePermutation n)\n\nextractVal : (Fin (S n)) -> Vect (S n) a -> (a, Vect n a)\nextractVal FZ (x :: xs) = (x, xs)\nextractVal (FS FZ) (y :: (x :: xs)) = (x, y :: xs)\nextractVal (FS (FS x)) (y :: (z :: xs)) with (extractVal (FS x) (z :: xs))\n extractVal (FS (FS x)) (y :: (z :: xs)) | (k, ks) = (k, y :: ks)\n\napplyPermutation : (1 _ : Permutation n) -> (1 _ : Vect n a) -> Vect n a\napplyPermutation [] [] = []\napplyPermutation (x :: xs) (y :: ys) =\n let (val, res) = extractVal x (y :: ys) in\n val :: applyPermutation ?kek res\n\n\n", "meta": {"hexsha": "8c2dd41464c1580491551280090327898e88edc9", "size": 3347, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "programs/permutations/src/FreshPerm.idr", "max_stars_repo_name": "andrevidela/dev-notes", "max_stars_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": "programs/permutations/src/FreshPerm.idr", "max_issues_repo_name": "andrevidela/dev-notes", "max_issues_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": "programs/permutations/src/FreshPerm.idr", "max_forks_repo_name": "andrevidela/dev-notes", "max_forks_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": 33.1386138614, "max_line_length": 102, "alphanum_fraction": 0.5661786675, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6350474668514413}} {"text": "> module Nat.Positive\n\n> import Syntax.PreorderReasoning\n\n> import Unique.Predicates\n> import Subset.Properties\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\n> |||\n> data Positive : Nat -> Type where\n> MkPositive : {n : Nat} -> Positive (S n)\n\n> |||\n> PositiveUnique : {n : Nat} -> Unique (Positive n)\n> PositiveUnique MkPositive MkPositive = Refl\n\n> |||\n> fromSucc : (m : Nat) -> (n : Nat) -> S m = n -> Positive n\n> fromSucc m n prf = s2 where\n> s1 : Positive (S m)\n> s1 = MkPositive\n> s2 : Positive n\n> s2 = replace prf s1\n\n> |||\n> implementation Uninhabited (Positive Z) where\n> uninhabited (MkPositive {n}) impossible\n\n> |||\n> positiveNotZ : {n : Nat} -> Positive n -> Not (n = Z)\n> positiveNotZ {n = Z} p = absurd p\n> positiveNotZ {n = S m} _ = SIsNotZ\n\n> |||\n> plusPreservesPositivity : Positive m -> Positive n -> Positive (m + n)\n> plusPreservesPositivity {m = Z } {n } MkPositive _ impossible\n> plusPreservesPositivity {m } {n = Z } _ MkPositive impossible\n> plusPreservesPositivity {m = S m} {n = S n} _ _ = MkPositive\n\n> |||\n> multPreservesPositivity : Positive m -> Positive n -> Positive (m * n)\n> multPreservesPositivity {m = Z } {n } MkPositive _ impossible\n> multPreservesPositivity {m } {n = Z } _ MkPositive impossible\n> multPreservesPositivity {m = S m} {n = S n} _ _ = MkPositive \n\n\n", "meta": {"hexsha": "0515bc0194d3b3c4f4984b5b3f3b0a3387c2ddcc", "size": 1444, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/Positive.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/Positive.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/Positive.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": 27.7692307692, "max_line_length": 82, "alphanum_fraction": 0.6024930748, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958426, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.635017546042329}} {"text": "module Data.Subset.Interfaces\n\nimport Data.Subset.Predicates\nimport Data.List\nimport public Decidable.Equality\n\n%default total\n\n||| In order to verify a predicate to hold for a given value\n||| at runtime, it has to implement this interface.\npublic export\ninterface Predicate t (0 p : t -> Type) | p where\n ||| Validates a value against the given predicate.\n validate : (v : t) -> Dec (p v)\n\n||| Runtime refinement of values.\npublic export\nrefineMay : Predicate t p => (v : t) -> Maybe (Subset t p)\nrefineMay v = case validate {p = p} v of\n (Yes prf) => Just (Element v prf)\n (No _) => Nothing\n\npublic export\nPredicate (List a) NonEmpty where\n validate [] = No absurd\n validate (_ :: _) = Yes IsNonEmpty\n\n\npublic export\nPredicate k p => Predicate k (Neg p) where\n validate v with (validate { p = p } v)\n validate v | (Yes prf) = No \\(IsNeg c) => c prf\n validate v | (No contra) = Yes $ IsNeg contra\n\n\npublic export\n{f : t -> Bool} -> Predicate t (Is f) where\n validate v = case decEq (f v) True of\n (Yes prf) => Yes $ ItIs prf\n (No contra) => No \\(ItIs prf) => contra prf\n\n\npublic export\n{f : a -> b} -> Predicate b p => Predicate a (Via f p) where\n validate v = case validate {p = p} (f v) of\n (Yes prf) => Yes $ Go v prf\n (No contra) => No \\(Go _ prf) => contra prf\n\n\n\n\nconsInjective : And (p::ps) v -> (p v, And ps v)\nconsInjective (prf :: prfs) = (prf, prfs)\n\npublic export\nPredicate t (And []) where\n validate v = Yes Nil\n\npublic export\nPredicate t p => Predicate t (And ps) => Predicate t (And (p :: ps)) where\n validate v with (validate {p = p} v)\n validate v | No contra = No (contra . fst . consInjective)\n validate v | Yes phead with (validate {p = And ps} v)\n validate v | Yes phead | Yes ptail = Yes $ phead :: ptail\n validate v | Yes phead | No contra = No (contra . snd . consInjective)\n\n\n\npublic export\nUninhabited (Or [] v) where\n uninhabited _ impossible\n\npublic export\nPredicate t (Or []) where\n validate v = No absurd\n\npublic export\nPredicate t p => Predicate t (Or ps) => Predicate t (Or (p::ps)) where\n validate v with (validate {p = p} v)\n validate v | Yes prf = Yes $ Z prf\n validate v | No contra with (validate {p = Or ps} v)\n validate v | No contra | Yes prf = Yes $ S prf\n validate v | No contra | No contra2 =\n No $ \\any => case any of\n (Z p) => contra p\n (S p) => contra2 p\n", "meta": {"hexsha": "88527713ea42f9cc63ee229089ab940f293770c5", "size": 2536, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Subset/Interfaces.idr", "max_stars_repo_name": "stefan-hoeck/idris2-subsets", "max_stars_repo_head_hexsha": "ec2da829c6e250b9f21659f822f3df1cffa69ee7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-30T09:53:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-19T19:06:24.000Z", "max_issues_repo_path": "src/Data/Subset/Interfaces.idr", "max_issues_repo_name": "stefan-hoeck/idris2-subsets", "max_issues_repo_head_hexsha": "ec2da829c6e250b9f21659f822f3df1cffa69ee7", "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": "src/Data/Subset/Interfaces.idr", "max_forks_repo_name": "stefan-hoeck/idris2-subsets", "max_forks_repo_head_hexsha": "ec2da829c6e250b9f21659f822f3df1cffa69ee7", "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.1494252874, "max_line_length": 76, "alphanum_fraction": 0.5954258675, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6348979495897297}} {"text": "module Crypto.Curve.Weierstrass\n\nimport Crypto.Curve\nimport Data.Bits\nimport Data.List\nimport Data.Vect\nimport Utils.Bytes\nimport Utils.Misc\n\n-- Weiserstrass curve y^2 = x^3 + ax + b in Jacobian coordinate\npublic export\ninterface WeierstrassPoint p where\n a_coefficent : Integer\n b_coefficent : Integer\n prime : Integer -- If this isn't prime the skinwalker will devour you\n to_jacobian : p -> (Integer, Integer, Integer)\n from_jacobian : (Integer, Integer, Integer) -> p\n g : p\n to_from_jacobian : (x : (Integer, Integer, Integer)) -> to_jacobian (from_jacobian x) = x\n bits' : Nat\n curve_n : Integer\n\nj_point_double : WeierstrassPoint p => (Integer, Integer, Integer) -> (Integer, Integer, Integer)\nj_point_double (x, y, z) =\n let modulus = prime {p=p}\n s = (4 * x * y * y) `mod'` modulus\n z4 = pow_mod z 4 modulus\n y4 = pow_mod y 4 modulus\n m = (3 * x * x + a_coefficent {p} * z4) `mod'` modulus\n x' = (m * m - 2 * s) `mod'` modulus\n y' = (m * (s - x') - 8 * y4) `mod'` modulus\n z' = (2 * y * z) `mod'` modulus\n in (x', y', z')\n\nj_point_add : WeierstrassPoint p => (Integer, Integer, Integer) -> (Integer, Integer, Integer) -> (Integer, Integer, Integer)\nj_point_add (x, y, 0) b = b\nj_point_add a (x, y, 0) = a\nj_point_add a@(xp, yp, zp) b@(xq, yq, zq) =\n let m = prime {p=p}\n zq2 = pow_mod zq 2 m\n zq3 = pow_mod zq 3 m\n zp2 = pow_mod zp 2 m\n zp3 = pow_mod zp 3 m\n u1 = mul_mod xp zq2 m\n u2 = mul_mod xq zp2 m\n s1 = mul_mod yp zq3 m\n s2 = mul_mod yq zp3 m\n h = u2 - u1\n r = s2 - s1\n h2 = pow_mod h 2 m\n h3 = mul_mod h h2 m\n u1h2 = mul_mod u1 h2 m\n nx = ((r * r) - h3 - 2 * u1h2) `mod'` m\n ny = (r * (u1h2 - nx) - s1 * h3) `mod'` m\n nz = (h * zp * zq) `mod'` m\n in if h == 0 then (if r == 0 then j_point_double {p=p} a else (0, 1, 0)) else (nx, ny, nz)\n\npoint_double : (Point p, WeierstrassPoint p) => p -> p\npoint_double b = from_jacobian {p=p} (j_point_double {p=p} (to_jacobian b))\n\nmul' : (Point p, WeierstrassPoint p) => p -> p -> Nat -> Integer -> p\nmul' r0 r1 m d =\n let (r0', r1') = if testBit d m then (point_add r0 r1, point_double r1) else (point_double r0, point_add r0 r1)\n in case m of\n S m' => mul' r0' r1' m' d\n Z => r0'\n\npublic export\nWeierstrassPoint p => Point p where\n infinity = from_jacobian (0, 1, 0)\n generator = g\n bits = bits' {p=p}\n to_affine point =\n let (x, y, z) = to_jacobian point\n m = prime {p=p}\n z' = inv_mul_mod z m\n z2 = z' * z'\n z3 = z2 * z'\n in (mul_mod x z2 m, mul_mod y z3 m)\n modulus = prime {p=p}\n order = curve_n {p=p}\n point_add a b = from_jacobian {p=p} (j_point_add {p=p} (to_jacobian a) (to_jacobian b))\n mul s pt = mul' infinity pt (bits {p=p}) s\n\n encode point =\n let bytes = (7 + bits {p=p}) `div` 8\n (x', y') = to_affine point\n x = toList $ integer_to_be bytes x'\n y = toList $ integer_to_be bytes y'\n in 4 :: (x <+> y)\n\n decode (4 :: body) = do\n let bytes = (7 + bits {p=p}) `div` 8\n let (x', y') = splitAt bytes body\n x <- map be_to_integer $ exactLength bytes $ fromList x'\n y <- map be_to_integer $ exactLength bytes $ fromList y'\n\n -- infinity check\n guard $ not $ (x == 0) && (y == 0)\n\n -- check on curve\n let pri = modulus {p=p}\n let lhs = pow_mod y 2 pri\n let a = a_coefficent {p=p}\n let b = b_coefficent {p=p}\n let rhs = ((pow_mod x 3 pri) + (mul_mod x a pri) + b) `mod'` pri\n guard $ lhs == rhs\n\n pure $ from_jacobian (x, y, 1)\n decode _ = Nothing\n\npublic export\ndata P256 : Type where\n MkP256 : (Integer, Integer, Integer) -> P256\n\npublic export\nWeierstrassPoint P256 where\n prime =\n 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff\n a_coefficent =\n 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc\n b_coefficent =\n 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b\n from_jacobian = MkP256\n to_jacobian (MkP256 p) = p\n g = MkP256\n ( 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296\n , 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5\n , 1 )\n to_from_jacobian x = Refl\n bits' = 256\n curve_n =\n 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551\n\npublic export\ndata P384 : Type where\n MkP384 : (Integer, Integer, Integer) -> P384\n\npublic export\nWeierstrassPoint P384 where\n prime =\n 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff\n a_coefficent =\n 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc\n b_coefficent =\n 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef\n from_jacobian = MkP384\n to_jacobian (MkP384 p) = p\n g = MkP384\n ( 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7\n , 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f\n , 1 )\n to_from_jacobian x = Refl\n bits' = 384\n curve_n =\n 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973\n\npublic export\ndata P521 : Type where\n MkP521 : (Integer, Integer, Integer) -> P521\n\npublic export\nWeierstrassPoint P521 where\n prime =\n 0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n a_coefficent =\n 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc\n b_coefficent =\n 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00\n from_jacobian = MkP521\n to_jacobian (MkP521 p) = p\n g = MkP521\n ( 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66\n , 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650\n , 1 )\n to_from_jacobian x = Refl\n bits' = 521\n curve_n =\n 0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409\n\n", "meta": {"hexsha": "9d5902234670cf592d2cef2979a2b84466cbe8ac", "size": 6378, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Crypto/Curve/Weierstrass.idr", "max_stars_repo_name": "octeep/idris2-tls", "max_stars_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_stars_repo_licenses": ["ISC"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-23T15:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T11:00:15.000Z", "max_issues_repo_path": "src/Crypto/Curve/Weierstrass.idr", "max_issues_repo_name": "octeep/idris2-tls", "max_issues_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_issues_repo_licenses": ["ISC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Crypto/Curve/Weierstrass.idr", "max_forks_repo_name": "octeep/idris2-tls", "max_forks_repo_head_hexsha": "951bef674c41f059d5ccddf568b45588b5dbceee", "max_forks_repo_licenses": ["ISC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2375690608, "max_line_length": 140, "alphanum_fraction": 0.7028849169, "num_tokens": 2475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.6791787121629466, "lm_q1q2_score": 0.6346212994234463}} {"text": "module Data.Num\n\n||| integral power\nexport\npower : Num a => a -> Nat -> a\npower a Z = 1\npower a (S i) = a * power a i\n\nexport\nsquare : Num a => a -> a\nsquare x = power x 2\n\nexport\ncube : Num a => a -> a\ncube x = power x 3\n", "meta": {"hexsha": "335ed5b718a318bfd92f45a78a24f3f37fbb738d", "size": 222, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Num.idr", "max_stars_repo_name": "tensorknower69/idris2-ml", "max_stars_repo_head_hexsha": "2ab861b50554e2b11a8ba32f1efec9d1f84e5d7c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-30T20:10:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T20:10:19.000Z", "max_issues_repo_path": "src/Data/Num.idr", "max_issues_repo_name": "tensorknower69/idris2-ml", "max_issues_repo_head_hexsha": "2ab861b50554e2b11a8ba32f1efec9d1f84e5d7c", "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/Num.idr", "max_forks_repo_name": "tensorknower69/idris2-ml", "max_forks_repo_head_hexsha": "2ab861b50554e2b11a8ba32f1efec9d1f84e5d7c", "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": 13.875, "max_line_length": 30, "alphanum_fraction": 0.5855855856, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6346006352825659}} {"text": "module Chapter4\n\n-- enumerated types\n\ndata Direction = North | East | South | West\n\nturnClockwise : Direction -> Direction\nturnClockwise North = East\nturnClockwise East = South\nturnClockwise South = West\nturnClockwise West = North\n\n-- union types\n\n{-\n||| Represents possible shapes\ndata Shape = Triangle Double Double\n | Rectangle Double Double \n | Circle Double\n -}\n\ndata Shape : Type where\n Triangle : Double -> Double -> Shape\n Rectangle : Double -> Double -> Shape\n Circle : Double -> Shape\n\narea : Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length breadth) = length * breadth\narea (Circle radius) = pi * radius * radius\n\n-- recursive types\n\ndata Picture : Type where\n Primitive : Shape -> Picture\n Combine : Picture -> Picture -> Picture\n Rotate : Double -> Picture -> Picture\n Translate : Double -> Double -> Picture -> Picture\n\ntestPicture : Picture\ntestPicture = Combine (Combine (Translate 5 5 (Primitive (Rectangle 20 10)))\n (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 _ p) = pictureArea p\npictureArea (Translate _ _ p) = pictureArea p\n\n-- generic types\n\ndata Biggest = NoTriangle | Size Double\n\nbiggestTriangle : Picture -> Biggest\nbiggestTriangle (Primitive s) = case s of\n t@(Triangle _ _) => Size (area t)\n _ => NoTriangle\nbiggestTriangle (Combine p1 p2) = case biggestTriangle p1 of\n Size d1 => case biggestTriangle p2 of\n Size d2 => Size (max d1 d2)\n NoTriangle => NoTriangle\n NoTriangle => case biggestTriangle p2 of\n Size d2 => Size d2\n NoTriangle => NoTriangle\nbiggestTriangle (Rotate _ p) = case biggestTriangle p of\n s@(Size _) => s\n _ => NoTriangle\nbiggestTriangle (Translate _ _ p) = case biggestTriangle p of\n s@(Size _) => s\n _ => NoTriangle\n\nsafeDivide : Double -> Double -> Maybe Double\nsafeDivide x y = if y == 0 then Nothing\n else Just (x / y)\n\ndata Tree elem = Empty | Node (Tree elem) elem (Tree elem)\n\n%name Tree tree, tree1\n\ninsert : Ord elem => elem -> Tree elem -> Tree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node l v r) = case compare x v of\n GT => Node l v (insert x r)\n EQ => orig\n LT => Node (insert x l) v r\n\ndata BSTree : (elem : Type) -> Type where\n BSEmpty : Ord elem => BSTree elem\n BSNode : Ord elem => (left : BSTree elem) -> (val : elem) -> (right : BSTree elem) -> BSTree elem\n\ninsertBST : elem -> BSTree elem -> BSTree elem\ninsertBST x BSEmpty = BSNode BSEmpty x BSEmpty\ninsertBST x orig@(BSNode l v r) = case compare x v of\n LT => BSNode (insertBST x l) v r\n EQ => orig\n GT => BSNode l v (insertBST x r)\n\n-- dependent types\n\n-- linear types", "meta": {"hexsha": "52f23f9f0f682d9cf253dfad470857b1f07f291f", "size": 3566, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter4/Chapter4.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": "chapter4/Chapter4.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": "chapter4/Chapter4.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.3069306931, "max_line_length": 99, "alphanum_fraction": 0.5386988222, "num_tokens": 787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6345642330903992}} {"text": "> module NonNegDouble.open_issues.Main\n\n> import Data.So\n\n> %default total\n> %access public export\n\n> data NonNegative : Double -> Type where\n> MkNonNegative : {x : Double} -> So (0.0 <= x) -> NonNegative x\n\n> NonNegDouble : Type\n> NonNegDouble = Subset Double NonNegative\n\n> plus : NonNegDouble -> NonNegDouble -> NonNegDouble\n> mult : NonNegDouble -> NonNegDouble -> NonNegDouble\n> fromNat : Nat -> NonNegDouble\n\n> implementation Num NonNegDouble where\n> (+) = plus\n> (*) = mult\n> fromInteger = fromNat . fromIntegerNat\n", "meta": {"hexsha": "b06e902e6330c2ea627e4230dfb5d7f7090923a3", "size": 530, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegDouble/issues/num_parameter.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/issues/num_parameter.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/issues/num_parameter.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.0909090909, "max_line_length": 66, "alphanum_fraction": 0.6962264151, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6344228611901163}} {"text": "module Data.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 sign : t -> Sign\n\npublic export\nSigned Int where\n sign x with (compare x 0)\n sign x | LT = Minus\n sign x | EQ = Zero\n sign x | GT = Plus\n\npublic export\nSigned Integer where\n sign x with (compare x 0)\n sign x | LT = Minus\n sign x | EQ = Zero\n sign x | GT = Plus\n\npublic export\nSigned Double where\n sign x with (compare x 0.0)\n sign x | LT = Minus\n sign x | EQ = Zero\n sign x | GT = Plus\n", "meta": {"hexsha": "b661349d54818928047f5093dce883e5fdcbce51", "size": 901, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "bautzen1945/idris/Data/Sign.idr", "max_stars_repo_name": "steshaw/hsgames", "max_stars_repo_head_hexsha": "4cf8cd02fcc93d1e030144676e2e1cbf9da2514f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-10-12T17:34:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-09T15:14:41.000Z", "max_issues_repo_path": "bautzen1945/idris/Data/Sign.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/Sign.idr", "max_forks_repo_name": "steshaw/hsgames", "max_forks_repo_head_hexsha": "4cf8cd02fcc93d1e030144676e2e1cbf9da2514f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-15T04:16:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-15T04:16:39.000Z", "avg_line_length": 19.170212766, "max_line_length": 63, "alphanum_fraction": 0.6625971143, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6341966371103066}} {"text": "import Data.Vect\n\ninputs : Vect 3 Double\ninputs = [1.2, 5.1, 2.1]\n\nweights : Vect 3 Double\nweights = [3.1, 2.1, 8.7]\n\nbias : Double\nbias = 3.0\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 : Double\noutput = (index 0 inputs)*(index 0 weights) +\n (index 1 inputs)*(index 1 weights) +\n (index 2 inputs)*(index 2 weights) + bias\n\nmain : IO ()\nmain = printLn output\n", "meta": {"hexsha": "c7ae4f80064a3ee2b6b07d2884644f81f85cf8b6", "size": 486, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/p001-Basic-Neuron-3-inputs.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/p001-Basic-Neuron-3-inputs.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/p001-Basic-Neuron-3-inputs.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": 23.1428571429, "max_line_length": 74, "alphanum_fraction": 0.6625514403, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.7154240079185318, "lm_q1q2_score": 0.633602027176201}} {"text": "module ColistFun\n\n-- Inspired by a pull request https://github.com/idris-lang/Idris2/pull/997\n-- by Stefan Hoeck and by discussion started by Mathew Polzin.\n\ndata Colist : Type -> Type where\n Nil : Colist a\n (::) : a -> Inf (Colist a) -> Colist a\n\nFunctor Colist where\n map f [] = []\n map f (x::xs) = f x :: map f xs\n\nfunctorId : (xs : Colist a) -> map Prelude.id xs = xs\nfunctorId [] = Refl\nfunctorId (x::Delay xs) = cong (x::) $ functorId xs\n", "meta": {"hexsha": "f7d260ed6c14ba0160a991b515cd1c0d7d9ee922", "size": 454, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ColistFun.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": "ColistFun.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": "ColistFun.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": 26.7058823529, "max_line_length": 75, "alphanum_fraction": 0.6387665198, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6336019980978206}} {"text": "module Intro\r\n\r\nsm : List Nat -> Nat\r\nsm [] = 0\r\nsm (x :: xs) = x + (sm xs)\r\n\r\nfct : Nat -> Nat\r\nfct Z = 1\r\nfct (S k) = (S k) * (fct k)\r\n\r\nfbp : Nat -> (Nat, Nat)\r\nfbp Z = (1, 1)\r\nfbp (S k) = (snd (fbp k), fst (fbp k) + snd (fbp k))\r\n\r\nfib : Nat -> Nat\r\nfib n = fst (fbp n)\r\n\r\npublic export\r\nadd : Nat -> Nat -> Nat\r\nadd Z j = j\r\nadd (S k) j = S (add k j)\r\n\r\n\r\nmul : Nat -> Nat -> Nat\r\nmul Z j = Z\r\nmul (S k) j = add j (mul k j)\r\n\r\nsub : (n: Nat) -> (m : Nat) -> (LTE m n) -> Nat\r\nsub n Z LTEZero = n\r\nsub (S right) (S left) (LTESucc x) = sub right left x\r\n\r\noneLTEFour : LTE 1 4\r\noneLTEFour = LTESucc LTEZero\r\n\r\nfourMinusOne : Nat\r\nfourMinusOne = sub 4 1 oneLTEFour\r\n\r\nreflLTE : (n: Nat) -> LTE n n\r\nreflLTE Z = LTEZero\r\nreflLTE (S k) = LTESucc (reflLTE k)\r\n\r\nsillyZero: Nat -> Nat\r\nsillyZero n = sub n n (reflLTE n)\r\n\r\nidNat : Nat -> Nat\r\nidNat = \\x => x\r\n\r\nloop: Nat -> Nat\r\nloop k = loop (S k)\r\n", "meta": {"hexsha": "e4bc4a9fea442e007d7cce448bb4f429d48cb376", "size": 899, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Assignments/piyushsati/Assignment1/Intro.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/piyushsati/Assignment1/Intro.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/piyushsati/Assignment1/Intro.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": 17.98, "max_line_length": 54, "alphanum_fraction": 0.5339265851, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672593, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6334790816121381}} {"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-- type for a Preorder\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\n-- type for a total order\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 y x) (rel x y)) -> TotalOrder a rel\r\n\r\n-- type that states the proposition that a property is satisified by all elements of a list\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\n-- concatenation of lists obeys the propery forall\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\n-- splitting a list obeys the property forall\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-- mapping lists by a function obeys the forall property\r\nforAllMap : (f : (x : elem) -> p x -> q x) -> (xs : List elem) -> ForAll p xs -> ForAll q xs\r\nforAllMap f [] None = None\r\nforAllMap f (x :: xs) (Append px pfxs) = Append (f x px) (forAllMap f xs pfxs)\r\n\r\n-- transitive mapping obeys the forall property\r\nforAllDobMap : (f : (x : elem) -> p x -> q x -> r x) -> (xs : List elem) -> ForAll p xs -> ForAll q xs -> ForAll r xs\r\nforAllDobMap f [] None None = None\r\nforAllDobMap f (x :: xs) (Append px pxs) (Append qx qxs) = Append (f x px qx) (forAllDobMap f xs pxs qxs)\r\n\r\n-- type that proves that length of one list is LTE length of the other\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\n-- LTE for lists holds when an element is added to larger list\r\nlemma1 : LTEforList xs ys -> LTEforList xs (y :: ys)\r\nlemma1 LTEEmpty = LTEEmpty\r\nlemma1 (LTEAppend pf) = LTEAppend (lemma1 pf)\r\n\r\n-- LTE for lists holds reflexively\r\nlemma2 : (xs : List elem) -> LTEforList xs xs\r\nlemma2 [] = LTEEmpty\r\nlemma2 (x :: xs) = LTEAppend (lemma2 xs)\r\n\r\n-- LTE for lists is transitive\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\n-- type for Sorted Lists\r\ndata IsSortedAlternate : (elem -> elem -> Type) -> List elem -> Type where\r\n EmptySorted : IsSortedAlternate rel []\r\n AppendSorted : {rel : elem -> elem -> Type} -> ForAll (rel x) xs -> IsSortedAlternate rel xs -> IsSortedAlternate rel (x :: xs)\r\n\r\n-- type for Permutations\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\n-- Permutations follow the for all property\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\n-- function that partitions a list according to some function on the elements of the list\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\npartitionFunc f (x :: xs) =\r\n let (ys ** (zs ** (ysltexs, zsltexs, pfys, pfzs, pfperm))) = partitionFunc f xs in\r\n case (f x) of\r\n (Left px) => ((x :: ys) ** (zs ** (LTEAppend ysltexs, lemma1 zsltexs, Append px pfys, pfzs, Split xs [] (ys ++ zs) pfperm)))\r\n (Right qx) => (ys ** ((x :: zs) ** (lemma1 ysltexs, LTEAppend zsltexs, pfys, Append qx pfzs, Split xs ys zs pfperm)))\r\n\r\n-- function that partitions according to a total order, and gives a proof that\r\n-- all elements of the first list are smaller than the pivot, pivot is smaller\r\n-- than all elements of the second list, all elements of first list are smaller\r\n-- than second list and the concatenation of the two lists is a permutation of the original list\r\nordPartition : TotalOrder elem rel -> (pivot : elem) ->\r\n (xs : List elem) -> (ys : List elem ** (zs : List elem ** (LTEforList ys xs, LTEforList zs xs, ForAll (flip rel pivot) ys, ForAll (rel pivot) zs,\r\n ForAll (\\y => ForAll (rel y) zs) ys, Permutation xs (ys ++ zs))))\r\nordPartition {rel} (TotOrd (PreOrd refl transt) eith) pivot xs =\r\n let (ys ** (zs ** (ysltexs, zsltexs, pfys, pfzs, perm))) =\r\n partitionFunc {p = flip rel pivot} {q = rel pivot} (eith pivot) xs in\r\n (ys ** (zs ** (ysltexs, zsltexs, pfys, pfzs, lem2 zs pfzs ys pfys, perm)))\r\n where\r\n lem2 : (zs : List elem) -> ForAll (rel pivot) zs -> (ys : List elem) -> ForAll (flip rel pivot) ys -> ForAll (\\y => ForAll (rel y) zs) ys\r\n lem2 zs xltzs = forAllMap (\\y, yltx => lem y yltx zs xltzs)\r\n where\r\n lem : (y : elem) -> rel y pivot -> (zs : List elem) -> ForAll (rel pivot) zs -> ForAll (rel y) zs\r\n lem y yltx = forAllMap (\\z ,xltz => transt y pivot z yltx xltz)\r\n\r\n-- proof that the concatenation of the two elements obtained after partitioning\r\n-- using the above function is a sorted list\r\npartSorted : (xs : List elem) -> IsSortedAlternate rel xs -> (ys : List elem) -> IsSortedAlternate rel ys ->\r\n ForAll (\\x => ForAll (rel x) ys) xs -> IsSortedAlternate rel (xs ++ ys)\r\npartSorted [] _ ys sortys _ = sortys\r\npartSorted (x :: xs) {rel} (AppendSorted xltxs sortxs) ys sortys (Append xltys xsltys) =\r\n AppendSorted xltxsys sortxsys\r\n where\r\n sortxsys : IsSortedAlternate rel (xs ++ ys)\r\n sortxsys = partSorted xs sortxs ys sortys xsltys\r\n xltxsys : ForAll (rel x) (xs ++ ys)\r\n xltxsys = forAllConcat xs xltxs ys xltys\r\n\r\n-- auxiliary function used to define quicksort\r\nquicksortAux : TotalOrder elem rel -> (xs : List elem) -> (listBound : List elem) -> (xsbdd : LTEforList xs listBound) ->\r\n (ys : List elem ** (IsSortedAlternate rel ys, Permutation xs ys))\r\nquicksortAux totorder [] _ _ = ([] ** (EmptySorted, Empty))\r\nquicksortAux {rel} totorder (x :: xs) (xB :: xsB) (LTEAppend xsbdd) =\r\n --partition\r\n let (ys ** (zs ** (ysSmall, zsSmall, ysltx, xltzs, ysltzs, perm))) = ordPartition totorder x xs in\r\n --recursive calls\r\n let (ys' ** (sortedys', permysys')) = quicksortAux totorder ys xsB (lemma3 ysSmall xsbdd) in\r\n let (zs' ** (sortedzs', permzszs')) = quicksortAux totorder zs xsB (lemma3 zsSmall xsbdd) in\r\n --proof that result list is sorted\r\n let ysltzs' : ForAll (\\y => ForAll (rel y) zs') ys\r\n = forAllMap (\\y, yltzs => forAllPerm zs yltzs zs' permzszs') ys ysltzs in\r\n let ys'ltzs' : ForAll (\\y => ForAll (rel y) zs') ys'\r\n = forAllPerm ys ysltzs' ys' permysys' in\r\n let ys'ltx : ForAll (flip rel x) ys'\r\n = forAllPerm ys ysltx ys' permysys' in\r\n let ys'ltxzs' : ForAll (\\y => ForAll (rel y) (x :: zs')) ys'\r\n = forAllDobMap (\\y => Append) ys' ys'ltx ys'ltzs' in\r\n let sortedxzs' : IsSortedAlternate rel (x :: zs')\r\n = AppendSorted (forAllPerm zs xltzs zs' permzszs') sortedzs' in\r\n let sortedys'xzs' : IsSortedAlternate rel (ys' ++ x :: zs')\r\n = partSorted ys' sortedys' (x :: zs') sortedxzs' ys'ltxzs' in\r\n -- proof that result is a Permutation\r\n let perm' : Permutation (ys ++ zs) (ys' ++ zs')\r\n = Cat permysys' permzszs' in\r\n let perm'' : Permutation xs (ys' ++ zs')\r\n = Compos perm perm' in\r\n let permAll : Permutation (x :: xs) (ys' ++ x :: zs')\r\n = Split xs ys' zs' perm'' in\r\n --merging everything together\r\n ((ys' ++ (x :: zs')) ** (sortedys'xzs', permAll))\r\n\r\n-- the quicksort funtion\r\nquickSort : TotalOrder elem rel -> (xs : List elem) -> (ys : List elem ** (IsSortedAlternate rel ys, Permutation xs ys))\r\nquickSort totorder xs = quicksortAux totorder xs xs (lemma2 xs)\r\n\r\n\r\n--Applying to Nat\r\nreflLTE : (n: Nat) -> LTE n n\r\nreflLTE Z = LTEZero\r\nreflLTE (S k) = LTESucc (reflLTE k)\r\n\r\nnatLTETrans : (a,b,c : Nat) -> LTE a b -> LTE b c -> LTE a c\r\nnatLTETrans Z _ _ _ _ = LTEZero\r\nnatLTETrans (S a) (S b) (S c) (LTESucc p) (LTESucc q) = LTESucc (natLTETrans a b c p q)\r\n\r\nnatLTEEith : (a, b : Nat) -> Either (LTE b a) (LTE a b)\r\nnatLTEEith Z _ = Right LTEZero\r\nnatLTEEith _ Z = Left LTEZero\r\nnatLTEEith (S n) (S m) with (natLTEEith n m)\r\n | Right x = Right (LTESucc x)\r\n | Left y = Left (LTESucc y)\r\n\r\ntotOrdNat : TotalOrder Nat LTE\r\ntotOrdNat = TotOrd (PreOrd reflLTE natLTETrans) natLTEEith\r\n\r\nquickSortNat : (xs : List Nat) -> (ys : List Nat ** (IsSortedAlternate LTE ys, Permutation xs ys))\r\nquickSortNat xs = quickSort totOrdNat xs\r\n", "meta": {"hexsha": "d4fd850cb619fe26528b43ac12a5ed77d45831d5", "size": 10441, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Quicksort.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/Quicksort.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/Quicksort.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": 54.9526315789, "max_line_length": 166, "alphanum_fraction": 0.6201513265, "num_tokens": 3425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6332796062984141}} {"text": "module Toolkit.Data.Whole\n\nimport Decidable.Equality\n\nimport Data.Nat\n\n%default total\n\npublic export\ndata Whole : Type where\n W : (n : Nat) -> (prf : IsSucc n) -> Whole\n\n\npublic export\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\nexport\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\npublic export\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\nexport\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\nexport\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\nexport\nShow Whole where\n show (W n prf) = show n\n\nexport\ntoNat : Whole -> Nat\ntoNat (W n prf) = n\n\nnamespace Auto\n export\n fromNat : (x : Nat) -> {auto prf : IsSucc x} -> Whole\n fromNat x {prf} = W x prf\n\npublic export\ndata LT : Whole -> Whole -> Type where\n IsLT : (prf : LT min max)\n -> LT (W min prfA) (W max prfB)\n\nisNotLT : (LTE (S n) k -> Void) -> LT (W n prf) (W k x) -> Void\nisNotLT f (IsLT y) = f y\n\nexport\nisLT : (a,b : Whole) -> Dec (LT a b)\nisLT (W n prf) (W k x) with (isLTE (S n) k)\n isLT (W n prf) (W k x) | (Yes y) = Yes (IsLT y)\n isLT (W n prf) (W k x) | (No contra) = No (isNotLT contra)\n\npublic export\ndata LTE : Whole -> Whole -> Type where\n IsLTE : (prf : LTE min max)\n -> LTE (W min prfA) (W max prfB)\n\n\nisLTENot : (contra : LTE n k -> Void)\n -> LTE (W n prf) (W k x) -> Void\nisLTENot contra (IsLTE y) = contra y\n\nexport\nisLTE : (a,b : Whole) -> Dec (LTE a b)\nisLTE (W n prf) (W k x) with (isLTE n k)\n isLTE (W n prf) (W k x) | (Yes y) = Yes (IsLTE y)\n isLTE (W n prf) (W k x) | (No contra) = No (isLTENot contra)\n\nexport\nEq Whole where\n (W l prfL) == (W r prfR) = l == r\n\nexport\nOrd Whole where\n compare (W l prfL) (W r prfR) = compare l r\n\nnamespace IsLteNatWhole\n\n public export\n data LTE : Nat -> Whole -> Type where\n IsLTE : (prf : LTE min max)\n -> LTE min (W max prfMax)\n\n isLTENot : (LTE n k -> Void) -> IsLteNatWhole.LTE n (W k prf) -> Void\n isLTENot f (IsLTE x) = f x\n\n export\n isLTE : (n : Nat) -> (w : Whole) -> Dec (LTE n w)\n isLTE n (W k prf) with (isLTE n k)\n isLTE n (W k prf) | (Yes x) = Yes (IsLTE x)\n isLTE n (W k prf) | (No contra) = No (isLTENot contra)\n\nnamespace Nat\n public export\n data IsWhole : Nat -> Type where\n YesIsWhole : IsWhole (S n)\n\n isZero : IsWhole 0 -> Void\n isZero YesIsWhole impossible\n\n\n export\n isWhole : (n : Nat) -> Dec (IsWhole n)\n isWhole 0 = No isZero\n isWhole (S k) = Yes YesIsWhole\n\n\n\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "3b5edc3eb2cb59fdf43f299d81ca341c9d3af73f", "size": 3763, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/Whole.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/Whole.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/Whole.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": 27.071942446, "max_line_length": 111, "alphanum_fraction": 0.6056338028, "num_tokens": 1445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6331440685824417}} {"text": "module Data.Fun.Extra\n\nimport Data.Fun\nimport Data.Rel\nimport Data.HVect\n\n%default total\n\n||| Apply an n-ary function to an n-ary tuple of inputs\npublic export\nuncurry : {0 n : Nat} -> {0 ts : Vect n Type} -> Fun ts cod -> HVect ts -> cod\nuncurry f [] = f\nuncurry f (x::xs) = uncurry (f x) xs\n\n||| Apply an n-ary function to an n-ary tuple of inputs\npublic export\ncurry : {n : Nat} -> {0 ts : Vect n Type} -> (HVect ts -> cod) -> Fun ts cod \ncurry {ts = [] } f = f []\ncurry {ts = _ :: _} f = \\x => curry (\\xs => f (x :: xs))\n\n{- \n\nThe higher kind Type -> Type has a monoid structure given by\ncomposition and the identity (Cayley). The type (n : Nat ** Vect n a)\nhas a monoid structure given by `(n, rs) * (m, ss) := (n + m, rs +\nss)` and `(0,[])`. \n\n `Fun' : (n : Nat ** Vect n Type) -> Type -> Type` \n \nis then a monoid homomorphism between them. I guess this is some\ninstance of Cayley's theorem, but because of extensionality we can't\nshow we have an isomorphism.\n-}\npublic export\nhomoFunNeut_ext : Fun [] cod -> id cod\nhomoFunNeut_ext x = x\n\npublic export\nhomoFunMult_ext : {n : Nat} -> {0 rs : Vect n Type} -> Fun (rs ++ ss) cod -> (Fun rs . Fun ss) cod\nhomoFunMult_ext {rs = [] } gs = gs\nhomoFunMult_ext {rs = t :: ts} fgs = \\x => homoFunMult_ext (fgs x)\n\npublic export\nhomoFunNeut_inv : id cod -> Fun [] cod\nhomoFunNeut_inv x = x\n\npublic export\nhomoFunMult_inv : {n : Nat} -> {0 rs : Vect n Type} -> (Fun rs . Fun ss) cod -> Fun (rs ++ ss) cod\nhomoFunMult_inv {rs = [] } gs = gs\nhomoFunMult_inv {rs = t :: ts} fgs = \\x => homoFunMult_inv (fgs x)\n\n\n||| Apply an n-ary function to an n-ary tuple of inputs\npublic export\napplyPartially : {n : Nat} -> {0 ts : Vect n Type} \n -> Fun (ts ++ ss) cod -> (HVect ts -> Fun ss cod)\napplyPartially fgs = uncurry {ts} {cod = Fun ss cod} (homoFunMult_ext {rs=ts} {ss} fgs)\n\n\n{- -------- (slightly) dependent versions of the above ---------------\n As usual, type dependencies make everything complicated -}\n\n||| Apply an n-ary dependent function to its tuple of inputs (given by an HVect)\npublic export\nuncurryAll : {0 n : Nat} -> {0 ts : Vect n Type} -> {0 cod : Fun ts Type} \n -> All ts cod -> (xs : HVect ts) -> uncurry cod xs\nuncurryAll f [] = f\nuncurryAll {ts = t :: ts} f (x :: xs) = uncurryAll {cod= cod x} (f x) xs\n\npublic export\ncurryAll : {n : Nat} -> {0 ts : Vect n Type} -> {0 cod : Fun ts Type}\n -> ((xs : HVect ts) -> uncurry cod xs)\n -> All ts cod\ncurryAll {ts = [] } f = f []\ncurryAll {ts = t :: ts} f = \\x => curryAll (\\ xs => f (x:: xs))\n\nchainGenUncurried : {n : Nat} -> {0 ts : Vect n Type} -> {0 cod,cod' : Fun ts Type} -> \n ((xs : HVect ts) -> uncurry cod xs -> uncurry cod' xs) -> \n All ts cod -> All ts cod'\nchainGenUncurried {ts = []} f gs = f [] gs\nchainGenUncurried {ts = (t :: ts)} f gs = \\x => chainGenUncurried (\\u => f (x :: u)) (gs x)\n\npublic export\nhomoAllNeut_ext : Fun [] cod -> id cod\nhomoAllNeut_ext x = x\n\n-- Not sure it's worth it getting the rest of Cayley's theorem to work\n\npublic export\nextractWitness : {n : Nat} -> {0 ts : Vect n Type} -> {0 r : Rel ts} -> Ex ts r -> HVect ts\nextractWitness {ts = [] } _ = []\nextractWitness {ts = t :: ts} (w ** f) = w :: extractWitness f\n\npublic export\nextractWitnessCorrect : {n : Nat} -> {0 ts : Vect n Type} -> {0 r : Rel ts} -> (f : Ex ts r) -> \n uncurry {ts} r (extractWitness {r} f)\nextractWitnessCorrect {ts = [] } f = f\nextractWitnessCorrect {ts = t :: ts} (w ** f) = extractWitnessCorrect f\n\npublic export\nintroduceWitness : {0 r : Rel ts} -> (witness : HVect ts) -> \n uncurry {ts} r witness -> Ex ts r\nintroduceWitness [] f = f\nintroduceWitness (w :: witness) f = (w ** introduceWitness witness f)\n\n----------------------------------------------------------------------\npublic export\ndata Pointwise : (r : a -> b -> Type) -> (ts : Vect n a) -> (ss : Vect n b) -> Type where\n Nil : Pointwise r [] []\n (::) : {0 ss, ts : Vect n Type} -> \n (f : r t s) -> Pointwise r ts ss -> Pointwise r (t::ts) (s::ss)\n\npublic export\nprecompose : Pointwise (\\a,b => a -> b) ts ss -> Fun ss cod -> Fun ts cod\nprecompose [] h = h\nprecompose (f :: fs) h = \\x => precompose fs (h (f x))\n", "meta": {"hexsha": "bad90f617f6abbb1f5f7b47672bd3e507654c903", "size": 4261, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/Fun/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/Fun/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/Fun/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": 36.4188034188, "max_line_length": 98, "alphanum_fraction": 0.5763905187, "num_tokens": 1401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6329713016933002}} {"text": "import Data.Vect\n\nmyLength : List a -> Nat\nmyLength [] = 0\nmyLength (x :: xs) = 1 + myLength xs\n\nmyReverse' : (acc : List a) -> (xs : List a) -> List a\nmyReverse' acc [] = acc\nmyReverse' acc (x :: xs) = let acc' = x :: acc in myReverse' acc' xs\n\nmyReverse : List a -> List a\nmyReverse xs = myReverse' [] xs\n\n\nmyMap : (a -> b) -> List a -> List b\nmyMap f [] = []\nmyMap f (x :: xs) = f x :: myMap f xs\n\nmyMapVect : (a -> b) -> Vect n a -> Vect n b\nmyMapVect f [] = []\nmyMapVect f (x :: xs) = f x :: myMapVect f xs\n", "meta": {"hexsha": "a76697e1d884d17a40a2110d2a1a7b50afdb3029", "size": 512, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter03/Exercises/ex_3_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/Chapter03/Exercises/ex_3_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/Chapter03/Exercises/ex_3_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": 23.2727272727, "max_line_length": 68, "alphanum_fraction": 0.564453125, "num_tokens": 190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6328293556459611}} {"text": "import Data.Either\nimport Data.Fin\nimport Data.List\nimport Data.List1\nimport Data.Nat\nimport Data.Maybe\nimport Data.Stream\nimport Data.String\nimport Data.String.Parser\nimport Data.Vect\n\nimport System.File\n\nEnergy : Type\nEnergy = Fin 10\n\ndata Flash = Flashed | E Energy\n\nincEnergy : Energy -> Flash\nincEnergy e = maybe Flashed E $ strengthen $ shift 1 e\n\nisFlash : Flash -> Bool\nisFlash Flashed = True\nisFlash _ = False\n\nresetFlash : Flash -> Energy\nresetFlash Flashed = 0\nresetFlash (E e) = e\n\n-- A Non empty grid\nGrid : Nat -> Type -> Type\nGrid n a = Vect (S n) (Vect (S n) a)\n\n\nparser : Parser (n ** Grid n Energy)\nparser = do row <- some digit <* char '\\n'\n let n = length row\n Just v <- pure $ toVect n row\n | Nothing => fail \"not length\"\n Yes ItIsSucc <- pure $ isItSucc n\n | No _ => fail \"Row is zero\"\n vs <- ntimes (pred n) ((ntimes n digit) <* char '\\n')\n pure $ MkDPair (pred n) (v :: vs)\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\nneighbours1 : {n : Nat} -> Fin n -> List (Fin n)\nneighbours1 x = catMaybes $ [ decFin x, Just x, incFin x ]\n\nneighbours : {n : Nat} -> Fin (S n) -> Fin (S n) -> List (Fin (S n), Fin (S n))\nneighbours x y = delete (x, y) $ join $ (\\x => (x,) <$> (neighbours1 y)) <$> neighbours1 x\n\nincNeighbours : {n : Nat} -> List (Fin (S n), Fin (S n)) -> Grid n Flash -> Grid n Flash\nincNeighbours [] g = g\nincNeighbours ((x, y) :: ps) g = case index x $ index y $ g of\n Flashed => incNeighbours ps g\n (E e) => case incEnergy e of\n Flashed => incNeighbours (neighbours x y ++ ps) (updateAt y (replaceAt x Flashed) g)\n en@(E _) => incNeighbours ps (updateAt y (replaceAt x en) g)\n\nstep : {n : Nat} -> Grid n Energy -> Grid n Flash\nstep {n} g = let gf = (E <$>) <$> g\n ps = join $ (\\y => (, y) <$> (forget $ allFins n)) <$> (forget $ allFins n) in\n incNeighbours ps gf\n\nreset : Grid n Flash -> (Nat, Grid n Energy)\nreset g = (sum $ count isFlash <$> g, (resetFlash <$>) <$> g)\n\nsimulate : {n : Nat} -> Nat -> Grid n Energy -> Nat\nsimulate 0 = const 0\nsimulate (S s) = (\\(f, g) => f + simulate s g) . reset . step \n\nallFlash : {n : Nat} -> Nat -> Grid n Energy -> Nat\nallFlash s g = let (c, gf) = reset $ step g in\n if c == (S n) * (S n)\n then S s\n else allFlash (S s) gf\n\nrun : String -> IO ()\nrun s = do Right (MkDPair n g, _) <- pure $ parse parser s\n | Left err => putStrLn $ show err\n putStrLn $ show $ simulate 195 g\n putStrLn $ show $ allFlash 0 g\n\nmain : IO ()\nmain = do Right s <- readFile \"input.txt\"\n | Left err => putStrLn $ show err\n run s\n\n", "meta": {"hexsha": "fbc6f7f6804d208c638c1a70109e64b9b6e6bd5f", "size": 2996, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "11/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": "11/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": "11/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": 32.2150537634, "max_line_length": 136, "alphanum_fraction": 0.5370493992, "num_tokens": 876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6323110908588805}} {"text": "module Rationals\n\nimport ZZ\nimport ZZUtils\nimport GCDZZ\nimport Divisors\nimport BoundedGCD\n\n%default total\n\n-- Everything in this file is total. \n\n-- The functions below are completely based on the code from GCDZZ; they were written to improve\n-- readability.\n\nQuotient: (a: ZZ) -> (b: ZZ) -> (IsNonNegative a) -> (IsPositive b) -> (ZZ)\nQuotient a b x y = Prelude.Pairs.DPair.fst (QuotRemZ a b x y)\n\nRemainder: (a: ZZ) -> (b: ZZ) -> (IsNonNegative a) -> (IsPositive b) -> (ZZ)\nRemainder a b x y = Prelude.Pairs.DPair.fst(Prelude.Pairs.DPair.snd (QuotRemZ a b x y))\n\n%access public export\n\nPair : Type\nPair = (Integer, Integer)\n\n\n\nZZPair : Type\nZZPair = (ZZ, ZZ)\n\nZZtoDb : ZZ -> Double\nZZtoDb x = cast{from=Integer}{to=Double} (cast{from=ZZ}{to=Integer} x)\n\nDbtoZZ : Double -> ZZ\nDbtoZZ x = cast{from=Integer}{to=ZZ} (cast{from=Double}{to=Integer} x)\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\n--Integer implemetation of gcd\nCalcGCD : (Integer, Integer) -> Integer\nCalcGCD (a, b) = case (decEq b 0) of\n (Yes prf) => a\n (No contra) => toIntegerNat (gcdAlgo (toNat a) (toNat b))\n\nOnlyPositive : (x: Pair) -> Pair\nOnlyPositive x = (if (fst x)>0 then fst x else (-1)*(fst x), if(snd x)>0 then (snd x) else (-1)*(snd x))\n\n--Integer implemetation of gcd\ngccd : (Integer, Integer) -> Integer\ngccd x = CalcGCD (OnlyPositive x)\n\ndata ZZNotZero : ZZ -> Type where\n ZZOneNotZero : ZZNotZero 1\n ZZNegativeNotZero : ( n: ZZ ) -> ZZNotZero n -> ZZNotZero (-n)\n ZZPositiveNotZero : ( m: ZZ ) -> LTE 1 (fromIntegerNat (cast(m))) -> ZZNotZero m\n\n-- A section on the custom equality of Rationals\n\n||| If a is not equal to zero and b is not equal to zero, their product is not equal to zero.\nproductNonZero: (NotZero a) -> (NotZero b) -> (NotZero (a*b))\nproductNonZero PositiveZ PositiveZ = PositiveZ\nproductNonZero PositiveZ NegativeZ = NegativeZ\nproductNonZero NegativeZ PositiveZ = NegativeZ\nproductNonZero NegativeZ NegativeZ = PositiveZ\n\n|||A rational number is equal to its component representation (Numerator,Denominator)\npairIsComponents: (x: ZZPair) -> (x=((fst x), (snd x)))\npairIsComponents (a, b) = Refl\n\n--Type for equality of two Rationals\nEqRat : (x: ZZPair) -> (NotZero (snd x)) -> (y: ZZPair) -> (NotZero (snd y)) -> Type\nEqRat x a y b = (fst x)*(snd y)=(snd x)*(fst y)\n\n|||The analog of 'Refl' for equality of rationals.\nEqRatRefl: (x: ZZPair) -> (a: NotZero (snd x)) -> (EqRat x a x a)\nEqRatRefl x a = rewrite (multCommutativeZ (fst x) (snd x)) in\n Refl\n\n|||The analog of 'sym' for equality of rationals.\nEqRatSym: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (EqRat x a y b) -> (EqRat y b x a)\nEqRatSym x a y b z = rewrite (multCommutativeZ (snd y) (fst x)) in\n rewrite (multCommutativeZ (fst y) (snd x)) in\n sym z\n\n\nequalMeansEqualPairs: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (x=y) -> (((fst x), (snd x)) = ((fst y), (snd y)))\nequalMeansEqualPairs x a y b prf = rewrite sym (pairIsComponents x) in\n rewrite sym (pairIsComponents y) in\n prf\n\n\nequalMeansCompEqual: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (x=y) -> ((fst x)=(fst y), (snd x)=(snd y))\nequalMeansCompEqual y a y b Refl = (Refl, Refl)\n\neqMeansEqRat: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (x=y) -> (EqRat x a y b)\neqMeansEqRat y a y b Refl = rewrite (multCommutativeZ (fst y) (snd y)) in\n Refl\n\n|||(0,1) is \"equal\" to (0,k) for any nonzero k\nreducedFormZeroLeft: {k: ZZ} -> (a: NotZero k) -> (EqRat (0,1) PositiveZ (0,k) a)\nreducedFormZeroLeft {k} a = rewrite (multZeroLeftZeroZ (k)) in\n Refl\n\n|||(0,k) is \"equal\" to (0,1) for any nonzero k\nreducedFormZeroRight: (k: ZZ) -> (a: NotZero k) -> (EqRat (0,k) a (0,1) PositiveZ )\nreducedFormZeroRight k a = rewrite (multZeroRightZeroZ (k)) in\n Refl\n\n||| (1,1) is \"equal\" to (k,k) for any nonzero k\nreducedFormOneLeft: {k: ZZ} -> (a: NotZero k) -> (EqRat (1,1) PositiveZ (k,k) a)\nreducedFormOneLeft {k} a = Refl\n\n||| (k,k) is \"equal\" to (1,1) for any nonzero k\nreducedFormOneRight: (k: ZZ) -> (a: NotZero k) -> (EqRat (k,k) a (1,1) PositiveZ)\nreducedFormOneRight k a = Refl\n|||If a = b and c = d, a*c = b*d\nmultEqualEqual: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (d: ZZ) -> (a=b) -> (c=d) -> (a*c=b*d)\nmultEqualEqual b b d d Refl Refl = Refl\n\n-- some helper functions for the first case of transitivity\n\ntransH1: {x: ZZPair} -> {y: ZZPair} -> {z: ZZPair} -> (((fst x)*(snd y)) = ((snd x)*(fst y))) -> (((fst y)*(snd z)) = ((snd y)*(fst z))) ->\n((((fst x)*(snd y))*((fst y)*(snd z))) = (((snd x)*(fst y))*((snd y)*(fst z))))\ntransH1 {x} {y} {z} prf prf1 = (multEqualEqual ((fst x)*(snd y)) ((snd x)*(fst y)) ((fst y)*(snd z)) ((snd y)*(fst z)) prf prf1)\n\ntransH2: {x: ZZPair} -> {y: ZZPair} -> {z: ZZPair} -> ((((fst x)*(snd y))*((fst y)*(snd z))) = (((snd x)*(fst y))*((snd y)*(fst z))))\n-> ((((fst x)*(snd z))*((fst y)*(snd y))) = (((snd x)*(fst z))*((fst y)*(snd y))))\ntransH2 {x} {y} {z} prf = rewrite (sym (multAssociativeZ (fst x) (snd z) ((fst y)*(snd y)) ) ) in\n rewrite (sym (multAssociativeZ (snd x) (fst z) ((fst y)*(snd y)) ) ) in\n rewrite (multCommutativeZ (fst y) (snd y)) in\n rewrite (multAssociativeZ (snd z) (snd y) (fst y)) in\n rewrite (multAssociativeZ (fst x) ((snd z)*(snd y)) (fst y) ) in\n rewrite (multCommutativeZ (snd z) (snd y)) in\n rewrite (multAssociativeZ (fst z) (snd y) (fst y)) in\n rewrite (multCommutativeZ (fst z) (snd y)) in\n rewrite (multAssociativeZ (fst x) (snd y) (snd z)) in\n rewrite (multCommutativeZ ((snd y)*(fst z)) (fst y)) in\n rewrite (multAssociativeZ (snd x) (fst y) ((snd y)*(fst z))) in\n rewrite (sym (multAssociativeZ ((fst x)*(snd y)) (snd z) (fst y))) in\n rewrite (multCommutativeZ (snd z) (fst y)) in\n prf\n\ntransH3: {x: ZZPair} -> {y: ZZPair} -> {z: ZZPair} -> ((((fst x)*(snd z))*((fst y)*(snd y))) = (((snd x)*(fst z))*((fst y)*(snd y))))\n-> (b: NotZero (snd y)) -> (k: NotZero (fst y)) -> (((fst x)*(snd z)) = ((snd x)*(fst z)))\ntransH3 {x} {y} {z} prf b k = (multRightCancelZ ((fst x)*(snd z)) ((snd x)*(fst z)) ((fst y)*(snd y)) (productNonZero k b) prf)\n\n|||Nothing is both zero and nonzero.\nNotZeroAndNonZero: (k: ZZ) -> (k=0) -> (NotZero k) -> Void\nNotZeroAndNonZero (Pos (S _)) Refl PositiveZ impossible\nNotZeroAndNonZero (NegS _) Refl NegativeZ impossible\n\n\n|||The integers are an integral domain.\nZZIntegralDomain: (a: ZZ) -> (b: ZZ) -> (a*b=0) -> (NotZero b) -> (a=0)\nZZIntegralDomain a b prod bNZ = case (decZero a) of\n (Yes aNZ) => void (NotZeroAndNonZero (a*b) prod (productNonZero aNZ bNZ))\n (No contra) => notNotZeroThenZero (contra)\n\n\nflipSidesAndTerms: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (d: ZZ) -> (a*b=c*d) -> (d*c=b*a)\nflipSidesAndTerms a b c d prf = rewrite (multCommutativeZ (b) (a)) in\n rewrite (multCommutativeZ (d) (c)) in\n sym prf\n\n\n|||If ab=cd and d =0 but b is not zero, then a is zero.\nzeroProductZero1: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (d: ZZ) -> (a*b=c*d) -> (d = 0) -> (NotZero b) -> (a=0)\nzeroProductZero1 a b c d prod dZ bNZ = ZZIntegralDomain (a) (b) (trans (prod) (trans (multEqualEqual c c d (Pos 0) Refl dZ) (multZeroRightZeroZ (c)) )) (bNZ)\n\n|||If ab=cd and a=0 but c is not zero, then d is zero.\nzeroProductZero2: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (d: ZZ) -> (a*b=c*d) -> (a = 0) -> (NotZero c) -> (d=0)\nzeroProductZero2 a b c d prod aZ cNZ = zeroProductZero1 d c b a (flipSidesAndTerms a b c d prod) aZ cNZ\n\n|||If the numerator is zero, the fraction is zero.\nallZeroesSame: (x: ZZPair) -> (a: NotZero (snd x)) -> (z: ZZPair) -> (c: NotZero (snd z)) -> (fst x = 0) -> (fst z = 0)\n-> EqRat x a z c\nallZeroesSame x a z c prf prf1 = rewrite prf in\n rewrite prf1 in\n rewrite multZeroLeftZeroZ (snd z) in\n rewrite multZeroRightZeroZ (snd x) in\n Refl\n\n|||The analog of 'trans' for rationals.\nEqRatTrans: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) ->\n(z: ZZPair) -> (c: NotZero (snd z)) -> (EqRat x a y b) -> (EqRat y b z c) -> (EqRat x a z c)\nEqRatTrans x a y b z c pxy pyz = case (decZero (fst y)) of\n (Yes k) => (transH3 {x} {y} {z} (transH2 {x} {y} {z} (transH1 {x} {y} {z} pxy pyz)) b k )\n (No contra) => (allZeroesSame x a z c (zeroProductZero1 (fst x) (snd y) (snd x) (fst y) pxy (notNotZeroThenZero (contra)) b ) (zeroProductZero2 (fst y) (snd z) (snd y) (fst z) pyz (notNotZeroThenZero (contra)) b ))\n\n-- NOTE: there is another case to be filled in. In the first case, cancellation is possible if the\n-- numerator is nonzero. However, if the numerator of Y is zero, then it remains to be shown that\n-- X and Z are (0,(snd x)) and (0,(snd z)) respectively (and are thus 'equal').\n\nmake_rational : (p: Nat) -> (q: ZZ) -> ZZNotZero q -> ZZPair\nmake_rational p q x = (fromInt(toIntegerNat(p)), q)\n\nInclusionMap : (n : Nat) -> ZZPair --Includes the naturals in Q\nInclusionMap n = make_rational n 1 ZZOneNotZero\n\nAddRationals : (x: ZZPair) -> NotZero (snd x) -> (y: ZZPair) -> NotZero (snd y) -> ZZPair\nAddRationals x a y b = ((fst x)*(snd y) + (snd x)*(fst y), (snd x)*(snd y))\n\nMultiplyRationals : (x: ZZPair) -> NotZero (snd x) -> (y: ZZPair) -> NotZero (snd y) -> ZZPair\nMultiplyRationals x a y b =((fst x)*(fst y), (snd x)*(snd y))\n\nMultInverse : (x: ZZPair) -> NotZero (fst x) -> NotZero (snd x) -> ZZPair\nMultInverse x y z = ((snd x), (fst x))\n\nAddInverse : (x: ZZPair) -> NotZero (snd x) -> ZZPair\nAddInverse x a = (-(fst x), (snd x))\n\nSubtraction : (x: ZZPair) -> NotZero (snd x) -> (y: ZZPair) -> NotZero (snd y) -> ZZPair\nSubtraction x a y b = AddRationals x a (AddInverse y b) b\n\nDivision : (x: ZZPair) -> NotZero (snd x) -> (y: ZZPair) -> NotZero (fst y) -> NotZero (snd y) -> ZZPair\nDivision x a y b c = MultiplyRationals x a (MultInverse y b c) b\n\nScaling: (a: ZZ) -> (x: ZZPair) -> ZZPair\nScaling a x = (a*(fst x), (snd x))\n\nremZeroDivisible: (a: ZZ) -> (b: ZZ) -> (quot: ZZ) -> (rem: ZZ) -> (a = rem + quot*b) -> (rem = 0) -> (a=quot*b)\nremZeroDivisible a b quot rem prf prf1 = rewrite sym (plusZeroLeftNeutralZ (quot*b)) in\n rewrite sym prf1 in\n prf\n\nIsRationalZPOS: (x: ZZPair) -> (prf1 :IsNonNegative (fst x)) -> (prf2: IsPositive (snd x)) -> Either (quot: ZZ ** ((fst x)=quot*(snd x))) (NotZero (fst (snd (QuotRemZ (fst x) (snd x) prf1 prf2) )) )\nIsRationalZPOS x prf1 prf2 = case (decEq (fst (snd (QuotRemZ (fst x) (snd x) prf1 prf2))) (Pos Z)) of\n (Yes prf) => Left ( (Quotient (fst x) (snd x) prf1 prf2) **\n (remZeroDivisible (fst x) (snd x) (Quotient (fst x) (snd x) prf1 prf2) (Remainder (fst x) (snd x) prf1 prf2) (Prelude.Basics.fst (Prelude.Pairs.DPair.snd (Prelude.Pairs.DPair.snd (QuotRemZ (fst x) (snd x) prf1 prf2)) )) prf ) )\n (No contra) => Right (nonZeroNotZero (fst (snd (QuotRemZ (fst x) (snd x) prf1 prf2))) contra)\n\n\nCheckIsQuotientZ: (a: ZZ) -> (b: ZZ) -> (NotZero b) -> Either (quot: ZZ ** (a=quot*b)) (ZZPair)\nCheckIsQuotientZ a (Pos Z) x impossible\nCheckIsQuotientZ (Pos Z) (Pos (S j)) x = case ((IsRationalZPOS ((Pos Z), (Pos (S j))) NonNegative Positive)) of\n (Left l) => (Left l)\n (Right r) => Right ((Pos Z),(Pos (S j)))\nCheckIsQuotientZ (Pos (S k)) (Pos (S j)) x = case ((IsRationalZPOS ((Pos (S k)), (Pos (S j))) NonNegative Positive)) of\n (Left l) => (Left l)\n (Right r) => Right ((Pos (S k)), (Pos (S j)))\nCheckIsQuotientZ (NegS k) (Pos (S j)) x = case ((IsRationalZPOS ((Pos (S k)), (Pos (S j))) NonNegative Positive)) of\n (Left l) => Left (QRproof1 (Pos (S k)) (Pos (S j)) Refl Refl l)\n (Right r) => Right ((Pos (S k)), (Pos (S j)))\nCheckIsQuotientZ (Pos Z) (NegS j) x = Left (Pos Z ** Refl)\nCheckIsQuotientZ (Pos (S k)) (NegS j) x = case ((IsRationalZPOS ((Pos (S k)), (Pos (S j))) NonNegative Positive)) of\n (Left l) => Left (QRproof3 (Pos (S k)) (Pos (S j)) Refl Refl l)\n (Right r) => Right ((Pos (S k)), (Pos (S j)))\nCheckIsQuotientZ (NegS k) (NegS j) x = case ((IsRationalZPOS ((Pos (S k)), (Pos (S j))) NonNegative Positive)) of\n (Left l) => Left (QRproof4 (Pos (S k)) (Pos (S j)) Refl Refl l)\n (Right r) => Right ((Pos (S k)), (Pos (S j)))\n\n-- The following section is on simplification of rationals. There was a function written earlier,\n-- called simplifyRational which used the existence of the numeric type 'Double' in Idris so that\n-- simplification could actually be done. This has now been superseded by the functions below as\n-- the GCD with proof has now been implemented.\n\n-- aByd and bByd are taken from the file 'Divisors.idr' (by Shafil)\n\n|||Extracts a/gcd(a,b) from the definition of GCDZ\naBydNum:GCDZ a b d ->ZZ\naBydNum dGcdab = (fst (fst (fst (snd dGcdab))))\n\n|||Extracts b/gcd(a,b) from the definition of GCDZ\nbBydDen:GCDZ a b d ->ZZ\nbBydDen dGcdab = (fst (snd (fst (snd dGcdab))))\n\n|||A helper routine which simplifies a rational number.\nsimplification: (a: ZZ) -> (b: ZZ) -> (NotBothZeroZ a b) -> (y: ZZPair ** (GCDZ (fst y) (snd y) 1))\nsimplification a b prf = ((aBydNum (snd (gcdZZ a b prf)), bBydDen (snd (gcdZZ a b prf))) ** (divideByGcdThenGcdOne (snd (gcdZZ a b prf))))\n\n|||If b is not zero, then it is not the case that both 'a' and 'b' are zero.\nNotZeroNotBothZero: (a: ZZ) -> (b: ZZ) -> (NotZero b) -> (NotBothZeroZ a b)\nNotZeroNotBothZero a (Pos (S k)) PositiveZ = RightPositive\nNotZeroNotBothZero a (NegS k) NegativeZ = RightNegative\n\n|||This takes a rational number and simplifies it and provides a proof that it is simplified\n|||(that is, the numerator and denominator have GCD 1)\nsimplifyWithProof: (x: ZZPair) -> (NotZero (snd x)) -> (y: ZZPair ** (GCDZ (fst y) (snd y) 1))\nsimplifyWithProof x prf = (simplification (fst x) (snd x) (NotZeroNotBothZero (fst x) (snd x) prf))\n\n|||Extracting the simplified rational from the dependent pair.\nsimplifyRationalProof: (x: ZZPair) -> (NotZero (snd x)) -> ZZPair\nsimplifyRationalProof x prf = fst (simplifyWithProof x prf)\n\n-- below is the old function simplifyRational. I need to make the GCD-based code above\n-- compatible with the code that implements simplifyRational before replacing it.\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 : ZZPair) -> ZZPair\nsimplifyRational (a, b) = (sa, sb) where\n sa = DbtoZZ (da / g) where\n da = ZZtoDb a\n g = cast {from=Integer} {to=Double}\n (gccd (cast {from=ZZ} {to=Integer}a,cast {from=ZZ} {to=Integer}b))\n sb = DbtoZZ (db / g) where\n db = ZZtoDb b\n g = cast {from=Integer} {to=Double}\n (gccd (cast {from=ZZ} {to=Integer}a,cast {from=ZZ} {to=Integer}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\nxAndInverseNotZeroPlus : (x: ZZPair) -> (k: NotZero (snd x)) -> (NotZero (snd (AddInverse x k)))\nxAndInverseNotZeroPlus x k = k\n\nxAndInverseNotZeroMult : (x: ZZPair) -> (j: NotZero (fst x)) -> (k: NotZero (snd x)) -> (NotZero (snd (MultInverse x j k)))\nxAndInverseNotZeroMult x j k = j\n\n\n\n\n\n{-\nFirstIsInverted : (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (a: ZZ) -> (a = (fst x)) -> ((-a) = fst (AddInverse x k))\nFirstIsInverted x k a prf = (apZZ (\\x => -x) a (fst x) prf)\n\nSecondStaysSame : (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (b: ZZ) -> (b = (snd x)) -> (b = (snd (AddInverse x k)))\nSecondStaysSame x k b prf = (apZZ (\\x => x) b (snd x) prf)\n\nxplusinverse: (x: ZZPair) -> (k: ZZNotZero (snd x)) -> ZZPair\nxplusinverse x k = AddRationals x k (AddInverse x k) (xAndInverseNotZero x k)\n\naddinverselemma: (a: ZZ) -> (b: ZZ) -> ((-a)=b) -> (a + b = ((-a) + a)) -> ((-a)+a =0 ) -> (a + b = 0)\naddinverselemma a b prf prf1 prf2 = trans prf1 prf2\n\naddinverseFST: (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (a: ZZ) -> (a = (fst x)) -> (fst (AddInverse x k) = b) -> ((-a) = b)\naddinverseFST x k a prf prf1 = trans (FirstIsInverted x k a prf) (prf1)\n\naddinverseSND: (x: ZZPair) -> (k: ZZNotZero (snd x)) -> (c: ZZ) -> (c = (snd x)) -> (snd (AddInverse x k) = b) -> (c = b)\naddinverseSND x k c prf prf1 = trans (SecondStaysSame x k c prf) (prf1)\n-}\n\n-- Proving the field axioms to show that Q is a field.\n-- The first section concerns those axioms which involve only one or two elements of Q.\n\n\n|||AddRationals is commutative\nplusCommutativeQ: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (AddRationals x a y b) = (AddRationals y b x a)\nplusCommutativeQ x a y b = rewrite (multCommutativeZ (snd y) (snd x)) in\n rewrite (plusCommutativeZ ((fst x)*(snd y)) ((snd x)*(fst y))) in\n rewrite (multCommutativeZ (snd x) (fst y)) in\n rewrite (multCommutativeZ (snd y) (fst x)) in\n Refl\n\n|||MultiplyRationals is commutative\nmultCommutativeQ: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (MultiplyRationals x a y b) = (MultiplyRationals y b x a)\nmultCommutativeQ x a y b = rewrite (multCommutativeZ (fst x) (fst y)) in\n rewrite (multCommutativeZ (snd x) (snd y)) in\n Refl\n\n||| Zero is the right additive identity, meaning that x + 0 = x\nzeroAddIdentityRight: (x: ZZPair) -> (a: NotZero (snd x)) -> ((AddRationals x a (0,1) PositiveZ) = x)\nzeroAddIdentityRight x a = rewrite (multZeroRightZeroZ (snd x)) in\n rewrite (multOneRightNeutralZ (fst x)) in\n rewrite (plusZeroRightNeutralZ (fst x)) in\n rewrite (multOneRightNeutralZ (snd x)) in\n rewrite (sym (pairIsComponents x)) in\n Refl\n\n||| Zero is the left additive identity, meaning that 0 + x = x\nzeroAddIdentityLeft: (x: ZZPair) -> (a: NotZero (snd x)) -> ((AddRationals (0,1) PositiveZ x a) = x)\nzeroAddIdentityLeft x a = rewrite (multZeroLeftZeroZ (snd x)) in\n rewrite (multOneLeftNeutralZ (fst x)) in\n rewrite (plusZeroLeftNeutralZ (fst x)) in\n rewrite (multOneLeftNeutralZ (snd x)) in\n rewrite ((pairIsComponents x)) in\n Refl\n\n|||One is the right multiplicative identity (x*1=x)\noneMultIdentityRight: (x: ZZPair) -> (a: NotZero (snd x)) -> ((MultiplyRationals x a (1,1) PositiveZ) = x)\noneMultIdentityRight x a = rewrite (multOneRightNeutralZ (fst x)) in\n rewrite (multOneRightNeutralZ (snd x)) in\n rewrite (sym (pairIsComponents x)) in\n Refl\n\n|||One is the left multiplicative identity (1*x=x)\noneMultIdentityLeft: (x: ZZPair) -> (a: NotZero (snd x)) -> ((MultiplyRationals (1,1) PositiveZ x a) = x)\noneMultIdentityLeft x a = rewrite (multOneLeftNeutralZ (fst x)) in\n rewrite (multOneLeftNeutralZ (snd x)) in\n rewrite ((pairIsComponents x)) in\n Refl\n\n||| x plus its additive inverse is equal to (0,(snd x)*(snd x)). A custom equality type is probably required to set\n||| this equal to (0,1).\naddInverseLeft: (x: ZZPair) -> (a: NotZero (snd x)) -> ((AddRationals x a (AddInverse x a) (xAndInverseNotZeroPlus x a)) = ((Pos 0), (snd x)*(snd x)))\naddInverseLeft x a = rewrite (multCommutativeZ (fst x) (snd x)) in\n rewrite (multNegateRightZ (snd x) (fst x)) in\n rewrite (plusNegateInverseLZ ((snd x)*(fst x)) ) in\n Refl\n\n||| The additive inverse of x plus itself is equal to (0,(snd x)*(snd x)). A custom equality type is probably required to set\n||| this equal to (0,1).\naddInverseRight: (x: ZZPair) -> (a: NotZero (snd x)) -> ((AddRationals (AddInverse x a) (xAndInverseNotZeroPlus x a) x a) = (0, (snd x)*(snd x)))\naddInverseRight x a = rewrite (multCommutativeZ (snd x) (fst x)) in\n rewrite (multNegateLeftZ (fst x) (snd x)) in\n rewrite (plusNegateInverseRZ ((fst x)*(snd x)) ) in\n Refl\n\n|||x times its multiplicative inverse is equal to ((fst x)*(snd x), (fst x)*(snd x)). A custom equality type is probably required to set\n||| this equal to (1,1).\nmultInverseLeft: (x: ZZPair) -> (a: NotZero (fst x)) -> (b: NotZero (snd x)) ->\n(MultiplyRationals x b (MultInverse x a b) (xAndInverseNotZeroMult x a b)) = ((fst x)*(snd x), (fst x)*(snd x))\nmultInverseLeft x a b = rewrite (multCommutativeZ (snd x) (fst x)) in\n Refl\n\n|||The multiplicative inverse of x times itself is equal to ((fst x)*(snd x), (fst x)*(snd x)). A custom equality type is probably required to set\n||| this equal to (1,1).\nmultInverseRight: (x: ZZPair) -> (a: NotZero (fst x)) -> (b: NotZero (snd x)) ->\n(MultiplyRationals (MultInverse x a b) (xAndInverseNotZeroMult x a b) x b ) = ((snd x)*(fst x), (snd x)*(fst x))\nmultInverseRight x a b = rewrite (multCommutativeZ (snd x) (fst x)) in\n Refl\n\n\n|||AddRationals is associative. It requires the helper function productNonZero.\nplusAssociativeQ: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (z: ZZPair) -> (c: NotZero (snd z)) ->\n((AddRationals (AddRationals x a y b) (productNonZero a b) z c) = (AddRationals x a (AddRationals y b z c) (productNonZero b c)))\nplusAssociativeQ x a y b z c = rewrite (multAssociativeZ (snd x) (snd y) (snd z)) in\n rewrite (multDistributesOverPlusLeftZ ((fst x)*(snd y)) ((snd x)*(fst y)) (snd z)) in\n rewrite (sym (plusAssociativeZ (((fst x)*(snd y))*(snd z)) (((snd x)*(fst y))*(snd z)) (((snd x)*(snd y))*(fst z)) )) in\n rewrite (sym (multAssociativeZ (snd x) (snd y) (fst z))) in\n rewrite (sym (multAssociativeZ (snd x) (fst y) (snd z))) in\n rewrite (sym (multAssociativeZ (fst x) (snd y) (snd z))) in\n rewrite (multDistributesOverPlusRightZ (snd x) ((fst y)*(snd z)) ((snd y)*(fst z)) ) in\n Refl\n\n\n|||MultiplyRationals is associative. It requires the helper function productNonZero.\nmultAssociativeQ: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (z: ZZPair) -> (c: NotZero (snd z)) ->\n((MultiplyRationals (MultiplyRationals x a y b) (productNonZero a b) z c) = (MultiplyRationals x a (MultiplyRationals y b z c) (productNonZero b c)))\nmultAssociativeQ x a y b z c = rewrite sym (multAssociativeZ (fst x) (fst y) (fst z)) in\n rewrite sym (multAssociativeZ (snd x) (snd y) (snd z)) in\n Refl\n\n\n\n", "meta": {"hexsha": "85a28ec08dfd2578c6f702f2bcf5f579015c5aa3", "size": 24115, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/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": "Code/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": "Code/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": 54.191011236, "max_line_length": 253, "alphanum_fraction": 0.5790586772, "num_tokens": 7958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6322094890956733}} {"text": "> module Basic.Properties\n\n> import Basic.Operations\n\n> %default total\n\n> %access public export\n\n\n* Replace properties:\n\n\n> |||\n> replaceLemma : {a : _} -> {x : _} -> {y : _} -> {P : a -> Type} ->\n> (prf : x = y) -> (px : P x) -> replace prf px = px\n> replaceLemma Refl px = Refl\n\n\n> |||\n> replaceLemma2 : {A : Type} -> {P : A -> Type} -> {Q : (a : A) -> P a -> Type} ->\n> {a1 : A} -> {a2 : A} ->\n> (f : (a : A) -> (pa : P a) -> Q a pa) ->\n> (prf : a1 = a2) ->\n> (pa2 : P a2) ->\n> f a1 (replace (sym prf) pa2) = f a2 pa2\n> replaceLemma2 f Refl pa2 = Refl\n\n\n", "meta": {"hexsha": "998a31cdbcdc8fc78debde68a396999d4608b6b2", "size": 652, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Basic/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": "Basic/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": "Basic/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.4827586207, "max_line_length": 82, "alphanum_fraction": 0.4156441718, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.631895651734097}} {"text": "||| This file implements a ``Tanaka-Garrigue''-style dependently-typed red-black tree\n|||\n||| The original implementation and reasoning was initially developed in Coq by \n||| K. Tanaka and J. Garrigue (and me) while trying to formalize dynamic bit vectors.\n|||\n||| I rewrote the dependently-typed development in Idris for a clearer \n||| presentation, as the original was largely unreadable and very complicated.\n\nmodule RedBlack\n\nimport Data.Vect\n\n%default total\n\n-- Color and color functions\npublic export\ndata Color = Red | Black\n\nColorValid : Color -> Color -> Type\nColorValid Red Red = Void\nColorValid _ _ = ()\n\nvalidAnyBlack : (c : Color) -> ColorValid c Black\nvalidAnyBlack Red = ()\nvalidAnyBlack Black = ()\n\nincrBlack : Nat -> Color -> Nat\nincrBlack d Red = d\nincrBlack d Black = S d\n\ninv : Color -> Color\ninv Red = Black\ninv Black = Red\n\n-- Red-black tree as an indexed inductive family\n-- Invariants: \n-- (1) no red node has a red child\n-- (2) every path to a leaf has the same ``black-depth''\nexport\ndata Tree : Nat -> Color -> Type -> Type where\n Leaf : Tree 0 Black a\n Node : {d : Nat} -> {cl : Color} -> {cr : Color} -> (c : Color) -> \n ColorValid c cl -> ColorValid c cr -> \n Tree d cl a -> a -> Tree d cr a -> Tree (incrBlack d c) c a\n\nexport\nempty : Tree 0 Black a\nempty = Leaf\n\nRNode : Tree d Black a -> a -> Tree d Black a -> Tree d Red a\nRNode l v r = Node Red () () l v r\n\nBNode : Tree d cl a -> a -> Tree d cr a -> Tree (incrBlack d Black) Black a\nBNode l v r = Node Black () () l v r\n\nexport\nmember : Ord a => a -> Tree d c a -> Bool\nmember x Leaf = False\nmember x (Node _ _ _ l v r) with (compare x v)\n | LT = member x l\n | EQ = True\n | GT = member x r\n\n\nsize : Tree d c a -> Nat\nsize Leaf = 0\nsize (Node _ _ _ l v r) = S (size l + size r)\n\ninOrderVec : (t : Tree d c a) -> Vect (size t) a\ninOrderVec Leaf = Nil\ninOrderVec (Node _ _ _ l v r) = rewrite plusSuccRightSucc (size l) (size r) \n in inOrderVec l ++ (v :: (inOrderVec r))\n\n\n-- We need an intermediate representation for a potentially malformed tree which may occur in insertion\ndata InsTree : Nat -> Color -> Type -> Type where\n Fix : {d : Nat} -> Tree d Black a -> a -> Tree d Black a -> a ->\n Tree d Black a -> InsTree d Red a\n T : {d : Nat} -> {c : Color} -> (pc : Color) -> Tree d c a -> InsTree d pc a\n\n\ninsTreeColor : InsTree d c a -> Color\ninsTreeColor (Fix _ _ _ _ _) = Red\ninsTreeColor (T _ _) = Black\n\nfixColor : InsTree d c a -> Color\nfixColor (Fix _ _ _ _ _) = Black\nfixColor (T {c = c} _ _) = c\n\nfixInsTree : (t : InsTree d c a) -> Tree (incrBlack d (inv (insTreeColor t))) (fixColor t) a\nfixInsTree (Fix t1 a t2 b t3) = BNode (RNode t1 a t2) b t3\nfixInsTree (T _ t) = t\n\n\nbalanceL : (c : Color) -> (l : InsTree d cl a) -> a -> (r : Tree d cr a) -> \n ColorValid c (insTreeColor l) -> ColorValid c cr -> InsTree (incrBlack d c) c a\nbalanceL Black (Fix t1 a t2 b t3) c t4 _ _ = T Black (RNode (BNode t1 a t2) b (BNode t3 c t4))\nbalanceL Black (T _ l) v r _ _ = T Black (BNode l v r)\nbalanceL {cl = Black} {cr = Black} Red (T _ (Node {cl = Black} {cr = Black} Red _ _ t1 a t2)) b t3 _ _ = Fix t1 a t2 b t3\nbalanceL {cr = Red} Red (T _ (Node Red _ _ _ _ _)) _ _ _ _ impossible\nbalanceL {cl = Black} {cr = Black} Red (T {c = Black} _ l) v r _ _ = T Red (RNode l v r)\nbalanceL {cr = Red} Red (T _ _) _ _ _ _ impossible\n\n\nbalanceR : (c : Color) -> (l : Tree d cl a) -> a -> (r : InsTree d cr a) -> \n ColorValid c cl -> ColorValid c (insTreeColor r) -> InsTree (incrBlack d c) c a\nbalanceR Black t1 a (Fix t2 b t3 c t4) _ _ = T Black (RNode (BNode t1 a t2) b (BNode t3 c t4))\nbalanceR Black l v (T _ r) _ _ = T Black (BNode l v r)\nbalanceR {cl = Black} {cr = Black} Red t1 a (T _ (Node {cl = Black} {cr = Black} Red _ _ t2 b t3)) _ _ = Fix t1 a t2 b t3\nbalanceR {cl = Red} Red _ _ (T _ (Node Red _ _ _ _ _)) _ _ impossible\nbalanceR {cl = Black} {cr = Black} Red l v (T {c = Black} _ r) _ _ = T Red (RNode l v r)\nbalanceR {cl = Red} Red _ _ (T _ _) _ _ impossible\n\n\nins : Ord a => a -> Tree d c a -> InsTree d c a\nins x Leaf = T Black (RNode Leaf x Leaf)\nins x (Node c validL validR l v r) with (compare x v) \n | LT with (ins x l) proof insL\n ins x (Node Black _ validR l v r) | _ | Fix _ _ _ _ _ = balanceL Black (ins x l) v r () validR\n ins x (Node c _ validR l v r) | _ | T _ _ = balanceL c (ins x l) v r leftValidPrf validR\n where leftValidPrf = rewrite (sym insL) in (validAnyBlack c)\n | EQ = T c (Node c validL validR l v r)\n | GT with (ins x r) proof insR \n ins x (Node Black validL _ l v r) | _ | Fix _ _ _ _ _ = balanceR Black l v (ins x r) validL ()\n ins x (Node c validL _ l v r) | _ | T _ _ = balanceR c l v (ins x r) validL rightValidPrf\n where rightValidPrf = rewrite (sym insR) in (validAnyBlack c)\n\n\nblacken : Tree d c a -> Tree (incrBlack d (inv c)) Black a\nblacken Leaf = Leaf\nblacken (Node c _ _ l v r) with (c)\n | Red = Node Black () () l v r\n | Black = Node Black () () l v r\n\n\nexport\ninsert : Ord a => a -> Tree d Black a -> (d : Nat ** Tree d Black a)\ninsert {d = d} x t with (ins x t) \n | T _ t' = (_ ** blacken t')\n", "meta": {"hexsha": "4db2fc3c61b952abc1aa13cbd31d15734860678e", "size": 5164, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "RedBlack.idr", "max_stars_repo_name": "xuanruiqi/dtp", "max_stars_repo_head_hexsha": "c0c33dff4b114381561c011df4d5cf5da7a083f0", "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": "RedBlack.idr", "max_issues_repo_name": "xuanruiqi/dtp", "max_issues_repo_head_hexsha": "c0c33dff4b114381561c011df4d5cf5da7a083f0", "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": "RedBlack.idr", "max_forks_repo_name": "xuanruiqi/dtp", "max_forks_repo_head_hexsha": "c0c33dff4b114381561c011df4d5cf5da7a083f0", "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.8857142857, "max_line_length": 121, "alphanum_fraction": 0.6134779241, "num_tokens": 1765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6316324732157202}} {"text": "import Data.Vect\n\n{-\ndata Range : (begin : Nat) -> (end : Nat) -> Type where\n EmptyRange : Range 0 0\n MkRange : (begin : Nat) -> (end: Nat) -> Range begin end\n\ninterface Encoding a where\n alphabet : Range n m\n digit : Range n m\n\nEncoding ASCII where\n alphabet = MkRange 64 116\n digit = MkRange 48 60\n\nCast ASCII Char where\n cast (MkASCII n) = chr (cast n)\n-}\n\ndata ASCII : Type where\n MkASCII : ASCII\n\ndata Unicode : Type where\n MkUnicode : Unicode\n\ninterface Encoding a where\n alphabet : a -> (Nat, Nat)\n upper : a -> (Nat, Nat)\n digits : a -> (Nat, Nat)\n\n\nEncoding ASCII where\n alphabet MkASCII = (64, 116)\n upper MkASCII = (64, 66)\n digits MkASCII = (0, 9)\n\nEncoding Unicode where\n alphabet MkUnicode = (0, 52)\n upper MkUnicode = (64, 66)\n digits MkUnicode = (100, 109)\n\ninRangeProof : (Nat, Nat) -> Nat -> Type\ninRangeProof (min, max) n = case (min <= n) && (n <= max) of\n True => Elem True [True]\n False => Elem False [True]\n\ndata Character : e -> Nat -> Type where\n Digit : Encoding e =>\n (e' : e) ->\n (n : Nat) ->\n { auto inRange : inRangeProof (digits e') n } ->\n Character e' n\n\n Upper : Encoding e =>\n (e' : e) ->\n (n : Nat) ->\n { auto inRange : inRangeProof (upper e') n } ->\n Character e' n\n\n Letter : Encoding e =>\n (e' : e) ->\n (n : Nat) ->\n { auto inRange : inRangeProof (alphabet e') n } ->\n Character e' n\n\nisDigit : Character e n -> Nat\nisDigit (Digit e n) = 0\nisDigit (Upper e n) = 1\nisDigit (Letter e n) = 2 \n", "meta": {"hexsha": "868d5112488acd58f59549e7f2c6f4d6dc0842e0", "size": 1636, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/Encodings.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/Encodings.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/Encodings.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": 23.3714285714, "max_line_length": 62, "alphanum_fraction": 0.543398533, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6311807413425614}} {"text": "module Data.OrderedVect\n\nimport Decidable.Order\n\n%default total\n\nmutual\n public export\n data OrderedVect : Nat -> (constraint : Ordered ty to) -> Type where\n Nil : .{auto constraint : Ordered ty to}\n -> OrderedVect Z constraint\n (::) : .{constraint : Ordered ty to}\n -> (x : ty)\n -> (v : OrderedVect n constraint)\n -> .{auto prf : Fits x v}\n -> OrderedVect (S n) constraint\n\n public export\n Fits : {constraint : Ordered ty to} -> ty -> OrderedVect n constraint -> Type\n Fits _ Nil = ()\n Fits n (m :: _) = to n m\n\n%name OrderedVect xs,ys,zs\n\nexport\nhead : .{constraint : Ordered ty to} -> OrderedVect (S _) constraint -> ty\nhead (x :: _) = x\n\nfitsTrans : (Fits {constraint} x ys) -> Fits {constraint} (head ys) zs -> Fits {constraint} x zs\nfitsTrans {zs = []} _ _ = ()\nfitsTrans {x} {ys = y' :: _} {zs = z' :: _} rel1 rel2 = transitive x y' z' rel1 rel2\n\nmutual\n merge' : .{constraint : Ordered ty to}\n -> {n : Nat}\n -> (v1 : OrderedVect (S n) constraint)\n -> {m : Nat}\n -> (v2 : OrderedVect (S m) constraint)\n -> (ret : OrderedVect ((S n) + (S m)) constraint ** Either (Fits (head v1) ret) (Fits (head v2) ret))\n merge' [] _ impossible\n merge' _ [] impossible\n merge' {to} [x] [y] = case order {to} x y of\n Left prf => ([x, y] ** Left (reflexive x))\n Right prf => ([y, x] ** Right (reflexive y))\n merge' {m} [x] (y :: ys) = rewrite sym $ plusZeroRightNeutral m in\n rewrite plusSuccRightSucc m Z in\n case assert_total $ merge' (y :: ys) [x] of\n (ref ** Left prf) => (ref ** Right prf)\n (ref ** Right prf) => (ref ** Left prf)\n merge' {n = S cntX} (x :: xs) [y]\n = case order {to} x y of\n Left prf => case mergeHelper xs [y] x of\n (zs ** fitsPrf) => (zs ** Left fitsPrf)\n Right prf => rewrite sym $ plusSuccRightSucc cntX Z in\n rewrite plusZeroRightNeutral cntX in\n ((y :: x :: xs) ** Right (reflexive y))\n merge' ((::) {n = S cntX} x (x' :: xs'))\n ((::) {n = S cntY} y (y' :: ys'))\n = case order {to} x y of\n Left prf => case mergeHelper (x' :: xs') (y :: y' :: ys') x of\n (zs ** fitsPrf) => (zs ** Left fitsPrf)\n Right prf => case mergeHelper (y' :: ys') (x :: x' :: xs') y of\n (zs ** fitsPrf) => rewrite plusCommutative cntX (S $ S $ cntY) in\n rewrite plusSuccRightSucc (S $ S cntY) cntX in\n rewrite plusSuccRightSucc (S cntY) (S cntX) in\n (zs ** Right fitsPrf)\n mergeHelper : .{constraint : Ordered ty to}\n -> {n : Nat}\n -> (xs : OrderedVect (S n) constraint)\n -> {m : Nat}\n -> (ys : OrderedVect (S m) constraint)\n -> (x : ty)\n -> .{auto prfXs : Fits x xs}\n -> .{auto prfYs : Fits x ys}\n -> (ret : OrderedVect (S $ (S n) + (S m)) constraint ** Fits x ret)\n mergeHelper xs ys x {prfXs} {prfYs}\n = case assert_total $ merge' xs ys of\n (zs ** Left fitsPrf) => let _ = fitsTrans prfXs fitsPrf in\n (x :: zs ** reflexive x)\n (zs ** Right fitsPrf) => let _ = fitsTrans prfYs fitsPrf in\n (x :: zs ** reflexive x)\n\nexport\nmerge : {constraint : Ordered ty to}\n -> (n : Nat)\n -> OrderedVect n constraint\n -> (m : Nat)\n -> OrderedVect m constraint\n -> OrderedVect (n + m) constraint\nmerge Z [] Z [] = Nil\nmerge n v1 Z [] = rewrite plusZeroRightNeutral n in v1\nmerge Z [] _ v2 = v2\nmerge (S _) v1 (S _) v2 = fst $ merge' v1 v2\n\nexport\ntail : OrderedVect (S n) constraint -> OrderedVect n constraint\ntail (_ :: v) = v\n\nexport\norderedVectToList : .{constraint : Ordered ty _} -> OrderedVect n constraint -> List ty\norderedVectToList [] = []\norderedVectToList {n = S _} (x :: xs) = x :: (orderedVectToList xs)\n", "meta": {"hexsha": "af140d93493f378c5d57359ad356d9ad8749b675", "size": 4089, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/OrderedVect.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/OrderedVect.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/OrderedVect.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": 39.6990291262, "max_line_length": 109, "alphanum_fraction": 0.5081927122, "num_tokens": 1220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.630897663445418}} {"text": "module Expr\n\ndata Expr : Type where\n Value : (a:Int) -> Expr \n Plus : Expr -> Expr -> Expr\n Minus : Expr -> Expr -> Expr\n Mult : Expr -> Expr -> Expr\n\nevaluate : Expr -> Int\nevaluate (Value x) = x\nevaluate (Plus x y) = (evaluate x) + (evaluate y)\nevaluate (Minus x y) = (evaluate x) - (evaluate y)\nevaluate (Mult x y) = (evaluate x) * (evaluate y)\n", "meta": {"hexsha": "b3b6dcc21a48547dad17f1a6f7e54c6779074a3e", "size": 352, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "expr.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": "expr.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": "expr.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": 25.1428571429, "max_line_length": 50, "alphanum_fraction": 0.6136363636, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.6859494550081926, "lm_q1q2_score": 0.6308282930637619}} {"text": "module FunExt\n\npublic export\nfunext : {a : Type} -> {b : a -> Type} -> \n {f, g : (1 x : a) -> b x} -> (0 _ : (1 x : a) -> f x = g x) -> f = g\nfunext _ = believe_me ()\n\npublic export\nfunextW : {a : Type} -> {b : a -> Type} -> \n {f, g : (x : a) -> b x} -> (0 _ : (x : a) -> f x = g x) -> f = g\nfunextW _ = believe_me ()\n\npublic export\n0 piext : {a : Type} -> {b : a -> Type} -> {b' : a -> Type} ->\n (0 _ : (1 x : a) -> b x = b' x) ->\n ((1 x : a) -> b x) = ((1 x : a) -> b' x)\npiext p = cong (\\ z => (1 x : a) -> z x) (funext p)\n", "meta": {"hexsha": "0ad240345925ec893a08f35053110fe28595ccef", "size": 561, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "FunExt.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": "FunExt.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": "FunExt.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": 31.1666666667, "max_line_length": 77, "alphanum_fraction": 0.3868092692, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.6992544147913994, "lm_q1q2_score": 0.6306720111680284}} {"text": "module Part2.Sec6_1_1_tyfunc\nimport Data.Vect\n\n{-\nFewer concept == smaller conceptual complexity\ntype aliasing is simply a type level function!!!\n-}\n\n||| Type level function with no params\nPosition : Type\nPosition = (Double, Double)\n\ntestData : List (Double, Double)\ntestData = [(1,2),(1,3.1)]\n\ntestData' : List Position\ntestData' = [(1,2),(1,3.1)]\n\n||| Naive test function\nsumFirst : List Position -> Double\nsumFirst list = sum (map fst list)\n\n\n||| Type level function with one param\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\n||| One param function acting as type synomym\nMyList : Type -> Type\nMyList = List\n\ntestMyList : MyList Integer -> MyList Integer\ntestMyList = map (+1) \n", "meta": {"hexsha": "3e4ce87fdf49a673ac315c2c97ebe56bcb850c58", "size": 748, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Part2/Sec6_1_1_tyfunc.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/Sec6_1_1_tyfunc.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/Sec6_1_1_tyfunc.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": 20.2162162162, "max_line_length": 48, "alphanum_fraction": 0.6885026738, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6306008220829209}} {"text": "module Graphics.Util.Transforms\n\nimport Data.So\nimport Data.Matrix\nimport Data.Matrix.Algebraic\nimport Data.Vect\nimport Control.Algebra\nimport Debug.Trace\n\n%access public export\n\n-- ----------------------------------------------------------------- [ Types ]\n\ndata Angle = Radians Double | Degree Double\n\nPos : Type\nPos = Vect 3 Double\n\nTransformationMatrix : Type\nTransformationMatrix = Matrix 4 4 Double\n\nvmult : Matrix n m Double -> Vect m Double -> Vect n Double\nvmult m v = map (<:> v) m\n\n-- ----------------------------------------------------------------- [ Utilities ]\ndata Interval : Type where\n MkInterval : (lower : Double) -> (upper : Double) ->\n So (lower < upper) -> Interval\n \n \npattern syntax \"[\" [x] \"...\" [y] \"]\" = MkInterval x y Oh\nterm syntax \"[\" [x] \"...\" [y] \"]\" = MkInterval x y ?bounds_lemma\n\n \nUnitInterval : Interval\nUnitInterval = MkInterval 0.0 1.0 Oh\n \nclamp : Double -> Interval -> Double\nclamp val (MkInterval lower upper _) = \n if val < lower\n then lower\n else if val > upper\n then upper\n else val\n\n-- ----------------------------------------------------------------- [ Angles ]\n\nexport\ngetRadians : Angle -> Double\ngetRadians (Radians a) = a\ngetRadians (Degree a) = a * pi / 180\n\nprivate\ncosA : Angle -> Double\ncosA a = cos $ getRadians a\n\nprivate\nsinA : Angle -> Double\nsinA a = sin $ getRadians a\n\n-- ----------------------------------------------------------------- [ Vectors + Matrices ]\n\n||| 3D Vector cross product\ncross: Pos -> Pos -> Pos\ncross (x1 :: x2 :: x3 :: []) (y1 :: y2 :: y3 :: []) = [x2*y3-x3*y2, x3*y1-x1*y3, x1*y2-x2*y1]\n\ndot: Pos -> Pos -> Double\ndot x y = x <:> y\n \n||| scalar multiplication\nscalar : Double -> Vect n Double -> Vect n Double\nscalar s v = map (\\e => s*e) v\n \n \nnorm : Vect n Double -> Double\nnorm v = sqrt $ v <:> v \n \n||| normalizes a vector to a unit vector \nnormalize : Vect n Double -> Vect n Double\nnormalize v = map (\\e => e / l ) v\n where l = norm v\n \n||| convert to a row major List \ntoGl : TransformationMatrix -> Vect 16 Double\ntoGl m = concat $ transpose m\n\n-- ----------------------------------------------------------------- [ Transformation Matrices ]\n\nidentity : TransformationMatrix\nidentity = [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1]\n ]\n\ntranslate : Pos -> TransformationMatrix\ntranslate (x :: y :: z :: []) = [ \n [1, 0, 0, x],\n [0, 1, 0, y],\n [0, 0, 1, z],\n [0, 0, 0, 1]\n ]\n\nscale : Pos -> TransformationMatrix\nscale (sx :: sy :: sz :: []) = [ \n [sx, 0, 0, 0],\n [0, sy, 0, 0],\n [0, 0, sz, 0],\n [0, 0, 0, 1]\n ]\n \nscaleAll : Double -> TransformationMatrix\nscaleAll s = scale [s, s, s]\n\nrotateX : Angle -> TransformationMatrix\nrotateX angle = [ \n [1, 0, 0, 0],\n [0, (cos a), -(sin a), 0],\n [0, (sin a), (cos a), 0],\n [0, 0, 0, 1]\n ]\n where a = getRadians angle\n\nrotateY : Angle -> TransformationMatrix\nrotateY angle = [ \n [ (cos a), 0, (sin a), 0],\n [ 0 , 1, 0 , 0],\n [ -(sin a), 0, (cos a), 0],\n [ 0 , 0, 0 , 1]\n ]\n where a = getRadians angle\n\n\nrotateZ : Angle -> TransformationMatrix\nrotateZ angle = [ \n [ (cos a), -(sin a), 0, 0],\n [ (sin a), (cos a), 0, 0],\n [ 0 , 0 , 1, 0],\n [ 0 , 0, 0, 1]\n ]\n where a = getRadians angle\n\nrotate : Vect 3 Angle -> TransformationMatrix\nrotate (ax :: ay :: az :: []) = (rotateX ax) <> (rotateY ay) <> (rotateZ az)\n\n-- ----------------------------------------------------------------- [ Projection Matrices ]\n\northographicProjection : (Double, Double) -> (Double, Double) -> (Double, Double) -> TransformationMatrix\northographicProjection (right, left) (top, bottom) (near, far) = [ \n [ 2/(right-left), 0, 0, -(right + left)/ (right-left)],\n [ 0, 2/(top-bottom), 0, -(top+bottom) / (top-bottom)],\n [ 0, 0, -2/(far-near), -(far+near) / (far-near) ],\n [ 0, 0, 0, 1 ]\n ]\n\n||| Matrix for Perspective Projection\n||| @ fov field of view / viewing angle\n||| @ aspect aspect ration for the projection\n||| @ clipping near and far clipping planes\nperspectiveProjection : (fov: Angle) -> (aspect: Double) -> (clipping: (Double, Double)) -> TransformationMatrix\nperspectiveProjection fov aspect (near, far) = [ \n [ 2 * near/(right-left), 0, (right + left)/ (right-left), 0 ],\n [ 0, 2*near/(top-bottom), (top+bottom) / (top-bottom), 0 ],\n [ 0, 0, -(far+near) / (far - near), -2 * far * near / (far - near)],\n [ 0, 0, -1 , 0 ]\n ]\n where top = near * tan((getRadians fov)/ 2)\n bottom = -top\n right = top * aspect\n left = -right\n\n \n||| transformation matrix to transform from world coordinates to view coordinates\n||| @ eye where the camera aims - a vector\n||| @ center location of the center of the camera\n||| @ up up direction for the viewer \nviewMatrix : (eye: Pos) -> (center: Pos) -> (up: Pos) -> TransformationMatrix\nviewMatrix eye center up = (transpose m) ++ [v] \n where\n f : Pos\n f = normalize (eye <-> center)\n s : Pos\n s = normalize (cross f up)\n u : Pos\n u = cross s f\n m : Matrix 4 3 Double\n m = [s, u, (scalar (-1) f), [0,0,0]]\n v : Vect 4 Double\n v = [0,0,0,1]\n \n||| a view matrix where the camera is located at the origin and points down the z-axis\n||| while the y-axis is the \"up\" direction\ndefaultViewMatrix : TransformationMatrix\ndefaultViewMatrix = viewMatrix [0,0,-1] [0,0,0] [0,1,0]\n\n||| a view matrix for a camer located at the origin\n||| @ eye direction of the camera (where the camera is pointing)\nstandardViewMatrix : (eye: Pos) -> TransformationMatrix\nstandardViewMatrix eye = viewMatrix eye [0,0,0] [0,1,0]\n\n\n-- ----------------------------------------------------------------- [ Quaternions ]\n\n\n-- Quaternions\n-- TODO: introduce a separate type for unit quaternions\nnamespace Quaternions\n \n record Quaternion where\n constructor Q\n scalar : Double\n vector : Vect 3 Double\n \n realPart : Quaternion -> Double\n realPart = scalar\n\n imagPart : Quaternion -> Vect 3 Double\n imagPart = vector\n\n qnorm : Quaternion -> Double\n qnorm (Q s v) = let q = s :: v\n in norm q\n\n\n implementation Show Quaternion where\n show (Q s (v1 :: v2 :: v3 :: [])) = (show s)++\" + \" ++ (show v1) ++\"i + \"++ (show v2) ++ \"k + \"++ (show v3)++\"j\"\n\n implementation Eq Quaternion where\n (==) q p = realPart q == realPart p && imagPart q == imagPart p\n\n ||| returns the quaternion as a 4 dimensional Vector with the scalar part last\n ||| this corresponds to the representation as a (x,y,z,w) vector\n toVect : Quaternion -> Vect 4 Double\n toVect (Q s v) = v ++ [s] \n\n fromVect : Vect 4 Double -> Quaternion\n fromVect (x :: y :: z :: w :: Nil) = Q w [x, y, z]\n\n export\n fromAxis : (rotation: Angle) -> (axis: Vect 3 Double) -> Quaternion\n fromAxis rot (bx :: by :: bz :: Nil) = \n let a = (getRadians rot) / 2\n in Q (cos a) [(sin a)*bx, (sin a)*by, (sin a)*bz]\n\n toMatrix : Quaternion -> TransformationMatrix\n toMatrix q@(Q w (x :: y :: z :: Nil)) = \n let s = 2 / (qnorm q)\n in [\n [(1-s*(y*y+z*z)), s*(x*y-w*z), s*(x*z+w*y), 0],\n [ s*(x*y+w*z), (1-s*(x*x+z*z)), s*(y*z-w*x), 0],\n [ s*(x*z-w*y), s*(y*z+w*x), (1-s*(x*x+y*y)), 0],\n [ 0, 0, 0, 1]\n ]\n\n conjugate : Quaternion -> Quaternion\n conjugate (Q s v) = Q s (scalar (-1) v)\n\n qsum : Quaternion -> Quaternion -> Quaternion\n qsum (Q s1 v1) (Q s2 v2) = Q (s1+s2) (v1 <+> v2)\n\n qmultiply : Quaternion -> Quaternion -> Quaternion\n qmultiply (Q s1 v1) (Q s2 v2) = Q (s1*s2 - (dot v1 v2)) ( (scalar s1 v2) <+> (scalar s2 v1) <+> (cross v1 v2))\n\n qinverse : Quaternion -> Quaternion\n qinverse q@(Q s v) = let q' = s :: v\n q'' = (1 / (q' <:> q'))\n in Q (s / q'') (scalar q'' v)\n\n ||| Exponential e^q\n qexp : Quaternion -> Quaternion\n qexp (Q s v) = let n = norm v \n e = exp s\n in Q (e * cos n) ( scalar ((sin n) / n) v) \n\n qlog : Quaternion -> Quaternion\n qlog q@(Q s v) = let q' = qnorm q\n in Q (log q') (scalar ((acos (s / q')) / (norm v)) v)\n \n \n qnormalize : Quaternion -> Quaternion\n qnormalize q = fromVect $ normalize (toVect q) \n \n ||| x ^ y\n rpow : Double -> Double -> Double\n rpow y x = let e = x * (log (abs y))\n in if y < 0 \n then 1 / (exp e)\n else if y > 0\n then exp e\n else 1\n\n ||| q^t where t is a Real\n qpow : Quaternion -> Double -> Quaternion \n qpow q@(Q s v) a = let e = (rpow (qnorm q) a)\n theta = acos (s / (qnorm q)) \n in Q (e * cos (s * theta)) (scalar (sin (s*theta)) v) \n \n ||| scalar multiplication\n qscalar : Double -> Quaternion -> Quaternion\n qscalar s (Q w v) = Q (s*w) (scalar s v) \n\n data GimbalPole = NorthPole | SouthPole | NoPole\n\n ||| Get the pole of the gimbal lock, if any. \n ||| If we have either a north pole or a south pole there is a gimbal lock\n gimbalPole : Quaternion -> GimbalPole\n gimbalPole (Q s v) = let v' = s :: v \n n' = v' <:> v' \n in if n' > 0.499\n then NorthPole \n else if n' < -0.499 \n then SouthPole\n else NoPole\n\n gimbalMultiplier : GimbalPole -> Double\n gimbalMultiplier NoPole = 0\n gimbalMultiplier NorthPole = 1\n gimbalMultiplier SouthPole = -1\n\n -- conversion between euler angles and quaternions\n -- see https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles\n\n ||| the roll = rotation around x-axis\n export\n roll : Quaternion -> Angle \n roll q = let q' = qnormalize q\n (Q w (x :: y :: z :: Nil)) = q' \n in case (gimbalPole q) of\n NoPole => Radians $ atan2 (2*(w*z + y*x)) (1 - 2*(x*x+z*z)) \n p@(_) => Radians $ (2 * (atan2 y w)) * (gimbalMultiplier p)\n\n ||| rotation around y-axis \n export\n pitch : Quaternion -> Angle \n pitch q = let q' = qnormalize q\n (Q w (x :: y :: z :: Nil)) = q' \n in case (gimbalPole q) of\n NoPole => Radians $ asin (2*(w*x - z*y)) -- might need clamping for asin\n _ => Radians $ (pi / 2)\n\n ||| rotation around z-axis \n export\n yaw : Quaternion -> Angle\n yaw q = let q' = qnormalize q\n (Q w (x :: y :: z :: Nil)) = q' \n in case (gimbalPole q) of\n NoPole => Radians $ atan2 (2*(y*w + x*z)) (1 - 2*(y*y + x*x))\n _ => Radians $ 0\n\n ||| creates a quaternion from a vector of euler angles \n export\n fromEulerAngles : Vect 3 Angle -> Quaternion\n fromEulerAngles (yaw :: pitch :: roll :: Nil) = \n let yawR = (getRadians yaw) / 2; pitchR = (getRadians pitch) / 2; rollR = (getRadians roll) / 2\n w = (cos yawR) * (cos pitchR) * (cos rollR) + (sin yawR) * (sin pitchR) * (sin rollR)\n x = (cos yawR) * (sin pitchR) * (cos rollR) + (sin yawR) * (cos pitchR) * (sin rollR)\n y = (sin yawR) * (cos pitchR) * (cos rollR) - (cos yawR) * (sin pitchR) * (sin rollR)\n z = (cos yawR) * (cos pitchR) * (sin rollR) - (sin yawR) * (sin pitchR) * (cos rollR)\n in (Q w [x,y,z]) \n\n export\n toEulerAngles : Quaternion -> Vect 3 Angle\n toEulerAngles q = [roll q, pitch q, yaw q]\n\n export\n fromCross : Vect 3 Double -> Vect 3 Double-> Quaternion\n fromCross v1 v2 = let theta = acos (dot (normalize v1) (normalize v2))\n vec = cross (normalize v1) (normalize v2)\n in fromAxis (Radians theta) vec \n\n\n {--\n slerpBetween : Vect (S n) Quaternion -> Quaternion\n slerpBetween qs = ?slerpBetween\n\n slerpBetweenWeighted : Vect (S n) (Quaternion, Double) -> Quaternion\n slerpBetweenWeighted qs = ?slerpBetweenWeighted\n --}\n\n -- ----------------------------------------------------------------- [ Algenbraic Classes for Quaternions ]\n\n implementation Semigroup Quaternion where\n (<+>) = qsum\n\n implementation Monoid Quaternion where\n neutral = Q 0 [0, 0, 0]\n\n implementation Group Quaternion where\n inverse (Q s v) = Q (-1*s) (scalar (-1) v)\n\n implementation AbelianGroup Quaternion where {}\n\n implementation Ring Quaternion where\n (<.>) = qmultiply\n\n implementation RingWithUnity Quaternion where\n unity = Q 1 [0,0,0]\n\n implementation Num Quaternion where\n (+) = qsum\n (*) = qmultiply\n fromInteger x = Q (fromInteger x) [0,0,0]\n\n \n implementation Field Quaternion where \n inverseM q _ = qinverse q\n\n -- ----------------------------------------------------------------- [ Quaternion Rotation ]\n\n qrotate : Vect 3 Double -> Quaternion -> Vect 3 Double\n qrotate v q = let p = Q 0 v -- make the vector a quaternion\n q' = qnormalize q -- normalize the rotation quaternion (until we have unit quaternions as a type)\n in imagPart $ q' <.> p <.> (conjugate q')\n\n ||| linear interpolation of quaternions\n ||| TODO handle corner cases (sintheta < 0.00001)\n slerp : Quaternion -> Quaternion -> Double -> Quaternion\n slerp q0 q1 t = let n1 = qnormalize q0\n n2 = qnormalize q1\n theta = acos ((toVect n1) <:> (toVect n2))\n sintheta = sin theta\n weight1 = (sin (theta * (1-t))) / sintheta\n weight2 = (sin (theta*t)) / sintheta\n in ((qscalar weight1 n1) + (qscalar weight2 n2))\n \n{--\n// if theta = 180 degrees then result is not fully defined\n\t// we could rotate around any axis normal to qa or qb\n\tif (fabs(sinHalfTheta) < 0.001){ // fabs is floating point absolute\n\t\tqm.w = (qa.w * 0.5 + qb.w * 0.5);\n\t\tqm.x = (qa.x * 0.5 + qb.x * 0.5);\n\t\tqm.y = (qa.y * 0.5 + qb.y * 0.5);\n\t\tqm.z = (qa.z * 0.5 + qb.z * 0.5);\n\t\treturn qm;\n\t} \n--} \n\n{--\n#define SLERP_TO_LERP_SWITCH_THRESHOLD 0.01f\n\nQuaternion Quaternion_slerp(Quaternion left, Quaternion right, float value) {\n\tfloat leftWeight, rightWeight, difference;\n\tQuaternion result;\n\t\n\tdifference = left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;\n\tif (1.0f - fabs(difference) > SLERP_TO_LERP_SWITCH_THRESHOLD) {\n\t\tfloat theta, oneOverSinTheta;\n\t\t\n\t\ttheta = acos(fabs(difference));\n\t\toneOverSinTheta = 1.0f / sin(theta);\n\t\tleftWeight = sin(theta * (1.0f - value)) * oneOverSinTheta;\n\t\trightWeight = sin(theta * value) * oneOverSinTheta;\n\t\tif (difference < 0.0f) {\n\t\t\tleftWeight = -leftWeight;\n\t\t}\n\t} else {\n\t\tleftWeight = 1.0f - value;\n\t\trightWeight = value;\n\t}\n\tresult.x = left.x * leftWeight + right.x * rightWeight;\n\tresult.y = left.y * leftWeight + right.y * rightWeight;\n\tresult.z = left.z * leftWeight + right.z * rightWeight;\n\tresult.w = left.w * leftWeight + right.w * rightWeight;\n\tQuaternion_normalize(&result);\n\t\n\treturn result;\n}\n--}\n", "meta": {"hexsha": "073e72d61ccaacd6141a2c0f70cbb026274fc6a9", "size": 16462, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Graphics/Util/Transforms.idr", "max_stars_repo_name": "spearman/gl-idris", "max_stars_repo_head_hexsha": "e207ae1cbe3f67f9561db2c0175d020dc91fca89", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-06-29T11:36:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-02T22:32:03.000Z", "max_issues_repo_path": "src/Graphics/Util/Transforms.idr", "max_issues_repo_name": "spearman/gl-idris", "max_issues_repo_head_hexsha": "e207ae1cbe3f67f9561db2c0175d020dc91fca89", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-01T13:01:39.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-01T13:01:39.000Z", "max_forks_repo_path": "src/Graphics/Util/Transforms.idr", "max_forks_repo_name": "spearman/gl-idris", "max_forks_repo_head_hexsha": "e207ae1cbe3f67f9561db2c0175d020dc91fca89", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-04-21T22:11:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-20T02:23:06.000Z", "avg_line_length": 35.0255319149, "max_line_length": 121, "alphanum_fraction": 0.4914955655, "num_tokens": 4675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.6959583250334525, "lm_q1q2_score": 0.6305311508251172}} {"text": "-- ----------------------------------------------------------- [ DataTypes.idr ]\n-- Module : Exercises.DataTypes\n-- Description : Solutions to the Chapter 4 exercises in Edwin Brady's\n-- book, \"Type-Driven Development with Idris.\"\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Exercises.DataTypes\n\nimport public Chapter.DataTypes\nimport public Data.Vect\n\n%access export\n\non : (b -> b -> c) -> (a -> b) -> a -> a -> c\non g f = \\x,y => f x `g` f y\n\nonIdentity : -- ((*) : b -> b -> c) ->\n ((*) `on` Basics.id) x y = (*) x y\nonIdentity = Refl\n\nonComposition : -- ((*) : c -> c -> d) -> (f : b -> c) -> (g : a -> b) -> \n (((*) `on` f) `on` g) x y = ((*) `on` (f . g)) x y\nonComposition = Refl \n\nflipOn : (a -> b) -> (b -> b -> c) -> a -> a -> c\nflipOn = flip on\n\nonFlip : -- (f : a -> b) -> (g : b -> c) ->\n (flipOn f . flipOn g) h x y = (flipOn (g . f)) h x y\nonFlip = Refl\n\n-- --------------------------------------------------------- [ 4.1.5 Exercises ]\n\n||| Insert every element of a list into a binary search tree.\n|||\n||| ```idris example\n||| listToTree [1,4,3,5,2]\n||| ```\nlistToTree : Ord a => List a -> Tree a\nlistToTree = foldr insert Empty\n\n||| Flatten a tree into a list using *inorder* traversal.\n|||\n||| ```idris example\n||| treeToList (listToTree [4,1,8,7,2,3,9,5,6])\n||| ```\ntreeToList : Tree a -> List a\ntreeToList Empty = []\ntreeToList (Node l x r) = treeToList l ++ [x] ++ treeToList r\n\n||| An integer arithmetic expression.\npublic export\ndata Expr = ||| A single integer.\n Val Int\n | ||| Addition of an expression to an expression.\n Add Expr Expr\n | ||| Subtraction of an expression from an expresison.\n Sub Expr Expr\n | ||| Multiplication of an expression with an expression.\n Mult Expr Expr\n\n||| Evaluate an integer arithmetic expression.\n|||\n||| ```idris example\n||| evaluate (Mult (Val 10) (Add (Val 6) (Val 3)))\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\n||| Return the larger of two inputs, or `Nothing` if both inputs are `Nothing`.\n|||\n||| ```idris example\n||| maxMaybe (Just 4) (Just 5)\n||| ```\n||| ```idris example\n||| maxMaybe (Just 4) Nothing\n||| ```\nmaxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe mx my = (max <$> mx <*> my) <|> mx <|> my\n\n-- --------------------------------------------------------- [ 4.2.4 Exercises ]\n\npublic export\ndata PowerSource = Petrol\n | Electricity\n | Pedal\n\npublic export\ndata Vehicle : PowerSource -> Type where\n Unicycle : Vehicle Pedal\n Bicycle : Vehicle Pedal\n GalacticPizzaCar : Vehicle Electricity\n Motorcycle : (fuel : Nat) -> Vehicle Petrol\n Car : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n\n||| Return the number of wheels on a vehicle.\n|||\n||| ```idris example\n||| wheels GalacticPizzaCar\n||| ```\nwheels : Vehicle power -> Nat\nwheels Unicycle = 1\nwheels Bicycle = 2\nwheels GalacticPizzaCar = 3\nwheels (Motorcycle _) = 2\nwheels (Car _) = 4\nwheels (Bus _) = 4\n\n||| Refuel a petrol-powered vehicle.\n|||\n||| ```idris example\n||| refuel (Car 0)\n||| ```\nrefuel : Vehicle Petrol -> Vehicle Petrol\nrefuel (Motorcycle _) = Motorcycle 50\nrefuel (Car _) = Car 100\nrefuel (Bus _) = Bus 200\n-- NOTE: refuel Unicycle impossible\n\n||| Get the first n elements of a Vect.\n|||\n||| ```idris example\n||| vectTake 3 [1,2,3,4,5,6,7]\n||| ```\n|||\n||| @ n the number of elements to take\nvectTake : (n : Nat) -> Vect (n + m) a -> Vect n a\nvectTake Z _ = []\nvectTake (S k) (x :: xs) = x :: vectTake k xs\n\n||| Return `Just` the sum of the entries at position `pos` in each of the\n||| inputs, if `pos` is within bounds, or `Nothing` otherwise.\n|||\n||| ```idris example\n||| sumEntries 2 [1,2,3,4] [5,6,7,8]\n||| ```\n||| ```idris example\n||| sumEntries 4 [1,2,3,4] [5,6,7,8]\n||| ```\n|||\n||| @ pos a possibly out-of-bounds index into the input vectors\nsumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos xs ys with (integerToFin pos n)\n | m = pure $ ((+) `on` index !m) xs ys\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "14358841280fc874828c14ff41d75b627058ed58", "size": 4410, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Exercises/DataTypes.idr", "max_stars_repo_name": "yurrriq/tdd-with-idris", "max_stars_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-15T01:29:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-15T01:29:36.000Z", "max_issues_repo_path": "src/Exercises/DataTypes.idr", "max_issues_repo_name": "yurrriq/tdd-with-idris", "max_issues_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-11-21T23:42:45.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-01T05:43:10.000Z", "max_forks_repo_path": "src/Exercises/DataTypes.idr", "max_forks_repo_name": "yurrriq/tdd-with-idris", "max_forks_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4, "max_line_length": 80, "alphanum_fraction": 0.5303854875, "num_tokens": 1313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6302867008424229}} {"text": "module ArithExp.SmallStep\nimport ArithExp.AST\n\n||| Definition of a relation, adapted from *Software Foundations*\nRelation : Type -> Type\nRelation a = a -> a -> Type\n\ndeterministic : Relation a -> Type\ndeterministic {a=a} Ra = {x, y, z : a} -> Ra x y -> Ra x z -> y = z\n\n||| Used or defining the \"transitive closure\" used in TAPL. \n|||\n||| This is also taken from *Software Foundations*\ndata MultiStep : Relation a -> Relation a where\n Reflexive : MultiStep r x x\n Transitive : r x y -> MultiStep r y z -> MultiStep r x z\n\nsyntax [x] THEN [y] = x `Transitive` (y)\nsyntax [a] \"=>>\" [b] = SmallStep a b\nsyntax [a] \"=>>*\" [b] = MultiStep SmallStep a b\n\n||| 'SmallStep' is the small step OS relation\ndata SmallStep : ArithBool -> ArithBool -> Type where\n\n IfTrue : (IF Tru a b) =>> a\n\n IfFalse : (IF Fals a b) =>> b\n\n IfStep : (t =>> t')\n -> (IF t a b) =>> (IF t' a b)\n\n SuccStep : (t =>> t')\n -> (Succ t) =>> (Succ t')\n\n IsZeroStep : (t =>> t')\n -> (IsZero t) =>> (IsZero t')\n\n IsZeroZero : (IsZero Zero) =>> Tru\n\n IsZeroSucc : {auto prf : NV n} -> (IsZero (Succ n)) =>> Fals\n\n PredStep : (t =>> t')\n -> (Pred t) =>> (Pred t')\n\n PredZero : (Pred Zero) =>> Zero\n\n PredSucc : {prf : NV n} -> (Pred (Succ n)) =>> n\n\n\ntest1 : (IF (IF Tru Fals Fals) Tru (IsZero (Succ (Succ Zero)))) =>>* Fals\ntest1 = (IfStep IfTrue) THEN\n IfFalse THEN\n IsZeroSucc THEN\n Reflexive\n", "meta": {"hexsha": "4d4224deb9b891a6cbbbdf67579d98707f83a604", "size": 1479, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ArithExp/SmallStep.idr", "max_stars_repo_name": "ezrosent/TAPL-idris", "max_stars_repo_head_hexsha": "edc7b1383456aaf4a47588ae2a4e5b48199be972", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-21T09:47:00.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-21T15:37:15.000Z", "max_issues_repo_path": "ArithExp/SmallStep.idr", "max_issues_repo_name": "ezrosent/TAPL-idris", "max_issues_repo_head_hexsha": "edc7b1383456aaf4a47588ae2a4e5b48199be972", "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": "ArithExp/SmallStep.idr", "max_forks_repo_name": "ezrosent/TAPL-idris", "max_forks_repo_head_hexsha": "edc7b1383456aaf4a47588ae2a4e5b48199be972", "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.8909090909, "max_line_length": 73, "alphanum_fraction": 0.5510480054, "num_tokens": 517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6298349092181038}} {"text": "twoPlusTwoNotFive : 2 + 2 = 5 -> Void\ntwoPlusTwoNotFive Refl impossible\n\nvalueNotSuc : (x : Nat) -> x = S x -> Void\nvalueNotSuc _ Refl impossible\n", "meta": {"hexsha": "080c0bfeef79f30eb3cc7b325d422d52be97b92d", "size": 146, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter08/Void.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/Void.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/Void.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.3333333333, "max_line_length": 42, "alphanum_fraction": 0.7054794521, "num_tokens": 51, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6297866953935758}} {"text": "> module Identity.Properties\n\n\n> import Control.Monad.Identity\n\n> import Identity.Operations\n> import Sigma.Sigma\n> import Decidable.Predicates\n> import Unique.Predicates\n> import Finite.Predicates\n> import Unit.Properties\n\n\n> %default total\n\n> %access public export\n\n\n> ||| Id is injective\n> injectiveId : {a : Type} -> {left : a} -> {right : a} -> (Id left) = (Id right) -> left = right\n> injectiveId Refl = Refl\n> %freeze injectiveId -- frozen\n\n\n* |Identity| is a functor:\n\n> -- functorSpec1 : fmap . id = id\n\n> -- functorSpec2 : fmap (f . g) = (fmap f) . (fmap g)\n\n\n* |Identity| is a monad:\n\n> -- monadSpec1 : (fmap f) . ret = ret . f\n\n> -- monadSpec21 : bind (ret a) f = f a\n\n> -- monadSpec22 : bind ma ret = ma\n\n> -- monadSpec23 : {A, B, C : Type} -> {f : A -> M B} -> {g : B -> M C} ->\n> -- bind (bind ma f) g = bind ma (\\ a => bind (f a) g)\n\n\n* |Identity| is a container monad:\n\n> |||\n> elemNonEmptySpec0 : {A : Type} ->\n> (a : A) -> (ia : Identity A) ->\n> a `Elem` ia -> NonEmpty ia\n> elemNonEmptySpec0 a (Id a) Refl = () \n\n> ||| \n> elemNonEmptySpec1 : {A : Type} ->\n> (ia : Identity A) ->\n> NonEmpty ia -> \n> Sigma A (\\ a => a `Elem` ia)\n> elemNonEmptySpec1 (Id a) _ = (MkSigma a Refl)\n\n> |||\n> containerMonadSpec1 : {A : Type} -> {a : A} -> a `Elem` (ret a)\n> containerMonadSpec1 {A} {a} = Refl\n\n> -- containerMonadSpec2 : {A : Type} -> (a : A) -> (ma : M A) -> (mma : M (M A)) ->\n> -- a `Elem` ma -> ma `Elem` mma -> a `Elem` (join mma)\n\n> -- containerMonadSpec2 : {A : Type} -> (a : A) -> (ma : M A) -> (mma : M (M A)) ->\n> -- a `Elem` ma -> ma `Elem` mma -> a `Elem` (join mma)\n\n> containerMonadSpec3 : {A : Type} -> {P : A -> Type} -> \n> (a : A) -> (ia : Identity A) -> All P ia -> a `Elem` ia -> P a\n> containerMonadSpec3 {A} {P} a1 (Id a2) pa2 a1eqa2 = replace (sym a1eqa2) pa2\n\n> -- containerMonadSpec4 : {A : Type} -> (ia : Identity A) -> fmap outl (tagElem ia) = ia\n\n> -- containerMonadSpec5 : {A : Type} -> {P : A -> Type} -> \n> -- (ia : Identity A) -> ((a : A) -> a `Elem` ia -> P a) -> All P ia \n\n\n* Specific container monad properties\n\n> |||\n> -- uniqueAllLemma : {A : Type} -> {P : A -> Type} -> \n> -- Unique1 P -> (ia : Identity A) -> Unique (All P ia)\n\n> ||| All is finite\n> finiteAll : {A : Type} -> {P : A -> Type} ->\n> Finite1 P -> (ia : Identity A) -> Finite (All P ia)\n> finiteAll f1P (Id a) = f1P a\n\n> ||| All is decidable\n> decidableAll : {A : Type} -> {P : A -> Type} -> \n> (dec : (a : A) -> Dec (P a)) -> (ia : Identity A) -> Dec (All P ia)\n> decidableAll dec ia = dec (unwrap ia)\n\n> ||| NotEmpty is finite\n> finiteNonEmpty : {A : Type} -> (ia : Identity A) -> Finite (NonEmpty ia)\n> finiteNonEmpty _ = finiteUnit\n\n> ||| NonEmpty is decidable\n> decidableNonEmpty : {A : Type} -> (ia : Identity A) -> Dec (NonEmpty ia)\n> decidableNonEmpty _ = Yes ()\n\n\n> ||| Values of type |Identity A| are never empty\n> nonEmptyLemma : {A : Type} -> (ia : Identity A) -> NonEmpty ia\n> nonEmptyLemma (Id a) = elemNonEmptySpec0 a (Id a) Refl \n\n> ||| |Elem| is decidable\n> decElem : {A : Type} -> DecEq0 A -> (a : A) -> (ma : Identity A) -> Dec (a `Elem` ma)\n> decElem dec a1 (Id a2) with (dec a1 a2)\n> | (Yes prf) = Yes prf\n> | (No contra) = No contra\n> %freeze decElem -- frozen\n\n> ||| |Elem| is unique\n> uniqueElem : {A : Type} -> UniqueEq0 A -> (a : A) -> (ma : Identity A) -> Unique (a `Elem` ma)\n> uniqueElem unique a1 (Id a2) p q = unique a1 a2 p q\n> %freeze uniqueElem -- frozen\n\n\n> {-\n\nThese properties are already defined in base/Control/Monad/Identity.idr\n\n> using (A : Type)\n> implementation (Eq A) => Eq (Identity A) where\n> (Id a) == (Id b) = a == b\n\n> using (A : Type)\n> implementation (Show A) => Show (Identity A) where\n> show (Id a) = show a\n\n> ---}\n", "meta": {"hexsha": "b8c7954bd897c1cbf50f76afdbd1348c6a36a56a", "size": 3966, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Identity/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": "Identity/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": "Identity/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": 29.5970149254, "max_line_length": 97, "alphanum_fraction": 0.5274836107, "num_tokens": 1345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6296335066749347}} {"text": "module Halfer\n\nimport public Numeric\n\n%default total\n\n||| Divide even integer by 2\npublic export\nhalfer : EvenInteger -> Integer\n-- a: input integer\n-- x: half of a\n-- p: proof that x is the half of a\nhalfer (a ** (Factor (x ** p))) = cast x\n", "meta": {"hexsha": "f04db142d1392d31d5c82176f46406b1821ef2b4", "size": 242, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "experimental/registry-dtl/service/Halfer.idr", "max_stars_repo_name": "nunet-io/ai-dsl", "max_stars_repo_head_hexsha": "cdcb630c6ea1785f8237c700621555046437d212", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-17T08:02:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T12:52:29.000Z", "max_issues_repo_path": "experimental/registry-dtl/service/Halfer.idr", "max_issues_repo_name": "nunet-io/ai-dsl", "max_issues_repo_head_hexsha": "cdcb630c6ea1785f8237c700621555046437d212", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2021-03-04T10:33:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-16T04:55:50.000Z", "max_forks_repo_path": "experimental/registry-dtl/service/Halfer.idr", "max_forks_repo_name": "nunet-io/ai-dsl", "max_forks_repo_head_hexsha": "cdcb630c6ea1785f8237c700621555046437d212", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-02-19T07:58:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-28T18:37:13.000Z", "avg_line_length": 17.2857142857, "max_line_length": 40, "alphanum_fraction": 0.673553719, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6294687614921647}} {"text": "import System\nimport Data.Vect\n\n{- Toy program that outputs the n first digits of Pi.\n\n Inspired from http://www.haskell.org/haskellwiki/Shootout/Pidigits.\n The original ns and str lazy lists have been replaced by strict functions.\n\n Memory usage seems to be excessive. One of the branches of str is tail recursive, and\n the other one only needs to cons an extra Integer.\n\n For reference, the Haskell version runs in 0m0.230s when printing to /dev/null.\n It almost runs in constant space.\n-}\n\ndata F = MkF Integer Integer Integer\n\n-- Prints the list of digits by groups of 10\nloop : Nat -> Nat -> List Integer -> IO ()\nloop n k' Nil = putStrLn $ (pack $ Vect.replicate n ' ') ++ \"\\t:\" ++ show k'\nloop Z k' xs = do\n putStrLn (\"\\t:\" ++ show k')\n loop 10 k' xs\nloop (S k) k' (x::xs) = do\n putStr (show x)\n loop k (S k') xs\n\nfn : Integer -> F\nfn k = MkF k (4*k+2) (2*k+1)\n\nflr : Integer -> F -> Integer\nflr x (MkF q r t) = (q*x + r) `div` t\n\ncomp : F -> F -> F\ncomp (MkF q r t) (MkF u v x) = MkF (q*u) (q*v + r*x) (t*x)\n\n-- Returns the list of digits of pi. Memory hungry.\nstr : F -> Integer -> Nat -> List Integer\nstr _ _ Z = Nil\nstr z k (S n) =\n if y == flr 4 z\n then y :: str (comp (MkF 10 (-10*y) 1) z ) k n\n else str (comp z (fn k)) (k+1) (S n)\n where y = flr 3 z\n\nmain : IO ()\nmain = do\n arg <- getLine\n let n = fromInteger (cast arg)\n let l = str (MkF 1 0 1) 1 n\n loop 10 0 l\n pure ()\n", "meta": {"hexsha": "f0d3ad28ed06fa391efabfe8c4fc9d65bc2125cf", "size": 1475, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Benchmarks/pidigits.idr", "max_stars_repo_name": "timjs/iris-clean", "max_stars_repo_head_hexsha": "b2ed1f982beec936cb6fe32e8fa6b97a1da4a4f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2017-01-02T14:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-24T08:43:55.000Z", "max_issues_repo_path": "Benchmarks/pidigits.idr", "max_issues_repo_name": "timjs/iris-clean", "max_issues_repo_head_hexsha": "b2ed1f982beec936cb6fe32e8fa6b97a1da4a4f6", "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": "Benchmarks/pidigits.idr", "max_forks_repo_name": "timjs/iris-clean", "max_forks_repo_head_hexsha": "b2ed1f982beec936cb6fe32e8fa6b97a1da4a4f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-20T09:57:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T09:57:55.000Z", "avg_line_length": 27.8301886792, "max_line_length": 88, "alphanum_fraction": 0.5938983051, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.7057850402140659, "lm_q1q2_score": 0.6294269026855565}} {"text": "module ZipWithN\n\nimport Data.List\nimport Data.Vect\n\n%default total\n\npublic export\ninterface ZipWithable f where\n zipWith : (a -> b -> c) -> f a -> f b -> f c\n\npublic export\nZipWithable List where\n zipWith = List.zipWith\n\npublic export\nZipWithable (Vect n) where\n zipWith = Vect.zipWith\n\nnamespace FunctionBased\n\n public export\n FunN : Vect n Type -> Type -> Type\n FunN [] ty = ty\n FunN (x::xs) ty = x -> FunN xs ty\n\n apFunN : {n : Nat} -> {0 args : Vect n Type} -> ZipWithable f => f $ FunN args res -> FunN (f <$> args) (f res)\n apFunN {n=Z} {args=[]} = id\n apFunN {n=S k} {args=a::as} = \\fs, fa => apFunN $ zipWith apply fs fa\n\n public export\n zipWithN : {n : Nat} -> {0 args : Vect n Type} -> (ZipWithable m, Applicative m) => FunN args res -> FunN (m <$> args) (m res)\n zipWithN {n=Z} {args=[]} = pure\n zipWithN {n=S k} {args=a::as} = \\f, xs => apFunN $ f <$> xs\n\nnamespace PseudoTypeclassBased_SearchBoth\n\n public export\n data FunN : (m : Type -> Type) -> ty -> mty -> Type where\n Constant : FunN m ty (m ty)\n Function : FunN m ty mty -> FunN m (a -> ty) (m a -> mty)\n\n apFunN : FunN m ty mty => ZipWithable m => m ty -> mty\n apFunN @{Constant} = id\n apFunN @{Function s} = \\fs, fa => apFunN $ zipWith apply fs fa\n\n public export\n zipWithN : FunN m ty mty => ZipWithable m => Applicative m => ty -> mty\n zipWithN @{Constant} = pure\n zipWithN @{Function s} = \\f, xs => apFunN $ f <$> xs\n", "meta": {"hexsha": "02c7a5e6fcd454831878ab410e720edfa2583927", "size": 1439, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZipWithN.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": "ZipWithN.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": "ZipWithN.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.2156862745, "max_line_length": 128, "alphanum_fraction": 0.6059763725, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505964, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6290339668886803}} {"text": "||| Views to show how a role interacts, or not, with a Term from a Global Type.\nmodule Sessions.Global.Involved\n\nimport Decidable.Equality\nimport Data.List\nimport Data.List.Elem\n\nimport Data.List1\n\nimport Sessions.Meta\nimport Sessions.Global\n\n%default total\n\npublic export\ndata Involved : (p, s, r : role)\n -> Type\n where\n Sends : (prfS : role = s)\n -> Involved role s r\n\n Recvs : (prfR : role = r)\n -> Involved role s r\n\n Skips : (prfSNot : Not (role = s))\n -> (prfRNot : Not (role = r))\n -> Involved role s r\n\npublic export\ninvolved : DecEq role\n => (p, s, r : role)\n -> (contra : Not (s = r))\n -> Involved p s r\ninvolved p s r contra with (decEq p s)\n involved p p r contra | (Yes Refl) = (Sends Refl)\n involved p s r contra | (No f) with (decEq p r)\n involved p s p contra | (No f) | (Yes Refl) = (Recvs Refl)\n involved p s r contra | (No f) | (No g) = (Skips f g)\n\n\n\n-- [ EOF ]\n", "meta": {"hexsha": "f2e7ec1ac1a21afc16d9a8561077d1ff94757ece", "size": 1016, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Sessions/Global/Involved.idr", "max_stars_repo_name": "DSbD-AppControl/sessions-playground", "max_stars_repo_head_hexsha": "d304de2a5bf9a5268f3cd8aef9402face1bc7fdc", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-19T13:13:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-19T13:13:10.000Z", "max_issues_repo_path": "Sessions/Global/Involved.idr", "max_issues_repo_name": "DSbD-AppControl/sessions-playground", "max_issues_repo_head_hexsha": "d304de2a5bf9a5268f3cd8aef9402face1bc7fdc", "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": "Sessions/Global/Involved.idr", "max_forks_repo_name": "DSbD-AppControl/sessions-playground", "max_forks_repo_head_hexsha": "d304de2a5bf9a5268f3cd8aef9402face1bc7fdc", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6279069767, "max_line_length": 79, "alphanum_fraction": 0.5600393701, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7154240018510025, "lm_q1q2_score": 0.6289626986260404}} {"text": "import Data.Vect \n\ndata Format = Number Format \n | Str Format\n | Dble Format\n | Chr Format\n | Lit String Format\n | End\n\nPrintfType : Format -> Type\nPrintfType (Number fmt) = (i : Int) -> PrintfType fmt\nPrintfType (Dble fmt) = (i : Double) -> PrintfType fmt\nPrintfType (Str fmt) = (str: String) -> PrintfType fmt\nPrintfType (Chr fmt) = (char : Char) -> PrintfType fmt\nPrintfType (Lit str fmt) = PrintfType fmt\nPrintfType End = String\n\nprintfFmt : (fmt : Format) -> (acc: String) -> PrintfType fmt\nprintfFmt (Number fmt) acc = \\i => printfFmt fmt (acc ++ show i)\nprintfFmt (Dble fmt) acc = \\i => printfFmt fmt (acc ++ show i)\nprintfFmt (Str fmt) acc = \\str => printfFmt fmt (acc ++ str)\nprintfFmt (Chr fmt) acc = \\char => printfFmt fmt (acc ++ show char)\nprintfFmt (Lit lit fmt) acc = printfFmt fmt (acc ++ lit) \nprintfFmt End acc = acc\n\ntoFormat : (xs : List Char) -> Format\ntoFormat [] = End\ntoFormat ('%' :: 'd' :: chars) = Number (toFormat chars) \ntoFormat ('%' :: 'f' :: chars) = Dble (toFormat chars) \ntoFormat ('%' :: 's' :: chars) = Str (toFormat chars) \ntoFormat ('%' :: 'c' :: chars) = Chr (toFormat chars) \ntoFormat ('%' :: chars) = Lit \"%\" (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 : Nat -> Nat -> Type\nMatrix n m = Vect n (Vect m Double)\n\n", "meta": {"hexsha": "6ed45730094ddb395dee5c68b62877849fc98fa3", "size": 1562, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp6/printf.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/printf.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/printf.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.3255813953, "max_line_length": 73, "alphanum_fraction": 0.5973111396, "num_tokens": 451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706735, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.628838856764645}} {"text": "module Sphere\n\nimport Hittable\nimport Vec3\nimport Ray\n\n%access export\n\npublic export\n\nrecord Sphere where\n constructor MkSphere\n center : Vec3\n radius : Double\n\nHittable Sphere where\n hit sphere ray t_min t_max = \n if discriminant > 0 \n then\n if temp < t_max && temp > t_min\n then set_face_normal ray oNormal rec\n else \n if temp' < t_max && temp' > t_min\n then set_face_normal ray oNormal' rec'\n else MkHitRecord (0,0,0) (0,0,0) temp' False False\n else MkHitRecord (0,0,0) (0,0,0) 1 False False\n where\n oc : Vec3\n oc = (orig ray) - center sphere\n a : Double\n a = lengthSquared (dir ray)\n half_b : Double\n half_b = dot oc (dir ray)\n c : Double\n c = (lengthSquared oc) - radius sphere * radius sphere\n discriminant : Double\n discriminant = half_b*half_b - a*c\n\n root : Double\n root = sqrt discriminant\n temp : Double\n temp = (-half_b - root) / a\n temp' : Double\n temp' = (-half_b + root) / a\n\n rec_p : Vec3\n rec_p = at ray temp\n rec : HitRecord\n rec = MkHitRecord rec_p (0, 0, 0) temp False True\n oNormal : Vec3\n oNormal = (rec_p - center sphere) / radius sphere\n\n rec_p' : Vec3\n rec_p' = at ray temp'\n rec' : HitRecord\n rec' = MkHitRecord rec_p (0, 0, 0) temp' False True\n oNormal' : Vec3\n oNormal' = (rec_p' - center sphere) / radius sphere\n ", "meta": {"hexsha": "eb26e0eb6377f7aa6ff4a526c1493f9b237dd2e7", "size": 1683, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "shapes/Sphere.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": "shapes/Sphere.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": "shapes/Sphere.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": 28.5254237288, "max_line_length": 78, "alphanum_fraction": 0.5080213904, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.665410558746814, "lm_q1q2_score": 0.6288094591294371}} {"text": "isSingleton : Bool -> Type\nisSingleton True = Nat\nisSingleton False = List Nat\n\nmkSingle : (x : Bool) -> isSingleton x\nmkSingle True = 0\nmkSingle False = []\n\nsum : (single : Bool) -> isSingleton single -> Nat\nsum True x = x\nsum False [] = 0\nsum False (x::xs) = x + sum False xs\n", "meta": {"hexsha": "de1a12455033ba2b47eb40c74685ddea523944f6", "size": 291, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/types.idr", "max_stars_repo_name": "0918nobita/idris", "max_stars_repo_head_hexsha": "e4ae7fbb95d7cd580b366e93747a069ccbeae31d", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-23T06:49:52.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-23T06:49:52.000Z", "max_issues_repo_path": "src/types.idr", "max_issues_repo_name": "0918nobita/idris", "max_issues_repo_head_hexsha": "e4ae7fbb95d7cd580b366e93747a069ccbeae31d", "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/types.idr", "max_forks_repo_name": "0918nobita/idris", "max_forks_repo_head_hexsha": "e4ae7fbb95d7cd580b366e93747a069ccbeae31d", "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": 22.3846153846, "max_line_length": 50, "alphanum_fraction": 0.6323024055, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6285278897791969}} {"text": "import Data.Vect\n\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", "meta": {"hexsha": "a4edf8ebd3bce48f5dc592a2e0efe4edd8cbae00", "size": 247, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter08/ExactLengthDec.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/ExactLengthDec.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/ExactLengthDec.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": 30.875, "max_line_length": 69, "alphanum_fraction": 0.4898785425, "num_tokens": 57, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.6791787056691698, "lm_q1q2_score": 0.6283964903051882}} {"text": "||| Fixed point fractional number. - Ported from Haskell base.\n|||\n||| Copyright 2021, HATTORI, Hiroki\n||| This file is released under the MIT license, see LICENSE for more detail.\n|||\nmodule Data.Fixed\n\nimport Data.Maybe\nimport Data.String\n\nimport Generics.Derive\n\nimport Data.Rational\n\n%default total\n%language ElabReflection\n\n-- --------------------------------------------------------------------------\n\nnamespace ResolutionV\n\n public export\n data ResolutionV : Nat -> Type where\n MkResV : (n:Nat) -> (res:Integer) -> (res > 0 = True) -> ResolutionV n\n\n export expToResolution : (n:Nat) -> ResolutionV n\n expToResolution n = go 1 Refl n where\n go : (ans:Integer) -> (ans > 0 = True) -> (m:Nat) -> ResolutionV n\n go ans prf Z = MkResV n ans prf\n go ans prf (S m) = go (ans * 10) (believe_me $ Refl {x=True}) m\n\n\n\n\n-- --------------------------------------------------------------------------\n\npublic export\ndata Fixed : Nat -> Type where\n MkFixed : Integer -> Fixed n\n\n%runElab derive \"Fixed\" [Generic, Meta, Eq, Ord, DecEq]\n\npublic export\n{n:Nat} -> Num (Fixed n) where\n (MkFixed x) + (MkFixed y) = MkFixed $ x + y\n (MkFixed x) * (MkFixed y) = let\n MkResV _ res _ = expToResolution n in MkFixed $ (x * y) `div` res\n fromInteger i = let\n MkResV _ res _ = expToResolution n in MkFixed $ i * res\n\npublic export\n{n:Nat} -> Neg (Fixed n) where\n negate (MkFixed x) = MkFixed $ negate x\n (MkFixed x) - (MkFixed y) = MkFixed $ x - y\n\npublic export\n{n:Nat} -> Abs (Fixed n) where abs (MkFixed x) = MkFixed $ abs x\n\npartial public export\n{n:Nat} -> Fractional (Fixed n) where\n (MkFixed x) / (MkFixed y) = let\n MkResV _ res _ = expToResolution n in MkFixed $ (x * res) `div` y\n recip (MkFixed x) = let\n MkResV _ res _ = expToResolution n in MkFixed $ (res * res) `div` x\n\n\npublic export\n{n:Nat} -> Show (Fixed n) where\n show (MkFixed x) = if n == 0 then show x\n else if x < 0 then \"-\" ++ go (negate x)\n else go x where\n go : Integer -> String\n go x = let MkResV _ r _ = expToResolution n\n i = x `div` r\n d' = show $ x `mod` r\n in show i ++ \".\" ++ replicate (fromInteger $ cast $ cast n - strLength d') '0' ++ d'\n\n-- --------------------------------------------------------------------------\n-- Type cast\n\n\npublic export\n{n:Nat} -> Cast Int (Fixed n) where\n cast i = let MkResV _ res _ = expToResolution n in MkFixed $ (cast i) * res\npublic export\n{n:Nat} -> Cast Integer (Fixed n) where\n cast i = let MkResV _ res _ = expToResolution n in MkFixed $ i * res\npublic export\n{n:Nat} -> Cast Rational (Maybe (Fixed n)) where\n cast x = let d = x.den\n MkResV _ res _ = expToResolution n\n in toMaybe (d == 0) $ MkFixed $ x.num * res `div` (natToInteger d)\npublic export\n{n:Nat} -> Cast (Fixed n) Rational where\n cast (MkFixed x) = let\n MkResV _ res _ = expToResolution n in x %: res\n\n-- --------------------------------------------------------------------------\n\npublic export resolution : {n:Nat} -> Fixed n -> Integer\nresolution {n=n} _ = let MkResV _ res _ = expToResolution n in res\n\n\nexport div' : {n:Nat} -> Fixed n -> Fixed n -> Integer\ndiv' {n=n} (MkFixed x) (MkFixed q) = x `div` q\n\nexport mod' : {n:Nat} -> Fixed n -> Fixed n -> Fixed n\nmod' {n=n} (MkFixed x) (MkFixed q) = MkFixed $ x `mod` q\n\nexport scale : {n:Nat} -> Integer -> Fixed n -> Fixed n\nscale {n=n} y (MkFixed x) = MkFixed $ x * y\n\n-- --------------------------------------------------------------------------\n-- vim: tw=80 sw=2 expandtab :", "meta": {"hexsha": "8eda50735b6e675205e704f9c6fe51cf1612bfc4", "size": 3573, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2-missing-numeric/src/Data/Fixed.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/Fixed.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/Fixed.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": 31.3421052632, "max_line_length": 96, "alphanum_fraction": 0.5477190036, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6283476739521265}} {"text": "> module SequentialDecisionProblems.TabBackwardsInduction1\n\n> import Data.Vect\n> import Control.Isomorphism\n> -- import Debug.Trace\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.Utils\n\n> import Nat.Operations\n> import Nat.OperationsProperties\n> import Nat.LTEProperties\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Decidable.Properties\n> import Sigma.Sigma\n> import Sigma.Operations\n> import Pairs.Operations\n> import Vect.Operations\n> import Vect.Properties\n> import Decidable.Predicates\n> import Fin.Operations\n\n> %default total\n> %access public export\n> -- %access export\n> %auto_implicits off\n\n\n* Tabulation\n\nIf the state space is finite\n\n> finiteState : (t : Nat) -> Finite (State t)\n\n, we can compute the number of values of type |State t| and collect them\nin a vector\n\n> cardState : (t : Nat) -> Nat\n> cardState t = card (finiteState t)\n\n> vectState : (t : Nat) -> Vect (cardState t) (State t)\n> vectState t = toVect (finiteState t)\n\nIf |Reachable| and |Viable n| are also decidable\n\n> decidableReachable : {t' : Nat} -> (x' : State t') -> Dec (Reachable x')\n\n< decidableViable : {t : Nat} -> (n : Nat) -> (x : State t) -> Dec (Viable n x)\n\nthen their conjunction\n\n> ReachableAndViable : {t : Nat} -> (n : Nat) -> (x : State t) -> Type\n> ReachableAndViable n x = (Reachable x , Viable n x)\n\nis decidable\n\n> decidableReachableAndViable : {t : Nat} -> (n : Nat) -> (x : State t) -> Dec (ReachableAndViable n x)\n> decidableReachableAndViable n x = decPair (decidableReachable x) (decidableViable n x)\n\nand we can collect all states which are reachable and viable in a vector:\n\n> cardReachableAndViableState : (t : Nat) -> (n : Nat) -> Nat\n> cardReachableAndViableState t n = outl (f t n) where\n> f : (t : Nat) -> (n : Nat) -> Sigma Nat (\\ m => Vect m (Sigma (State t) (ReachableAndViable n)))\n> f t n = filterTagSigma (decidableReachableAndViable n) (vectState t)\n\n> vectReachableAndViableState : (t : Nat) -> (n : Nat) -> \n> Vect (cardReachableAndViableState t n) (Sigma (State t) (ReachableAndViable n))\n> vectReachableAndViableState t n = outr (f t n) where\n> f : (t : Nat) -> (n : Nat) -> Sigma Nat (\\ m => Vect m (Sigma (State t) (ReachableAndViable n)))\n> f t n = filterTagSigma (decidableReachableAndViable n) (vectState t)\n\nIn this case, we can implement a \"tabulated\" versions of |bi| which is\nlinear in the number of decidion steps. Remember that |optExt| takes a\npolicy sequence for |n| steps and computes a policy sequence for |n + 1|\nsteps:\n\n< optExt : {t, n : Nat} -> \n< (ps : PolicySeq (S t) n) -> Policy t (S n)\n\nThe idea is to replace the |ps| argument of |optExt| with a \"value\ntable\" |vt : Vect (cardReachableAndViableState t n) Val| storing the\nvalue, for every state in |vectReachableAndViableState (S t) n|, of\ntaking |n| decision steps with |ps| starting from that state. Also ...\n\n\n> |||\n> PolicyTable : (t : Nat) -> (n : Nat) -> Type\n> PolicyTable t Z = Unit\n> PolicyTable t (S m) = Vect \n> (cardReachableAndViableState t (S m)) \n> (Sigma (State t) (\\x => (ReachableAndViable (S m) x, GoodCtrl t x m)))\n\n> |||\n> data PolicyTableSeq : (t : Nat) -> (n : Nat) -> Type where\n> Nil : {t : Nat} -> \n> PolicyTableSeq t Z\n> (::) : {t, n : Nat} -> \n> PolicyTable t (S n) -> PolicyTableSeq (S t) n -> PolicyTableSeq t (S n)\n\n> ||| \n> ValueTable : Nat -> Nat -> Type\n> ValueTable t n = Vect (cardReachableAndViableState t n) Val\n\n> |||\n> tabOptExt : {t, n : Nat} -> \n> (vt : ValueTable (S t) n) -> \n> -- (vt : Vect (cardReachableAndViableState (S t) n) Val) -> \n> PolicyTable t (S n)\n\nWe implement |tabOptExt| on the basis of the implementation of |optExt|\nof the core theory. We start with a tabulated version of |sval|:\n\n> tabSval : {t,n : Nat} -> \n> (x : State t) -> .(r : Reachable x) -> .(v : Viable (S n) x) ->\n> (gy : GoodCtrl t x n) -> \n> (vt : Vect (cardReachableAndViableState (S t) n) Val) ->\n> PossibleNextState x (ctrl gy) -> Val\n> tabSval {t} {n} x r v gy vt (MkSigma x' x'emx') =\n> let y : Ctrl t x\n> = ctrl gy in\n> let mx' : M (State (S t))\n> = nexts t x y in\n> let ar' : All Reachable mx'\n> = reachableSpec1 x r y in\n> let av' : All (Viable n) mx'\n> = allViable gy in\n> let r' : Reachable x'\n> = allElemSpec0 x' mx' ar' x'emx' in\n> let v' : Viable n x'\n> = allElemSpec0 x' mx' av' x'emx' in\n> let rvxs : Vect (cardReachableAndViableState (S t) n) (State (S t))\n> = map outl (vectReachableAndViableState (S t) n) in\n> let dRV : ((x' : State (S t)) -> Dec (ReachableAndViable n x'))\n> = decidableReachableAndViable n in\n> let prf : Elem x' (vectState (S t))\n> = toVectComplete (finiteState (S t)) x' in\n> let prf' : Elem x' rvxs\n> = filterTagSigmaLemma {P = ReachableAndViable n} dRV x' (vectState (S t)) prf (r',v') in\n> let k : Fin (cardReachableAndViableState (S t) n)\n> -- = trace (\"Lookup \" ++ show n) (lookup x' rvxs prf') in\n> = lookup x' rvxs prf' in\n> reward t x y x' `plus` index k vt\n\nNext, we implement a tabulated version of |cval|:\n\n> tabCval : {t, n : Nat} -> \n> (x : State t) -> .(r : Reachable x) -> .(v : Viable (S n) x) ->\n> (vt : Vect (cardReachableAndViableState (S t) n) Val) -> \n> GoodCtrl t x n -> Val\n> tabCval {t} x r v vt gy = let y : Ctrl t x\n> = ctrl gy in\n> let mx' : M (State (S t))\n> = nexts t x y in\n> meas (fmap (tabSval x r v gy vt) (tagElem mx'))\n\nAnd finally\n\n> tabCvalargmax : {t, n : Nat} -> \n> (x : State t) -> .(r : Reachable x) -> .(v : Viable (S n) x) ->\n> (vt : Vect (cardReachableAndViableState (S t) n) Val) -> GoodCtrl t x n\n\n> {-\n> tabOptExt {t} {n} vt = pt where\n> pt : PolicyTable t (S n)\n> pt = toVect ptf where\n> ptf : Fin (cardReachableAndViableState t (S n)) -> (Sigma (State t) (\\x => (ReachableAndViable (S n) x, GoodCtrl t x n)))\n> ptf k = MkSigma x (rv, gy) where\n> xrv : Sigma (State t) (ReachableAndViable (S n))\n> xrv = index k (vectReachableAndViableState t (S n))\n> x : State t\n> x = outl xrv\n> rv : ReachableAndViable (S n) x\n> rv = outr xrv\n> gy : GoodCtrl t x n\n> gy = tabCvalargmax x (fst rv) (snd rv) vt\n> -}\n> tabOptExt {t} {n} vt = \n> let xrv -- : ((k : Fin (cardReachableAndViableState t (S n))) -> Sigma (State t) (ReachableAndViable (S n)))\n> = \\ k => index k (vectReachableAndViableState t (S n)) in\n> let x : ((k : Fin (cardReachableAndViableState t (S n))) -> State t)\n> = \\ k => outl (xrv k) in\n> let rv -- : ((k : Fin (cardReachableAndViableState t (S n))) -> ReachableAndViable (S n) (x k))\n> = \\ k => outr (xrv k) in\n> let gy -- : ((k : Fin (cardReachableAndViableState t (S n))) -> GoodCtrl t (x k) n)\n> = \\ k => tabCvalargmax (x k) (fst (rv k)) (snd (rv k)) vt in\n> let ptf -- : ((k : Fin (cardReachableAndViableState t (S n))) -> (Sigma (State t) (\\ x => (ReachableAndViable (S n) x, GoodCtrl t x n))))\n> = \\ k => MkSigma (x k) (rv k, gy k) in\n> let pt : PolicyTable t (S n)\n> = toVect ptf in\n> pt \n\n* Tabulated tail-recursive backwards induction\n\nWith |tabOptExt| in place, it is easy to implement a tabulated version of\n|trbi|:\n\n> |||\n> PolicySeqAndTab : Nat -> Nat -> Type\n> PolicySeqAndTab t n = (PolicySeq t n, ValueTable t n)\n\n> |||\n> zeroVec : (n : Nat) -> Vect n Val\n> zeroVec Z = Nil\n> zeroVec (S n) = zero :: zeroVec n\n\n> ||| Tabulated tail-recursive backwards induction iteration\n> ttrbii : (t : Nat) -> (n : Nat) -> (c : Nat) -> (LTE c n) ->\n> PolicyTableSeq (c + t) (n - c) ->\n> (vt : Vect (cardReachableAndViableState (c + t) (n - c)) Val) ->\n> PolicyTableSeq t n\n> \n> ttrbii t n Z prf pts vt = replace {P = \\ z => PolicyTableSeq t z} (minusZeroRight n) pts\n> {-\n> ttrbii t n (S c') prf pts vt = ttrbii t n c' prf' pts' vt'' where\n> bic : S (n - S c') = n - c'\n> bic = minusLemma4 prf\n> prf' : LTE c' n\n> prf' = lteLemma1 c' n prf\n> pt : PolicyTable (c' + t) (S (n - S c'))\n> pt = tabOptExt vt\n> pts' : PolicyTableSeq (c' + t) (n - c')\n> pts' = replace {P = \\ z => PolicyTableSeq (c' + t) z} bic (pt :: pts)\n> vt' : Vect (cardReachableAndViableState (c' + t) (S (n - S c'))) Val\n> vt' = toVect vt'f where\n> vt'f : Fin (cardReachableAndViableState (c' + t) (S (n - S c'))) -> Val\n> vt'f k = tabCval x r v vt gy where\n> xrvgy : Sigma (State (c' + t)) (\\ x => (ReachableAndViable (S (n - S c')) x, GoodCtrl (c' + t) x (n - S c')))\n> xrvgy = index k pt\n> x : State (c' + t)\n> x = outl xrvgy\n> rv : ReachableAndViable (S (n - S c')) x\n> rv = fst (outr xrvgy)\n> r : Reachable x\n> r = fst rv\n> v : Viable (S (n - S c')) x\n> v = snd rv\n> gy : GoodCtrl (c' + t) x (n - S c')\n> gy = snd (outr xrvgy)\n> vt'' : Vect (cardReachableAndViableState (c' + t) (n - c')) Val\n> vt'' = replace {P = \\z => Vect (cardReachableAndViableState (c' + t) z) Val} bic vt'\n> -}\n> ttrbii t n (S c') prf pts vt = \n> let bic : (S (n - S c') = n - c')\n> = minusLemma4 prf in\n> let prf' : LTE c' n\n> = lteLemma1 c' n prf in\n> let pt : PolicyTable (c' + t) (S (n - S c'))\n> = tabOptExt vt in\n> let pts' : PolicyTableSeq (c' + t) (n - c')\n> = replace {P = \\ z => PolicyTableSeq (c' + t) z} bic (pt :: pts) in\n> let xrvgy -- : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> \n> -- Sigma (State (c' + t)) (\\ x => (ReachableAndViable (S (n - S c')) x, GoodCtrl (c' + t) x (n - S c'))))\n> = \\ k => index k pt in\n> let x : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> State (c' + t))\n> = \\ k => outl (xrvgy k) in\n> let rv -- : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> ReachableAndViable (S (n - S c')) (x k))\n> = \\ k => fst (outr (xrvgy k)) in\n> let r : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> Reachable {t' = c' + t} (x k))\n> = \\ k => fst (rv k) in\n> let v : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> Viable {t = c' + t} (S (n - S c')) (x k))\n> = \\ k => snd (rv k) in\n> let gy : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> GoodCtrl (c' + t) (x k) (n - S c'))\n> = \\ k => snd (outr (xrvgy k)) in \n> let vt'f : ((k : Fin (cardReachableAndViableState (c' + t) (S (n - S c')))) -> Val)\n> = \\ k => tabCval (x k) (r k) (v k) vt (gy k) in\n> let vt' : Vect (cardReachableAndViableState (c' + t) (S (n - S c'))) Val\n> = toVect vt'f in\n> let vt'' : Vect (cardReachableAndViableState (c' + t) (n - c')) Val\n> = replace {P = \\z => Vect (cardReachableAndViableState (c' + t) z) Val} bic vt' in\n> ttrbii t n c' prf' pts' vt'' \n\n> ||| Tabulated tail-recursive backwards induction\n> tabTailRecursiveBackwardsInduction1 : (t : Nat) -> (n : Nat) -> PolicyTableSeq t n\n> tabTailRecursiveBackwardsInduction1 t n = ttrbii t n n (reflexiveLTE n) zps (zeroVec _) where\n> zps : PolicyTableSeq (n + t) (n - n)\n> zps = replace {P = \\ z => PolicyTableSeq (n + t) z} (minusZeroN n) Nil\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "43cffdb68bec360cc631b4dc5428034d3a79006b", "size": 11708, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/TabBackwardsInduction1.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/TabBackwardsInduction1.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/TabBackwardsInduction1.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": 41.2253521127, "max_line_length": 141, "alphanum_fraction": 0.5521011274, "num_tokens": 4166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6282941327496583}} {"text": "\nmodule EDSL\n\n--import TypeTrans.AST\nimport TypeTrans.Transformations\nimport TypeTrans.Array\nimport Control.Monad.State\n\nimport Data.Vect\n\ndata TypeT = TyInt | TyBool | TyFun TypeT TypeT | TyVect Nat TypeT\n\n-- Difference between stream and seq?\ndata MapVariant = MSeq | MPar | MStream\ndata FoldVariant = FSeq | FStream | FTree\n\ntotal\ninterpType : TypeT -> Type\ninterpType TyInt = Int\ninterpType TyBool = Bool\ninterpType (TyFun i o) = interpType i -> interpType o\ninterpType (TyVect i t) = Vect i (interpType t)\n\n\n\n-- Locate \"base\"/primitive type e.g. int, bool\n--total \n--baseType : TypeT -> TypeT\n--baseType (TyFun i o) = \n--baseType TyVect Nat \n\n\nusing (G : Vect xs TypeT) {\n\ndata HasType : Fin n -> Vect n TypeT -> TypeT -> Type where\n Stop : HasType FZ (t :: G) t\n Pop : HasType k G t -> HasType (FS k) (u :: G) t \n\n\ndata Expr : (Vect xs TypeT) -> TypeT -> Type where\n Var : HasType i G t -> Expr G t\n Val : (x : Int) -> Expr G TyInt \n Map : MapVariant -> Expr G (TyFun a b) -> Expr G (TyVect n a) -> Expr G (TyVect n b)\n\n -- Treat Composition as Concatonation of multiple Applys in a row\n -- Apply f (Apply g o) is a composition of f and g, can be used for\n -- map streaming optimisation\n Apply : Expr G (TyFun a b) -> Expr G a -> Expr G b\n --Let : Expr (a :: gam) (Val () :: gam’) (R t) -> Expr gam gam’ t\n \n FoldL : FoldVariant -> Expr G (TyFun a (TyFun b a)) -> \n Expr G a -> Expr G (TyVect n b) -> Expr G a\n FoldR : FoldVariant -> Expr G (TyFun a (TyFun b b)) -> \n Expr G b -> Expr G (TyVect n a) -> Expr G b\n \n -- For Assoc Fold, the function needs to be closed e.g. (a -> a -> a), possibly \n -- ensure given type is a monoid and use the respective monoid function for that type,\n -- using implicit type class instances we can select which monoid we wish to use\n -- e.g. the natural numbers can create a monoid instance for both addition and multiplication \n --FoldAssoc : (Monoid (interpType a)) => FoldVariant -> Expr G a -> Expr G (TyVect n a) -> Expr G a\n\n Lambda : Expr (a :: G) t -> Expr G (TyFun a t)\n --Compose : Expr G (TyFun a -> Expr (head a\n\n Split : (m: Nat) -> Expr G (TyVect n t) -> \n {default SIsNotZ nz : Not (m = Z)} ->\n {auto mz : modNatNZ n m nz = Z} -> \n Expr G (TyVect m (TyVect (divNatNZ n m nz) t))\n\n Merge : Expr G (TyVect x1 (TyVect x2 t)) -> Expr G (TyVect (x1 * x2) t)\n Op : (interpType a -> interpType b -> interpType c) -> Expr G a -> Expr G b -> Expr G c\n UnOp : (interpType a -> interpType b) -> Expr G a -> Expr G b\n\n\n-- Idris Interpreter which executes the AST\n\n-- When we produce an expression we need to know which variables are in scope,\n-- as well as their types. Env is an environment indexed over the types in scope.\ndata Env : Vect n TypeT -> Type where\n Nil : Env Nil\n (::) : interpType a -> Env G -> Env (a :: G)\n\n\nlookup : HasType i G t -> Env G -> interpType t\nlookup Stop (x :: xs) = x\nlookup (Pop k) (x :: xs) = lookup k xs\n\ninterp : Env G -> Expr G t -> interpType t\ninterp env (Var i) = lookup i env\ninterp env (Val x) = x\ninterp env (Apply f s) = (interp env f) (interp env s)\ninterp env (Lambda body) = \\x => interp (x :: env) body\ninterp env (Map vt f xs) = \n case (interp env xs) of\n [] => Nil\n (y::ys) => (interp env (Apply f (UnOp head xs))) :: (interp env (Map vt f (UnOp tail xs))) \n\n\ninterp env (FoldL vt f x xs) = \n case (interp env xs) of\n [] => interp env x \n (y::ys) => interp env $ FoldL vt f (Apply (Apply f x) $ UnOp head xs) $ UnOp tail xs \n\ninterp env (FoldR vt f x xs) =\n case (interp env xs) of\n [] => interp env x\n (y::ys) => interp env $ Apply (Apply f $ UnOp head xs) (FoldR vt f x $ UnOp tail xs) \n \n\n--interp env (FoldAssoc vt f x xs) = interp env (FoldL vt f x xs)\n\ninterp env (Op op x y) = op (interp env x) (interp env y)\ninterp env (UnOp op x) = op (interp env x) \n--interp env (Merge xs) = merge $ interp env xs \n--interp env (Split m xs {nz} {mz}) = splitV m {nz} {mz} $ interp env xs\n\n\n-- Generate All Different Combinations\ngenerate : Env G -> Expr G t -> Expr G t\ngenerate env (Var i) = (Var i)\ngenerate env (Val x) = (Val x)\ngenerate env (Apply f s) = Apply (convertS env f) (convertS env s)\ngenerate env (Lambda body) = Lambda (convertS body)\ngenerate env (Map vt f xs) = ?todo45 \n-- case (interp env xs) of\n-- [] => Nil\n-- (y::ys) => (interp env (Apply f (UnOp head xs))) :: (interp env (Map vt f (UnOp tail xs))) \ngenerate env (FoldL vt f x xs) = ?todo57\n-- case (interp env xs) of\n-- [] => interp env x \n-- (y::ys) => interp env $ FoldL vt f (Apply (Apply f x) $ UnOp head xs) $ UnOp tail xs \n\ngenerate env (FoldR vt f x xs) = ?todo56\n-- case (interp env xs) of\n-- [] => interp env x\n-- (y::ys) => interp env $ Apply (Apply f $ UnOp head xs) (FoldR vt f x $ UnOp tail xs) \n \n\n--interp env (FoldAssoc vt f x xs) = interp env (FoldL vt f x xs)\n\ninterp env (Op op x y) = Op op (generate env x) (generate env y)\ninterp env (UnOp op x) = UnOp op (generate env x) \n\n\nmkLam : TTName -> Expr (t::g) t' -> Expr g (TyFun t t')\nmkLam _ body = Lambda body\n\n-- Specify structures for DSL\ndsl expr\n lambda = mkLam\n variable = Var\n index_first = Stop\n index_next = Pop\n variable = Var\n\n\npure : Expr G a -> Expr G a\npure = id\n\n(<$>) : (f : Lazy (Expr G (TyFun a t))) -> Expr G a -> Expr G t\n(<$>) f a = Apply f a\n\n-- Examples:\nsyntax \"map\" [f] [xs] = Map MSeq f xs\nsyntax [x] \"+\" [y] = Op (+) x (Val y)\n\n\n-- AST for lambda function which adds 3 to a given integer\nadd3 : Expr G (TyFun TyInt TyInt)\nadd3 = Lambda (Op (+) (Var Stop) (Val 3))\n\nadd3Pretty : Expr G (TyFun TyInt TyInt)\nadd3Pretty = expr (\\x => Op (+) (Val 3) x)\n\nadd3Pretty2 : Expr G (TyFun TyInt TyInt)\nadd3Pretty2 = expr (\\x => x + 3)\n\n-- AST for lambda function which adds 2 integers\nadd : Expr G (TyFun TyInt (TyFun TyInt TyInt))\nadd = Lambda (Lambda (Op (+) (Var Stop) (Var (Pop Stop))))\n\naddPretty : Expr G (TyFun TyInt (TyFun TyInt TyInt))\naddPretty = expr (\\x,y => (Op (+) x y))\n\n-- AST for simple mapping over list\nmapAdd3 : Expr G (TyFun (TyVect n TyInt) (TyVect n TyInt))\nmapAdd3 = Lambda (Map MSeq (add3) (Var Stop)) \n\nmapAdd3Pretty : Expr G (TyFun (TyVect n TyInt) (TyVect n TyInt))\nmapAdd3Pretty = expr (\\xs => map add3 xs) \n\n\n-- AST for simple merge and mapping\nmap2dAdd3 : Expr G (TyFun (TyVect m (TyVect n TyInt)) (TyVect (m * n) TyInt)) \nmap2dAdd3 = Lambda (Apply (mapAdd3) (Merge (Var Stop))) \n\ntestAdd : Int -> Expr G (TyFun TyInt TyInt)\ntestAdd i = Lambda (Op (+) (Var Stop) (Val i))\n\ntestAdd' : {n : Nat} -> Vect n t -> Expr G (TyFun TyInt TyInt)\ntestAdd' v {n} = Lambda (Op (+) (Var Stop) (Val $ fromNat n))\n\n--splitEx : Expr G (TyFun (TyVect (m * n) TyInt) (TyVect m (TyVect n TyInt)))\n--splitEx {m = Z} = ?todo45 --Lambda (Var Stop)\n--splitEx {m = S k} {n} = rewrite (modMProof m n) in (Lambda (Split m (Var Stop)))\n\n--AST for merge, map, then split again\n--mapAddSplit : Expr G (TyFun (TyVect m (TyVect n TyInt)) (TyVect m (TyVect n TyInt))) \n--mapAddSplit {m = Z} = Lambda (Var Stop)\n--mapAddSplit {m = S k} = Lambda (Split m $ Apply (mapAdd3) (Merge (Var Stop)))\n\n{-\nprint2dV : Vect m (Vect n Int) -> IO ()\nprint2dV xs = \n do print \"[\" \n print2dV' xs\n\n where print2dV' : Vect m (Vect n Int) -> IO ()\n print2dV' [] = print \"]\"\n print2dV' (x::[]) = do print x \n print \"]\"\n\n print2dV' (x::xs) = do print x \n print \", \"\n print2dV' xs \n\n-}\n\ninterpStuff : IO ()\ninterpStuff = do \n print $ interp [] mapAdd3 [1,2,3,4]\n print v2d\n\n print v3\n\n\n where v2d : Vect 3 Int\n v2d = interp [] map2dAdd3 [[1,1,1]]\n\n v3 : Int\n v3 = interp [] add3 3\n}\n\n\n\n\n\n", "meta": {"hexsha": "1ec0a2a320217f2e3a50c753aff5c14d80fcc484", "size": 7815, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/TypeTrans/EDSL.idr", "max_stars_repo_name": "RossMeikleham/MSci-Project", "max_stars_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-20T11:17:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-20T11:17:45.000Z", "max_issues_repo_path": "src/TypeTrans/EDSL.idr", "max_issues_repo_name": "RossMeikleham/MSci-Project", "max_issues_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/TypeTrans/EDSL.idr", "max_forks_repo_name": "RossMeikleham/MSci-Project", "max_forks_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5120967742, "max_line_length": 119, "alphanum_fraction": 0.5973128599, "num_tokens": 2558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.627643991743161}} {"text": "module Naturality\n\nimport public TypesAndFunctions\nimport public Category\nimport public Isomorphism\n\n%default total\n\npublic export\nNaturality : {cat : Category} -> {a, b, x, y : Object cat} ->\n (f : Morphism cat a b) -> (g : Morphism cat y x) ->\n (preCompose {cat} {a=y} {b=x} {c=b} g) .\n (postCompose {cat} {a=x} {b=a} {c=b} f) =\n (postCompose {cat} {a=y} {b=a} {c=b} f) .\n (preCompose {cat} {a=y} {b=x} {c=a} g)\nNaturality f g =\n functionalExtensionality (\\h : Morphism cat x a => Associativity cat f h g)\n\npublic export\nSubjectChange : {cat : Category} -> (subjectA, subjectB : Object cat) -> Type\nSubjectChange {cat} subjectA subjectB =\n (observer : Object cat) ->\n Morphism cat observer subjectA -> Morphism cat observer subjectB\n\npublic export\nObserverChange : {cat : Category} -> (observerA, observerB : Object cat) -> Type\nObserverChange {cat} observerA observerB =\n (subject : Object cat) ->\n Morphism cat observerA subject -> Morphism cat observerB subject\n\npublic export\nInvertibleSubjectChange : {cat : Category} ->\n (subjectA, subjectB : Object cat) -> Type\nInvertibleSubjectChange subjectA subjectB =\n DPair (SubjectChange subjectA subjectB) IsBijectionForEach\n\npublic export\nInvertibleObserverChange : {cat : Category} ->\n (observerA, observerB : Object cat) -> Type\nInvertibleObserverChange observerA observerB =\n DPair (ObserverChange observerA observerB) IsBijectionForEach\n\npublic export\nSubjectChangeIsNatural : {cat : Category} ->\n {subjectA, subjectB : Object cat} ->\n SubjectChange {cat} subjectA subjectB -> Type\nSubjectChangeIsNatural {cat} alpha =\n (x, y : Object cat) -> (g : Morphism cat y x) ->\n alpha y . preCompose g = preCompose g . alpha x\n\npublic export\nObserverChangeIsNatural : {cat : Category} ->\n {observerA, observerB : Object cat} ->\n ObserverChange {cat} observerA observerB -> Type\nObserverChangeIsNatural {cat} beta =\n (x, y : Object cat) -> (g : Morphism cat x y) ->\n postCompose g . beta x = beta y . postCompose g\n\npublic export\nSubjectChangeInducedMorphism : {cat : Category} ->\n {subjectA, subjectB : Object cat} ->\n (alpha : SubjectChange {cat} subjectA subjectB) ->\n Morphism cat subjectA subjectB\nSubjectChangeInducedMorphism {subjectA} {subjectB} alpha =\n alpha subjectA (catId subjectA)\n\npublic export\nSubjectChangeIsPostComposition : {cat : Category} ->\n {subjectA, subjectB : Object cat} ->\n (alpha : SubjectChange {cat} subjectA subjectB) ->\n (natural : SubjectChangeIsNatural {cat} {subjectA} {subjectB} alpha) ->\n (x : Object cat) -> alpha x =\n postCompose {cat} {a=x} {b=subjectA} {c=subjectB}\n (SubjectChangeInducedMorphism {cat} {subjectA} {subjectB} alpha)\nSubjectChangeIsPostComposition {subjectA} {subjectB} alpha natural x =\n functionalExtensionality (\\g =>\n replace\n {p=(\\g' =>\n alpha x g' = After cat (alpha subjectA (Identity cat subjectA)) g)}\n (LeftIdentity cat g)\n (appEq {x=(catId subjectA)} (natural _ _ g)))\n\npublic export\nObserverChangeInducedMorphism : {cat : Category} ->\n {observerA, observerB : Object cat} ->\n (beta : ObserverChange {cat} observerA observerB) ->\n Morphism cat observerB observerA\nObserverChangeInducedMorphism {observerA} {observerB} beta =\n beta observerA (catId observerA)\n\npublic export\nObserverChangeIsPreComposition : {cat : Category} ->\n {observerA, observerB : Object cat} ->\n (beta : ObserverChange {cat} observerA observerB) ->\n (natural : ObserverChangeIsNatural {cat} {observerA} {observerB} beta) ->\n (y : Object cat) -> beta y =\n preCompose {cat} {a=observerB} {b=observerA} {c=y}\n (ObserverChangeInducedMorphism {cat} {observerA} {observerB} beta)\nObserverChangeIsPreComposition {observerA} {observerB} beta natural y =\n functionalExtensionality (\\f =>\n replace\n {p=(\\f' =>\n beta y f' = After cat f (beta observerA (Identity cat observerA)))}\n (RightIdentity cat f)\n (sym (appEq {x=(catId observerA)} (natural _ _ f))))\n\npublic export\nNaturalBijectiveSubjectChangeInducesIsomorphism :\n {cat : Category} ->\n {subjectA, subjectB : Object cat} ->\n (alpha : SubjectChange {cat} subjectA subjectB) ->\n (natural : SubjectChangeIsNatural {cat} {subjectA} {subjectB} alpha) ->\n (bijective : IsBijectionForEach alpha) ->\n IsIsomorphism {cat} {a=subjectA} {b=subjectB}\n (SubjectChangeInducedMorphism {cat} {subjectA} {subjectB} alpha)\nNaturalBijectiveSubjectChangeInducesIsomorphism\n {subjectA} {subjectB} alpha natural bijective =\n let\n bRight = snd (ForEachInverseIsInverse bijective subjectB) (catId subjectB)\n in\n ((fst (bijective subjectB) (Identity cat subjectB)) **\n (HasLeftInverseImpliesInjective\n {f=(alpha subjectA)} {g=(fst (bijective subjectA))}\n {x=(After cat\n (fst (bijective subjectB) (Identity cat subjectB))\n (alpha subjectA (Identity cat subjectA)))}\n {x'=(catId subjectA)}\n (fst (ForEachInverseIsInverse bijective subjectA))\n (trans\n (replace\n {p=\n (\\g' =>\n alpha subjectA\n (After cat\n (fst (bijective subjectB) (Identity cat subjectB))\n (alpha subjectA (Identity cat subjectA))) =\n After cat g' (alpha subjectA (Identity cat subjectA)))}\n bRight\n (appEq\n {x=(fst (bijective subjectB) (Identity cat subjectB))}\n (natural _ _ (alpha _ (catId subjectA)))))\n (LeftIdentity cat (alpha subjectA (Identity cat subjectA)))),\n (trans\n (replace\n {p=\n (\\g' =>\n After cat\n (alpha subjectA (Identity cat subjectA))\n (fst (bijective subjectB) (Identity cat subjectB)) =\n alpha subjectB g')}\n (LeftIdentity cat (fst (bijective subjectB) (Identity cat subjectB)))\n (sym\n (appEq {x=(catId subjectA)}\n (natural _ _ (fst (bijective subjectB) (catId subjectB))))))\n bRight)))\n\npublic export\nNaturalBijectiveObserverChangeInducesIsomorphism :\n {cat : Category} ->\n {observerA, observerB : Object cat} ->\n (beta : ObserverChange {cat} observerA observerB) ->\n (natural : ObserverChangeIsNatural {cat} {observerA} {observerB} beta) ->\n (bijective : IsBijectionForEach beta) ->\n IsIsomorphism {cat} {a=observerB} {b=observerA}\n (ObserverChangeInducedMorphism {cat} {observerA} {observerB} beta)\nNaturalBijectiveObserverChangeInducesIsomorphism\n {observerA} {observerB} beta natural bijective =\n let\n bRight =\n snd (ForEachInverseIsInverse bijective observerB) (catId observerB)\n in\n (fst (bijective observerB) (catId observerB) **\n (trans\n (replace\n {p=\n (\\g' =>\n After cat\n (fst (bijective observerB) (Identity cat observerB))\n (beta observerA (Identity cat observerA)) =\n beta observerB g'\n )}\n (RightIdentity cat\n (fst (bijective observerB) (Identity cat observerB)))\n (appEq {x=(catId observerA)}\n (natural _ _ (fst (bijective observerB) (catId observerB))))\n ) bRight,\n HasLeftInverseImpliesInjective\n {f=(beta observerA)} {g=(fst (bijective observerA))}\n (fst (ForEachInverseIsInverse bijective observerA))\n (trans (sym (\n replace\n {p=(\\g' =>\n After cat (beta observerA (Identity cat observerA)) g' =\n beta observerA (After cat\n (beta observerA (Identity cat observerA))\n (fst (bijective observerB) (Identity cat observerB))))}\n bRight\n (appEq {x=(fst (bijective observerB) (catId observerB))}\n (natural _ _ (beta _ (catId observerA))))\n )) (RightIdentity cat _))))\n", "meta": {"hexsha": "515aa194bb1f67fdd0cd31abab1c18fec195bf88", "size": 7870, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Naturality.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/Naturality.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/Naturality.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": 39.1542288557, "max_line_length": 80, "alphanum_fraction": 0.6434561626, "num_tokens": 2108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6275767098797708}} {"text": "data 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\nlabelWith : InfList Integer -> List a -> List (Integer, a)\nlabelWith (lbl :: lbls) [] = []\nlabelWith (lbl :: lbls) (val :: vals) = (lbl, val) :: labelWith lbls vals\n\nlabel : List a -> List (Integer, a)\nlabel = labelWith (countFrom 0)\n", "meta": {"hexsha": "409cc845abee595c7e45879538482ef07a0cdc7b", "size": 571, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter11/InfList.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": "Chapter11/InfList.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": "Chapter11/InfList.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": 30.0526315789, "max_line_length": 73, "alphanum_fraction": 0.6252189142, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6271786544996115}} {"text": "import Data.List.Views\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 = if x == y\n then palindrome ys | rec\n else False\n", "meta": {"hexsha": "593f19f11bb97e4b3cf642289ab6835598e35ec5", "size": 261, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/palindrome.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/palindrome.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/palindrome.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": 23.7272727273, "max_line_length": 45, "alphanum_fraction": 0.5938697318, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6271752298732556}} {"text": "module LittleLang\n-- Warning: only briefly tested, may have bugs\n\n-- a Type, Naturals, Booleans and iterated function types built from these\npublic export\ndata Ty : Type where\n NT : Ty\n BT : Ty\n FT : Ty -> Ty -> Ty\n\n-- An expression with type\npublic export\ndata Exp : Ty -> Type where\n N : Nat -> Exp NT -- a literal natural number\n B : Bool -> Exp BT -- a literal boolean\n LTE : Exp NT -> Exp NT -> Exp BT\n EQ : Exp NT -> Exp NT -> Exp BT\n If : {a: Ty} -> Exp BT -> Exp a -> Exp a -> Exp a -- if expression\n Var : (name: String) -> (type: Ty) -> Exp type -- a variable\n Lam : {domain: Ty} -> -- a lambda expression defining a function\n {codomain: Ty} -> (var : Exp domain) ->\n (value : Exp codomain) -> Exp (FT domain codomain)\n App : (a: Ty) -> (b: Ty) -> -- function application\n (f : Exp (FT a b)) -> (arg: Exp a) -> Exp b\n Sum : Exp NT -> Exp NT -> Exp NT\n Prod: Exp NT -> Exp NT -> Exp NT\n Pred: Exp NT -> Exp NT -- predecessor of a natural number\n\n-- An example\nnot: Exp (FT BT BT)\nnot = Lam (Var \"x\" BT) (If (Var \"x\" BT) (B False) (B True))\n\n-- If `a == b` returns an expression of type `a` as one of type `b`\nmapTyp : (a : Ty) -> (b: Ty) -> Exp a -> Maybe (Exp b)\nmapTyp NT NT x = Just x\nmapTyp NT BT x = Nothing\nmapTyp NT (FT y z) x = Nothing\nmapTyp BT NT x = Nothing\nmapTyp BT BT x = Just x\nmapTyp BT (FT y z) x = Nothing\nmapTyp (FT y z) NT x = Nothing\nmapTyp (FT y z) BT x = Nothing\nmapTyp (FT y z) (FT w s) (If x t u) =\n case (mapTyp (FT y z) (FT w s) t) of\n Nothing => Nothing\n (Just q) => (case (mapTyp (FT y z) (FT w s) u) of\n Nothing => Nothing\n (Just p) => Just (If x q p))\nmapTyp (FT y z) (FT w s) (Var name (FT y z)) =\n if (isJust (mapTyp y w (Var name y))) && (isJust (mapTyp z s (Var name z)))\n then Just(Var name (FT w s)) else Nothing\nmapTyp (FT y z) (FT w s) (Lam var value) =\n case (mapTyp y w var) of\n Nothing => Nothing\n (Just x) => (case (mapTyp z s value) of\n Nothing => Nothing\n (Just p) => Just (Lam x p))\nmapTyp (FT y z) (FT w s) (App a (FT y z) f arg) =\n (case mapTyp (FT a (FT y z)) (FT a (FT w s)) f of\n Nothing => Nothing\n (Just g) =>\n Just(App a (FT w s) g arg)\n )\n\n-- equality of types\nexport\neqTyp : Ty -> Ty -> Bool\neqTyp x y = isJust (mapTyp x y (Var \"test\" x))\n\n-- substitute `x` by `y` in `base`\nsubs: (a: Ty) -> (b: Ty) -> (base: Exp a) -> (x: Exp b) -> (y: Exp b) -> Exp a\nsubs NT b (N k) x y = N k\nsubs BT b (B z) x y = B z\nsubs BT b (LTE z w) x y = LTE (subs NT b z x y) (subs NT b w x y)\nsubs BT b (EQ z w) x y = EQ (subs NT b z x y) (subs NT b w x y)\nsubs a b (If z w s) x y =\n If (subs _ _ z x y) (subs _ _ w x y) (subs _ _ s x y)\nsubs a b (Var name a) (Var other b) y =\n if name == other\n then (case mapTyp b a y of\n Nothing => Var name a\n (Just x) => x)\n else Var name a\nsubs a b (Var name a) x y = Var name a\nsubs (FT domain codomain) b (Lam var value) x y =\n Lam (subs domain b var x y) (subs codomain b value x y)\nsubs a b (App c a f arg) x y =\n App c a (subs _ _ f x y) (subs c b arg x y)\nsubs NT b (Sum z w) x y = Sum (subs NT b z x y) (subs NT b w x y)\nsubs NT b (Pred z) x y = Pred (subs NT b z x y)\nsubs NT b (Prod z w) x y = Prod (subs NT b z x y) (subs NT b w x y)\n\n-- A list of definitions of variables\npublic export\ndata Context : Type where\n Empty: Context\n Cons : (name: String) -> (type: Ty) -> (value: Exp type) -> (tail: Context) -> Context\n\nvarValue: Context -> (name: String) -> (ty: Ty) -> Maybe (Exp ty)\nvarValue Empty name ty = Nothing\nvarValue (Cons x type value tail) name ty =\n if (x==name)\n then (case mapTyp type ty value of\n Nothing => Nothing\n (Just x) => Just x)\n else Nothing\n\n{-\nSimplify an expression in context by one step if possible. The simplifications are:\n * if an expression is a variable defined in the context, it is replaced by its value\n * sums, products and predecessors of _literals_ are simplifed, e.g. `Sum (N 2) (N 3)` becomes `N 5`\n * a lambda function `x :-> y` applied to `z` simplifies to the result of subtituting `x` by `z` in `y`.\n * for any other composite term, we simplify the components.\n-}\nexport\nsimplify : (ctx: Context) -> (a: Ty) -> (exp : Exp a) -> Exp a\nsimplify ctx NT (N k) = N k\nsimplify ctx BT (B x) = B x\nsimplify ctx BT (LTE (N x) (N y)) = B (x <= y)\nsimplify ctx BT (LTE x y) = LTE (simplify ctx NT x) (simplify ctx NT y)\nsimplify ctx BT (EQ (N x) (N y)) = B (x == y)\nsimplify ctx BT (EQ x y) = EQ (simplify ctx NT x) (simplify ctx NT y)\nsimplify ctx a (If (B True) y z) = y\nsimplify ctx a (If (B False) y z) = z\nsimplify ctx a (If x y z) = If (simplify ctx _ x) (simplify ctx _ y) (simplify ctx _ z)\nsimplify ctx a (Var name a) =\n (case varValue ctx name a of\n Nothing => Var name a\n (Just x) => x)\nsimplify ctx (FT domain codomain) (Lam var value) = Lam var value\nsimplify ctx a (App x a (Lam var value) arg) = subs _ _ value var arg\nsimplify ctx a (App x a f arg) = App x a (simplify ctx _ f) (simplify ctx _ arg)\nsimplify ctx NT (Sum (N x) (N y)) = N (x + y)\nsimplify ctx NT (Sum x y) = Sum (simplify ctx NT x) (simplify ctx NT y)\nsimplify ctx NT (Pred (N x)) = N (pred x)\nsimplify ctx NT (Pred x) = Pred (simplify ctx NT x)\nsimplify ctx NT (Prod (N x) (N y)) = N (x * y)\nsimplify ctx NT (Prod x y) = Prod (simplify ctx NT x) (simplify ctx NT y)\n\n-- repeatedly simplify an expression giving a natural number till we get a literal (or loop forever)\nreduce : Context -> Exp NT -> Nat\nreduce ctx exp = case (simplify ctx NT exp) of\n (N k) => k\n x => reduce ctx x\n\n-- a variable\nn: Exp NT\nn = Var \"n\" NT\n\n-- a variable for the factorial function\nfac : Exp (FT NT NT)\nfac = Var \"fac\" (FT NT NT)\n\n-- the expression `fac(n - 1)`\nprev: Exp NT\nprev = Prod (App NT NT fac (Pred n)) n\n\n-- the expression `if n == 0 then 1 else fac(n-1)`\nrhs : Exp NT\nrhs = If (EQ n (N Z)) (N 1) prev\n\n{- the context with definition:\n fac := n :-> (if (n == 0) then 1 else fac(n - 1)\n-}\nctx: Context\nctx = Cons \"fac\" (FT NT NT) (Lam n rhs) Empty\n\n-- function computing factorial\nfacFn: Nat -> Nat\nfacFn n = reduce ctx (App NT NT fac (N n))\n", "meta": {"hexsha": "3e36c46a25d9e9ec3e8ddf394fe4e1763dafb43f", "size": 6239, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/LittleLang.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/LittleLang.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/LittleLang.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.485380117, "max_line_length": 105, "alphanum_fraction": 0.5891969867, "num_tokens": 2133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6270787159697845}} {"text": "module ProofColDivSeqBase\n-- module Main -- ビルドするときはこっち > idris ProofColDivSeqBase.idr -o run\n\n%default total\n-- %language ElabReflection\n%access export\n\n\n-- mod2\npublic export\ndata Parity : Nat -> Type where\n Even : Parity (n + n)\n Odd : Parity (S (n + n))\nhelpEven : (j : Nat) -> Parity (S j + S j) -> Parity (S (S (plus j j)))\nhelpEven j p = rewrite plusSuccRightSucc j j in p\nhelpOdd : (j : Nat) -> Parity (S (S (j + S j))) -> Parity (S (S (S (j + j))))\nhelpOdd j p = rewrite plusSuccRightSucc j j in p\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 = helpEven j (Even {n = S j})\n parity (S (S (S (j + j)))) | Odd = helpOdd j (Odd {n = S j})\n\n-- mod3\npublic export\ndata Mod3 : Nat -> Type where\n ThreeZero : Mod3 (n + n + n)\n ThreeOne : Mod3 (S (n + n + n))\n ThreeTwo : Mod3 (S (S (n + n + n)))\nhelpThreeZero : (j:Nat) -> (plus (plus (S j) (S j)) (S j)) = S (S (S (plus (plus j j) j)))\nhelpThreeZero j = rewrite sym $ plusSuccRightSucc j j in\n rewrite sym $ plusSuccRightSucc (plus j j) j in Refl\nhelpThreeOne : (j:Nat) -> S (plus (plus (S j) (S j)) (S j)) = S (S (S (S (plus (plus j j) j))))\nhelpThreeOne j = cong {f=S} $ helpThreeZero j\nhelpThreeTwo : (j:Nat) -> S (S (plus (plus (S j) (S j)) (S j))) = S (S (S (S (S (plus (plus j j) j)))))\nhelpThreeTwo j = cong {f=S} $ helpThreeOne j\nmod3 : (n:Nat) -> Mod3 n\nmod3 Z = ThreeZero {n=Z}\nmod3 (S Z) = ThreeOne {n=Z}\nmod3 (S (S Z)) = ThreeTwo {n=Z}\nmod3 (S (S (S k))) with (mod3 k)\n mod3 (S (S (S (j + j + j)))) | ThreeZero =\n rewrite sym $ helpThreeZero j in ThreeZero {n=S j}\n mod3 (S (S (S (S (j + j + j))))) | ThreeOne =\n rewrite sym $ helpThreeOne j in ThreeOne {n=S j}\n mod3 (S (S (S (S (S (j + j + j)))))) | ThreeTwo =\n rewrite sym $ helpThreeTwo j in ThreeTwo {n=S j}\n-- ---------------------------------\n\n\n-- allDivSeqの実装に必要な関数\n-- ----- from libs/contrib/Data/CoList.idr -----\npublic export\ncodata CoList : Type -> Type where\n Nil : CoList a\n (::) : a -> CoList a -> CoList a\n\nimplementation Functor CoList where\n map f [] = []\n map f (x::xs) = f x :: map f xs\n\nimplementation Show a => Show (CoList a) where\n show xs = \"[\" ++ show' \"\" 20 xs ++ \"]\" where\n show' : String -> (n : Nat) -> (xs : CoList a) -> String\n show' acc Z _ = acc ++ \"...\"\n show' acc (S n) [] = acc\n show' acc (S n) [x] = acc ++ show x\n show' acc (S n) (x :: xs) = show' (acc ++ (show x) ++ \", \") n xs\n\nunfoldr : (a -> Maybe (b, a)) -> a -> CoList b\nunfoldr f x =\n case f x of\n Just (y, new_x) => y :: (unfoldr f new_x)\n _ => []\n-- ----- from libs/contrib/Data/CoList.idr -----\n\n-- ----- from libs/base/Data/List/Quantifiers.idr -----\npublic export\ndata Any : (P : a -> Type) -> List a -> Type where\n Here : {P : a -> Type} -> {xs : List a} -> P x -> Any P (x :: xs)\n There : {P : a -> Type} -> {xs : List a} -> Any P xs -> Any P (x :: xs)\n\nanyNilAbsurd : {P : a -> Type} -> Any P Nil -> Void\nanyNilAbsurd (Here _) impossible\nanyNilAbsurd (There _) impossible\n\nimplementation Uninhabited (Any p Nil) where\n uninhabited = anyNilAbsurd\n\npublic export\ndata All : (P : a -> Type) -> List a -> Type where\n NilA : {P : a -> Type} -> All P Nil\n Cons : {P : a -> Type} -> {xs : List a} -> P x -> All P xs -> All P (x :: xs)\n-- ----- from libs/base/Data/List/Quantifiers.idr -----\n\n\ndsp : List Integer -> Maybe (CoList Integer) -> Maybe (CoList Integer)\ndsp xs Nothing = Nothing\ndsp xs (Just []) = Nothing\ndsp [] (Just (y :: ys)) = Nothing\ndsp (x :: []) (Just (y :: ys)) = Nothing\ndsp (x1 :: (x2 :: xs)) (Just (y :: ys)) = Just (x1 :: (x2+y) :: ys)\n\ndsp2 : List Integer -> Maybe (CoList Integer) -> Maybe (CoList Integer)\ndsp2 xs Nothing = Nothing\ndsp2 xs (Just []) = Nothing\ndsp2 [] (Just (y :: ys)) = Nothing\ndsp2 (x :: xs) (Just (y :: ys)) = Just ((x+y) :: ys)\n\ncountEven : Nat -> Nat -> Nat -> (Nat, Nat)\ncountEven n Z acc = (acc, n)\ncountEven n (S nn) acc =\n if (modNatNZ n 2 SIsNotZ) == 1\n then (acc, n)\n else countEven (divNatNZ n 2 SIsNotZ) nn (acc+1)\n\n-- odd only!\ndivSeq : Nat -> CoList Integer\ndivSeq = (map toIntegerNat) .\n unfoldr (\\b => if b==1 then Nothing\n else Just (countEven (b*3+1) (b*3+1) 0) )\n-- ---------------------------------\n\n\n-- allDivSeqの実装\nmutual\n allDivSeq : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeq x Z = if (modNatNZ x 2 SIsNotZ) == 0 then [Nothing]\n else [Just (divSeq x)]\n ++ (if (modNatNZ (x+7) 4 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+7) 4 SIsNotZ) 2 SIsNotZ) == 1 then [[6,-4] `dsp` (Just (divSeq (divNatNZ ((x+7)*3) 4 SIsNotZ)))] else [])\n ++ (if (modNatNZ (x*6+3) 2 SIsNotZ) == 1 then [[1,-2] `dsp` (Just (divSeq (x*6+3)))] else [])\n ++ (if (modNatNZ (x*3+6) 2 SIsNotZ) == 1 then [[4,-4] `dsp` (Just (divSeq (x*3+6)))] else [])\n ++ (if (modNatNZ (x+1) 2 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+1) 2 SIsNotZ) 2 SIsNotZ) == 1 then [[3,-2] `dsp` (Just (divSeq (divNatNZ ((x+1)*3) 2 SIsNotZ)))] else [])\n ++ (if (modNatNZ (x*12+9) 2 SIsNotZ) == 1 then [[2,-4] `dsp` (Just (divSeq (x*12+9)))] else [])\n ++ (if (modNatNZ (x+3) 8 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+3) 8 SIsNotZ) 2 SIsNotZ) == 1 then [[5,-2] `dsp` (Just (divSeq (divNatNZ ((x+3)*3) 8 SIsNotZ)))] else [])\n ++ (if (modNatNZ (x `minus` 21) 64 SIsNotZ) == 0 && x > 21 && (modNatNZ (modNatNZ (x `minus` 21) 64 SIsNotZ) 2 SIsNotZ) == 1 then [[6] `dsp2` (Just (divSeq (divNatNZ (x `minus` 21) 64 SIsNotZ)))] else [])\n allDivSeq x (S lv) = allDivSeq x lv\n ++ allDivSeqA x lv\n ++ allDivSeqB x lv\n ++ allDivSeqC x lv\n ++ allDivSeqD x lv\n ++ allDivSeqE x lv\n ++ allDivSeqF x lv\n ++ allDivSeqG x lv\n\n allDivSeqA : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqA x Z =\n if (modNatNZ (x+7) 4 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+7) 4 SIsNotZ) 2 SIsNotZ) == 1\n then [[6,-4] `dsp` (Just (divSeq (divNatNZ ((x+7)*3) 4 SIsNotZ)))]\n else []\n allDivSeqA x (S lv) =\n if (modNatNZ (x+7) 4 SIsNotZ) == 0\n then map ([6,-4] `dsp`) $ allDivSeq (divNatNZ ((x+7)*3) 4 SIsNotZ) (S lv)\n else []\n\n allDivSeqB : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqB x Z =\n if (modNatNZ (x*6+3) 2 SIsNotZ) == 1\n then [[1,-2] `dsp` (Just (divSeq (x*6+3)))]\n else []\n allDivSeqB x (S lv) =\n map ([1,-2] `dsp`) $ allDivSeq (x*6+3) (S lv)\n\n allDivSeqC : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqC x Z =\n if (modNatNZ (x*3+6) 2 SIsNotZ) == 1\n then [[4,-4] `dsp` (Just (divSeq (x*3+6)))]\n else []\n allDivSeqC x (S lv) =\n map ([4,-4] `dsp`) $ allDivSeq (x*3+6) (S lv)\n\n allDivSeqD : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqD x Z =\n if (modNatNZ (x+1) 2 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+1) 2 SIsNotZ) 2 SIsNotZ) == 1\n then [[3,-2] `dsp` (Just (divSeq (divNatNZ ((x+1)*3) 2 SIsNotZ)))]\n else []\n allDivSeqD x (S lv) =\n if (modNatNZ (x+1) 2 SIsNotZ) == 0\n then map ([3,-2] `dsp`) $ allDivSeq (divNatNZ ((x+1)*3) 2 SIsNotZ) (S lv)\n else []\n\n allDivSeqE : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqE x Z =\n if (modNatNZ (x*12+9) 2 SIsNotZ) == 1\n then [[2,-4] `dsp` (Just (divSeq (x*12+9)))]\n else []\n allDivSeqE x (S lv) =\n map ([2,-4] `dsp`) $ allDivSeq (x*12+9) (S lv)\n\n allDivSeqF : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqF x Z =\n if (modNatNZ (x+3) 8 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+3) 8 SIsNotZ) 2 SIsNotZ) == 1\n then [[5,-2] `dsp` (Just (divSeq (divNatNZ ((x+3)*3) 8 SIsNotZ)))]\n else []\n allDivSeqF x (S lv) =\n if (modNatNZ (x+3) 8 SIsNotZ) == 0\n then map ([5,-2] `dsp`) $ allDivSeq (divNatNZ ((x+3)*3) 8 SIsNotZ) (S lv)\n else []\n\n allDivSeqG : Nat -> Nat -> List (Maybe (CoList Integer))\n allDivSeqG x Z =\n if (modNatNZ (x `minus` 21) 64 SIsNotZ) == 0 && x > 21 && (modNatNZ (modNatNZ (x `minus` 21) 64 SIsNotZ) 2 SIsNotZ) == 1\n then [[6] `dsp2` (Just (divSeq (divNatNZ (x `minus` 21) 64 SIsNotZ)))]\n else []\n allDivSeqG x (S lv) =\n if (modNatNZ (x `minus` 21) 64 SIsNotZ) == 0 && x > 21\n then map ([6] `dsp2`) $ allDivSeq (divNatNZ (x `minus` 21) 64 SIsNotZ) (S lv)\n else []\n-- ---------------------------------\n\n\n-- その他関数\ndefini : (x, lv:Nat) -> allDivSeq x (S lv) = allDivSeq x lv\n ++ allDivSeqA x lv\n ++ allDivSeqB x lv\n ++ allDivSeqC x lv\n ++ allDivSeqD x lv\n ++ allDivSeqE x lv\n ++ allDivSeqF x lv\n ++ allDivSeqG x lv\ndefini x lv = Refl\n\ndefiniA0 : (x : Nat) -> (allDivSeqA x Z) =\n (if (modNatNZ (x+7) 4 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+7) 4 SIsNotZ) 2 SIsNotZ) == 1\n then [[6,-4] `dsp` (Just (divSeq (divNatNZ ((x+7)*3) 4 SIsNotZ)))]\n else [])\ndefiniA0 x = Refl\ndefiniA : (x, lv:Nat) -> (allDivSeqA x (S lv)) =\n (if (modNatNZ (x+7) 4 SIsNotZ) == 0\n then map ([6,-4] `dsp`) $ allDivSeq (divNatNZ ((x+7)*3) 4 SIsNotZ) (S lv)\n else [])\ndefiniA x lv = Refl\n\ndefiniB0 : (x : Nat) -> (allDivSeqB x Z) =\n (if (modNatNZ (x*6+3) 2 SIsNotZ) == 1\n then [[1,-2] `dsp` (Just (divSeq (x*6+3)))]\n else [])\ndefiniB0 x = Refl\ndefiniB : (x, lv:Nat) -> (allDivSeqB x (S lv)) =\n map ([1,-2] `dsp`) $ allDivSeq (x*6+3) (S lv)\ndefiniB x lv = Refl\n\ndefiniC0 : (x : Nat) -> (allDivSeqC x Z) =\n (if (modNatNZ (x*3+6) 2 SIsNotZ) == 1\n then [[4,-4] `dsp` (Just (divSeq (x*3+6)))]\n else [])\ndefiniC0 x = Refl\ndefiniC : (x, lv:Nat) -> (allDivSeqC x (S lv)) =\n map ([4,-4] `dsp`) $ allDivSeq (x*3+6) (S lv)\ndefiniC x lv = Refl\n\ndefiniD0 : (x : Nat) -> (allDivSeqD x Z) =\n (if (modNatNZ (x+1) 2 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+1) 2 SIsNotZ) 2 SIsNotZ) == 1\n then [[3,-2] `dsp` (Just (divSeq (divNatNZ ((x+1)*3) 2 SIsNotZ)))]\n else [])\ndefiniD0 x = Refl\ndefiniD : (x, lv:Nat) -> (allDivSeqD x (S lv)) =\n (if (modNatNZ (x+1) 2 SIsNotZ) == 0\n then map ([3,-2] `dsp`) $ allDivSeq (divNatNZ ((x+1)*3) 2 SIsNotZ) (S lv)\n else [])\ndefiniD x lv = Refl\n\ndefiniE0 : (x : Nat) -> (allDivSeqE x Z) =\n (if (modNatNZ (x*12+9) 2 SIsNotZ) == 1\n then [[2,-4] `dsp` (Just (divSeq (x*12+9)))]\n else [])\ndefiniE0 x = Refl\ndefiniE : (x, lv:Nat) -> (allDivSeqE x (S lv)) =\n map ([2,-4] `dsp`) $ allDivSeq (x*12+9) (S lv)\ndefiniE x lv = Refl\n\ndefiniF0 : (x : Nat) -> (allDivSeqF x Z) =\n (if (modNatNZ (x+3) 8 SIsNotZ) == 0 && (modNatNZ (modNatNZ (x+3) 8 SIsNotZ) 2 SIsNotZ) == 1\n then [[5,-2] `dsp` (Just (divSeq (divNatNZ ((x+3)*3) 8 SIsNotZ)))]\n else [])\ndefiniF0 x = Refl\ndefiniF : (x, lv:Nat) -> (allDivSeqF x (S lv)) =\n (if (modNatNZ (x+3) 8 SIsNotZ) == 0\n then map ([5,-2] `dsp`) $ allDivSeq (divNatNZ ((x+3)*3) 8 SIsNotZ) (S lv)\n else [])\ndefiniF x lv = Refl\n\ndefiniG0 : (x : Nat) -> (allDivSeqG x Z) =\n (if (modNatNZ (x `minus` 21) 64 SIsNotZ) == 0 && x > 21 && (modNatNZ (modNatNZ (x `minus` 21) 64 SIsNotZ) 2 SIsNotZ) == 1\n then [[6] `dsp2` (Just (divSeq (divNatNZ (x `minus` 21) 64 SIsNotZ)))]\n else [])\ndefiniG0 x = Refl\ndefiniG : (x, lv:Nat) -> (allDivSeqG x (S lv)) =\n (if (modNatNZ (x `minus` 21) 64 SIsNotZ) == 0 && x > 21\n then map ([6] `dsp2`) $ allDivSeq (divNatNZ (x `minus` 21) 64 SIsNotZ) (S lv)\n else [])\ndefiniG x lv = Refl\n\n-- myAny : (a->Bool) -> List a -> Bool\n-- myAny pp [] = False\n-- myAny pp (x :: xs) = (pp x) || myAny pp xs\n\nlimitedNStep : Maybe (CoList Integer) -> Nat -> Bool\nlimitedNStep Nothing _ = True\nlimitedNStep (Just []) _ = True\nlimitedNStep (Just (_ :: _)) Z = False\nlimitedNStep (Just (_ :: xs)) (S n) = limitedNStep (Just xs) n\n\npublic export\ndata Limited : Maybe (CoList Integer) -> Type where\n IsLimited : (n : Nat ** limitedNStep xs n = True) -> Limited xs\n\nP : Nat -> Nat -> Type\nP n lv = Not $ All Limited $ allDivSeq (n+n+n) lv\n\ndefiniP : (n, lv : Nat)\n -> P n lv = Not $ All Limited $ allDivSeq (n+n+n) lv\ndefiniP n lv = Refl\n-- ---------------------------------\n\n\n\n\n\n\n\n\n\n\n-- allDivSeq 0 2が有限項である事を示すため、mainを使う(ビルドして)\nmain : IO ()\nmain = traverse_ (putStrLn . show) $ allDivSeq 0 2\n\n\n\n", "meta": {"hexsha": "34915fd093800e61c88241a2827f3b48bdd23141", "size": 12492, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program/ProofColDivSeqBase.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program/ProofColDivSeqBase.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program/ProofColDivSeqBase.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.6265060241, "max_line_length": 210, "alphanum_fraction": 0.5283381364, "num_tokens": 5031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6270698130964852}} {"text": "module Date\n\nimport Coda.Range\n\n%access public export\n%default total\n\n{-\n ISO 8601 Date Package\n\n Date Representation inclues:\n\n Year - Month - Day\n\n Show interface includes zero-padding of up to 3 zeroes for Year, and 1 zero\n for month and day.\n\n-}\n\n{-\n Type Definitions\n-}\n\ndata Year : Type where\n MkYear : (year : Integer) -> Year\n\n%name Year y,y1,y2,y3\n\nisLeap : Year -> Bool\nisLeap (MkYear year) = (modNatNZ (toNat year) 4 SIsNotZ) == 0\n\ndata Month : Type where\n January : Month\n February : Month\n March : Month\n April : Month\n May : Month\n June : Month\n July : Month\n August : Month\n September : Month\n October : Month\n November : Month\n December : Month\n\n%name Month m,m1,m2,m3\n\nmonthOrder : Month -> Nat\nmonthOrder January = 1\nmonthOrder February = 2\nmonthOrder March = 3\nmonthOrder April = 4\nmonthOrder May = 5\nmonthOrder June = 6\nmonthOrder July = 7\nmonthOrder August = 8\nmonthOrder September = 9\nmonthOrder October = 10\nmonthOrder November = 11\nmonthOrder December = 12\n\nmonthDays : Year -> Month -> Nat\nmonthDays _ January = 30\nmonthDays year February = if isLeap year then 29 else 28\nmonthDays _ March = 30\nmonthDays _ April = 31\nmonthDays _ May = 30\nmonthDays _ June = 31\nmonthDays _ July = 30\nmonthDays _ August = 31\nmonthDays _ September = 30\nmonthDays _ October = 31\nmonthDays _ November = 30\nmonthDays _ December = 31\n\npreviousMonth : Month -> Month\npreviousMonth January = December\npreviousMonth February = January\npreviousMonth March = February\npreviousMonth April = March\npreviousMonth May = April\npreviousMonth June = May\npreviousMonth July = June\npreviousMonth August = July\npreviousMonth September = August\npreviousMonth October = September\npreviousMonth November = October\npreviousMonth December = November\n\ndata Day : Type where\n MkDay : (day : Nat) -> Day\n\n%name Day d,d1,d2,d3\n\ninDayRange : Nat -> Day -> Type\ninDayRange n (MkDay day) = inRange (MkRange Z (S n)) day\n\nvalidDate : Year -> Month -> Day -> Type\nvalidDate year month = inDayRange (monthDays year month)\n\ndata Date : Type where\n MkDate : (year : Year) ->\n (month : Month) ->\n (day : Day) ->\n { auto p : (validDate year month day) } -> Date\n\n%name Date d,d1,d2,d3\n\n\n{-\n Standard Interface Implementations\n-}\n\nEq Year where\n (==) (MkYear y) (MkYear y') = y == y'\n\nEq Month where\n (==) x y = monthOrder x == monthOrder y\n\nEq Day where\n (==) (MkDay y) (MkDay y') = y == y'\n\nEq Date where\n (==) (MkDate y m d) (MkDate y' m' d') = d == d' && m == m' && y == y'\n\nOrd Year where\n compare (MkYear y) (MkYear y') = compare y y'\n\nOrd Month where\n compare x y = compare (monthOrder x) (monthOrder y)\n\nOrd Day where\n compare (MkDay d) (MkDay d') = compare d d'\n\nOrd Date where\n compare (MkDate y m d) (MkDate y' m' d') =\n case compare y y' of\n EQ => case compare m m' of\n EQ => compare d d'\n result => result\n result => result\n\nShow Year where\n show (MkYear year) =\n let s = show year\n in case length s of\n Z => \"0000\"\n (S Z) => \"000\" ++ s\n (S (S Z)) => \"00\" ++ s\n (S (S (S Z))) => \"0\" ++ s\n _ => s\n\nShow Month where\n show x =\n let s = show $ monthOrder x\n in case length s of\n (S Z) => \"0\" ++ s\n _ => s\n\nShow Day where\n show (MkDay day) =\n let s = show day\n in case length s of\n (S Z) => \"0\" ++ s\n _ => s\n\nShow Date where\n show (MkDate y m d) = show y ++ \"-\" ++ show m ++ \"-\" ++ show d\n\n", "meta": {"hexsha": "25ee80e33cacbec5ddfbf854ef84778b961184a5", "size": 3675, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Coda/Date.idr", "max_stars_repo_name": "ostera/idris-coda", "max_stars_repo_head_hexsha": "0d8b29b7b73aa1ea80bf216e5e6dea5e81156e32", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-09-23T00:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-10T21:24:10.000Z", "max_issues_repo_path": "Coda/Date.idr", "max_issues_repo_name": "ostera/idris-coda", "max_issues_repo_head_hexsha": "0d8b29b7b73aa1ea80bf216e5e6dea5e81156e32", "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": "Coda/Date.idr", "max_forks_repo_name": "ostera/idris-coda", "max_forks_repo_head_hexsha": "0d8b29b7b73aa1ea80bf216e5e6dea5e81156e32", "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": 21.6176470588, "max_line_length": 77, "alphanum_fraction": 0.5945578231, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156293, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6268639418445014}} {"text": "module Linear.Epsilon\n\npublic export\ninterface Num a => Epsilon a where\n ||| Determine if a quantity is near zero.\n nearZero : a -> Bool\n\npublic export\nimplementation Epsilon Double where\n nearZero a = abs a <= (10 `pow` -12)\n", "meta": {"hexsha": "a202f7b6bf64ae6c2098c27baa64e740fb7eb322", "size": 229, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Linear/Epsilon.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/Epsilon.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/Epsilon.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": 20.8181818182, "max_line_length": 43, "alphanum_fraction": 0.7161572052, "num_tokens": 61, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6265582785038402}} {"text": "module Examples\n\nimport Data.Nat\nimport Data.Vect\nimport Data.List\nimport LinearTypes\nimport Control.Linear.LIO\nimport Unitary\nimport QStateT\nimport System.Random\nimport Injection\nimport Complex\nimport QuantumOp\n\n\n------------------------ Example of circuits built with unitary contructors -----------------------\n\n-- These functions only use the 4 constructors of the Unitary data type : IdGate, H, P, and CNOT\n\n||| Put two qubits initally in state |00> in the Bell state\npublic export\ntoBellBasis : Unitary 2\ntoBellBasis = CNOT 0 1 (H 0 IdGate)\n\n||| Draw the circuit toBellBasis using draw function\nexport\ndrawToBellBasis : IO ()\ndrawToBellBasis = do\n putStrLn \"\\nDrawing ToBellBasis: \\nCNOT 0 1 (H 0 IdGate)\"\n draw toBellBasis\n\n\nconstructorsExample : Unitary 3\nconstructorsExample = H 1 (P (pi/2) 2 (CNOT 2 0 IdGate))\n\ndrawConstructorsExample : IO ()\ndrawConstructorsExample = do\n putStrLn \"An example of circuit built with H, P and CNOT constructors :\"\n putStrLn \" H 1 (P (pi/2) 2 (CNOT 2 0 IdGate))\"\n draw constructorsExample\n\n\n---------------------------------- Examples using composition -------------------------------------\n\n-- Sequential composition of unitary circuits\n\ncompose_example1 : Unitary 1\ncompose_example1 = TGate . HGate\n\ncompose_example2 : Unitary 2\ncompose_example2 = (H 1 IdGate) . (P pi 0 IdGate) . toBellBasis\n\ndrawComposeExamples : IO ()\ndrawComposeExamples = do\n putStrLn \"Examples using composition\"\n putStrLn \"Example 1 : TGate . HGate\"\n draw compose_example1\n putStrLn \"Example 2 : (H 1 IdGate) . (P pi 0 IdGate) . toBellBasis\"\n draw compose_example2\n\n------------------------------------ Examples using tensor product --------------------------------\n\n-- Parallel composition (ie tensor product) of unitary circuits\n\n||| Example using the # operator for tensor product\ntensorExample1 : Unitary 4\ntensorExample1 = HGate # PGate pi # CNOTGate\n\n||| Example using tensorn function :\n|||Make n tensor products of the same unitary of size 1\ntensornExample : Unitary 3\ntensornExample = tensorn 3 HGate\n\n||| Example using tensorMapSimple function\n||| Tensor product of a Vector of single-qubit Unitary operators\ntensorMapSimpleExample : Unitary 3\ntensorMapSimpleExample = tensorMapSimple [HGate, PGate pi, HGate]\n\n||| Example using tensorMap function\n||| Tensor product of a Vector of Unitary operators\ntensorMapExample : Unitary 6\ntensorMapExample = tensorMap [CNOTGate, toBellBasis, CNOTGate]\n\ndrawTensorExamples : IO ()\ndrawTensorExamples = do\n putStrLn \"Examples using tensor product\"\n putStrLn \"Example 1 : HGate # PGate pi # CNOTGate\"\n draw tensorExample1\n putStrLn \"Example 2 : tensorn 3 HGate\"\n draw tensornExample\n putStrLn \"Example 3 : tensorMapSimple [HGate, PGate pi, HGate]\"\n draw tensorMapSimpleExample\n putStrLn \"Example 4 : tensorMap [CNOTGate, toBellBasis, CNOTGate]\"\n draw tensorMapExample\n\n\n||| Another version of toBellBasis using composition and tensor product\ntoBellBasis2 : Unitary 2\ntoBellBasis2 = CNOTGate . (HGate # IdGate)\n\ndrawToBellBasis2 : IO ()\ndrawToBellBasis2 = do\n putStrLn \"\\nAnother possibility for toBellBasis: \\nCNOTGate . (HGate # IdGate)\"\n draw toBellBasis2\n\n---------------------------------------- Examples using adjoint -----------------------------------\n\n-- The adjoint of a unitary circuit is the inverse unitary circuit\n\nadjoint_example1 : Unitary 2\nadjoint_example1 = adjoint toBellBasis\n\nadjoint_example2 : Unitary 3\nadjoint_example2 = adjoint toffoli\n\ndrawAdjointExamples : IO ()\ndrawAdjointExamples = do\n putStrLn \"Examples using adjoint\"\n putStrLn \"Example 1 : adjoint toBellBasis\"\n draw adjoint_example1\n putStrLn \"Example 2 : adjoint toffoli\"\n draw adjoint_example2\n\n\n||| Draw an example of circuit using tensor, compose and adjoint\nexport\nexampleComposeTensor1 : IO ()\nexampleComposeTensor1 = do\n putStrLn \"\\nAn example of usage of compose, tensor and adjoint: \\n(adjoint toBellBasis # IdGate) . (TGate # toBellBasis)\"\n let circuit = (adjoint toBellBasis # IdGate) . (TGate # toBellBasis)\n draw circuit\n\n\n---------------------------------------- Examples using apply -------------------------------------\n\n-- Apply : apply a smaller unitary circuit of size i to a bigger one of size n, giving the vector v of wire indices on which we wish to apply the smaller circuit\n\nU : Unitary 3\nU = HGate # IdGate {n = 1} # (PGate pi)\n\napply_example1 : Unitary 3\napply_example1 = apply toBellBasis U [0,1]\n\napply_example2 : Unitary 3\napply_example2 = apply toBellBasis U [0,2]\n\napply_example3 : Unitary 3\napply_example3 = apply toBellBasis U [2,0]\n\napply_example4 : Unitary 3\napply_example4 = apply toBellBasis U [2,1]\n\napply_example5 : Unitary 3\napply_example5 = apply toffoli IdGate [2,0,1]\n\ndrawApplyExamples : IO ()\ndrawApplyExamples = do\n putStrLn \"\\nApply Examples \\nU = HGate # IdGate {n = 1} # (PGate pi)\\n\"\n putStrLn \"Example 1 : apply toBellBasis U [0,1]\"\n draw apply_example1\n putStrLn \"Example 2 : apply toBellBasis U [0,2]\"\n draw apply_example2\n putStrLn \"Example 3 : apply toBellBasis U [2,0]\"\n draw apply_example3\n putStrLn \"Example 4 : apply toBellBasis U [2,1]\"\n draw apply_example4\n putStrLn \"Example 5 : apply toffoli [2,0,1]\"\n draw apply_example5\n\n-------------------------------------- Example using controlled -----------------------------------\n\n-- Compute the controlled version of a unitary circuit\n\ncontrolled_example1 : Unitary 2\ncontrolled_example1 = controlled TGate\n\n||| Example using multipleQubitControlledNOT\n||| Makes a multiple qubit CNOT gate : control on the first n qubits, target on the last\nmultipleQubitsCNOTExample : Unitary 4\nmultipleQubitsCNOTExample = multipleQubitControlledNOT 4\n\n--------------------------------- Examples of parametrized circuits -------------------------------\n\n-- Unitary circuits can be parametrized by classical information\n\n\nparametrized_example1 : Bool -> Unitary 1\nparametrized_example1 b = if b then HGate else PGate pi\n\nparametrized_example2 : Bool -> Bool -> Double -> Unitary 2\nparametrized_example2 b1 b2 p = CNOTGate . (if b1 then H 0 IdGate else IdGate) . (if b2 then IdGate else P p 1 IdGate)\n\ndrawParamExamples : IO ()\ndrawParamExamples = do\n putStrLn \"Examples of circuits parametrized by classical data\"\n putStrLn \"Example 1 : for b : bool , if b then HGate else PGate pi\"\n putStrLn \"For b = True : \"\n draw (parametrized_example1 True)\n putStrLn \"For b = False : \"\n draw (parametrized_example1 False)\n putStrLn \"Example 2 : for b1, b2 : Bool and p : Double , CNOTGate . (if b1 then H 0 IdGate else IdGate) . (if b2 then IdGate else P p 1 IdGate)\"\n putStrLn \"For b1 = True, b2 = False, p = pi/2\"\n draw (parametrized_example2 True False (pi/2))\n\n\n------------------------------------ Example of depth computation ---------------------------------\n-- Compute the depth of a circuit \n\n\ndepthExample1 : Unitary 3\ndepthExample1 = CNOT 0 1 $ CNOT 2 1 $ H 1 $ CNOT 0 2 IdGate \n\ndepthExample2 : Unitary 3\ndepthExample2 = H 2 $ H 1 $ H 0 $ H 1 IdGate\n\ndepthExample3 : Unitary 3\ndepthExample3 = CNOT 1 2 $ CNOT 0 2 $ CNOT 0 1 $ H 1 $ P pi 1 $ H 1 IdGate\n\ndrawDepthExamples : IO ()\ndrawDepthExamples = do\n putStrLn \"Examples of depth computation\"\n putStrLn \"The depth of the following circuit\"\n draw depthExample1\n putStrLn (\"is \" ++ show (depth depthExample1))\n putStrLn \"\\n\\nThe depth of the following circuit\"\n draw depthExample2\n putStrLn $ \"is \" ++ show (depth depthExample2)\n putStrLn \"\\n\\nThe depth of the following circuit\"\n draw depthExample3\n putStrLn $ \"is \" ++ show (depth depthExample3)\n\n\n----------------------------------- Examples of quantum operations --------------------------------\n\n\n||| Sequencing quantum operations using run\n||| \nquantum_operation4 : QuantumOp t => IO (Vect 3 Bool)\nquantum_operation4 = \n run (do\n [q1,q2] <- newQubits {t=t} 2 --create 2 new qubits q1 and q2\n [q1,q2] <- applyUnitary [q1,q2] toBellBasis --apply the toBellBasis unitary circuit to q1 and q2\n q3 <- newQubit --create 1 new qubit q3\n [q1,q3,q2] <- applyUnitary [q1,q3,q2] toffoli --apply toffoli gate on q1, q3 and q2\n [b2] <- measure [q2] --measure q2\n (q3 # q1) <- applyCNOT q3 q1 --apply CNOT on q3 and q1\n [b1,b3] <- measure [q1,q3] --measure q1 and q3\n pure [b1,b2,b3] --return the results\n )\n\ndrawQuantumOp : IO ()\ndrawQuantumOp = do\n [b1,b2,b3] <- quantum_operation4 {t = SimulatedOp}\n putStrLn \"\\n\\nExecuting an example of quantum operations : sequencing quantum operations using run\"\n putStrLn \"Create 2 qubits q1 and q2\"\n putStrLn \"Apply `toBellBasis` circuit on q1 and q2\"\n putStrLn \"Create one new qubit q3\"\n putStrLn \"Apply the toffoli gate on q1,q3 and q2\"\n putStrLn $ \"Measure q2 : result is \" ++ show b2\n putStrLn \"Apply CNOT on q3 and q1\"\n putStrLn $ \"Measure q1 and q3 : results are \" ++ show b1 ++ \" and \" ++ show b3\n\n------------------------------------ Draw all example circuits ------------------------------------\n\nexport\ndrawExamples : IO ()\ndrawExamples = do\n drawToBellBasis\n drawConstructorsExample\n drawComposeExamples\n drawTensorExamples\n drawToBellBasis2\n drawAdjointExamples\n exampleComposeTensor1\n drawApplyExamples\n drawParamExamples\n drawDepthExamples\n drawQuantumOp\n", "meta": {"hexsha": "f35179f561a0d2bcd7826be28f0b5e27236aaffb", "size": 9343, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Examples.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": "Examples.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": "Examples.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.4874551971, "max_line_length": 161, "alphanum_fraction": 0.6746227122, "num_tokens": 2596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6258141202285894}} {"text": "module Main\n\nimport Data.Vect\n\n%default total\n\ndata Ty = TyBool | TyInt | TyFun Ty Ty\n\ninterpTy : Ty -> Type\ninterpTy TyBool = Bool\ninterpTy TyInt = Integer\ninterpTy (TyFun a b) = interpTy a -> interpTy b\n\ndata HasType : (i : Fin n) -> Vect n Ty -> Ty -> Type where\n Stop : HasType FZ (t :: ctx) t\n Pop : HasType k ctx t -> HasType (FS k) (u :: ctx) t\n\ndata Expr : Vect n Ty -> Ty -> Type where\n Var : HasType i ctx t -> Expr ctx t\n Val : (x : Integer) -> Expr ctx TyInt\n Lam : Expr (a :: ctx) t -> Expr ctx (TyFun a t)\n App : Expr ctx (TyFun a t) -> Expr ctx a -> Expr ctx t\n Op : (interpTy a -> interpTy b -> interpTy c) -> Expr ctx a -> Expr ctx b -> Expr ctx c\n If : Expr ctx TyBool -> Lazy (Expr ctx a) -> Lazy (Expr ctx a) -> Expr ctx a\n\ndata Env : Vect n Ty -> Type where\n Nil : Env Nil\n (::) : interpTy a -> Env ctx -> Env (a :: ctx)\n\nlookup : HasType i ctx t -> Env ctx -> interpTy t\nlookup Stop (x :: xs) = x\nlookup (Pop k) (x :: xs) = lookup k xs\n\ninterp : Env ctx -> Expr ctx t -> interpTy t\ninterp env (Var i) = lookup i env\ninterp env (Val n) = n\ninterp env (Lam sc) = \\x => interp (x :: env) sc\ninterp env (App f s) = interp env f (interp env s)\ninterp env (Op op x y) = op (interp env x) (interp env y)\ninterp env (If x t e) = if interp env x then interp env t \n else interp env e\n\nadd : Expr ctx (TyFun TyInt (TyFun TyInt TyInt))\nadd = Lam (Lam (Op (+) (Var Stop) (Var (Pop Stop))))\n\npartial\nfac : Expr ctx (TyFun TyInt TyInt)\nfac = Lam (If (Op (==) (Var Stop) (Val 0))\n (Val 1)\n (Op (*) (App fac (Op (-) (Var Stop) (Val 1)))\n (Var Stop)))\n\npartial\nmain : IO ()\nmain = do putStr \"Enter a number: \"\n x <- getLine\n printLn (interp [] fac (cast x))\n", "meta": {"hexsha": "64cb16958799657ab6c646c043f78d39b19bcb81", "size": 1777, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "the_well_typed_interpreter/WellTypedInterpreter.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": "the_well_typed_interpreter/WellTypedInterpreter.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": "the_well_typed_interpreter/WellTypedInterpreter.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": 30.6379310345, "max_line_length": 89, "alphanum_fraction": 0.5711873945, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.625751009634046}} {"text": "module Specifications.OrderedGroup\n\nimport public Specifications.TranslationInvariance\n\n%default total\n%access public export\n\n||| composed specification \ndata OrderedGroupSpec : Binop s -> s -> (s -> s) -> Binrel s -> Type where\n MkOrderedGroup :\n PartiallyOrderedGroupSpec op inv e leq ->\n isTotalOrder leq ->\n OrderedGroupSpec op inv e leq\n\n||| forget\npartiallyOrderedGroup : OrderedGroupSpec add zero neg leq ->\n PartiallyOrderedGroupSpec add zero neg leq\npartiallyOrderedGroup (MkOrderedGroup p _) = p\n\n||| forget\ntotalOrder : OrderedGroupSpec _ _ _ leq -> TotalOrderSpec leq\ntotalOrder (MkOrderedGroup p t) =\n MkTotalOrder (order (invariantOrder p)) t\n", "meta": {"hexsha": "21feea17a84aadee62f456bcdbc96854d38e20b7", "size": 669, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Specifications/OrderedGroup.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/OrderedGroup.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/OrderedGroup.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": 27.875, "max_line_length": 74, "alphanum_fraction": 0.7608370703, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.625658238268}} {"text": "-- 参考Belleve@zhihu\n\ndata Tree:Type -> Type where\n Leaf: a-> Tree a\n Branch : a->Tree a->Tree a->Tree a\n\nflipTree : Tree a-> Tree a\nflipTree (Leaf x)= Leaf x\nflipTree (Branch x l r) = Branch x (flipTree r) (flipTree l)\n\nflipTreeSym : (t:Tree a) -> t = flipTree (flipTree t)\nflipTreeSym (Leaf x) = Refl\nflipTreeSym (Branch x l r) = do \n let recL = flipTreeSym l\n let recR = flipTreeSym r\n rewrite recL in \n rewrite recR in Refl\n\n{-\nmap_id : Functor f => f a -> f a\nmap_id : map id\n\ninterface Functor f => VerifiedFunctor (f:Type->Type) where\n identity: (fa:fa) -> map_id fa = fa\n dist : (fa:fa) -> (g:b->c)->(h:a->b)->map (g.h) fa = (map g).(map h) $ fa\n\nVerifiedFunctor List where\n identity [] = Refl\n identity (x:xs) = let ih = (identity xs) in rewrite ih in Refl\n\ndist [] _ _ = Refl\ndist (x:xs) g h = let ih = (dist xs g h) in rewrite ih in Refl\n-}", "meta": {"hexsha": "53bea4040b5a4c673bb79bd203427657f70a62b1", "size": 884, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "flip.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": "flip.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": "flip.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": 26.7878787879, "max_line_length": 77, "alphanum_fraction": 0.6176470588, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6256178828589}} {"text": "\n\ndata Shape : Type where\n ||| Triangle; Base & Height\n Triangle : Double -> Double -> Shape\n ||| Rectangle; Width & Height\n Rectangle : Double -> Double -> Shape\n ||| Circle; Radius\n Circle : Double -> Shape\n%name Shape shape, shape1, shape2\n\ndata Picture = Primitive Shape\n | Combine Picture Picture\n | Roatate Double Picture\n | Translate Double Double Picture\n%name Picture pic, pic1, pic2\n\n\narea : Shape -> Double\narea (Triangle x y) = 0.5 * x * y\narea (Rectangle x y) = x * y\narea (Circle r) = pi * r * r\n\n\nmyTriangle : Picture\nmyTriangle = Primitive (Triangle 10 10)\n\nmyRect : Picture\nmyRect = Primitive (Rectangle 20 10)\n\nmyCircle : Picture\nmyCircle = Primitive (Circle 5)\n\ntestPic : Picture\ntestPic = Combine (Translate 5 5 myRect) (Combine (Translate 35 5 myCircle) (Translate 15 25 myTriangle))\n\n\npictureArea : Picture -> Double\npictureArea (Primitive shape) = area shape\npictureArea (Combine pic pic1) = pictureArea pic + pictureArea pic1\npictureArea (Roatate x pic) = pictureArea pic\npictureArea (Translate x y pic) = pictureArea pic\n\n\n\n\n", "meta": {"hexsha": "e9f9e7175cb52c911997f98880d4a4939a1e2594", "size": 1092, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/picture.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/picture.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/picture.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": 23.2340425532, "max_line_length": 105, "alphanum_fraction": 0.6895604396, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.6619228625116081, "lm_q1q2_score": 0.6255136046311287}} {"text": "module decDivZ\nimport ZZ\nimport ZZUtils\nimport Divisors\nimport GCDZZ\nimport Primes\nimport gcd\n%access public export\n%default total\n\nisDivisibleImpliesIsDivisibleZ:isDivisible a b ->\n IsDivisibleZ (Pos a) (Pos b)\nisDivisibleImpliesIsDivisibleZ (n**(gpf,eqpf)) = ((Pos n)**(cong eqpf))\n\nposIntToSuccNat:{m:ZZ}->(IsPositive m) ->(t:Nat**(((m = (Pos t)),(IsSucc t))))\nposIntToSuccNat {m = (Pos (S k))} Positive = ((S k)**(Refl,(ItIsSucc )))\n\nsuccGtZero:{t:Nat}->(IsSucc t)->GT t Z\nsuccGtZero {t = (S n)} ItIsSucc = LTESucc LTEZero\n\nrehelp2:{m:ZZ}->{k:ZZ}->(s:ZZ)-> m = k->s*k = s*m\nrehelp2 s prf = rewrite sym $ prf in\n Refl\n\nisDivisibleZImpliesIsDivisible :{a:Nat}->{b:Nat}->\n IsPositive (Pos a) -> IsDivisibleZ (Pos a) (Pos b) ->isDivisible a b\nisDivisibleZImpliesIsDivisible {a = (S k)}{b = Z} Positive x =\n void (zeroDoesntDivideNonZero PositiveZ x)\nisDivisibleZImpliesIsDivisible {a = (S k)}{b = (S j)} Positive (m**eqpf) =\n (case posDivByPosIsPos {c = (Pos (S k))}{d =(Pos (S j))} Positive Positive eqpf of\n mPos => (case posIntToSuccNat mPos of\n (t**(equal,tsucc)) => ( t**((succGtZero tsucc),( posInjective( rewrite rehelp2 {m=m}{k=(Pos t)} (Pos (S j)) equal in\n eqpf))))))\n\nposSSknotOne: (Pos ( S (S k)))=1->Void\nposSSknotOne Refl impossible\n\nposSSknotMinusOne: (Pos ( S (S k)))=(-1)->Void\nposSSknotMinusOne Refl impossible\n\ngt2DoesntDivideOne: {k:Nat}->IsDivisibleZ 1 (Pos ( S (S k))) ->Void\ngt2DoesntDivideOne {k} (n**eqpf) =\n (case productOneThenNumbersOne (Pos (S (S k))) n (sym eqpf) of\n (Left (a, b)) => posSSknotOne a\n (Right (a, b)) => posSSknotMinusOne a)\n\nsuccNotZ:( S n) = Z ->Void\nsuccNotZ Refl impossible\n\n\n\ndecDivisibleZnn: (a:ZZ)->(b:ZZ)->IsNonNegative a->IsNonNegative b -> Dec (IsDivisibleZ a b)\ndecDivisibleZnn (Pos Z) b NonNegative y = Yes (zzDividesZero _)\ndecDivisibleZnn (Pos (S Z)) (Pos Z) NonNegative NonNegative = No (zeroDoesntDivideNonZero PositiveZ )\ndecDivisibleZnn (Pos (S Z)) (Pos (S Z)) NonNegative NonNegative= Yes ( oneDiv 1)\ndecDivisibleZnn (Pos (S Z)) (Pos (S (S k))) NonNegative NonNegative= No (gt2DoesntDivideOne )\ndecDivisibleZnn (Pos (S (S k))) (Pos Z) NonNegative NonNegative= No (zeroDoesntDivideNonZero PositiveZ )\ndecDivisibleZnn (Pos (S (S k))) (Pos (S j)) NonNegative NonNegative=\n (case decDiv (S (S k)) (LTESucc (LTESucc LTEZero)) (S j)\n {euc = eculidDivideAux (S(S k)) (S j) (succNotZ)} of\n (Yes prf) => (Yes (isDivisibleImpliesIsDivisibleZ prf))\n (No contra) => No(contra . (isDivisibleZImpliesIsDivisible {b =(S j)} Positive)))\n\n|||Given two integers , a and b, it either returns a proof that b|a or\n||| a proof that b|a is impossible.\ndecDivisibleZ: (a:ZZ)->(b:ZZ)->(Dec (IsDivisibleZ a b))\ndecDivisibleZ (Pos k) (Pos j) =\n decDivisibleZnn (Pos k) (Pos j) NonNegative NonNegative\ndecDivisibleZ (Pos k) (NegS j) =\n (case decDivisibleZnn (Pos k) (-(NegS j)) NonNegative NonNegative of\n (Yes prf) => Yes (negativeDivides prf )\n (No contra) => No (contra . negativeDivides {d =NegS j} ))\ndecDivisibleZ (NegS k) (Pos j) =\n (case decDivisibleZnn (-(NegS k)) (Pos j) NonNegative NonNegative of\n (Yes prf) => Yes ( dDividesNegative prf)\n (No contra) => No (contra . dDividesNegative {a = (NegS k)}))\ndecDivisibleZ (NegS k) (NegS j) =\n (case decDivisibleZnn (-(NegS k)) (-(NegS j)) NonNegative NonNegative of\n (Yes prf) => Yes ( dDividesNegative (negativeDivides prf))\n (No contra) => No ( contra . doubleNegativeDivides { a =NegS k}{d = NegS j}))\n", "meta": {"hexsha": "c564089bea12209395c11bf809b71dfd72b0911d", "size": 3616, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/decDivZ.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/decDivZ.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/decDivZ.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.6419753086, "max_line_length": 136, "alphanum_fraction": 0.6465707965, "num_tokens": 1293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.6893056104028799, "lm_q1q2_score": 0.6254154080261615}} {"text": "> module Matrix.Matrix\n\n> import Data.Vect\n\n> %default total\n\n> %access public export\n\n\n> Matrix : (m : Nat) -> (n : Nat) -> Type -> Type\n> Matrix m n t = Vect m (Vect n t)\n", "meta": {"hexsha": "ec6e26d75dde7d9bc19ce4e38c9059054cc052b3", "size": 173, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Matrix/Matrix.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": "Matrix/Matrix.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": "Matrix/Matrix.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": 14.4166666667, "max_line_length": 49, "alphanum_fraction": 0.6011560694, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.62533582759504}} {"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 defines functionality for Bayesian optimization, the data-efficient optimization of\n||| objective functions. Bayesian optimization recommends new points at which to query your\n||| objective by placing a probabilistic model over historic data then, typically, optimizing an\n||| _acquisition function_ which quantifies how useful it would be to evaluate the objective at any\n||| given set of points.\nmodule BayesianOptimization\n\nimport public Data.Stream\nimport Tensor\n\nimport public BayesianOptimization.Acquisition as BayesianOptimization\nimport public BayesianOptimization.Morphisms as BayesianOptimization\n\n||| A Bayesian optimization loop as a (potentially infinite) stream of values. The values are\n||| typically the observed data, and the models of that data. The loop iteratively finds new points\n||| with the specified `tactic` then updates the values with these new points (assuming some\n||| implicit objective function).\n|||\n||| @tactic The tactic which which to recommend new points. This could be optimizing an acquisition\n||| function, for example. Note this is a `Morphism`, not a function.\n||| @observer A function which evaluates the optimization objective at the recommended points, then\n||| updates the values (typically data and models).\nexport\nloop : (tactic : i ~> Tensor shape dtype)\n -> (observer : Tensor shape dtype -> i -> i) -> i -> Stream i\nloop tactic observer = iterate (\\ii => observer (run tactic ii) ii)\n", "meta": {"hexsha": "223588d95d87f9c905d25fdaaaa84e06719055ac", "size": 2019, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/BayesianOptimization.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/BayesianOptimization.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/BayesianOptimization.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": 48.0714285714, "max_line_length": 99, "alphanum_fraction": 0.7786032689, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6249809112555696}} {"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 functionality for Gaussian process inference.\nmodule Model.GaussianProcess\n\nimport Tensor\nimport Data\nimport Model\nimport Model.Kernel\nimport Model.MeanFunction\nimport Optimize\nimport Distribution\n\n||| A Gaussian process is a collection of random variables, any finite number of which have joint\n||| Gaussian distribution. It can be viewed as a function from a feature space to a joint Gaussian\n||| distribution over a target space.\n|||\n||| @features The shape of the feature domain.\npublic export\ndata GaussianProcess : (0 features : Shape) -> Type where\n ||| Construct a `GaussianProcess` as a pair of mean function and kernel.\n MkGP : MeanFunction features -> Kernel features -> GaussianProcess features\n\nposterior :\n GaussianProcess features\n -> Tensor [] Double\n -> {s : _} -> (Tensor ((S s) :: features) Double, Tensor [S s] Double)\n -> GaussianProcess features\nposterior (MkGP prior_meanf prior_kernel) noise (x_train, y_train) =\n let l = cholesky (prior_kernel x_train x_train + diag {n=S s} noise)\n alpha = l.T \\\\ (l \\\\ y_train)\n\n posterior_meanf : MeanFunction features\n posterior_meanf x = prior_meanf x + (prior_kernel x x_train) @@ alpha\n\n posterior_kernel : Kernel features\n posterior_kernel x x' = prior_kernel x x' -\n (l \\\\ (prior_kernel x_train x)).T @@ (l \\\\ (prior_kernel x_train x'))\n\n in MkGP posterior_meanf posterior_kernel\n\nlog_marginal_likelihood :\n GaussianProcess features\n -> Tensor [] Double\n -> {s : _} -> (Tensor ((S s) :: features) Double, Tensor [S s] Double)\n -> Tensor [] Double\nlog_marginal_likelihood (MkGP _ kernel) noise (x, y) =\n let l = cholesky (kernel x x + diag {n=S s} noise)\n alpha = l.T \\\\ (l \\\\ y)\n log2pi = log $ const $ 2.0 * pi\n in - y @@ alpha / const 2 - trace (log l) - (const $ cast (S s)) * log2pi / const 2\n\n||| A trainable model implementing vanilla Gaussian process regression. That is, regression with a\n||| Gaussian process as conjugate prior for homoscedastic Gaussian likelihoods. See the following\n||| for details:\n|||\n||| Gaussian Processes for Machine Learning\n||| Carl Edward Rasmussen and Christopher K. I. Williams\n||| The MIT Press, 2006. ISBN 0-262-18253-X.\n|||\n||| or\n|||\n||| Pattern Recognition and Machine Learning, Christopher M. Bishop\npublic export\ndata ConjugateGPRegression : (0 features : Shape) -> Type where\n MkConjugateGPR : (Tensor [p] Double -> GaussianProcess features) -> Tensor [p] Double\n -> Tensor [] Double -> ConjugateGPRegression features\n\n||| Construct a probabilistic model for the latent target values.\nexport\npredict_latent : ConjugateGPRegression features\n -> ProbabilisticModel features {marginal=Gaussian [1]}\npredict_latent (MkConjugateGPR mk_gp gp_params _) x =\n let (MkGP meanf kernel) = mk_gp gp_params\n in MkGaussian (expand 1 $ meanf x) (expand 2 $ kernel x x)\n\n||| Fit the Gaussian process and noise to the specified data.\nexport\nfit : ConjugateGPRegression features\n -> (forall n . Tensor [n] Double -> Optimizer $ Tensor [n] Double)\n -> Dataset features [1]\n -> ConjugateGPRegression features\nfit (MkConjugateGPR {p} mk_prior gp_params noise) optimizer (MkDataset x y) =\n let objective : Tensor [S p] Double -> Tensor [] Double\n objective params = let (noise, prior_params) = split 1 params\n in log_marginal_likelihood (mk_prior prior_params)\n (squeeze noise) (x, squeeze y)\n\n (noise, gp_params) := split 1 $ optimizer (concat (expand 0 noise) gp_params) objective\n\n mk_posterior : Tensor [p] Double -> GaussianProcess features\n mk_posterior params' = posterior (mk_prior params') (squeeze noise) (x, squeeze y)\n\n in MkConjugateGPR mk_posterior gp_params (squeeze noise)\n", "meta": {"hexsha": "f2b453d66a591de14c7f0b940214b30db95d2b18", "size": 4351, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Model/GaussianProcess.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/GaussianProcess.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/GaussianProcess.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.287037037, "max_line_length": 99, "alphanum_fraction": 0.7101815675, "num_tokens": 1103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.6723316860482763, "lm_q1q2_score": 0.6248922350908364}} {"text": "-- | Exercises on Ranges\nmodule Koans.Ranges\n\nrangeNums : Bool\nrangeNums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] == [1..13]\n\nstepUp : Bool\nstepUp = [3, 6, 9, 12, 15, 18] == [3,6..20]\n\n-- stepDown : Bool\n-- stepDown = False == [20,17..1]\n\nstopMe : List Integer\nstopMe = take 5 [1..]\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "af0c33c0ef868a16d6996194a426e107871a390e", "size": 370, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "list-expansion/Idris/idris-koans-master/Koans/04-Ranges.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/04-Ranges.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/04-Ranges.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.7647058824, "max_line_length": 80, "alphanum_fraction": 0.4513513514, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6247108396764288}} {"text": "module Sub06LTE108t27\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\n\n%default total\n\n\n-- 6(18t+4)+3 --CF[4,1,-2]--> 6(16t+3)+3\nexport\nlte108t27 : (l : Nat) -> LTE (S (S (S (S (l+l+l+l)+(l+l+l+l)+(l+l+l+l)+(l+l+l+l)))))\n (S ((S ((l+l+l)+(l+l+l))) + (S ((l+l+l)+(l+l+l))) + (S ((l+l+l)+(l+l+l)))))\nlte108t27 Z = (LTESucc . LTESucc . LTESucc . LTESucc) LTEZero\nlte108t27 (S l) =\n let lemma = lte108t27 l in\n\n rewrite (sym (plusSuccRightSucc l l)) in\n\n rewrite (sym (plusSuccRightSucc (plus l l) l)) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l) l)) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) l)\n (S (S (S (plus (plus (plus l l) l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) l)\n (S (S (plus (plus (plus l l) l) l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) l)\n (S (plus (plus (plus l l) l) l)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) l)\n (plus (plus (plus l l) l) l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (S (S (S (plus (plus (plus l l) l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (S (S (plus (plus (plus l l) l) l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (S (plus (plus (plus l l) l) l)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (plus (plus (plus l l) l) l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (plus (plus (plus l l) l) l))\n (S (S (S (plus (plus (plus l l) l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (plus (plus (plus l l) l) l))\n (S (S (plus (plus (plus l l) l) l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (plus (plus (plus l l) l) l))\n (S (plus (plus (plus l l) l) l)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus (plus l l) l) l) (plus (plus (plus l l) l) l))\n (plus (plus (plus l l) l) l))\n (plus (plus (plus l l) l) l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l)\n (S (S (plus (plus l l) l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l)\n (S (plus (plus l l) l)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) l)\n (plus (plus l l) l))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (S (S (plus (plus (plus l l) l) (plus (plus l l) l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (S (plus (plus (plus l l) l) (plus (plus l l) l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))) in\n\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))\n (S (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l)\n l)))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))\n (S (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l)\n l))))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))\n (S (S (S (S (plus (plus (plus l l) l) (plus (plus l l)\n l)))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))\n (S (S (S (plus (plus (plus l l) l) (plus (plus l l)\n l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))\n (S (S (plus (plus (plus l l) l) (plus (plus l l)\n l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus l l) l) (plus (plus l l) l))\n (S (plus (plus (plus l l) l) (plus (plus l l) l))))\n (S (plus (plus (plus l l) l) (plus (plus l l)\n l))))) in\n\n (lteSuccRight . lteSuccRight . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "3847256ea7a8115a2265f5d33b69194dd4a73a68", "size": 6673, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program3/Sub06LTE108t27.idr", "max_stars_repo_name": "righ1113/collatzProof_DivSeq", "max_stars_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program3/Sub06LTE108t27.idr", "max_issues_repo_name": "righ1113/collatzProof_DivSeq", "max_issues_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-26T12:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-19T07:02:00.000Z", "max_forks_repo_path": "program3/Sub06LTE108t27.idr", "max_forks_repo_name": "righ1113/collatzProof_DivSeq", "max_forks_repo_head_hexsha": "eef9da457fe77f0b58fb4407ab128d38ada9071e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.786407767, "max_line_length": 199, "alphanum_fraction": 0.4251461112, "num_tokens": 2038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.6893056231680121, "lm_q1q2_score": 0.6245038829723321}} {"text": "module CosetRep\n\nimport Group\nimport Cosets\n%access public export\n\n--Generates (equivalent) representatives of the image in g of a\n--coset (element of the transversal type) in the transversal type\nrepgen: (trav: Type) -> Transversal trav -> (y: trav) -> trav\nrepgen trav (MkTransversal h (MkGroup h (+) pfh) g (MkGroup g (*) pfg) sbgrp trav pftrav) y = (DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) (f y)) )) where\n f: trav -> g\n f = DPair.fst pftrav\n incl: h->g\n incl = DPair.fst sbgrp\n\n--Proof of uniqueness of the coset representative in trav, in the following sense\n--Proof that the operation that generates coset representative in trav for an\n--element of g (from CosetAll) inverts the function generating a coset representative by going from trav to g (from IsTraversal)\nCorepFinv: (trav: Type) -> (pft: Transversal trav) -> (y: trav) -> (repgen trav pft y = y)\nCorepFinv trav (MkTransversal h (MkGroup h (+) pfh) g (MkGroup g (*) pfg) sbgrp trav pftrav)\n y = (sym (\n (Basics.fst (DPair.snd pftrav)) y rep (p ** (sym (DPair.snd (DPair.snd ((Basics.snd (DPair.snd pftrav)) (f y)) ))))\n )) where\n rep: trav\n rep = (DPair.fst (DPair.snd ((Basics.snd (DPair.snd pftrav)) ((DPair.fst pftrav) y) ) ))\n f: trav -> g\n f = (DPair.fst pftrav)\n p: h\n p = (DPair.fst ((Basics.snd (DPair.snd pftrav)) (f y)))\n", "meta": {"hexsha": "f5d1d579ce1aa1260e1daf8a6ef3c1b3826b0c27", "size": 1338, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Group.CosetRep.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.CosetRep.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.CosetRep.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": 44.6, "max_line_length": 165, "alphanum_fraction": 0.6748878924, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6245034371967721}} {"text": "module Chapter11\n\ndata InfList : Type -> Type where\n (::) : (value: elem) -> Inf (InfList elem) -> InfList elem\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 :: x) = value :: getPrefix k ?hole\n", "meta": {"hexsha": "a11c7894effdd378e0c376fb0f052fdd1d91c5e7", "size": 326, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter11.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": "Chapter11.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": "Chapter11.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": 27.1666666667, "max_line_length": 60, "alphanum_fraction": 0.6380368098, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6243340446387966}} {"text": "> module Fraction.BasicProperties\n\n> import Syntax.PreorderReasoning\n\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.Normal\n> import Nat.LTProperties\n> import PNat.PNat\n> import PNat.Operations\n> import PNat.Properties\n> import Nat.Positive\n> import Basic.Operations\n> import Nat.Coprime\n> import Nat.CoprimeProperties\n> import Nat.OperationsProperties\n\n> %default total\n> -- %access export\n> %access public export\n\n\nProperties of |num|, |den|, |fromNat|:\n\n> ||| Denominators of fractions are greater than zero\n> denLTLemma : (x : Fraction) -> Z `LT` den x\n> denLTLemma x = s2 where\n> s1 : Z `LT` toNat (snd x)\n> s1 = toNatLTLemma (snd x)\n> s2 : Z `LT` den x\n> s2 = replace {P = \\ ZUZU => Z `LT` ZUZU} Refl s1\n\n\n> |||\n> fromNatNormal : {n : Nat} -> Normal (fromNat n)\n> fromNatNormal = MkNormal anyCoprimeOne\n\n\n> {-\n> ||| Fraction is an instance of Show\n> instance Show Fraction where\n> show q = show (num q) ++ \"/\" ++ show (den q)\n> -}\n\n\n> ||| Fraction is an instance of Num\n> implementation Num Fraction where\n> (+) = plus\n> (*) = mult\n> fromInteger = fromNat . fromIntegerNat\n\n\nProperties of |plus|:\n\n> ||| Addition is commutative\n> plusCommutative : (x : Fraction) -> (y : Fraction) -> x + y = y + x\n> plusCommutative (m, d') (n, e') =\n> let d = toNat d' in\n> let e = toNat e' in\n> ( (m, d') + (n, e') )\n> ={ Refl }=\n> ( (m * e + n * d, d' * e') )\n> ={ cong2 (plusCommutative (m * e) (n * d)) (multCommutative d' e') }=\n> ( (n * d + m * e, e' * d') )\n> ={ Refl }=\n> ( (n, e') + (m, d') )\n> QED\n\n\n> ||| 0 is neutral element of addition\n> plusZeroRightNeutral : (x : Fraction) -> x + 0 = x\n> plusZeroRightNeutral (n, d') =\n> let d = toNat d' in\n> ( (n, d') + 0 )\n> ={ Refl }=\n> ( (n, d') + fromNat (fromIntegerNat 0) )\n> ={ Refl }=\n> ( (n, d') + fromNat 0 )\n> ={ Refl }=\n> ( (n, d') + (0, Element 1 MkPositive) )\n> ={ Refl }=\n> ( (n * 1 + 0 * d, d' * (Element 1 MkPositive)) )\n> ={ cong2 (multOneRightNeutralPlusMultZeroLeftZero n d) (multOneRightNeutral d') }=\n> ( (n, d') )\n> QED\n\n\n> ||| 0 is neutral element of addition\n> plusZeroLeftNeutral : (x : Fraction) -> 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\n> ||| Addition is associative\n> plusAssociative : (x : Fraction) -> (y : Fraction) -> (z : Fraction) -> x + (y + z) = (x + y) + z\n> plusAssociative (m, d') (n, e') (o, f') = \n> let d = toNat d' in\n> let e = toNat e' in\n> let f = toNat f' in\n> ( (m, d') + ((n, e') + (o, f')) )\n> ={ Refl }=\n> ( (m, d') + (n * f + o * e, e' * f') )\n> ={ Refl }=\n> ( (m * (toNat (e' * f')) + (n * f + o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (m * (ZUZU) + (n * f + o * e) * d, d' * (e' * f'))} \n> toNatMultLemma }=\n> ( (m * (e * f) + (n * f + o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (m * (e * f) + ZUZU, d' * (e' * f'))} \n> (multDistributesOverPlusLeft (n * f) (o * e) d) }=\n> ( (m * (e * f) + ((n * f) * d + (o * e) * d), d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (ZUZU, d' * (e' * f'))}\n> (plusAssociative (m * (e * f)) ((n * f) * d) ((o * e) * d)) }=\n> ( ((m * (e * f) + (n * f) * d) + (o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => ((ZUZU + (n * f) * d) + (o * e) * d, d' * (e' * f'))}\n> (multAssociative m e f) }=\n> ( (((m * e) * f + (n * f) * d) + (o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (((m * e) * f + ZUZU) + (o * e) * d, d' * (e' * f'))}\n> (sym (multAssociative n f d)) }=\n> ( (((m * e) * f + n * (f * d)) + (o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (((m * e) * f + n * (ZUZU)) + (o * e) * d, d' * (e' * f'))}\n> (multCommutative f d) }=\n> ( (((m * e) * f + n * (d * f)) + (o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (((m * e) * f + ZUZU) + (o * e) * d, d' * (e' * f'))}\n> (multAssociative n d f) }=\n> ( (((m * e) * f + (n * d) * f) + (o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => (ZUZU + (o * e) * d, d' * (e' * f'))}\n> (sym (multDistributesOverPlusLeft (m * e) (n * d) f)) }=\n> ( ((m * e + n * d) * f + (o * e) * d, d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => ((m * e + n * d) * f + ZUZU, d' * (e' * f'))}\n> (sym (multAssociative o e d)) }=\n> ( ((m * e + n * d) * f + o * (e * d), d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => ((m * e + n * d) * f + o * (ZUZU), d' * (e' * f'))}\n> (multCommutative e d) }= \n> ( ((m * e + n * d) * f + o * (d * e), d' * (e' * f')) )\n> ={ cong {f = \\ ZUZU => ((m * e + n * d) * f + o * (d * e), ZUZU)}\n> (multAssociative d' e' f')}=\n> ( ((m * e + n * d) * f + o * (d * e), (d' * e') * f') )\n> ={ cong {f = \\ ZUZU => ((m * e + n * d) * f + o * (ZUZU), (d' * e') * f')}\n> (sym toNatMultLemma) }=\n> ( ((m * e + n * d) * f + o * (toNat (d' * e')), (d' * e') * f') )\n> ={ Refl }= \n> ( (m * e + n * d, d' * e') + (o, f') )\n> ={ Refl }=\n> ( ((m, d') + (n, e')) + (o, f') )\n> QED\n\n\nProperties of |mult|:\n\n> ||| Multiplication is commutative\n> multCommutative : (x : Fraction) -> (y : Fraction) -> x * y = y * x\n> multCommutative (m, d') (n, e') =\n> ( (m, d') * (n, e') )\n> ={ Refl }=\n> ( (m * n, d' * e') )\n> ={ cong2 (multCommutative m n) (multCommutative d' e') }=\n> ( (n * m, e' * d') )\n> ={ Refl }=\n> ( (n, e') * (m, d') )\n> QED\n\n\n> ||| 1 is neutral element of multiplication\n> multOneRightNeutral : (x : Fraction) -> x * 1 = x\n> multOneRightNeutral (n, d') =\n> let d = toNat d' in\n> ( (n, d') * 1 )\n> ={ Refl }=\n> ( (n, d') * (fromNat (fromIntegerNat 1)) )\n> ={ Refl }=\n> ( (n, d') * (fromNat 1) )\n> ={ Refl }=\n> ( (n, d') * (1, Element 1 MkPositive) )\n> ={ Refl }=\n> ( (n * 1, d' * (Element 1 MkPositive)) )\n> ={ cong2 (multOneRightNeutral n) (multOneRightNeutral d') }=\n> ( (n, d') )\n> QED\n\n\n> ||| 1 is neutral element of multiplication\n> multOneLeftNeutral : (x : Fraction) -> 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> {-\n\n> ---}\n\n", "meta": {"hexsha": "5970e5cec29c835ac72b9391d6271fa3664ed23a", "size": 6282, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fraction/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": "Fraction/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": "Fraction/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": 31.2537313433, "max_line_length": 99, "alphanum_fraction": 0.4310729067, "num_tokens": 2671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6242602384434123}} {"text": "import Data.Vect\n\ndata Ty = TyInt | TyBool | TyFun Ty Ty\n\ninterpTy : Ty -> Type\ninterpTy TyInt = Integer\ninterpTy TyBool = Bool\ninterpTy (TyFun a t) = interpTy a -> interpTy t\n\ndata HasType : (i : Fin n) -> Vect n Ty -> Ty -> Type where\n Stop : HasType FZ (t :: ctxt) t\n Pop : HasType k ctxt t -> HasType (FS k) (u :: ctxt) t\n\ndata Expr : Vect n Ty -> Ty -> Type where\n Var : HasType i ctxt t -> Expr ctxt t\n Val : (x : Integer) -> Expr ctxt TyInt\n Lam : Expr (a :: ctxt) t -> Expr ctxt (TyFun a t)\n App : Expr ctxt (TyFun a t) -> Expr ctxt a -> Expr ctxt t\n Op : (interpTy a -> interpTy b -> interpTy c) ->\n Expr ctxt a -> Expr ctxt b -> Expr ctxt c\n If : Expr ctxt TyBool ->\n Lazy (Expr ctxt a) ->\n Lazy (Expr ctxt a) -> Expr ctxt a\n\ndata Env : Vect n Ty -> Type where\n Nil : Env Nil\n (::) : interpTy a -> Env ctxt -> Env (a :: ctxt)\n\nlookup : HasType i ctxt t -> Env ctxt -> interpTy t\nlookup Stop (x :: xs) = x\nlookup (Pop k) (x :: xs) = lookup k xs\n\ninterp : Env ctxt -> Expr ctxt t -> interpTy t\ninterp env (Var i) = lookup i env\ninterp env (Val x) = x\ninterp env (Lam sc) = \\x => interp (x :: env) sc\ninterp env (App f s) = interp env f (interp env s)\ninterp env (Op op x y) = op (interp env x) (interp env y)\ninterp env (If x t e) = if interp env x then interp env t\n else interp env e\n\nadd : Expr ctxt (TyFun TyInt (TyFun TyInt TyInt))\nadd = Lam (Lam (Op (+) (Var Stop) (Var (Pop Stop))))\n\nfact : Expr ctxt (TyFun TyInt TyInt)\nfact = Lam (If (Op (==) (Var Stop) (Val 0))\n (Val 1)\n (Op (*) (App fact (Op (-) (Var Stop) (Val 1)))\n (Var Stop)))\n\nmain : IO ()\nmain = do putStr \"Enter a number: \"\n x <- getLine\n printLn (interp [] fact (cast x))\n\n\n\n", "meta": {"hexsha": "82fb451d5d4e0c175575bfecca6bf1c70c903693", "size": 1850, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/samples/Interp.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/Interp.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/Interp.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": 31.8965517241, "max_line_length": 61, "alphanum_fraction": 0.5454054054, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.6859494678483918, "lm_q1q2_score": 0.6241502215558289}} {"text": "||| An abstract Shape data type (from Listing 10.11).\nmodule Shape\n\n%access export\n-- %default total\n\n||| A shape is a triangle, rectangle or circle.\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\n--------------------------------------------------------------- [ Constructors ]\n-- Export functions for building shapes, rather than their constructors.\n\ntriangle : (base, height : Double) -> Shape\ntriangle = Triangle\n\nrectangle : (width, height : Double) -> Shape\nrectangle = Rectangle\n\ncircle : (radius : Double) -> Shape\ncircle = Circle\n\n---------------------------------------------------------- [ Exercise 10.3.4.2 ]\n\npublic export\ndata ShapeView : (shape : Shape) -> Type where\n STriangle : ShapeView (triangle base height)\n SRectangle : ShapeView (rectangle width height)\n SCircle : ShapeView (circle radius)\n\nshapeView : (shape : Shape) -> ShapeView shape\nshapeView (Triangle _ _) = STriangle\nshapeView (Rectangle _ _) = SRectangle\nshapeView (Circle _) = SCircle\n\narea : (shape : Shape) -> Double\narea shape with (shapeView shape)\n area (triangle base height) | STriangle = 0.5 * base * height\n area (rectangle width height) | SRectangle = width * height\n area (circle radius) | SCircle = pi * pow radius 2\n\n------------------------------------------------------------------------ [ EOF ]\n", "meta": {"hexsha": "65ad9aab267bef41a269d46531e4281fc6465d2e", "size": 1395, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Shape.idr", "max_stars_repo_name": "yurrriq/tdd-with-idris", "max_stars_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-15T01:29:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-15T01:29:36.000Z", "max_issues_repo_path": "src/Shape.idr", "max_issues_repo_name": "yurrriq/tdd-with-idris", "max_issues_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-11-21T23:42:45.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-01T05:43:10.000Z", "max_forks_repo_path": "src/Shape.idr", "max_forks_repo_name": "yurrriq/tdd-with-idris", "max_forks_repo_head_hexsha": "873c6c719706d06179527c5d93982bb7c184da90", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7045454545, "max_line_length": 80, "alphanum_fraction": 0.5849462366, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6240982574637786}} {"text": "module VectRankedElem\n\nimport Data.Vect\nimport Decidable.Order\n\n%default total\n\npublic export\ndata RankedElem : ty -> Vect _ ty -> (idx : Nat) -> Type where\n Here : {v : Vect (S _) ty} -> RankedElem (head v) v Z\n There : RankedElem a xs idx -> RankedElem a (x::xs) (S idx)\n\nexport\nindexSmallerThanSize : {v : Vect size ty} -> {idx : Nat} -> RankedElem x v idx -> LT idx size\nindexSmallerThanSize {size = Z} _ impossible\nindexSmallerThanSize {size = S len} Here = shift Z len zeroAlwaysSmaller\nindexSmallerThanSize {size = S len} {v = (x::xs)} {idx = S n} (There elem)\n = shift (S n) len $ indexSmallerThanSize elem\n\nexport\nUninhabited (RankedElem _ [] _) where\n uninhabited _ impossible\n\nexport\ncons_ : (x : ty) -> (v : Vect size ty)\n -> (ret : Vect (S size) ty\n ** ({a : ty} -> {n : Nat} -> RankedElem a v n -> RankedElem a ret (S n),\n RankedElem x ret Z))\ncons_ x [] = ([x] ** (absurd, Here))\ncons_ x (y::ys) = (x::y::ys ** (f, Here))\n where f : {a : ty} -> {n : Nat} -> RankedElem a (y::ys) n -> RankedElem a (x::y::ys) (S n)\n f elem = There elem\n\nexport\ncons : ty -> Vect size ty -> Vect (S size) ty\ncons x v = fst $ cons_ x v\n\nexport\nconcat_ : {size1, size2 : Nat}\n -> (v1 : Vect size1 ty) -> (v2 : Vect size2 ty)\n -> (ret : Vect (size1 + size2) ty\n ** ({a : ty} -> {n : Nat} -> RankedElem a v1 n -> RankedElem a ret n,\n {a : ty} -> {n : Nat} -> RankedElem a v2 n -> RankedElem a ret (size1 + n)))\nconcat_ [] ys = (ys ** (absurd, id))\nconcat_ {size1} xs [] = rewrite plusZeroRightNeutral size1 in\n (xs ** (id, absurd))\nconcat_ (x::xs) (y::ys) = let (ret ** (f, g)) = xs `concat_` (y::ys) in\n (x :: ret ** (ff f, gg g))\n where ff : {ret : Vect (size1 + size2) ty}\n -> ({a : ty} -> {n : Nat} -> RankedElem a xs n -> RankedElem a ret n)\n -> {a : ty} -> {n : Nat} -> (RankedElem a (x::xs) n -> RankedElem a (x::ret) n)\n ff f Here = Here\n ff f (There elem) = There $ f elem\n gg : {ret : Vect (size1 + size2) ty}\n -> ({a : ty} -> {n : Nat} -> RankedElem a (y::ys) n -> RankedElem a ret (size1 + n))\n -> {a : ty} -> {n : Nat} -> (RankedElem a (y::ys) n -> RankedElem a (x::ret) (S $ size1 + n))\n gg g elem = There $ g elem\n\nexport\nconcat : {size1, size2 : Nat} -> Vect size1 ty -> Vect size2 ty -> Vect (size1 + size2) ty\nconcat v1 v2 = fst $ concat_ v1 v2\n\nexport\nrev_ : {size : Nat} -> (orig : Vect size ty)\n -> (ret : Vect size ty ** {a : ty} -> {n : Nat} -> RankedElem a orig n -> RankedElem a ret (size `minus` (S n)))\nrev_ [] = ([] ** absurd)\nrev_ ((::) {len} x xs) = rewrite plusCommutative 1 len in\n let (sx ** h) = rev_ xs\n (ret ** (f, g)) = sx `concat_` [x] in\n (ret ** fgh f g h)\n where fgh : ({a : ty} -> {n : Nat} -> RankedElem a sx n -> RankedElem a ret n)\n -> ({a : ty} -> {n : Nat} -> RankedElem a [x] n -> RankedElem a ret (len + n))\n -> ({a : ty} -> {n : Nat} -> RankedElem a xs n -> RankedElem a sx (len `minus` (S n)))\n -> {a : ty} -> {n : Nat} -> RankedElem a (x::xs) n -> RankedElem a ret (len `minus` n)\n fgh f g h Here = rewrite minusZeroRight len in\n rewrite sym $ plusZeroRightNeutral len in\n g Here\n fgh f g h (There elem) = f $ h elem\n\nexport\nrev : {size : Nat} -> Vect size ty -> Vect size ty\nrev v = fst $ rev_ v", "meta": {"hexsha": "65399ce994a5cc77c8fe8a8b3e3429b447253d81", "size": 3929, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/VectRankedElem.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/VectRankedElem.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/VectRankedElem.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": 47.9146341463, "max_line_length": 127, "alphanum_fraction": 0.463985747, "num_tokens": 1166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6240293073332959}} {"text": "Shape : Nat -> Type\nShape n = Vect n Nat\n\nVector : Shape n -> Type -> Type\nVector Nil t = t\nVector (v::vs) t = Vect v (Array vs t) \n", "meta": {"hexsha": "61f78ab1d088d34dfb0f51156252e1eecfef365f", "size": 132, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "proposal/code/vector.idr", "max_stars_repo_name": "RossMeikleham/MSci-Project", "max_stars_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-20T11:17:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-20T11:17:45.000Z", "max_issues_repo_path": "proposal/code/vector.idr", "max_issues_repo_name": "RossMeikleham/MSci-Project", "max_issues_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proposal/code/vector.idr", "max_forks_repo_name": "RossMeikleham/MSci-Project", "max_forks_repo_head_hexsha": "4e1e3e08bf8440add18b4a87b96ca42920336e14", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.8571428571, "max_line_length": 39, "alphanum_fraction": 0.6060606061, "num_tokens": 44, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.6791787056691698, "lm_q1q2_score": 0.6238122233197937}} {"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\nFunctor Expr where\n map f (Val x) = Val (f x)\n map f (Add x y) = Add (map f x) (map f y)\n map f (Sub x y) = Sub (map f x) (map f y)\n map f (Mul x y) = Mul (map f x) (map f y)\n map f (Div x y) = Div (map f x) (map f y)\n map f (Abs x) = Abs (map f x)\n", "meta": {"hexsha": "8abfc070236c52ae66971cc7df46084db5a02bcf", "size": 898, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter7/Exercises/ex_7_3_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": "Chapter7/Exercises/ex_7_3_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": "Chapter7/Exercises/ex_7_3_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": 27.2121212121, "max_line_length": 49, "alphanum_fraction": 0.5011135857, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.6584175072643413, "lm_q1q2_score": 0.6237722661881019}} {"text": "module Tree\n\nimport Data.List\n\n%default total\n\n{-\n interface Functor (f : Type -> Type) where\n map : (func : a -> b) -> f a -> f b\n\n Functor List where\n map func [] = []\n map func (x :: xs) = f x :: map func xs\n\n-}\n\ninterface MyFunctor f where\n myMap : (a -> b) -> f a -> f b\n\nMyFunctor List where\n myMap func [] = []\n myMap func (x :: xs) = func x :: myMap func xs\n\ndata Tree elem = Empty \n | Node (Tree elem) elem (Tree elem)\n\nFunctor Tree where\n map func Empty = Empty\n map func (Node l v r) = Node (map func l) (func v) (map func r)\n\npartial\nfromList : List a -> Tree a\nfromList [] = Empty\nfromList (x :: xs) = Node (fromList left) x (fromList right)\n where\n len : Nat\n len = fromInteger $ natToInteger (length xs) `div` 2\n\n left : List a\n left = take len xs\n\n right : List a \n right = drop len xs\n\n{-\n Functor (Vect n) where \n map func [] = []\n map func (x :: xs) = func x :: map func xs\n\n-}\n\n{-\n foldr : Foldable t => (a -> b -> b) -> b -> t a -> b\n foldl : Foldable t => (b -> a -> b) -> b -> t a -> b\n\n-}\n\nsampleTree : Tree Int\nsampleTree = Node (Node (Node Empty 1 Empty) 2 (Node Empty 3 Empty)) 4 (Node (Node Empty 5 Empty) 6 (Node Empty 7 Empty))\n\nFoldable Tree where\n foldr func acc Empty = acc\n foldr func acc (Node l v r) = let rightFold = foldr func acc r\n leftFold = foldr func rightFold l in\n func v leftFold", "meta": {"hexsha": "0b1d4d89554ed41a08cd176eaf3dd62ef48eb7fe", "size": 1455, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter7/Tree.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": "chapter7/Tree.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": "chapter7/Tree.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": 22.3846153846, "max_line_length": 121, "alphanum_fraction": 0.560137457, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971212, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6237014274919206}} {"text": "module STLC\nimport Data.Fin\nimport Data.Vect\n\ndata Ty = TyInt | TyBool | TyFun Ty Ty\n\ninterpTy : Ty -> Type\ninterpTy TyInt = Int\ninterpTy TyBool = Bool\ninterpTy (TyFun A T) = interpTy A -> interpTy T\n\nusing (G:Vect n Ty)\n data HasType : (i : Fin n) -> Vect n Ty -> Ty -> Type where\n Stop : HasType FZ (t :: G) t\n Pop : HasType k G t -> HasType (FS k) (u :: G) t\n \n data Expr : Vect n Ty -> Ty -> Type where\n Var : HasType i G t -> Expr G t\n Val : (x : Int) -> Expr G TyInt\n Lam : Expr (a :: G) t -> Expr G (TyFun a t)\n App : Expr G (TyFun a t) -> Expr G a -> Expr G t\n Op : (interpTy a -> interpTy b -> interpTy c) ->\n Expr G a -> Expr G b -> Expr G c\n If : Expr G TyBool -> Lazy (Expr G a) -> Lazy (Expr G a) -> Expr G a\n \n data Env : Vect n Ty -> Type where\n Nil : Env Nil\n (::) : interpTy a -> Env G -> Env (a :: G)\n \n lookup : HasType i G t -> Env G -> interpTy t\n lookup Stop (x :: xs) = x\n lookup (Pop k) (x :: xs) = lookup k xs\n \n interp : Env G -> Expr G t -> interpTy t\n interp env (Var i) = lookup i env\n interp env (Val x) = x\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 interp env (If x t e) = if interp env x then interp env t\n else interp env e\n \n-- Unit Tests\n sub1 : Expr G (TyFun TyInt TyInt)\n sub1 = Lam (Op (-) (Var Stop) (Val 1))\n \n sub2 : Expr G (TyFun TyInt TyInt)\n sub2 = Lam (App sub1 (App sub1 (Var Stop)))\n \n add : Expr G (TyFun TyInt (TyFun TyInt TyInt))\n add = Lam (Lam (Op (+) (Var Stop) (Var (Pop Stop))))\n\n fact : Expr G (TyFun TyInt TyInt)\n fact = Lam (If (Op (==) (Var Stop) (Val 0))\n (Val 1)\n (Op (*) (App fact (Op (-) (Var Stop) (Val 1)))\n (Var Stop)))\n \n fib : Expr G (TyFun TyInt TyInt)\n fib = Lam (If (Op (==) (Var Stop) (Val 0))\n (Val 1)\n (If (Op (==) (Var Stop) (Val 1))\n (Val 1)\n (Op (*) (App fib (App sub1 (Var Stop)))\n (App fib (App sub2 (Var Stop))))))\n \n \n \n", "meta": {"hexsha": "fb834a3aad3d1677c4a7a3e248129749d48b751c", "size": 2348, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/STLC.idr", "max_stars_repo_name": "akuhlens/metaprogramming", "max_stars_repo_head_hexsha": "785793afa547bf1e0fa6c856c2fc4a3050e81fae", "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/STLC.idr", "max_issues_repo_name": "akuhlens/metaprogramming", "max_issues_repo_head_hexsha": "785793afa547bf1e0fa6c856c2fc4a3050e81fae", "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/STLC.idr", "max_forks_repo_name": "akuhlens/metaprogramming", "max_forks_repo_head_hexsha": "785793afa547bf1e0fa6c856c2fc4a3050e81fae", "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.0289855072, "max_line_length": 73, "alphanum_fraction": 0.4740204429, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.623386849521149}} {"text": "data 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\n{- 3 and 4-}\n\nvectTake : (n : Nat) -> Vect (n + m) a -> Vect n a\nvectTake Z xs = []\nvectTake (S k) (x :: xs) = x :: vectTake k xs\n", "meta": {"hexsha": "dd581c655ba14576698ffd9b74661959f76ace4b", "size": 268, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/Exercises/ex_4_2_3.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": "Chapter4/Exercises/ex_4_2_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": "Chapter4/Exercises/ex_4_2_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": 22.3333333333, "max_line_length": 54, "alphanum_fraction": 0.4850746269, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6233318732487381}} {"text": "import STLC\n\nnamespace Example\n nat : Typ\n nat = Arrow (Arrow Base Base) (Arrow Base Base)\n\n zero : Term\n zero = Abs \"s\" (Arrow Base Base) \n (Abs \"z\" Base \n (Var \"z\"))\n \n suc : Term\n suc = Abs \"n\" nat\n (Abs \"s\" (Arrow Base Base) \n (Abs \"z\" Base \n (App (Var \"s\") \n (App (App (Var \"n\") \n (Var \"s\")) \n (Var \"z\")))))\n\n one : Term\n one = App suc zero\n\n plus : Term\n plus = \n Abs \"m\" nat\n (Abs \"n\" nat\n (Abs \"s\" (Arrow Base Base) \n (Abs \"z\" Base \n (App (App (Var \"m\") \n (Var \"s\")) \n (App (App (Var \"n\") \n (Var \"s\")) \n (Var \"z\"))))))\n example : Term\n example = App (App plus one) one\n", "meta": {"hexsha": "886865989323f0c408987cb2346aa07e8d0ddfe1", "size": 980, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Example.idr", "max_stars_repo_name": "Gwin73/idris-stlc", "max_stars_repo_head_hexsha": "fc715710b9f3ba8bb6746ec887dcf9eb4cc0bcfe", "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/Example.idr", "max_issues_repo_name": "Gwin73/idris-stlc", "max_issues_repo_head_hexsha": "fc715710b9f3ba8bb6746ec887dcf9eb4cc0bcfe", "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/Example.idr", "max_forks_repo_name": "Gwin73/idris-stlc", "max_forks_repo_head_hexsha": "fc715710b9f3ba8bb6746ec887dcf9eb4cc0bcfe", "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.4864864865, "max_line_length": 51, "alphanum_fraction": 0.3173469388, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.6859494614282923, "lm_q1q2_score": 0.623265960439985}} {"text": "module HackyLang\n-- Warning: only briefly tested, may have bugs\n\n-- An expression\ndata Exp : Type where\n N : Nat -> Exp -- a literal natural number\n B : Bool -> Exp -- a literal boolean\n LTE : Exp -> Exp -> Exp\n EQ : Exp -> Exp -> Exp\n If : Exp -> Exp -> Exp -> Exp -- if expression\n Var : (name: String) -> Exp -- a variable\n Lam : (var : Exp) -> (value : Exp) -> Exp -- a lambda expression\n App : (f : Exp ) -> (arg: Exp) -> Exp -- function application\n Sum : Exp -> Exp -> Exp -- sum\n Prod: Exp -> Exp -> Exp -- product\n Pred: Exp -> Exp -- predecessor of a natural number\n Null : Exp\n Cons: Exp -> Exp -> Exp\n Left: Exp -> Exp\n Right : Exp -> Exp\n\n-- substitute `x` by `y` in `base`\nsubs: (base: Exp) -> (x: Exp) -> (y: Exp) -> Exp\nsubs (N k) x y = N k\nsubs (B z) x y = B z\nsubs (LTE z w) x y = LTE (subs z x y) (subs w x y)\nsubs (EQ z w) x y = EQ (subs z x y) (subs w x y)\nsubs (If z w s) x y =\n If (subs z x y) (subs w x y) (subs s x y)\nsubs (Var name) (Var other) y =\n if name == other\n then y\n else Var name\nsubs (Var name) x y = Var name\nsubs (Lam var value) x y =\n Lam (subs var x y) (subs value x y)\nsubs (App f arg) x y =\n App (subs f x y) (subs arg x y)\nsubs (Sum z w) x y = Sum (subs z x y) (subs w x y)\nsubs (Pred z) x y = Pred (subs z x y)\nsubs (Prod z w) x y = Prod (subs z x y) (subs w x y)\nsubs Null x y = Null\nsubs (Left a) x y = Left (subs a x y)\nsubs (Right a) x y = Right (subs a x y)\nsubs (Cons a b) x y = Cons (subs a x y) (subs b x y)\n\ndata Defn : Type where\n Let : (name: String) -> (value: Exp) -> Defn\n\n-- A list of definitions of variables\nContext : Type\nContext = List Defn\n\nvarValue: Context -> (name: String) -> Maybe (Exp)\nvarValue [] name = Nothing\nvarValue ((Let x value) :: xs) name =\n if x == name then Just value else Nothing\n\n{-\nSimplify an expression in context by one step if possible. The simplifications are:\n * if an expression is a variable defined in the context, it is replaced by its value\n * sums, products and predecessors of _literals_ are simplifed, e.g. `Sum (N 2) (N 3)` becomes `N 5`\n * a lambda function `x :-> y` applied to `z` simplifies to the result of subtituting `x` by `z` in `y`.\n * for any other composite term, we simplify the components.\n-}\nsimplify : (ctx: Context) -> (exp : Exp) -> Exp\nsimplify ctx (N k) = N k\nsimplify ctx (B x) = B x\nsimplify ctx Null = Null\nsimplify ctx (LTE (N x) (N y)) = B (x <= y)\nsimplify ctx (LTE x y) = LTE (simplify ctx x) (simplify ctx y)\nsimplify ctx (EQ (N x) (N y)) = B (x == y)\nsimplify ctx (EQ (B x) (B y)) = B (x == y)\nsimplify ctx (EQ Null Null) = B True\nsimplify ctx (EQ Null (N _)) = B False\nsimplify ctx (EQ Null (B _)) = B False\nsimplify ctx (EQ Null (Cons _ _)) = B False\nsimplify ctx (EQ (N _) Null) = B False\nsimplify ctx (EQ (B _) Null) = B False\nsimplify ctx (EQ (Cons _ _) Null) = B False\nsimplify ctx (EQ (B _) (N _)) = B False\nsimplify ctx (EQ (N _) (B _)) = B False\nsimplify ctx (EQ x y) = EQ (simplify ctx x) (simplify ctx y)\nsimplify ctx (If (B True) y z) = y\nsimplify ctx (If (B False) y z) = z\nsimplify ctx (If x y z) = If (simplify ctx x) (simplify ctx y) (simplify ctx z)\nsimplify ctx (Var name) = (case varValue ctx name of\n Nothing => Var name\n (Just x) => x)\nsimplify ctx (Lam var value) = Lam var value\nsimplify ctx (App (Lam var value) arg) = subs value var arg\nsimplify ctx (App f arg) = App (simplify ctx f) (simplify ctx arg)\nsimplify ctx (Sum (N x) (N y)) = N (x + y)\nsimplify ctx (Sum x y) = Sum (simplify ctx x) (simplify ctx y)\nsimplify ctx (Pred (N x)) = N (pred x)\nsimplify ctx (Pred x) = Pred (simplify ctx x)\nsimplify ctx (Prod (N x) (N y)) = N (x * y)\nsimplify ctx (Prod x y) = Prod (simplify ctx x) (simplify ctx y)\nsimplify ctx (Left (Cons a b)) = a\nsimplify ctx (Right (Cons a b)) = b\nsimplify ctx (Left a) = Left (simplify ctx a)\nsimplify ctx (Right a) = Right (simplify ctx a)\nsimplify ctx (Cons a b) = Cons (simplify ctx a) (simplify ctx b)\n\n\ndata Program: Type where\n Code: (context: Context) -> (main: Exp) -> Program\n\n-- repeatedly simplify an expression till we get a literal natural (or loop forever)\ngetNat : Context -> Exp -> Nat\ngetNat ctx exp = case (simplify ctx exp) of\n (N k) => k\n x => getNat ctx x\n\nsteps: Context -> Exp -> Nat -> Exp\nsteps x y Z = y\nsteps x y (S k) = simplify x (steps x y k)\n\nrun: Program -> Exp -> Nat\nrun (Code context main) exp = getNat context (App main exp)\n\n-- An example\nnot: Exp\nnot = Lam (Var \"x\" ) (If (Var \"x\" ) (B False) (B True))\n\n-- a variable\nn: Exp\nn = Var \"n\"\n\n-- a variable for the factorial function\nfac : Exp\nfac = Var \"fac\"\n\n-- the expression `fac(n - 1)`\nprev: Exp\nprev = Prod (App fac (Pred n)) n\n\n-- the expression `if n == 0 then 1 else fac(n-1)`\nrhs : Exp\nrhs = If (EQ n (N Z)) (N 1) prev\n\n{- the context with definition:\n fac := n :-> (if (n == 0) then 1 else fac(n - 1)\n-}\nctx: Context\nctx = (Let \"fac\" (Lam n rhs)) :: []\n\n-- function computing factorial\nfacFn: Nat -> Nat\nfacFn n = getNat ctx (App fac (N n))\n\nfacProg: Program\nfacProg = Code ctx fac\n\n\n--- Another program, summing lists\nsm: Exp\nsm = Var \"sum\"\n\nl: Exp\nl = Var \"l\"\n\nsid: Exp\nsid = If (EQ Null l) (N 0) (Sum (Left l) (App sm (Right l)))\n\nsctx : Context\nsctx = (Let \"sum\" (Lam l sid)) :: []\n\nsumProg: Program\nsumProg = Code sctx sm\n\negList: Exp\negList = Cons (N 5) (Cons (N 3) (Cons (N 4) Null ))\n--- Run `run sumProg egList` to see lists being added\n", "meta": {"hexsha": "21f9f41bd5968c0416c5f5b5ab1d6dd54047748b", "size": 5508, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/HackyLang.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/HackyLang.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/HackyLang.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": 31.4742857143, "max_line_length": 105, "alphanum_fraction": 0.6047567175, "num_tokens": 1912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6231470237989502}} {"text": "||| Contains:\n|||\n||| 1. Tail recursive versions of the list processing functions from\n||| Data.List.\n|||\n||| 2. Extensional equality proofs that these variants are\n||| (extensionally) equivalent to their non-tail-recursive\n||| counterparts.\n|||\n||| Note:\n|||\n||| 1. Written in one sitting, feel free to refactor\n|||\n||| 2. The proofs below also work on non-publicly exported\n||| definitions. This could be due to a bug, and will need to be\n||| moved elsewhere if it's fixed.\nmodule Data.List.TailRec\n\nimport Syntax.PreorderReasoning\nimport Syntax.WithProof\n\nimport Data.List\nimport Data.List1\nimport Data.Vect\nimport Data.Nat\n\ntotal\nlengthAcc : List a -> Nat -> Nat\nlengthAcc [] acc = acc\nlengthAcc (_::xs) acc = lengthAcc xs $ S acc\n\nexport total\nlength : List a -> Nat\nlength xs = lengthAcc xs Z\n\ntotal\nlengthAccSucc : (xs : List a) -> (n : Nat) -> lengthAcc xs (S n) = S (lengthAcc xs n)\nlengthAccSucc [] _ = Refl\nlengthAccSucc (_::xs) n = rewrite lengthAccSucc xs (S n) in cong S Refl\n\nexport total\nlength_ext : (xs : List a) -> List.length xs = Data.List.TailRec.length xs\nlength_ext [] = Refl\nlength_ext (_::xs) = rewrite length_ext xs in sym $ lengthAccSucc xs Z\n\ntake_aux : Nat -> List a -> List a -> List a\ntake_aux Z xs acc = reverseOnto [] acc\ntake_aux (S n) [] acc = reverseOnto [] acc\ntake_aux (S n) (x :: xs) acc = take_aux n xs (x :: acc)\n\nexport\ntake : Nat -> List a -> List a\ntake n xs = take_aux n xs []\n\nexport\ntake_ext :\n (n : Nat) -> (xs : List a) ->\n Data.List.take n xs = Data.List.TailRec.take n xs\ntake_ext n xs = Calc $\n |~ Data.List.take n xs\n ~~ reverse [] ++ (Data.List.take n xs) ...( Refl )\n ~~ reverseOnto (Data.List.take n xs) [] ...( sym (revOnto (Data.List.take n xs) []) )\n ~~ take_aux n xs [] ...( sym (lemma n xs []) )\n where\n lemma : (n : Nat) -> (xs, acc : List a) ->\n take_aux n xs acc = reverseOnto (Data.List.take n xs) acc\n lemma Z xs acc = Refl\n lemma (S n) [] acc = Refl\n lemma (S n) (x::xs) acc = lemma n xs (x :: acc)\n\n\nspan_aux : (a -> Bool) -> List a -> List a -> (List a, List a)\nspan_aux p [] acc = (reverseOnto [] acc, [])\nspan_aux p (x::xs) acc =\n if p x then\n Data.List.TailRec.span_aux p xs (x :: acc)\n else\n (reverseOnto [] acc, x::xs)\n\nexport\nspan : (a -> Bool) -> List a -> (List a, List a)\nspan p xs = span_aux p xs []\n\ncoe : (f : (i : a) -> Type) -> i = i' -> f i -> f i'\ncoe f Refl x = x\n\nspan_aux_ext : (p : a -> Bool) -> (xs, acc : List a) ->\n (reverseOnto (fst $ Data.List.span p xs) acc, snd $ Data.List.span p xs)\n =\n span_aux p xs acc\nspan_aux_ext p [] acc = Refl\n-- This is disgusting. Please teach me a better way.\nspan_aux_ext p (x::xs) acc with (@@(p x), @@(Data.List.span p xs))\n span_aux_ext p (x::xs) acc | ((True ** px_tru), ((pre, rest)**dl_pf)) =\n rewrite px_tru in\n rewrite dl_pf in\n let u = span_aux_ext p xs (x::acc) in\n coe (\\u => (reverseOnto (x :: fst u) acc, snd u) =\n Data.List.TailRec.span_aux p xs (x :: acc)) dl_pf u\n span_aux_ext p (x::xs) acc | ((False**px_fls), ((pre,rest)**dl_pf)) =\n rewrite px_fls in\n Refl\n\nexport\nspan_ext : (p : a -> Bool) -> (xs : List a) ->\n Data.List.span p xs = Data.List.TailRec.span p xs\nspan_ext p xs with (@@(Data.List.span p xs))\n span_ext p xs | ((pre, rest) ** pf) =\n rewrite pf in\n let u = span_aux_ext p xs [] in\n coe (\\u => (fst u, snd u) = span_aux p xs []) pf u\n\nexport\nbreak : (a -> Bool) -> List a -> (List a, List a)\nbreak p xs = Data.List.TailRec.span (not . p) xs\n\nexport\nbreak_ext : (p : a -> Bool) -> (xs : List a) ->\n Data.List.break p xs = Data.List.TailRec.break p xs\nbreak_ext p xs = span_ext (not . p) xs\n\nsplitOnto : List (List a) -> (a -> Bool) -> List a -> List1 (List a)\nsplitOnto acc p xs =\n case Data.List.break p xs of\n (chunk, [] ) => reverseOnto [chunk] acc\n (chunk, (c::rest)) => splitOnto (chunk::acc) p rest\n\nexport\nsplit : (a -> Bool) -> List a -> List1 (List a)\nsplit p xs = splitOnto [] p xs\n\nsplitOnto_ext : (acc : List (List a)) -> (p : a -> Bool) -> (xs : List a) ->\n reverseOnto (Data.List.split p xs) acc\n = Data.List.TailRec.splitOnto acc p xs\nsplitOnto_ext acc p xs with (@@(Data.List.break p xs))\n splitOnto_ext acc p xs | ((chunk, [] )**pf) =\n rewrite pf in\n Refl\n splitOnto_ext acc p xs | ((chunk, c::rest)**pf) =\n rewrite pf in\n rewrite splitOnto_ext (chunk::acc) p rest in\n Refl\n\nexport\nsplit_ext : (p : a -> Bool) -> (xs : List a) ->\n Data.List.split p xs = Data.List.TailRec.split p xs\nsplit_ext p xs = splitOnto_ext [] p xs\n\n\nsplitAtOnto : List a -> (n : Nat) -> (xs : List a) -> (List a, List a)\nsplitAtOnto acc Z xs = (reverseOnto [] acc, xs)\nsplitAtOnto acc (S n) [] = (reverseOnto [] acc, [])\nsplitAtOnto acc (S n) (x::xs) = splitAtOnto (x::acc) n xs\n\nexport\nsplitAt : (n : Nat) -> (xs : List a) -> (List a, List a)\nsplitAt n xs = splitAtOnto [] n xs\n\nsplitAtOnto_ext : (acc : List a) -> (n : Nat) -> (xs : List a) ->\n (reverseOnto (fst $ Data.List.splitAt n xs) acc, snd $ Data.List.splitAt n xs)\n = splitAtOnto acc n xs\nsplitAtOnto_ext acc Z xs = Refl\nsplitAtOnto_ext acc (S n) [] = Refl\nsplitAtOnto_ext acc (S n) (x::xs) with (@@(Data.List.splitAt n xs))\n splitAtOnto_ext acc (S n) (x::xs) | ((tk, dr)**pf) =\n rewrite pf in\n let u = splitAtOnto_ext (x::acc) n xs in\n coe (\\u => (reverseOnto (x :: fst u) acc, snd u) =\n splitAtOnto (x :: acc) n xs) pf u\n\nexport\nsplitAt_ext : (n : Nat) -> (xs : List a) ->\n Data.List.splitAt n xs =\n Data.List.TailRec.splitAt n xs\nsplitAt_ext n xs with (@@(Data.List.splitAt n xs))\n splitAt_ext n xs | ((tk, dr)**pf) =\n rewrite pf in\n rewrite sym $ splitAtOnto_ext [] n xs in\n rewrite pf in\n Refl\n\npartitionOnto : List a -> List a -> (a -> Bool) -> List a -> (List a, List a)\npartitionOnto lfts rgts p [] = (reverseOnto [] lfts, reverseOnto [] rgts)\npartitionOnto lfts rgts p (x::xs) =\n if p x then\n partitionOnto (x :: lfts) rgts p xs\n else\n partitionOnto lfts (x::rgts) p xs\n\nexport\npartition : (a -> Bool) -> List a -> (List a, List a)\npartition p xs = partitionOnto [] [] p xs\n\npartitionOnto_ext : (lfts, rgts : List a) -> (p : a -> Bool) -> (xs : List a) ->\n (reverseOnto (fst $ Data.List.partition p xs) lfts\n ,reverseOnto (snd $ Data.List.partition p xs) rgts)\n = Data.List.TailRec.partitionOnto lfts rgts p xs\npartitionOnto_ext lfts rgts p [] = Refl\npartitionOnto_ext lfts rgts p (x::xs) with (@@(p x), @@(Data.List.partition p xs))\n partitionOnto_ext lfts rgts p (x::xs) | ((True **px_tru), ((dl_l, dl_r)**dl_pf))\n = rewrite px_tru in\n rewrite dl_pf in\n rewrite px_tru in\n let u = partitionOnto_ext (x :: lfts) rgts p xs in\n coe (\\u => (reverseOnto (x :: fst u) lfts\n ,reverseOnto ( snd u) rgts)\n = partitionOnto (x :: lfts) rgts p xs) dl_pf u\n\n partitionOnto_ext lfts rgts p (x::xs) | ((False**px_fls), ((dl_l, dl_r)**dl_pf))\n = rewrite px_fls in\n rewrite dl_pf in\n rewrite px_fls in\n let u = partitionOnto_ext lfts (x :: rgts) p xs in\n coe (\\u => (reverseOnto ( fst u) lfts\n ,reverseOnto (x :: snd u) rgts)\n = partitionOnto lfts (x::rgts) p xs) dl_pf u\n\nmergeReplicate_aux : a -> List a -> List a -> List a\nmergeReplicate_aux sep [] acc = reverseOnto [] acc\nmergeReplicate_aux sep (x::xs) acc = mergeReplicate_aux sep xs (x :: sep :: acc)\n\nmergeReplicate_ext : (sep : a) -> (xs : List a) -> (acc : List a) ->\n mergeReplicate_aux sep xs acc =\n reverseOnto (mergeReplicate sep xs) acc\nmergeReplicate_ext sep [] acc = Refl\nmergeReplicate_ext sep (x::xs) acc = Calc $\n |~ mergeReplicate_aux sep xs (x :: sep :: acc)\n ~~ reverseOnto (sep :: x :: mergeReplicate sep xs) acc\n ...( mergeReplicate_ext sep xs (x :: sep :: acc) )\n\nexport\nintersperse : a -> List a -> List a\nintersperse sep [] = []\nintersperse sep (y::ys) = y :: mergeReplicate_aux sep ys []\n\nexport\nintersperse_ext : (sep : a) -> (xs : List a) ->\n Data.List.intersperse sep xs =\n Data.List.TailRec.intersperse sep xs\nintersperse_ext sep [] = Refl\nintersperse_ext sep (y::ys) = cong (y::) (sym $ mergeReplicate_ext sep ys [])\n\nmapMaybeOnto : List b -> (a -> Maybe b) -> List a -> List b\nmapMaybeOnto acc f [] = reverseOnto [] acc\nmapMaybeOnto acc f (x::xs) =\n case f x of\n Nothing => mapMaybeOnto acc f xs\n Just y => mapMaybeOnto (y :: acc) f xs\n\nexport\nmapMaybe : (a -> Maybe b) -> List a -> List b\nmapMaybe f xs = mapMaybeOnto [] f xs\n\nmapMaybeOnto_ext : (acc : List b) -> (f : a -> Maybe b) -> (xs : List a) ->\n reverseOnto (Data.List.mapMaybe f xs) acc\n =\n mapMaybeOnto acc f xs\nmapMaybeOnto_ext acc f [] = Refl\nmapMaybeOnto_ext acc f (x::xs) with (f x)\n mapMaybeOnto_ext acc f (x::xs) | Nothing = mapMaybeOnto_ext acc f xs\n mapMaybeOnto_ext acc f (x::xs) | Just y = mapMaybeOnto_ext (y :: acc) f xs\n\nexport\nmapMaybe_ext : (f : a -> Maybe b) -> (xs : List a) ->\n Data.List.mapMaybe f xs = Data.List.TailRec.mapMaybe f xs\nmapMaybe_ext f xs = mapMaybeOnto_ext [] f xs\n\nexport\nsorted : Ord a => List a -> Bool\nsorted [ ] = True\nsorted [x] = True\nsorted (x :: xs@(y :: ys)) = case (x <= y) of\n False => False\n True => Data.List.TailRec.sorted xs\n\nexport\nsorted_ext : Ord a => (xs : List a) ->\n Data.List.sorted xs = Data.List.TailRec.sorted xs\nsorted_ext [] = Refl\nsorted_ext [x] = Refl\nsorted_ext (x :: y :: ys) with (x <= y)\n sorted_ext (x :: y :: ys) | False = Refl\n sorted_ext (x :: y :: ys) | True = sorted_ext (y::ys)\n\nmergeByOnto : List a -> (a -> a -> Ordering) -> List a -> List a -> List a\nmergeByOnto acc order [] right = reverseOnto right acc\nmergeByOnto acc order left [] = reverseOnto left acc\nmergeByOnto acc order left@(x::xs) right@(y::ys) =\n -- We need the variant annotations (bug #300)\n case order x y of\n LT => mergeByOnto (x :: acc) order (assert_smaller left xs) right\n _ => mergeByOnto (y :: acc) order left (assert_smaller right ys)\n\nmergeByOnto_ext : (acc : List a)\n -> (order : a -> a -> Ordering)\n -> (left, right : List a)\n -> reverseOnto (mergeBy order left right) acc\n = mergeByOnto acc order left right\nmergeByOnto_ext acc order [] right = Refl\nmergeByOnto_ext acc order left [] with( left)\n mergeByOnto_ext acc order _ [] | [] = Refl\n mergeByOnto_ext acc order _ [] | (_::_) = Refl\nmergeByOnto_ext acc order left@(x::xs) right@(y::ys) with (order x y)\n mergeByOnto_ext acc order left@(x::xs) right@(y::ys) | LT =\n mergeByOnto_ext (x :: acc) order xs (y::ys)\n -- We need to exhaust the two other cases explicitly to convince the\n -- typecheker. See #140\n mergeByOnto_ext acc order left@(x::xs) right@(y::ys) | EQ =\n mergeByOnto_ext (y :: acc) order (x::xs) ys\n mergeByOnto_ext acc order left@(x::xs) right@(y::ys) | GT =\n mergeByOnto_ext (y :: acc) order (x::xs) ys\n\nexport\nmergeBy : (a -> a -> Ordering) -> List a -> List a -> List a\nmergeBy order left right = mergeByOnto [] order left right\n\nexport\nmergeBy_ext : (order : a -> a -> Ordering) -> (left, right : List a) ->\n Data.List.mergeBy order left right =\n Data.List.TailRec.mergeBy order left right\nmergeBy_ext order left right = mergeByOnto_ext [] order left right\n\nexport\nmerge : Ord a => List a -> List a -> List a\nmerge = Data.List.TailRec.mergeBy compare\n\nexport\nmerge_ext : Ord a => (left, right : List a) ->\n Data.List.merge left right = Data.List.TailRec.merge left right\nmerge_ext left right = mergeBy_ext compare left right\n\n\n-- Not quite finished due to a bug.\n\nsortBy_splitRec : List a -> List a -> (List a -> List a) -> (List a, List a)\nsortBy_splitRec (_::_::xs) (y::ys) zs = sortBy_splitRec xs ys (zs . ((::) y))\nsortBy_splitRec _ ys zs = (zs [], ys)\n\nsortBy_split : List a -> (List a, List a)\nsortBy_split xs = sortBy_splitRec xs xs id\n\nexport\nsortBy : (cmp : a -> a -> Ordering) -> (xs : List a) -> List a\nsortBy cmp [] = []\nsortBy cmp [x] = [x]\nsortBy cmp zs = let (xs, ys) = sortBy_split zs in\n Data.List.TailRec.mergeBy cmp\n (Data.List.TailRec.sortBy cmp (assert_smaller zs xs))\n (Data.List.TailRec.sortBy cmp (assert_smaller zs ys))\n\n\n {- Can't really finish this proof because Data.List doesn't export the definition of sortBy. -}\n {-\nexport\nsortBy_ext : (cmp : a -> a -> Ordering) -> (xs : List a) ->\n Data.List.sortBy cmp xs = Data.List.TailRec.sortBy cmp xs\nsortBy_ext cmp [] = Refl\nsortBy_ext cmp [x] = Refl\nsortBy_ext cmp zs'@(z::zs) =\n Calc $\n |~ Data.List.sortBy cmp (z::zs)\n ~~ (let (xs, ys) = sortBy_split zs' in\n Data.List.mergeBy cmp\n (Data.List.sortBy cmp xs)\n (Data.List.sortBy cmp ys))\n ...( ?help0 )\n ~~\n let (xs, ys) = sortBy_split (z::zs) in\n Data.List.TailRec.mergeBy cmp\n (Data.List.TailRec.sortBy cmp xs)\n (Data.List.TailRec.sortBy cmp ys)\n ...( ?help1 )\n-}\n", "meta": {"hexsha": "82990a65011b95745ff3abee5ee7b429934a0df6", "size": 13266, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/List/TailRec.idr", "max_stars_repo_name": "yurrriq/Idris2-Erlang", "max_stars_repo_head_hexsha": "7b422b9bd179b061fe6d1bcf46e2f758eb7d16c1", "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/TailRec.idr", "max_issues_repo_name": "yurrriq/Idris2-Erlang", "max_issues_repo_head_hexsha": "7b422b9bd179b061fe6d1bcf46e2f758eb7d16c1", "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/TailRec.idr", "max_forks_repo_name": "yurrriq/Idris2-Erlang", "max_forks_repo_head_hexsha": "7b422b9bd179b061fe6d1bcf46e2f758eb7d16c1", "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.4705882353, "max_line_length": 96, "alphanum_fraction": 0.5992009649, "num_tokens": 4246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6228835031180681}} {"text": "module Intro\n\n% access public export\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\npublic export\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\noneLTEFour : LTE 1 4\noneLTEFour = LTESucc LTEZero\n\nfourMinusOne : Nat\nfourMinusOne = sub 4 1 oneLTEFour\n\nreflLTE : (n: Nat) -> LTE n n\nreflLTE Z = LTEZero\nreflLTE (S k) = LTESucc (reflLTE k)\n\nsillyZero: Nat -> Nat\nsillyZero n = sub n n (reflLTE n)\n\nidNat : Nat -> Nat\nidNat = \\x => x\n\nloop: Nat -> Nat\nloop k = loop (S k)\n", "meta": {"hexsha": "1106e1db6e0e0dbd2fadf4c004583908a8b49ce4", "size": 873, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Intro.idr", "max_stars_repo_name": "gitter-badger/LTS2019", "max_stars_repo_head_hexsha": "d5ddc0b685d3fe9079fc7308916dd14629bdadb5", "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/Intro.idr", "max_issues_repo_name": "gitter-badger/LTS2019", "max_issues_repo_head_hexsha": "d5ddc0b685d3fe9079fc7308916dd14629bdadb5", "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/Intro.idr", "max_forks_repo_name": "gitter-badger/LTS2019", "max_forks_repo_head_hexsha": "d5ddc0b685d3fe9079fc7308916dd14629bdadb5", "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.1176470588, "max_line_length": 53, "alphanum_fraction": 0.5704467354, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6225421833094954}} {"text": "> import Data.So\n\n> %default total\n\n> data LTE : Double -> Double -> Type where\n> MkLTE : {x : Double} -> {y : Double} -> So (x <= y) -> LTE x y\n\n> NonNegDouble : Type\n> NonNegDouble = Subset Double (\\ x => 0.0 `LTE` x)\n\n> zero : NonNegDouble\n> one : NonNegDouble\n> toDouble : NonNegDouble -> Double\n> toDouble = getWitness\n> plus : NonNegDouble -> NonNegDouble -> NonNegDouble\n> mult : NonNegDouble -> NonNegDouble -> NonNegDouble\n> div : NonNegDouble -> NonNegDouble -> NonNegDouble\n> fromNat : (n : Nat) -> NonNegDouble\n\n> implementation [NumNonNegDouble] Num NonNegDouble where\n> (+) = plus\n> (*) = mult\n> fromInteger = fromNat . fromIntegerNat\n\n> using implementation NumNonNegDouble\n> implementation [FractionalNonNegDouble] Fractional NonNegDouble where\n> (/) = div\n\n> implementation [EqNonNegDouble] Eq NonNegDouble where\n> (==) x y = (toDouble x) == (toDouble y)\n\n> using implementation EqNonNegDouble\n> implementation [OrdNonNegDouble] Ord NonNegDouble where\n> compare x y = compare (toDouble x) (toDouble y)\n", "meta": {"hexsha": "88c3945439d1f69e662d675bd01bc0f63f61ac29", "size": 1064, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegDouble/issues/implementation.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/issues/implementation.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/issues/implementation.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": 30.4, "max_line_length": 73, "alphanum_fraction": 0.6729323308, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.6688802471698041, "lm_q1q2_score": 0.6223651479161264}} {"text": "-- ---------------------------------------------------------------- [ Tree.idr ]\n-- Module : Tree.idr\n-- Copyright : (c) 2015,2016 See CONTRIBUTORS.md\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\n||| A Dependently Typed Implementation of an AVL Tree optimised for\n||| Dictionaries.\n|||\n||| This code is dervied from an original design by David\n||| Christiansen.\n|||\n||| *Note* When using this Data Structure, the design is such that the\n||| tree does not factor in unbalanced trees and so removal of items\n||| is not permited.\nmodule Data.AVL\n\n%default total\n%access export\n\nnamespace Core\n -- ------------------------------------------------------------- [ Definitions ]\n data Balance : Nat -> Nat -> Type where\n LHeavy : Balance (S n) n\n RHeavy : Balance n (S n)\n Balanced : Balance n n\n\n %name Balance b, bal\n\n ||| Indirection ensures that it reduces to at least S n' without\n ||| needing to case split on balance.\n |||\n ||| Should make proofs easier.\n height : Balance n m -> Nat\n height b = S (height' b)\n where\n height' : Balance n m -> Nat\n height' (LHeavy {n}) = S n\n height' (RHeavy {n}) = S n\n height' {n} (Balanced {n}) = n\n\n ||| The core tree key-value data structure used to represent an AVL\n ||| Tree.\n |||\n ||| This structure doesn't encode the invariants of the tree and is\n ||| *simply* a container. This structure ideally shouldn't be exposed\n ||| to the user at all. This structure should be used to build other\n ||| data structures. See the modules alongside this for appropriate\n ||| interfaces for using the tree.\n |||\n ||| @keyTy The type associated with the key.\n ||| @valTy The type associated with the value.\n public export\n data Tree : (keyTy : Type)\n -> (valTy : Type)\n -> Type\n where\n ||| An empty Tree node.\n Empty : Tree k v\n\n ||| A Key Value node in the Tree.\n |||\n ||| @key The key.\n ||| @val The value associated with the key.\n ||| @left The left child of the Node\n ||| @right THe right child of the Node.\n Node : (key : k)\n -> (val : v)\n -> (left : Tree k v)\n -> (right : Tree k v)\n -> Tree k v\n\n %name Tree t, tree\n\n ||| Encoding of the AVL tree height invariants.\n |||\n ||| @height The height of a Tree.\n ||| @tree The tree whose height we are capturing.\n public export\n data AVLInvariant : (height : Nat)\n -> (tree : Tree k v)\n -> Type\n where\n ||| A tree of height zero.\n AVLEmpty : AVLInvariant 0 Empty\n ||| A Balanced tree.\n |||\n ||| @left The invariant of the left child.\n ||| @right The invariant of the right child.\n ||| @b The encoding of the nodes' balance.\n AVLNode : (left : AVLInvariant n l)\n -> (right : AVLInvariant m r)\n -> (b : Balance n m)\n -> AVLInvariant (height b) (Node k v l r)\n\n %name AVLInvariant inv\n\n||| An AVL Tree.\n|||\n||| Modelled using subset to separate the invariants from the tree\n||| implementation itself.\n|||\n||| @height The height of the Tree.\n||| @keyTy The type associated with the keys.\n||| @valueTy The type associated with the values.\npublic export\nAVLTree : (height : Nat)\n -> (keyTy : Type)\n -> (valueTy : Type)\n -> Type\nAVLTree n k v = Subset (Tree k v) (AVLInvariant n)\n\nnamespace Modification\n\n -- --------------------------------------------------------------- [ Rotations ]\n private\n data InsertRes : Nat -> (k : Type) -> Type -> Type where\n Same : AVLTree n k v -> InsertRes n k v\n Grew : AVLTree (S n) k v -> InsertRes n k v\n\n %name InsertRes res, r\n\n ||| Process the result of an insertion of a new Key-Value pair into\n ||| the Tree, returning the new tree and proof of the new tree's\n ||| height.\n |||\n ||| `InsertRes` is obtained from the result of running `Tree.insert`.\n private\n runInsertRes : InsertRes n k v -> (n : Nat ** AVLTree n k v)\n runInsertRes (Same t) = (_ ** t)\n runInsertRes (Grew t) = (_ ** t)\n\n ||| Perform a Left roation.\n private\n rotLeft : k\n -> v\n -> AVLTree n k v\n -> AVLTree (S (S n)) k v\n -> InsertRes (S (S n)) k v\n -- Impossible because Empty has depth 0 and we know the depth is at least 2 from the type\n rotLeft key val l (Element Empty AVLEmpty) impossible\n\n rotLeft key val (Element l invl) (Element (Node key' val' rl rr) (AVLNode invrl invrr Balanced)) =\n Grew $ Element (Node key' val' (Node key val l rl) rr)\n (AVLNode (AVLNode invl invrl RHeavy) invrr LHeavy)\n\n rotLeft key val (Element l invl) (Element (Node key' val' (Node key'' val'' rll rlr) rr) (AVLNode (AVLNode invrll invrlr LHeavy) invrr LHeavy)) =\n Same $ Element (Node key'' val'' (Node key val l rll) (Node key' val' rlr rr)) -- Needs Checking\n (AVLNode (AVLNode invl invrll Balanced) (AVLNode invrlr invrr RHeavy) Balanced)\n\n rotLeft key val (Element l invl) (Element (Node key' val' (Node key'' val'' rll rlr) rr) (AVLNode (AVLNode invrll invrlr RHeavy) invrr LHeavy)) =\n Same $ Element (Node key'' val'' (Node key val l rll) (Node key' val' rlr rr))\n (AVLNode (AVLNode invl invrll LHeavy) (AVLNode invrlr invrr Balanced) Balanced)\n\n rotLeft key val (Element l invl) (Element (Node key' val' (Node key'' val'' rll rlr) rr) (AVLNode (AVLNode invrll invrlr Balanced) invrr LHeavy)) =\n Same $ Element (Node key'' val'' (Node key val l rll) (Node key' val' rlr rr))\n (AVLNode (AVLNode invl invrll Balanced) (AVLNode invrlr invrr Balanced) Balanced) -- Needs Checking\n\n rotLeft key val (Element l invl) (Element (Node key' val' rl rr) (AVLNode invrl invrr RHeavy)) =\n Same $ Element (Node key' val' (Node key val l rl) rr)\n (AVLNode (AVLNode invl invrl Balanced) invrr Balanced)\n\n ||| Perform a Right rotation.\n private\n rotRight : k\n -> v\n -> AVLTree (S (S n)) k v\n -> AVLTree n k v\n -> InsertRes (S (S n)) k v\n rotRight key val (Element Empty AVLEmpty) r impossible\n\n rotRight key'' val'' (Element (Node key val ll (Node key' val' lrl lrr))\n (AVLNode invll (AVLNode invlrl invlrr RHeavy) RHeavy)) (Element r invr) =\n Same $ Element (Node key' val' (Node key val ll lrl) (Node key'' val'' lrr r))\n (AVLNode (AVLNode invll invlrl LHeavy) (AVLNode invlrr invr Balanced) Balanced)\n\n rotRight key'' val'' (Element (Node key val ll (Node key' val' lrl lrr))\n (AVLNode invll (AVLNode invlrl invlrr LHeavy) RHeavy)) (Element r invr) =\n Same $ Element (Node key' val' (Node key val ll lrl) (Node key'' val'' lrr r))\n (AVLNode (AVLNode invll invlrl Balanced) (AVLNode invlrr invr RHeavy) Balanced)\n\n rotRight key val (Element (Node key' val' ll lr) (AVLNode invll invlr Balanced)) (Element r invr) =\n Grew $ Element (Node key' val' ll (Node key val lr r))\n (AVLNode invll (AVLNode invlr invr LHeavy) RHeavy)\n\n rotRight key val (Element (Node key' val' ll lr) (AVLNode invll invlr LHeavy)) (Element r invr) =\n Same $ Element (Node key' val' ll (Node key val lr r))\n (AVLNode invll (AVLNode invlr invr Balanced) Balanced)\n\n rotRight key val (Element (Node key' val' ll (Node key'' val'' lrl lrr))\n (AVLNode invll (AVLNode invlrl invlrr Balanced) RHeavy)) (Element r invr) =\n Same $ Element (Node key'' val'' (Node key' val' ll lrl) (Node key val lrr r))\n (AVLNode (AVLNode invll invlrl Balanced) (AVLNode invlrr invr Balanced) Balanced)\n\n\n-- --------------------------------------------------------------- [ Insertion ]\n\n ||| Perform an insertion into the tree returning the new tree wrapped\n ||| in a description describing the height change.\n private\n doInsert : (Ord k) => k\n -> v\n -> AVLTree n k v\n -> InsertRes n k v\n doInsert newKey newVal (Element Empty AVLEmpty) = Grew (Element (Node newKey newVal Empty Empty)\n (AVLNode AVLEmpty AVLEmpty Balanced))\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr b)) with (compare newKey key)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr b)) | EQ = Same (Element (Node newKey newVal l r) (AVLNode invl invr b))\n\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr b)) | LT with (assert_total $ doInsert newKey newVal (Element l invl))\n -- Totality checker not clever enough to see that this is smaller\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr b)) | LT | (Same (Element l' invl'))\n = Same $ Element (Node key val l' r) (AVLNode invl' invr b)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr LHeavy)) | LT | (Grew (Element l' invl'))\n = rotRight key val (Element l' invl') (Element r invr)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr Balanced)) | LT | (Grew (Element l' invl'))\n = Grew $ Element (Node key val l' r) (AVLNode invl' invr LHeavy)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr RHeavy)) | LT | (Grew (Element l' invl'))\n = Same $ Element (Node key val l' r) (AVLNode invl' invr Balanced)\n\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr b)) | GT with (assert_total $ doInsert newKey newVal (Element r invr))\n -- Totality checker not clever enough to see that this is smaller\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr b)) | GT | (Same (Element r' invr'))\n = Same $ Element (Node key val l r') (AVLNode invl invr' b)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr LHeavy)) | GT | (Grew (Element r' invr'))\n = Same $ Element (Node key val l r') (AVLNode invl invr' Balanced)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr Balanced)) | GT | (Grew (Element r' invr'))\n = Grew $ Element (Node key val l r') (AVLNode invl invr' RHeavy)\n doInsert newKey newVal (Element (Node key val l r) (AVLNode invl invr RHeavy)) | GT | (Grew (Element r' invr'))\n = rotLeft key val (Element l invl) (Element r' invr')\n\n-- --------------------------------------- [ Public API for working with Trees ]\nnamespace API\n\n ||| Insert a key value pair into the tree, returning a the new tree\n ||| and possibly its new height.\n insert : Ord k => k -> v -> AVLTree n k v -> (n : Nat ** AVLTree n k v)\n insert k v t = runInsertRes (doInsert k v t)\n\n\n ||| Find a value in the tree.\n lookup : (Ord k) => k -> AVLTree h k v -> Maybe v\n lookup key (Element t _) = lookup' key t\n where\n lookup' : (Ord k) => k -> Tree k v -> Maybe v\n lookup' key Empty = Nothing\n lookup' key (Node key' value' l r) with (compare key key')\n lookup' key (Node key' value' l r) | LT = lookup' key l\n lookup' key (Node key' value' l r) | EQ = Just value'\n lookup' key (Node key' value' l r) | GT = lookup' key r\n\n ||| Update an element in the tree.\n update : (Ord k) => k\n -> (v -> v)\n -> AVLTree h k v\n -> AVLTree h k v\n update key f t@(Element Empty inv) = t\n update key f (Element (Node key' value' l r) inv) with (compare key key')\n update key f (Element (Node key' value' l r) (AVLNode invl invr b)) | LT with (assert_total $ update key f (Element l invl)) -- Totality checker again\n update key f (Element (Node key' value' l r) (AVLNode invl invr b)) | LT | (Element l' invl')\n = Element (Node key' value' l' r) (AVLNode invl' invr b)\n update key f (Element (Node key' value' l r) (AVLNode invl invr b)) | EQ\n = Element (Node key' (f value') l r) (AVLNode invl invr b)\n update key f (Element (Node key' value' l r) (AVLNode invl invr b)) | GT with (assert_total $ update key f (Element r invr))\n update key f (Element (Node key' value' l r) (AVLNode invl invr b)) | GT | (Element r' invr')\n = Element (Node key' value' l r') (AVLNode invl invr' b)\n\n ||| Perform a right fold over the tree.\n foldr : (step : k -> v -> p -> p)\n -> (init : p)\n -> AVLTree n k v\n -> p\n foldr step init (Element t _) = foldr' step init t\n where\n foldr' : (k -> v -> p -> p) -> p -> Tree k v -> p\n foldr' step' init' Empty = init'\n foldr' step' init' (Node key val l r) = foldr' step' (step' key val (foldr' step' init' r)) l\n\n ||| Construct a AVL Tree from an association list.\n fromList : (Ord k) => List (k, v)\n -> (n : Nat ** AVLTree n k v)\n fromList [] = (0 ** Element Empty AVLEmpty)\n fromList ((k, v) :: xs) with (doInsert k v (snd (fromList xs)))\n fromList ((k, v) :: xs) | (Same x) = (_ ** x)\n fromList ((k, v) :: xs) | (Grew x) = (_ ** x)\n\n ||| Flatten the tree to an association list.\n toList : AVLTree n k v -> List (k, v)\n toList = foldr (\\k,v,xs => (k, v) :: xs) []\n\n ||| Is the tree empty?\n isEmpty : AVLTree h k v -> Bool\n isEmpty (Element t _) = isEmpty' t\n where\n isEmpty' : Tree k v -> Bool\n isEmpty' Empty = True\n isEmpty' (Node _ _ _ _) = False\n\n ||| Calculate the size of the tree.\n size : AVLTree h k v -> Nat\n size = foldr (\\_,_=> S) 0\n\n ||| Return a list of keys in the tree.\n keys : AVLTree h k v -> List k\n keys = map fst . toList\n\n ||| Return a list of the values in the key.\n values : AVLTree h k v -> List v\n values = map snd . toList\n\n ||| Check if the provided check holds for all elements in the tree.\n all : (pred : k -> v -> Bool) -> AVLTree h k v -> Bool\n all pred = foldr (\\k,v,pred' => pred' && pred k v) True\n\n ||| Check if the provided check holds for at least one element in the tree.\n any : (pred : k -> v -> Bool) -> AVLTree h k v -> Bool\n any pred = foldr (\\k,v,pred' => pred' || pred k v) False\n\n ||| Does the given key exist in the tree?\n hasKey : (o : Ord k) => k -> AVLTree h k v -> Bool\n hasKey key = any (\\key',value' => key == key')\n\n ||| Does the given value exist in the tree?\n hasValue : (Eq v) => v -> AVLTree h k v -> Bool\n hasValue value = any (\\key',value' => value == value')\n\n ||| Find the first key that satisfies the provided predicate.\n findKey : (pred : v -> Bool) -> AVLTree h k v -> Maybe k\n findKey pred = foldr (\\k,v,p => if pred v then Just k else p) Nothing\n\n ||| Find the key that is associated with provided value.\n findKeyOf : (Eq v) => v -> AVLTree h k v -> Maybe k\n findKeyOf value = findKey (== value)\n\n-- --------------------------------------------------------- [ Implementations ]\n\nprivate\neqTree : (Eq k, Eq v) => Tree k v -> Tree k v -> Bool\neqTree Empty Empty = True\neqTree (Node xk xv xl xr) (Node yk yv yl yr) =\n xk == yk &&\n xv == yv &&\n eqTree xl yl &&\n eqTree xr yr\neqTree _ _ = False\n\nnamespace Implementation\n\n (Eq k, Eq v) => Eq (Tree k v) where\n (==) = eqTree\n\n (Eq k, Eq v) => Eq (AVLTree h k v) where\n (==) (Element t _) (Element t' _) = t == t'\n\n (Show k, Show v) => Show (Tree k v) where\n show Empty = \"\"\n show (Node k v l r) = unwords\n [\n \"{\"\n , show l\n , \"(\", show k, \":\", show v, \"),\"\n , show r\n , \"}\"\n ]\n\n (Show k, Show v) => Show (AVLTree h k v) where\n show (Element t _) = show t\n\n-- --------------------------------------------------------------------- [ Key ]\n\nnamespace Core\n namespace Quantifiers\n namespace OnKeys\n public export\n data AllKeys : (predicate : typeKey -> Type)\n -> (tree : Tree typeKey typeValue)\n -> Type\n where\n Leaf : AllKeys p Empty\n Node : (prf : p key)\n -> (leftBranch : AllKeys p left)\n -> (rightBranch : AllKeys p right)\n -> AllKeys p (Node key _ left right)\n\n namespace OnValues\n data AllValues : (predicate : typeValue -> Type)\n -> (tree : Tree typeKey typeValue)\n -> Type\n where\n Leaf : AllValues p Empty\n Node : (prf : p value)\n -> (leftBranch : AllValues p left)\n -> (rightBranch : AllValues p right)\n -> AllValues p (Node _ value left right)\n\n namespace OnKVPairs\n data AllKVPairs : (predicate : typeKey -> typeValue -> Type)\n -> (tree : Tree typeKey typeValue)\n -> Type\n where\n Leaf : AllKVPairs p Empty\n Node : (prf : p key value)\n -> (leftBranch : AllKVPairs p left)\n -> (rightBranch : AllKVPairs p right)\n -> AllKVPairs p (Node key value left right)\n\n namespace Predicate\n namespace OnValues\n public export\n data IsValueIn : (value : typeValue)\n -> (tree : Tree typeKey typeValue)\n -> Type\n where\n Here : IsValueIn value (Node _ value _ _)\n InRight : (later : IsValueIn value r) -> IsValueIn value (Node _ _ _ r)\n InLeft : (later : IsValueIn value l) -> IsValueIn value (Node _ _ l _)\n\n emptyTreeHasNoValue : IsValueIn value Empty -> Void\n emptyTreeHasNoValue Here impossible\n emptyTreeHasNoValue (InRight _) impossible\n emptyTreeHasNoValue (InLeft _) impossible\n\n Uninhabited (IsValueIn value Empty) where\n uninhabited Here impossible\n uninhabited (InRight _) impossible\n uninhabited (InLeft _) impossible\n\n ||| A decision procedure for Value\n valueNotFound : (notHere : (value = val) -> Void)\n -> (isNotLeft : IsValueIn value left -> Void)\n -> (isNotRight : IsValueIn value right -> Void)\n -> IsValueIn value (Node key val left right)\n -> Void\n valueNotFound notHere isNotLeft isNotRight Here = notHere Refl\n valueNotFound notHere isNotLeft isNotRight (InRight later) = isNotRight later\n valueNotFound notHere isNotLeft isNotRight (InLeft later) = isNotLeft later\n\n isValue : DecEq typeValue\n => (value : typeValue)\n -> (tree : Tree typeKey typeValue)\n -> Dec (IsValueIn value tree)\n isValue value Empty = No emptyTreeHasNoValue\n isValue value (Node key val left right) with (decEq value val)\n isValue val (Node key val left right) | (Yes Refl) = Yes Here\n isValue value (Node key val left right) | (No notHere) with (isValue value left)\n isValue value (Node key val left right) | (No notHere) | (Yes prf) = Yes (InLeft prf)\n isValue value (Node key val left right) | (No notHere) | (No isNotLeft) with (isValue value right)\n isValue value (Node key val left right) | (No notHere) | (No isNotLeft) | (Yes prf) = Yes (InRight prf)\n isValue value (Node key val left right) | (No notHere) | (No isNotLeft) | (No isNotRight) = No (valueNotFound notHere isNotLeft isNotRight)\n\n\n\n\n namespace OnKeys\n ||| A proof that some key is found in a Tree\n public export\n data IsKeyIn : k -> Tree k v -> Type where\n Here : IsKeyIn key (Node key _ _ _)\n InRight : (later : IsKeyIn key r) -> IsKeyIn key (Node _ not_key _ r)\n InLeft : (later : IsKeyIn key l) -> IsKeyIn key (Node _ not_key l _)\n\n\n ||| An empty tree has no key\n emptyTreeHasNoKey : {key : k} -> IsKeyIn key Empty -> Void\n emptyTreeHasNoKey Here impossible\n emptyTreeHasNoKey (InRight _) impossible\n emptyTreeHasNoKey (InLeft _) impossible\n\n Uninhabited (IsKeyIn key Empty) where\n uninhabited = emptyTreeHasNoKey\n\n ||| An item that is not in the root, not in the left child and not in the\n ||| right child is not in the Tree at all\n noKeyFound : {key : k}\n -> {val : v}\n -> {key' : k}\n -> {l : Tree k v}\n -> {r : Tree k v}\n -> Not (key = key')\n -> Not (IsKeyIn key l)\n -> Not (IsKeyIn key r)\n -> Not (IsKeyIn key (Node key' val l r))\n noKeyFound notHere notInLeft notInRight Here = notHere Refl\n noKeyFound notHere notInLeft notInRight (InLeft later) = notInLeft later\n noKeyFound notHere notInLeft notInRight (InRight later) = notInRight later\n\n ||| A decision procedure for Key\n isKey : DecEq k\n => (key : k)\n -> (tree : Tree k v)\n -> Dec (IsKeyIn key tree)\n isKey key Empty = No emptyTreeHasNoKey\n isKey key (Node key' _ l r) with (decEq key key')\n isKey key (Node key _ l r) | (Yes Refl) = Yes Here\n isKey key (Node key' _ l r) | (No notHere) with (isKey key l)\n isKey key (Node key' _ l r) | (No notHere) | (Yes inLeft) = Yes (InLeft inLeft)\n isKey key (Node key' _ l r) | (No notHere) | (No notInLeft) with (isKey key r)\n isKey key (Node key' _ l r) | (No notHere) | (No notInLeft) | (Yes inRight) = Yes (InRight inRight)\n isKey key (Node key' _ l r) | (No notHere) | (No notInLeft) | (No notInRight) = No (noKeyFound notHere notInLeft notInRight)\n\npublic export\ndata HasKey : (key : typeKey)\n -> (tree : AVLTree h typeKey typeValue)\n -> Type\n where\n IsKey : (prf : IsKeyIn key (Subset.getWitness avl))\n -> HasKey key avl\n\nkeyNotInAVlTree : (contra : IsKeyIn key tree -> Void)\n -> HasKey key (Element tree prf)\n -> Void\nkeyNotInAVlTree contra (IsKey x) = contra x\n\nisKey : DecEq typeKey\n => (key : typeKey)\n -> (tree : AVLTree h typeKey typeValue)\n -> Dec (HasKey key tree)\nisKey key (Element tree prf) with (isKey key tree)\n isKey key (Element tree prf) | (Yes x) = Yes (IsKey x)\n isKey key (Element tree prf) | (No contra) = No (keyNotInAVlTree contra)\n\npublic export\ndata HasValue : (value : typeValue)\n -> (tree : AVLTree h typeKey typeValue)\n -> Type\n where\n IsValue : (prf : IsValueIn value (Subset.getWitness avl))\n -> HasValue value avl\n\nvalueNotInAVLTree : (contra : IsValueIn value tree -> Void)\n -> HasValue value (Element tree prf)\n -> Void\nvalueNotInAVLTree contra (IsValue prf) = contra prf\n\nisValue : DecEq typeValue\n => (value : typeValue)\n -> (tree : AVLTree h typeKey typeValue)\n -> Dec (HasValue value tree)\nisValue value (Element tree prf) with (isValue value tree)\n isValue value (Element tree prf) | (Yes x) = Yes (IsValue x)\n isValue value (Element tree prf) | (No contra) = No (valueNotInAVLTree contra)\n\n-- Quantifiers\npublic export\ndata AllKeys : (predicate : typeKey -> Type)\n -> (tree : AVLTree h typeKey typeValue)\n -> Type\n where\n AllKeysSatisfyPredicate : (prf : OnKeys.AllKeys p (Subset.getWitness avl))\n -> AllKeys p avl\n\npublic export\ndata AllValues : (predicate : typeValue -> Type)\n -> (tree : AVLTree h typeKey typeValue)\n -> Type\n where\n AllValuesSatisfyPredicate : (prf : OnValues.AllValues p (Subset.getWitness avl))\n -> AllValues p avl\n\npublic export\ndata AllKVPairs : (predicate : typeKey -> typeValue -> Type)\n -> (tree : AVLTree k typeKey typeValue)\n -> Type\n where\n AllKVPairsSatisfyPredicate : (prf : OnKVPairs.AllKVPairs p (Subset.getWitness avl))\n -> AllKVPairs p avl\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "fd6939cf1254725aeb212c7d746f98bbb04c87a2", "size": 24607, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/AVL.idr", "max_stars_repo_name": "elba/idris-containers", "max_stars_repo_head_hexsha": "b92d489abcb32774fb6adfd7f26a28c082cc4bef", "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/AVL.idr", "max_issues_repo_name": "elba/idris-containers", "max_issues_repo_head_hexsha": "b92d489abcb32774fb6adfd7f26a28c082cc4bef", "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/AVL.idr", "max_forks_repo_name": "elba/idris-containers", "max_forks_repo_head_hexsha": "b92d489abcb32774fb6adfd7f26a28c082cc4bef", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-19T12:29:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-19T12:29:49.000Z", "avg_line_length": 43.3985890653, "max_line_length": 158, "alphanum_fraction": 0.5566302272, "num_tokens": 6867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118213, "lm_q2_score": 0.6825737279551494, "lm_q1q2_score": 0.6219473314998608}} {"text": "module Control.Optics.Vect\n\nimport Data.Vect\nimport Control.Optics.Setter\nimport Control.Optics.Lens\n\nexport\nat : Fin n -> Simple Lens (Vect n a) a\nat i = lens (index i) (\\s, b => replaceAt i b s)\n", "meta": {"hexsha": "6d713d8deef2aa335730293dfe1e71e514f15be9", "size": 197, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Control/Optics/Vect.idr", "max_stars_repo_name": "tensorknower69/idris2-optics", "max_stars_repo_head_hexsha": "df10a006620e30d1a727780d4fb4d62b3e5d9984", "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/Control/Optics/Vect.idr", "max_issues_repo_name": "tensorknower69/idris2-optics", "max_issues_repo_head_hexsha": "df10a006620e30d1a727780d4fb4d62b3e5d9984", "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/Control/Optics/Vect.idr", "max_forks_repo_name": "tensorknower69/idris2-optics", "max_forks_repo_head_hexsha": "df10a006620e30d1a727780d4fb4d62b3e5d9984", "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.7, "max_line_length": 48, "alphanum_fraction": 0.7157360406, "num_tokens": 63, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6217705824210794}} {"text": "import Data.Vect\n\ntotal allLengths' : Vect len String -> Vect len Nat\nallLengths' [] = []\nallLengths' (word :: words) = length word :: allLengths' words\n", "meta": {"hexsha": "0691a28d72caca07523418e69068fbf1b13d6c6c", "size": 153, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter3/WordLenths.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": "Chapter3/WordLenths.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": "Chapter3/WordLenths.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": 25.5, "max_line_length": 62, "alphanum_fraction": 0.6928104575, "num_tokens": 45, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6209046399141599}} {"text": "module Data.Functor.Coyoneda\n\n%access public export\n\ndata Coyoneda : (f : Type -> Type) -> (a : Type) -> Type where\n Coyo : {b : Type} -> (b -> a) -> f b -> Coyoneda f a\n\nFunctor (Coyoneda f) where\n map f (Coyo h c) = Coyo (f . h) c\n\nliftCoyoneda : f a -> Coyoneda f a\nliftCoyoneda f = Coyo id f\n\nlowerCoyoneda : Functor f => Coyoneda f a -> f a\nlowerCoyoneda (Coyo f c) = map f c\n", "meta": {"hexsha": "5c5a0bac0714f1c202ca0860d9f8f321a23f1333", "size": 383, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Functor/Coyoneda.idr", "max_stars_repo_name": "idris-industry/idris-free", "max_stars_repo_head_hexsha": "224da5ed197f1ca2729450cecd4f07b4ac78bcc5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-08-11T15:40:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-18T01:43:22.000Z", "max_issues_repo_path": "Data/Functor/Coyoneda.idr", "max_issues_repo_name": "idris-industry/idris-free", "max_issues_repo_head_hexsha": "224da5ed197f1ca2729450cecd4f07b4ac78bcc5", "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": "Data/Functor/Coyoneda.idr", "max_forks_repo_name": "idris-industry/idris-free", "max_forks_repo_head_hexsha": "224da5ed197f1ca2729450cecd4f07b4ac78bcc5", "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.9375, "max_line_length": 62, "alphanum_fraction": 0.6266318538, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.6205586454025458}} {"text": "> module SequentialDecisionProblems.examples.Main\n\n> import Decidable.Order\n\n> import Data.List\n> import Data.List.Quantifiers\n> import Effects\n> import Effect.Exception\n> import Effect.StdIO\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.FullTheory\n> import SequentialDecisionProblems.Utils\n\n> import SequentialDecisionProblems.examples.LeftAheadRight\n\n> import SimpleProb.SimpleProb\n> import SimpleProb.BasicOperations\n> import SimpleProb.BasicProperties\n> import SimpleProb.MonadicOperations\n> import SimpleProb.MonadicProperties\n> import SimpleProb.Measures\n> import BoundedNat.BoundedNat\n> import BoundedNat.Operations\n> import BoundedNat.Properties\n> import Sigma.Sigma\n> import Sigma.Operations\n> import Sigma.Properties\n> import Nat.LTProperties\n> import NonNegRational.NonNegRational\n> import NonNegRational.BasicOperations\n> import NonNegRational.BasicProperties\n> import NonNegRational.Predicates\n> import NonNegRational.LTEProperties\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Void.Properties\n> import Unit.Properties\n> import Opt.Operations\n> import Rel.TotalPreorder\n> import LocalEffect.Exception\n> import LocalEffect.StdIO\n\n> -- %default total\n> %auto_implicits off\n\n> -- %logging 5\n\nWe reimplement \"Example2.lidr\", this time with |M = SimpleProb|.\n\n* The monad M (SimpleProb):\n\n** SimpleProb is a monad:\n\n> SequentialDecisionProblems.CoreTheory.M = \n> SimpleProb\n\n> SequentialDecisionProblems.CoreTheory.fmap = \n> SimpleProb.MonadicOperations.fmap\n\n> SequentialDecisionProblems.Utils.ret = \n> SimpleProb.MonadicOperations.ret\n\n> SequentialDecisionProblems.Utils.bind = \n> SimpleProb.MonadicOperations.bind\n\n** M is a container monad:\n\n> SequentialDecisionProblems.CoreTheory.Elem = \n> SimpleProb.MonadicOperations.Elem\n\n> SequentialDecisionProblems.CoreTheory.NotEmpty = \n> SimpleProb.MonadicOperations.NonEmpty\n\n> SequentialDecisionProblems.CoreTheory.All = \n> SimpleProb.MonadicOperations.All\n\n> SequentialDecisionProblems.CoreTheory.elemNotEmptySpec0 = \n> SimpleProb.MonadicProperties.elemNonEmptySpec0\n\n> SequentialDecisionProblems.CoreTheory.elemNotEmptySpec1 = \n> SimpleProb.MonadicProperties.elemNonEmptySpec1\n\n> SequentialDecisionProblems.CoreTheory.tagElem = \n> SimpleProb.MonadicOperations.tagElem\n\n> SequentialDecisionProblems.CoreTheory.allElemSpec0 = \n> SimpleProb.MonadicProperties.containerMonadSpec3\n\n\n* The decision process:\n\n> maxColumn : Nat\n> maxColumn = 10\n> %freeze maxColumn\n\n> nColumns : Nat\n> nColumns = S maxColumn\n\n** States:\n\n> SequentialDecisionProblems.CoreTheory.State t = LTB nColumns\n\n** Controls:\n\n> SequentialDecisionProblems.CoreTheory.Ctrl t x = LeftAheadRight\n\n** Transition function:\n\n> SequentialDecisionProblems.CoreTheory.nexts t (MkSigma Z prf) Left =\n> SimpleProb.MonadicOperations.ret (MkSigma maxColumn (ltIdS maxColumn))\n> SequentialDecisionProblems.CoreTheory.nexts t (MkSigma (S n) prf) Left =\n> SimpleProb.MonadicOperations.ret (MkSigma n (ltLemma1 n nColumns prf))\n> SequentialDecisionProblems.CoreTheory.nexts t x Ahead = SimpleProb.MonadicOperations.ret x\n> SequentialDecisionProblems.CoreTheory.nexts t (MkSigma n prf) Right with (decLT n maxColumn)\n> | (Yes p) = SimpleProb.MonadicOperations.ret (MkSigma (S n) (LTESucc p))\n> | (No contra) = SimpleProb.MonadicOperations.ret (MkSigma Z (LTESucc LTEZero))\n\n** |Val| and |LTE|:\n\n> SequentialDecisionProblems.CoreTheory.Val = \n> NonNegRational.NonNegRational\n\n> SequentialDecisionProblems.CoreTheory.plus = \n> NonNegRational.BasicOperations.plus\n\n> SequentialDecisionProblems.CoreTheory.zero = \n> fromInteger 0\n\n> SequentialDecisionProblems.CoreTheory.LTE = \n> NonNegRational.Predicates.LTE\n\n> SequentialDecisionProblems.FullTheory.reflexiveLTE = \n> NonNegRational.LTEProperties.reflexiveLTE\n\n> SequentialDecisionProblems.FullTheory.transitiveLTE = \n> NonNegRational.LTEProperties.transitiveLTE\n\n> SequentialDecisionProblems.FullTheory.monotonePlusLTE = \n> NonNegRational.LTEProperties.monotonePlusLTE\n\n** Reward function:\n\n> SequentialDecisionProblems.CoreTheory.reward t x y (MkSigma c _) =\n> if c == Z\n> then (fromInteger 1)\n> else if (S c) == nColumns\n> then (fromInteger 2)\n> else (fromInteger 0)\n\n** Measure:\n\n> SequentialDecisionProblems.CoreTheory.meas = average\n> SequentialDecisionProblems.FullTheory.measMon = monotoneAverage\n\n** |Ctrl| is finite:\n\n> SequentialDecisionProblems.Utils.finiteCtrl _ = \n> finiteLeftAheadRight\n> %freeze SequentialDecisionProblems.Utils.finiteCtrl\n\n** Reachability\n\n> SequentialDecisionProblems.CoreTheory.Reachable x' = Unit\n> SequentialDecisionProblems.CoreTheory.reachableSpec1 {t} x r y = all (nexts t x y) where\n> all : (sp : SimpleProb (State (S t))) -> SequentialDecisionProblems.CoreTheory.All (Reachable {t' = S t}) sp\n> all sp = all' (support sp) where\n> all' : (xs : List (State (S t))) -> Data.List.Quantifiers.All (Reachable {t' = S t}) xs\n> all' Nil = Nil\n> all' (x :: xs) = () :: (all' xs)\n\n** Viability:\n\n> SequentialDecisionProblems.CoreTheory.Viable n x = Unit\n\n> SequentialDecisionProblems.CoreTheory.viableSpec1 {t} {n} x _ = MkSigma Ahead (ne, av) where\n> ne : SequentialDecisionProblems.CoreTheory.NotEmpty (nexts t x Ahead)\n> ne = nonEmptyLemma (nexts t x Ahead) \n> av : SequentialDecisionProblems.CoreTheory.All (Viable {t = S t} n) (nexts t x Ahead)\n> av = [()]\n\n> SequentialDecisionProblems.Utils.finiteViable n x = finiteUnit\n\n> SequentialDecisionProblems.Utils.decidableViable n x = decidableUnit\n\n** |cvalargmax| and |cvalmax| \n\nWe want to implement |cvalmax|, |cvalargmax|, |cvalmaxSpec| and\n|cvalargmaxSpec|. This can be easily done in terms of |Opt.max| and\n|Opt.argmax| if we can show that\n\n1) |LTE| is a *total* preorder \n\n2) |GoodCtrl t x n| is finite and, for every |t : Nat|, |x : State t|\n such that |Viable (S n) x|, its cardinality is not zero.\n\nThe first condition trivially holds, see\n|NonNegRational.LTEProperties|. Finiteness and non-zero cardinality of\n|GoodCtrl t x n|\n\n< finiteGoodCtrl : {t : Nat} -> {n : Nat} -> \n< (x : State t) -> \n< Finite (GoodCtrl t x n) \n\nand\n\n< cnzGoodCtrl : {t : Nat} -> {n : Nat} -> \n< (x : State t) -> (v : Viable {t = t} (S n) x) ->\n< CardNotZ (finiteGoodCtrl {t} {n} x)\n\nfollow from finiteness of |Viable| (previous section ), finiteness of\n|All|\n\n> SequentialDecisionProblems.Utils.finiteAll = SimpleProb.MonadicProperties.finiteAll\n\n, finiteness of |NotEmpty|\n\n> SequentialDecisionProblems.Utils.finiteNotEmpty = SimpleProb.MonadicProperties.finiteNonEmpty\n\nand finiteness of controls (see above). With these results in place, we have\n\n> SequentialDecisionProblems.FullTheory.cvalmax {n} x r v ps =\n> Opt.Operations.max totalPreorderLTE (finiteGoodCtrl n x) (cardNotZGoodCtrl n x v) (cval x r v ps)\n\n> SequentialDecisionProblems.CoreTheory.cvalargmax {n} x r v ps =\n> Opt.Operations.argmax totalPreorderLTE (finiteGoodCtrl n x) (cardNotZGoodCtrl n x v) (cval x r v ps)\n\n> SequentialDecisionProblems.FullTheory.cvalmaxSpec {n} x r v ps =\n> Opt.Operations.maxSpec totalPreorderLTE (finiteGoodCtrl n x) (cardNotZGoodCtrl n x v) (cval x r v ps)\n\n> SequentialDecisionProblems.FullTheory.cvalargmaxSpec {n} x r v ps =\n> Opt.Operations.argmaxSpec totalPreorderLTE (finiteGoodCtrl n x) (cardNotZGoodCtrl n x v) (cval x r v ps)\n\n\n* The computation:\n\n> -- showState : {t : Nat} -> State t -> String\n> SequentialDecisionProblems.Utils.showState = show\n\n> -- showControl : {t : Nat} -> {x : State t} -> Ctrl t x -> String\n> SequentialDecisionProblems.Utils.showCtrl = show\n\n> computation : { [STDIO] } Eff ()\n> computation =\n> do putStr (\"enter number of steps:\\n\")\n> nSteps <- getNat\n> putStr (\"enter initial column:\\n\")\n> x0 <- getLTB nColumns\n> case (decidableViable {t = Z} nSteps x0) of\n> (Yes v0) => do putStrLn (\"computing optimal policies ...\")\n> ps <- pure (backwardsInduction Z nSteps)\n> putStrLn (\"computing optimal controls ...\")\n> mxys <- pure (possibleStateCtrlSeqs x0 () v0 ps)\n> putStrLn (show mxys)\n> putStrLn (\"done!\") \n> (No _) => putStrLn (\"initial column non viable for \" ++ cast {from = Int} (cast nSteps) ++ \" steps\")\n\n> main : IO ()\n> main = run computation\n\n\n> {-\n\n> ---}\n\n-- Local Variables:\n-- idris-packages: (\"effects\")\n-- End:\n", "meta": {"hexsha": "c589f4a0f0a942465a3489ab2e15c0e618f91423", "size": 8510, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/examples/Example4.Original.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/Example4.Original.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/Example4.Original.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.5185185185, "max_line_length": 113, "alphanum_fraction": 0.7290246769, "num_tokens": 2310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439707, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6203810548467308}} {"text": "module AOC.Day.Two\n\nimport AOC.Solution\nimport Data.String\n\n%default total\n\n----------------------------------------------------------------------------\n-- Types -------------------------------------------------------------------\n----------------------------------------------------------------------------\n\ndata Direction = Forward Integer\n | Up Integer\n | Down Integer\n\nInputType : Type\nInputType = List Direction\n\n\n----------------------------------------------------------------------------\n-- Interfaces --------------------------------------------------------------\n----------------------------------------------------------------------------\n\n-- These interfaces not strictly necessary, but are helpful for debugging.\n\npartial\nCast String (Maybe Direction) where\n cast x = case (words x) of\n (\"forward\" :: (a :: [])) => Just (Forward (cast a))\n (\"up\" :: (a :: [])) => Just (Up (cast a))\n (\"down\" :: (a :: [])) => Just (Down (cast a))\n _ => Nothing\n\nShow Direction where\n show (Forward x) = \"forward \" ++ (show x)\n show (Up x) = \"up \" ++ (show x)\n show (Down x) = \"down \" ++ (show x)\n\n\n----------------------------------------------------------------------------\n-- Helper Functions --------------------------------------------------------\n----------------------------------------------------------------------------\n\ndirection_helper : (Integer, Integer) -> List Direction -> (Integer, Integer)\ndirection_helper vals [] = vals\ndirection_helper (f, ud) ((Forward x) :: dirs) = direction_helper (f + x, ud) dirs\ndirection_helper (f, ud) ((Up x) :: dirs) = direction_helper (f, ud - x) dirs\ndirection_helper (f, ud) ((Down x) :: dirs) = direction_helper (f, ud + x) dirs\n\ndirection : List Direction -> Integer\ndirection dirs = let\n (f, ud) = direction_helper (0, 0) dirs\n in f * ud\n\ndirection_helper2 : (Integer, Integer, Integer) -> List Direction -> (Integer, Integer, Integer)\ndirection_helper2 vals [] = vals\ndirection_helper2 (f, ud, aim) ((Forward x) :: dirs) = direction_helper2 (f + x, ud + aim * x, aim) dirs\ndirection_helper2 (f, ud, aim) ((Up x) :: dirs) = direction_helper2 (f, ud, aim - x) dirs\ndirection_helper2 (f, ud, aim) ((Down x) :: dirs) = direction_helper2 (f, ud, aim + x) dirs\n\n\ndirection2 : List Direction -> Integer\ndirection2 dirs = let\n (f, ud, aim) = direction_helper2 (0, 0, 0) dirs\n in f * ud\n\n\n----------------------------------------------------------------------------\n-- Solutions ---------------------------------------------------------------\n----------------------------------------------------------------------------\n\npart1 : InputType -> Integer\npart1 = direction\n\npart2 : InputType -> Integer\npart2 = direction2\n\n\n----------------------------------------------------------------------------\n-- Interface for input/output ----------------------------------------------\n----------------------------------------------------------------------------\n\n-- Why is this partial?\npartial\nparser : String -> Maybe InputType\nparser = sequence . map (the (Maybe Direction) . cast) . lines\n\npartial\nexport\nday2 : (inputType ** AOCSolution inputType)\nday2 = solutionToDP (MkAOCSolution {\n day = 2\n , parser = parser\n , part1 = show . part1\n , part2 = show . part2\n })\n", "meta": {"hexsha": "833af58eefa77a3f607989dd6295b5e786dd148f", "size": 3277, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/AOC/Day/Two.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/Two.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/Two.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": 33.7835051546, "max_line_length": 104, "alphanum_fraction": 0.4314922185, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6201482477269172}} {"text": "module Main\nimport Data.List\n\nmySum : List Double -> Double\nmySum [] = 0\nmySum (x :: xs) = x + mySum xs\n\nms : List Double\nms = [1.0, 2.0, 3.0]\n\nbs : List Double\nbs = []\n\nmain : IO ()\nmain = do printLn $ sum ms\n printLn $ mySum ms\n printLn $ mySum bs\n", "meta": {"hexsha": "e56fbb47fb828272a036477a549541e3c649973e", "size": 268, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "5_function.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": "5_function.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": "5_function.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": 14.8888888889, "max_line_length": 30, "alphanum_fraction": 0.5708955224, "num_tokens": 95, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6201071094334336}} {"text": "\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\ndata Elem : a -> Vect n a -> Type where\n Here : Elem x (x :: xs)\n There : {xs : Vect n a} -> Elem x xs -> Elem x (y :: xs)\n\ngetIndex : Elem x xs -> Nat\ngetIndex Here = 0\ngetIndex (There p) = S (getIndex p)\n\nBeatles : Vect ? String\nBeatles = [\"John\", \"Paul\", \"George\", \"Ringo\"]\n\ngeorgeInBeatles : Elem \"George\" Beatles\ngeorgeInBeatles = There (There Here)\n", "meta": {"hexsha": "a9533a219c88adef90cb2d2ea557485da4ee6b0a", "size": 465, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic015/George.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/basic015/George.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/basic015/George.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": 24.4736842105, "max_line_length": 61, "alphanum_fraction": 0.5806451613, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6199321051632833}} {"text": "data 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\nzipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\nzipWith f [] [] = []\nzipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys\n", "meta": {"hexsha": "53620400bea424fc2de1561828ac3dc060a8ef47", "size": 261, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples/type-driven-development/idris/solution.idr", "max_stars_repo_name": "bemayr/talk.developer-confidence", "max_stars_repo_head_hexsha": "af300fb7c1ea695020fcd0ddece5ec2a34b471b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-12T09:28:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-12T09:28:28.000Z", "max_issues_repo_path": "examples/type-driven-development/idris/solution.idr", "max_issues_repo_name": "bemayr/talk.developer-confidence", "max_issues_repo_head_hexsha": "af300fb7c1ea695020fcd0ddece5ec2a34b471b7", "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/type-driven-development/idris/solution.idr", "max_forks_repo_name": "bemayr/talk.developer-confidence", "max_forks_repo_head_hexsha": "af300fb7c1ea695020fcd0ddece5ec2a34b471b7", "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.1, "max_line_length": 59, "alphanum_fraction": 0.4827586207, "num_tokens": 98, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.6199320941715213}} {"text": "module Main\n\n-- Vect is a typed list, the first type argument is the number of elements, the second is the type of them.\n-- x -> y means 'given an x, yields a y'\n-- x -> y -> z means 'given an x and a y, yields a z', something like BiFunction in Java or (X, Y) => Z in Scala, etc.\n-- Suggest operations for the following types:\n--\n-- 1) Vect n elem -> Vect n elem -- identity/id\n-- 2) Vect n elem -> Vect (n * 2) elem -- append/(++)\n-- 3) Vect (1 + n) elem -> Vect n elem -- remove first element\n-- Assume Bounded n is a number between 0 and n - 1,\n-- Bounded n -> Vect n elem -> elem -- get at index\n\n-- Function calls don't need parentheses, e.g., sin x rather than sin(x).\n\n-- Functions are pure, no observable side effects. Idris is strict by default.\n-- Real programs are possible, similar to Java methods that return\n-- ListenableFuture<>, we set up a chain of actions but never actually wait on a\n-- ListenableFuture.\n-- Idris' IO is similar to ListenableFuture but there is no way of waiting.\n-- Sounds slow but it isn't. IO String ~= ListenableFuture.\n\nexample_integer : Integer\nexample_integer = 6 + 8 * 11 -- 94\n\nexample_double : Double\nexample_double = 2.1 * 20\n\nreversing_a_string : String\nreversing_a_string = reverse \"abcdefg\"\n\nappending_strings : String\nappending_strings = \"Hello\" ++ \" \" ++ \"World!\"\n\n-- At the REPL, begun by executing idris with no command line args:\n-- Idris> :t 2 + 2\n-- 2 + 2 : Integer -- not 4 : Integer, :t doesn't execute anything.\n\n-- Idris> 2 + 2\n-- 4 : Integer\n\n-- Idris> :t Type\n-- Type : Type 1 -- The type of simple types is Type 1, the type of Type 1 is\n-- Type 2, etc., but we only ever need to write Type.\n\n-- Example program, needs module Main which is at the top of this file.\n-- idris Chapter1.idr\n-- Idris> :exec\n\nmain : IO ()\nmain = putStrLn \"Hello, Idris World!\"\n\n-- Or idris Chapter1.idr -o Hello\n-- ./Hello\n\n-- If we don't know what a value should be yet we can add a hole, e.g.:\n-- main = putStrLn ?greeting\n-- This will compile and give a warning, but can be executed.\n\n-- Can use this to help understand more complex types, e.g., when we want to\n-- putStrLn a Char instead of a String\n-- main = putStrLn (?convert 'x')\n-- Chapter1> :t convert\n-- convert : Char -> String\n-- can replace convert with cast.\n-- main = putStrLn (cast 'x')\n\n-- Types are values. x = Int is fine.\n\n-- Calculating a type given a Boolean as a input:\n-- StringOrInt is a function, the convention is to capitalize functions that\n-- return Type.\nStringOrInt : Bool -> Type\nStringOrInt x = case x of\n True => Int\n False => String\n\ngetStringOrInt : (x : Bool) -> StringOrInt x\ngetStringOrInt x = case x of\n True -> 94\n False => \"Ninety four\"\n\nvalToString : (x : Bool) -> StringOrInt x -> String\nvalToString x val = case x of\n True => cast val\n False => val\n", "meta": {"hexsha": "ba56e347f16c2cba1df4f4a7d4c92d5d68495c47", "size": 2811, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tdd/Chapter1.idr", "max_stars_repo_name": "rickyclarkson/idris-playground", "max_stars_repo_head_hexsha": "3bd9b5fd76df4b2a6c0cf40fa537624e7b692e21", "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": "tdd/Chapter1.idr", "max_issues_repo_name": "rickyclarkson/idris-playground", "max_issues_repo_head_hexsha": "3bd9b5fd76df4b2a6c0cf40fa537624e7b692e21", "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": "tdd/Chapter1.idr", "max_forks_repo_name": "rickyclarkson/idris-playground", "max_forks_repo_head_hexsha": "3bd9b5fd76df4b2a6c0cf40fa537624e7b692e21", "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.3103448276, "max_line_length": 127, "alphanum_fraction": 0.6798292423, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6199244765680341}} {"text": "> module SequentialDecisionProblems.FullTheory\n\n> import SequentialDecisionProblems.CoreTheory\n\n> import Sigma.Sigma\n> import Sigma.Operations\n> import Nat.OperationsProperties\n> import Nat.Predicates\n> import Nat.LTEProperties\n> import Finite.Predicates\n> import Finite.Properties\n> import Decidable.Predicates\n> import Decidable.Properties\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\n* The avoidability theory:\n\nWe can build a theory of avoidability on the top of the theory of\nmonadic SDPs. First we have to explain what it means for a possible\nfuture state to be avoidable. For this, we have to introduce a\nreachability relation:\n\n> ReachableFrom : State t'' -> State t -> Type\n> ReachableFrom {t'' = Z } {t} x'' x = (t = Z , x = x'')\n> ReachableFrom {t'' = S t'} {t} x'' x =\n> Either (t = S t' , x = x'') (Sigma (State t') (\\ x' => (x' `ReachableFrom` x , x' `Pred` x'')))\n\nIt is easy to show that we are indeed modeling reachability of \"future\"\nstates:\n\n> reachableFromLemma : (x'' : State t'') -> (x : State t) -> x'' `ReachableFrom` x -> t'' `GTE` t\n> reachableFromLemma {t'' = Z} {t = Z} x'' x prf = LTEZero\n> reachableFromLemma {t'' = S t'} {t = Z} x'' x prf = LTEZero\n> reachableFromLemma {t'' = Z} {t = S m} x'' x (prf1 , prf2) = void (uninhabited (sym prf1))\n> reachableFromLemma {t'' = S t'} {t = S t'} x'' x (Left (Refl , prf2)) = eqInLTE (S t') (S t') Refl\n> reachableFromLemma {t'' = S t'} {t = t} x'' x (Right (MkSigma x' (prf1 , prf2))) = s2 where\n> s1 : t' `GTE` t\n> s1 = reachableFromLemma x' x prf1\n> s2 : S t' `GTE` t\n> s2 = idSuccPreservesLTE t t' s1\n\nNow we can explain what it means for a state |x'| to be avoidable in a\ndecision process starting from a previous state |x|:\n\n> Alternative : (x : State t) -> (m : Nat) -> (x' : State t') -> (x'' : State t') -> Type\n> Alternative x m x' x'' = (x'' `ReachableFrom` x , Viable m x'' , Not (x'' = x'))\n\n> AvoidableFrom' : (x' : State t') -> (x : State t) -> x' `ReachableFrom` x -> Viable n x' -> Type\n> AvoidableFrom' {t'} {n} x' x r v = Sigma (State t') (\\ x'' => Alternative x n x' x'')\n\n> AvoidableFrom : (x' : State t') -> (x : State t) -> x' `ReachableFrom` x -> (m : Nat) -> Type\n> AvoidableFrom {t'} x' x r m = Sigma (State t') (\\ x'' => Alternative x m x' x'')\n\n\n* Decidability of |Viable|\n\nA relevant question for applications is under which conditions\navoidability is decidable. A fundamental result is that, for a finite\ntype |A| and a decidable predicate |P : A -> Type|, |Sigma A P| is\ndecidable, see\n\n< finiteDecSigmaLemma : {A : Type} -> {P : A -> Type} -> Finite A -> Dec1 P -> Dec (Sigma A P)\n\nin |Finite.Properties|. \n\n> decEqState : (x : State t) -> (x' : State t') -> Dec (x = x')\n\n> SequentialDecisionProblems.CoreTheory.Viable {t} Z _ = Unit\n> SequentialDecisionProblems.CoreTheory.Viable {t} (S m) x = GoodCtrl t x m\n\n> SequentialDecisionProblems.CoreTheory.viableSpec0 _ = ()\n> SequentialDecisionProblems.CoreTheory.viableSpec1 x = id\n> SequentialDecisionProblems.CoreTheory.viableSpec2 x = id\n\n> finCtrl : (x : State t) -> Finite (Ctrl t x)\n> -- decAll : {A : Type} -> (P : A -> Type) -> ((a : A) -> Dec (P a)) -> (ma : M A) -> Dec (All P ma)\n> -- decNotEmpty : {A : Type} -> (ma : M A) -> Dec (NotEmpty ma)\n> decAll : (P : (State t) -> Type) -> ((x : State t) -> Dec (P x)) -> (mx : M (State t)) -> Dec (All P mx)\n> decNotEmpty : (mx : M (State t)) -> Dec (NotEmpty mx)\n\n> mutual\n\n> decGood : (x : State t) -> (m : Nat) -> (y : Ctrl t x) -> Dec (Good t x m y)\n> decGood {t} x m y = decPair (decNotEmpty mx') (decAll (Viable m) (decViable m) mx') where\n> mx' : M (State (S t))\n> mx' = nexts t x y\n\n> decViable : (n : Nat) -> (x : State t) -> Dec (Viable n x)\n> decViable Z _ = Yes ()\n> decViable {t} (S m) x = finiteDecSigmaLemma (finCtrl x) (decGood x m)\n\n\n* Decidability of |ReachableFrom|\n\n> -- decElem : {A : Type} -> (a : A) -> (ma : M A) -> Dec (a `Elem` ma)\n> decElem : (x : State t) -> (mx : M (State t)) -> Dec (x `Elem` mx) \n\n> decPred : (x : State t) -> (x' : State (S t)) -> Dec (x `Pred` x')\n> decPred {t} x x' = finiteDecSigmaLemma (finCtrl x) (\\ y => decElem x' (nexts t x y))\n\n> finState : (t : Nat) -> Finite (State t)\n\n> decReachableFrom : (x'' : State t'') -> (x : State t) -> Dec (x'' `ReachableFrom` x)\n> decReachableFrom {t'' = Z } {t} x'' x = decPair dp dq where\n> dp : Dec (t = Z)\n> dp = decEq t Z\n> dq : Dec (x = x'')\n> dq = decEqState x x''\n> decReachableFrom {t'' = S t'} {t} x'' x = decEither dp dq where\n> dp : Dec (t = S t' , x = x'')\n> dp = decPair (decEq t (S t')) (decEqState x x'')\n> dq : Dec (Sigma (State t') (\\ x' => (x' `ReachableFrom` x , x' `Pred` x'')))\n> dq = finiteDecSigmaLemma fState dRP where\n> fState : Finite (State t')\n> fState = finState t'\n> -- dRP : Dec1 (\\ x' => (x' `ReachableFrom` x , x' `Pred` x''))\n> dRP : (x' : State t') -> Dec (x' `ReachableFrom` x , x' `Pred` x'')\n> dRP x' = decPair drf dpred where\n> drf : Dec (x' `ReachableFrom` x)\n> drf = decReachableFrom x' x\n> dpred : Dec (x' `Pred` x'')\n> dpred = decPred x' x''\n\n\n\n\n> {-\n\n\n> ---}\n", "meta": {"hexsha": "00ee86bddda9d5654e12f6a20cfd2565e264a538", "size": 5281, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/AvoidabilityTheory.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/AvoidabilityTheory.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/AvoidabilityTheory.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.1185185185, "max_line_length": 113, "alphanum_fraction": 0.5709145995, "num_tokens": 1897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.619737482534933}} {"text": "module Chapter10\n\nimport Data.Vect\n\n-- describeList : List Int -> String\n-- describeList [] = \"Empty\"\n-- describeList (x::xs) = \"Non-empty, tail \" ++ show xs\n\n-- data ListLast : List a -> Type where\n-- Empty : ListLast []\n-- NonEmpty: (xs: List a)-> (x:a) -> ListLast (xs ++ [x])\n\n-- describeHelper : (input: List Int) -> (form: ListLast input) -> String\n-- describeHelper [] Empty = ?describeHelper_rhs_1\n-- describeHelper (xs ++ [x]) (NonEmpty xs x) = ?describeHelper_rhs_2\n\n\n-- describeHelper [] form = ?describeHelper_rhs_1\n-- describeHelper (_ :: _) Empty impossible\n-- describeHelper (_ :: _) (NonEmpty _ _) impossible\n\n\n--describeHelper [] Empty = \"Empty\"\n--describeHelper (xs ++ [x]) (NonEmpty xs x) = ?hole\n\n-- total\n-- listLast : (xs: List a) -> ListLast xs\n-- listLast [] = Empty\n-- listLast (x :: xs) = case listLast xs of\n-- Empty => NonEmpty [] x\n-- NonEmpty ys y => NonEmpty (x::ys) y\n\n-- describeListEnd : List Int -> String\n-- describeListEnd input with (listLast input)\n-- describeListEnd [] | Empty = \"test\"\n-- describeListEnd (xs ++ [x]) | NonEmpty xs x = \"test2\"\n\n-- recursive views\n--data SnocList ty = Empty | Snoc (SnocList ty) ty\n\n--reverseSnoc : SnocList ty -> List ty\n--reverseSnoc Empty = []\n--reverseSnoc (Snoc xs x) = x :: reverseSnoc xs\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 = input} snoc [] = rewrite appendNilRightNeutral input in snoc\nsnocListHelp {input = input} snoc (x :: xs) =\n rewrite appendAssociative input [x] xs in\n snocListHelp (Snoc snoc {x}) xs\n\n\nsnocList : (input : List a) -> SnocList input\nsnocList xs = snocListHelp 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 = myReverseHelper input (snocList input)\n\n\n--myReverse : List a -> List a\n--myReverse xs = myReverseHelper xs (snocList input)\n\n-- myReverseHelper (xs ++ [x]) (Snoc rec) = ?myReverseHelper_2\n", "meta": {"hexsha": "4070ccebb1c30708d64d4fcb5439437e711cfb9a", "size": 2161, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter10.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": "Chapter10.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": "Chapter10.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": 30.0138888889, "max_line_length": 83, "alphanum_fraction": 0.6626561777, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8056321913146128, "lm_q1q2_score": 0.6195957966880526}} {"text": "\nmodule Progress\n\n-- Progress theorem for the 'Step' relation.\n\n\nimport Step\nimport Subst\nimport Term\n\n\n%default total\n%access export\n\n\n-------------------------------------\n-- Begin: PROGRESS (AND PRESERVATION)\n\n-- Function 'progress' proves the usual progress lemma.\n--\n-- Progress: a closed, well-typed term is either a value\n-- or it can take a step in the reduction relation.\n--\n-- Preservation: after reducing a term of type 't' by one\n-- step, the resulting term is again of type 't'.\n-- \n-- *** Note that preservation is already built into ***\n-- *** the relation 'Step' as defined in module \"Step\". ***\n--\nprogress : (e : Term [] t) -> Either (Value e) (e' : Term [] t ** (Step e e'))\n-- Expressions that are variables cannot occur in an empty context:\n-- (In other words, variables are not closed expressions.)\nprogress (TVar i) = absurd $ FinZAbsurd i\n-- Abstractions are values already:\nprogress (TAbs _) = Left VAbs\n-- Applications can reduce in three different ways, the most\n-- interesting of which occurs when both arguments of 'App'\n-- are values already: in this case, the function 'subst'\n-- is required:\nprogress (TApp e1 e2) = case progress e1 of\n Right (e' ** st) => Right (TApp e' e2 ** StApp1 st)\n Left v1 => \n case progress e2 of\n Right (e' ** st) => Right (TApp e1 e' ** StApp2 v1 st)\n Left v2 => case e1 of\n TAbs f => let e'' = subst e2 FZ f\n in Right (e'' ** StBeta v2)\n-- When the fix-point operator is applied to a value,\n-- that value is necessarily an abstraction; hence\n-- the function 'subst' is used in reducing 'Fix _':\nprogress (TFix e) = case progress e of\n Right (e' ** st) => Right (TFix e' ** StFix st)\n Left v =>\n case e of\n TAbs f => let e'' = subst (TFix (TAbs f)) FZ f\n in Right (e'' ** StFixBeta)\n-- The constant 'Zero' is a value already:\nprogress TZero = Left VZero\n--\nprogress (TSucc e) = case progress e of\n Right (e' ** st) => Right (TSucc e' ** StSucc st)\n Left v => Left (VSucc v)\nprogress (TPred e) = case progress e of\n Right (e' ** st) => Right (TPred e' ** StPred st)\n Left v => \n case e of\n TZero => Right (TZero ** StPredZero)\n TSucc e' => case v of \n VAbs impossible\n VZero impossible\n VSucc v' => Right (e' ** StPredSucc v')\n-- \nprogress (TIfz e1 e2 e3) = case progress e1 of\n Right (e' ** st) => Right $ (TIfz e' e2 e3 ** StIfz st)\n Left v => case v of\n VAbs impossible\n VZero => Right (e2 ** StIfzZero)\n VSucc v' => Right (e3 ** StIfzSucc v')\n\n-- End: PROGRESS (AND PRESERVATION)\n-----------------------------------\n\n\n\n-------------------------------\n-- Begin: VALUE <=> IRREDUCIBLE\n\n-- Establish that values cannot be further reduced under 'Step'.\nvalueIrreducible : (e : Term [] t) -> \n Value e -> \n {e' : Term [] t} -> Step e e' -> Void\nvalueIrreducible TZero VZero _ impossible\nvalueIrreducible (TSucc n) (VSucc v) (StSucc st) = valueIrreducible n v st\nvalueIrreducible (TAbs _) VAbs _ impossible\n\n\n-- Establish that irreducible expressions (under 'Step') are values:\nirreducibleValue : (e : Term [] t) -> \n ({e' : Term [] t} -> Step e e' -> Void) ->\n Value e \nirreducibleValue e notStep = case progress e of \n Right (_ ** st) => absurd $ notStep st \n Left v => v\n\n-- End: VALUE <=> IRREDUCIBLE\n-----------------------------\n\n\n\n------------------------------------------\n-- Begin: DIVERGENCE OF TERM 'Subst.omega'\n\n-- Term 'omega' steps to itself in one step:\nstepOmega : Step Subst.omega Subst.omega\nstepOmega = let st = StFixBeta {t=TVar {ctx=[TyNat]} FZ}\n in replace {P = \\x => Step Subst.omega x} substOmega st\n\n\n-- That 'omega' steps to itself under the reflexive,\n-- transitive closure of 'Step' is trivial:\ntransStepOmega : TransStep Subst.omega Subst.omega\ntransStepOmega = TStRefl _\n\n\n-- Term 'omega' steps to nothing but itself:\n-- (This could also be derived as a consequence of determinism of 'Step'.)\nstepOmegaOnly : (e : Term [] TyNat) -> Step Subst.omega e -> e = Subst.omega \nstepOmegaOnly (TFix _) (StFix st) = absurd $ valueIrreducible (TAbs $ TVar FZ) VAbs st\nstepOmegaOnly (subst (TFix (TAbs (TVar FZ))) FZ (TVar FZ)) StFixBeta = substOmega\n\n\n-- To extend the previous result 'stepOmegaOnly' to the transitive closure\n-- of the 'Step' relation, an indexed version of 'TransStep' is needed:\ndata TransStepN : Nat -> Term [] t -> Term [] t -> Type where\n TStNRefl : (e : Term [] t) -> TransStepN Z e e\n TStNTrans : {e : Term [] t} -> {e' : Term [] t} -> {e'' : Term [] t} ->\n Step e e' -> TransStepN n e' e'' -> TransStepN (S n) e e''\n\n\ntransStepFromN : TransStepN n e1 e2 -> TransStep e1 e2\ntransStepFromN (TStNRefl e1) = TStRefl e1\ntransStepFromN (TStNTrans st tstn) = TStTrans st (transStepFromN tstn)\n\n\ntransStepToN : TransStep e1 e2 -> (n : Nat ** TransStepN n e1 e2)\ntransStepToN (TStRefl e1) = (Z ** TStNRefl e1)\ntransStepToN (TStTrans st tst) = let (m ** tstn) = transStepToN tst\n in ((S m) ** TStNTrans st tstn)\n\n\ntransStepNOmegaOnly : (e : Term [] TyNat) -> (n : Nat) -> \n TransStepN n Subst.omega e -> e = Subst.omega\ntransStepNOmegaOnly _ Z (TStNRefl _) = Refl\ntransStepNOmegaOnly e (S k) (TStNTrans st tstk) = \n let eq = stepOmegaOnly _ st \n tstk' = replace {P = \\x => TransStepN k x e} eq tstk\n in transStepNOmegaOnly _ k tstk'\n\n\n-- Finally, the fact that 'omega' only steps to itself is proven\n-- by appealing to the indexed version of the transitive closure:\n-- (An induction argument analogous to the one in 'transStepNOmegaOnly'\n-- is not accepted by Idris' totality checker. Induction would proceed on\n-- the structure of the 'TransStep omega e' argument, and the induction\n-- hypothesis would be applied to the second argument of the 'TStTrans'\n-- constructor, which would again have the type 'TransStep omega e' but\n-- only after rewriting with the equation obtained from 'stepOmegaOnly'.)\ntransStepOmegaOnly : (e : Term [] TyNat) -> TransStep Subst.omega e -> e = Subst.omega\ntransStepOmegaOnly e tst = let (n ** tstn) = transStepToN tst\n in transStepNOmegaOnly e n tstn\n\n\ndivergenceOmega : TransStep Subst.omega e -> (Value e -> Void)\ndivergenceOmega {e} tst v = let eq = transStepOmegaOnly e tst\n in case (replace {P = \\x => Value x} eq v) of\n VZero impossible\n (VSucc _) impossible\n VAbs impossible\n\n-- End: DIVERGENCE OF TERM 'Subst.omega'\n----------------------------------------\n", "meta": {"hexsha": "dec89e1401eb950d4cb2208a86408dae6f5bb2cf", "size": 7037, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "typed/src/Progress.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/Progress.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/Progress.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": 38.6648351648, "max_line_length": 88, "alphanum_fraction": 0.5785135711, "num_tokens": 1954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895106480586, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6195198763229073}} {"text": "module Data.BinarySearchTree\n\nimport Decidable.Order\n\n%default total\n\ncontraSym : ((lhs = rhs) -> Void) -> (rhs = lhs) -> Void\ncontraSym contra eq = contra $ sym eq\n\nstrictRel : Ordered ty rel => {lhs : ty} -> {rhs : ty} ->\n lhs `rel` rhs -> (lhs = rhs -> Void ) -> (rhs `rel` lhs -> Void)\nstrictRel {lhs} {rhs} smaller notEq assumption =\n notEq $ antisymmetric lhs rhs smaller assumption\n\nrevStrictRel : {auto constraint : Ordered ty rel} -> {lhs : ty} -> {rhs : ty} ->\n (lhs `rel` rhs -> Void) -> (rhs `rel` lhs)\nrevStrictRel {rel} {lhs} {rhs} gt =\n case order {to = rel} lhs rhs of\n Left lte => absurd $ gt lte\n Right gte => gte\n\nusing (constraint : Ordered ty rel)\n export\n data Bounded : Ordered ty rel -> Maybe ty -> ty -> Maybe ty -> Type where\n WithinBounds : {lbound, ubound : Maybe ty} -> {pivot : ty} ->\n (gt : (x ** (lbound = Just x, rel pivot x)) -> Void) ->\n (lt : (x ** (ubound = Just x, rel x pivot)) -> Void) ->\n Bounded constraint lbound pivot ubound\n\n GTNothing : {auto constraint : Ordered ty rel} -> {value: ty} -> Type\n GTNothing {ty} {rel} {value} = (x : ty ** (Nothing = Just x, rel value x))\n\n anythingGTNothing : {auto constraint : Ordered ty rel} -> GTNothing -> Void\n anythingGTNothing (_ ** (Refl, _)) impossible\n\n LTNothing : {auto constraint : Ordered ty rel} -> {value: ty} -> Type\n LTNothing {ty} {rel} {value} = (x : ty ** (Nothing = Just x, rel x value))\n\n anythingLTNothing : {auto constraint : Ordered ty rel} -> LTNothing -> Void\n anythingLTNothing (_ ** (Refl, _)) impossible\n\n export\n WithinUnconstrainedBounds : {pivot : ty} -> Bounded _ Nothing pivot Nothing\n WithinUnconstrainedBounds {pivot} =\n WithinBounds {pivot} anythingGTNothing anythingLTNothing\n\n export\n changeLbound : Bounded constraint _ pivot ubound -> (rel pivot v -> Void) ->\n Bounded constraint (Just v) pivot ubound\n changeLbound {v} (WithinBounds _ lt) gt = WithinBounds {pivot} gt' lt\n where gt' : (x ** (Just v = Just x, rel pivot x)) -> Void\n gt' (x ** (prf, gte)) = gt $ rewrite justInjective prf in gte\n\n export\n changeUbound : Bounded constraint lbound pivot _ -> (rel v pivot -> Void) ->\n Bounded constraint lbound pivot (Just v)\n changeUbound {v} (WithinBounds gt _) lt = WithinBounds {pivot} gt lt'\n where lt' : (x ** (Just v = Just x, rel x pivot)) -> Void\n lt' (x ** (prf, lte)) = lt $ rewrite justInjective prf in lte\n\n public export\n data BinarySearchTree_ : Ordered ty rel -> Maybe ty -> Maybe ty -> Nat -> Type where\n Empty : BinarySearchTree_ _ _ _ Z\n Node : (v : ty) ->\n .{bounded : Bounded constraint lbound v ubound} ->\n {leftCount, rightCount : Nat} ->\n (left : BinarySearchTree_ constraint lbound (Just v) leftCount) ->\n (right : BinarySearchTree_ constraint (Just v) ubound rightCount) ->\n BinarySearchTree_ constraint lbound ubound (S $ leftCount + rightCount)\n\n value : BinarySearchTree_ constraint _ _ (S _) -> ty\n value (Node v _ _) = v\n\n leftCount : BinarySearchTree_ constraint _ _ (S _) -> Nat\n leftCount (Node {leftCount = len} _ _ _) = len\n\n left : {constraint : Ordered ty rel} ->\n (orig : BinarySearchTree_ constraint lbound _ (S _)) ->\n BinarySearchTree_ constraint lbound (Just (value orig)) (leftCount orig)\n left (Node _ l _) = l\n\n rightCount : BinarySearchTree_ constraint _ _ (S _) -> Nat\n rightCount (Node {rightCount = len} _ _ _) = len\n\n right : {constraint : Ordered ty rel} ->\n (orig : BinarySearchTree_ constraint _ ubound (S _)) ->\n BinarySearchTree_ constraint (Just (value orig)) ubound (rightCount orig)\n right (Node _ _ r) = r\n\n export\n data Elem : ty -> BinarySearchTree_ constraint _ _ _ -> Type where\n Here : Elem v (Node {constraint} v _ _)\n Left : Elem v l -> Elem v (Node _ l _)\n Right : Elem v r -> Elem v (Node _ _ r)\n\n export\n noEmptyElem : Elem _ Empty -> Void\n noEmptyElem _ impossible\n\n export\n lboundRespected :\n {lbound : ty} -> {tree : BinarySearchTree_ constraint (Just lbound) _ _} ->\n Elem pivot tree -> rel pivot lbound -> Void\n lboundRespected {rel} {lbound} {tree} elem {pivot} prf =\n let Node {bounded = WithinBounds gt _} v _ _ = tree in\n case elem of\n Here => gt (lbound ** (Refl, prf))\n Left elemL => lboundRespected elemL prf\n Right elemR => case order {to = rel} lbound v of\n Left lte => let prf' = transitive pivot _ _ prf lte in\n lboundRespected elemR prf'\n Right gte => gt (lbound ** (Refl, gte))\n\n export\n uboundRespected :\n {ubound : ty} -> {tree : BinarySearchTree_ constraint _ (Just ubound) _} ->\n Elem pivot tree -> rel ubound pivot -> Void\n uboundRespected {rel} {ubound} {tree} elem {pivot} prf =\n let Node {bounded = WithinBounds _ lt} v _ _ = tree in\n case elem of\n Here => lt (ubound ** (Refl, prf))\n Left elemL => case order {to = rel} v ubound of\n Left lte => let prf' = transitive v _ _ lte prf in\n uboundRespected elemL prf'\n Right gte => lt (ubound ** (Refl, gte))\n Right elemR => uboundRespected elemR prf\n\n data SearchSpace : Type where\n MkSearchSpace : Bounded constraint lbound pivot ubound ->\n BinarySearchTree_ constraint lbound ubound len -> SearchSpace\n\n data Finding : SearchSpace -> (SearchSpace -> Type) -> Type where\n GoLeft : .{retCalc : SearchSpace -> Type} ->\n .{bounded : Bounded constraint lbound pivot ubound} ->\n {orig : BinarySearchTree_ constraint lbound ubound (S _)} ->\n {leftBounded : Bounded constraint lbound pivot (Just (value orig))} ->\n (rel (value orig) pivot -> Void) ->\n retCalc (MkSearchSpace leftBounded (left orig)) ->\n Finding (MkSearchSpace bounded orig) retCalc\n GoRight : .{retCalc : SearchSpace -> Type} ->\n .{bounded : Bounded constraint lbound pivot ubound} ->\n {orig : BinarySearchTree_ constraint lbound ubound (S _)} ->\n {rightBounded : Bounded constraint (Just (value orig)) pivot ubound} ->\n (rel pivot (value orig) -> Void) ->\n retCalc (MkSearchSpace rightBounded (right orig)) ->\n Finding (MkSearchSpace bounded orig) retCalc\n Found : .{bounded : Bounded constraint lbound pivot ubound} ->\n {orig : BinarySearchTree_ constraint lbound ubound (S _)} ->\n (pivot = value orig) -> Finding (MkSearchSpace bounded orig) _\n DeadEnd : .{bounded : Bounded constraint lbound pivot ubound} ->\n {orig : BinarySearchTree_ constraint lbound ubound Z} ->\n Finding (MkSearchSpace bounded orig) _\n\n FindingTransform : Ordered ty _ -> ty -> (SearchSpace -> Type) -> Type\n FindingTransform {ty} constraint pivot retCalc =\n (lbound', ubound': Maybe ty) ->\n (bounded' : Bounded constraint lbound' pivot ubound') ->\n {len' : Nat} ->\n (tree' : BinarySearchTree_ constraint lbound' ubound' len') ->\n Finding (MkSearchSpace bounded' tree') retCalc ->\n retCalc (MkSearchSpace bounded' tree')\n\n find_ : DecEq ty => (pivot : ty) ->\n {lbound, ubound : Maybe ty} -> {len : Nat} ->\n (tree : BinarySearchTree_ constraint lbound ubound len) ->\n (bounded : Bounded constraint lbound pivot ubound) ->\n FindingTransform constraint pivot retCalc ->\n Finding (MkSearchSpace bounded tree) retCalc\n find_ _ Empty _ _ = DeadEnd\n find_ {rel} {len = S _} pivot (Node v l r) pivotBounded extract =\n case decEq pivot v of\n Yes Refl => Found Refl\n No contra => case order {to = rel} pivot v of\n Left prf => let lt = strictRel prf contra\n bounded = changeUbound pivotBounded lt\n finding = find_ pivot l bounded extract\n ret = extract _ _ _ _ finding in\n GoLeft lt ret\n Right prf => let gt = strictRel prf (contraSym contra)\n bounded = changeLbound pivotBounded gt\n finding = find_ pivot r bounded extract\n ret = extract _ _ _ _ finding in\n GoRight gt ret\n\n public export\n BinarySearchTree : Ordered ty rel -> Nat -> Type\n BinarySearchTree constraint len =\n BinarySearchTree_ constraint Nothing Nothing len\n\n public export\n CountedBinarySearchTree : Ordered ty rel -> Type\n CountedBinarySearchTree constraint =\n (len : Nat ** BinarySearchTree constraint len)\n\n find : DecEq ty => (pivot : ty) ->\n (ct : CountedBinarySearchTree constraint) ->\n FindingTransform constraint pivot retCalc ->\n retCalc $ MkSearchSpace (WithinUnconstrainedBounds {pivot}) (snd ct)\n find pivot (_ ** tree) transform =\n transform _ _ _ _ $ find_ pivot tree _ transform\n\n export\n decElem : DecEq ty => (v : ty) ->\n (ct : CountedBinarySearchTree constraint) ->\n Dec (Elem v (snd ct))\n decElem {constraint} value ct = find value ct transform\n where retCalc : SearchSpace -> Type\n retCalc (MkSearchSpace (WithinBounds {pivot} _ _) tree') =\n Dec (Elem pivot tree')\n transform : FindingTransform constraint value retCalc\n transform lbound' ubound' (WithinBounds {pivot = value} _ _) len tree' finding =\n case finding of\n GoLeft {orig = Node _ _ _} {leftBounded} contra prev =>\n let WithinBounds _ _ = leftBounded in\n case prev of\n Yes prf => Yes $ Left prf\n No contra' => No $ \\prop => case prop of\n Here => contra $ reflexive value\n Left elem => contra' elem\n Right elem => lboundRespected elem (revStrictRel contra)\n GoRight {orig = Node _ _ _} {rightBounded} contra prev =>\n let WithinBounds _ _ = rightBounded in\n case prev of\n Yes prf => Yes $ Right prf\n No contra' => No $ \\prop => case prop of\n Here => contra $ reflexive value\n Left elem => uboundRespected elem (revStrictRel contra)\n Right elem => contra' elem\n Found {orig = Node _ _ _} Refl => Yes Here\n DeadEnd {orig = Empty} => No noEmptyElem\n\n export\n elem : DecEq ty => ty -> CountedBinarySearchTree constraint -> Bool\n elem v ct = decAsBool $ decElem v ct\n\n export\n insert : DecEq ty => CountedBinarySearchTree constraint -> ty ->\n CountedBinarySearchTree constraint\n insert {constraint} ct value = find value ct transform\n where retCalc : SearchSpace -> Type\n retCalc (MkSearchSpace {constraint} (WithinBounds {pivot} {lbound} {ubound} _ _) tree') =\n (len : Nat ** BinarySearchTree_ constraint lbound ubound len)\n transform : FindingTransform constraint value retCalc\n transform lbound' ubound' (WithinBounds {pivot = value} gt lt) len tree' finding =\n case finding of\n GoLeft {orig} {leftBounded} _ prev =>\n let Node {bounded} v _ r = orig\n WithinBounds _ _ = leftBounded\n (_ ** l') = prev in\n (_ ** Node {bounded} v l' r)\n GoRight {orig} {rightBounded} _ prev =>\n let Node {bounded} v l _ = orig\n WithinBounds _ _ = rightBounded\n (_ ** r') = prev in\n (_ ** Node {bounded} v l r')\n Found {orig} Refl => (_ ** orig)\n DeadEnd {orig = Empty} =>\n let bounded = WithinBounds gt lt in\n (_ ** Node {bounded} value Empty Empty)", "meta": {"hexsha": "98f926b5bc98bc2a55e35ea3e4dca5af9380f6fe", "size": 11876, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/BinarySearchTree.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/BinarySearchTree.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/BinarySearchTree.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.8532818533, "max_line_length": 104, "alphanum_fraction": 0.5945604581, "num_tokens": 3042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6195198693871202}} {"text": "data 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\ncomp : (a -> b) -> (b -> c) -> a -> c\ncomp = ?baz\n\nzipWith : (a -> b -> c) -> (1 xs : Vect n a) -> (1 ys : Vect n b) -> Vect n c\nzipWith f [] [] = []\nzipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys\n\ntransposeHelper : Vect m a -> (1 xs_trans : Vect m (Vect k a)) -> Vect m (Vect (S k) a)\ntransposeHelper xs ys = zipWith ?foo xs ys\n", "meta": {"hexsha": "1c2c62a7f5590c5283697d9b75a35e806919e39f", "size": 463, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive008/IEdit.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/interactive008/IEdit.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/interactive008/IEdit.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": 28.9375, "max_line_length": 87, "alphanum_fraction": 0.5075593952, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117855317473, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.619279236734749}} {"text": "||| N-ary dependent functions using telescopes\n|||\n||| Compare with `base/Data.Fun` and:\n||| Guillaume Allais. 2019. Generic level polymorphic n-ary functions. TyDe 2019.\nmodule Data.Telescope.Fun\n\nimport Data.Telescope.Telescope\nimport Data.Telescope.Segment\nimport Data.Telescope.SimpleFun\n\npublic export\n0 Fun : (env : Left.Environment gamma) -> {n : Nat} -> (0 delta : Segment n gamma)\n -> (cod : SimpleFun env delta Type)\n -> Type\nFun env {n = 0 } [] cod = cod\nFun env {n = S n} (ty :: delta) cod = (x : ty env) -> Fun (env ** x) delta (cod x)\n\npublic export\nuncurry : {0 n : Nat} -> {0 env : Left.Environment gamma} -> {0 delta : Segment n gamma}\n -> {0 cod : SimpleFun env delta Type}\n -> (f : Fun env delta cod) -> (ext : Environment env delta)\n -> uncurry cod ext\nuncurry f Empty = f\nuncurry f (x .= xs) = Fun.uncurry (f x) xs\n\npublic export\ncurry : {n : Nat} -> {0 env : Left.Environment gamma} -> {0 delta : Segment n gamma}\n -> {0 cod : SimpleFun env delta Type}\n -> ((ext : Environment env delta) -> SimpleFun.uncurry cod ext)\n -> Fun env delta cod\ncurry {n = 0 } {delta = [] } f = f Empty\ncurry {n = S n} {delta = ty :: delta} f = \\x => Fun.curry (\\xs => f (x .= xs))\n", "meta": {"hexsha": "c6f581c187533a49b6396700b3b6fc4876ede3d1", "size": 1245, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Telescope/Fun.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/Telescope/Fun.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/Telescope/Fun.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": 37.7272727273, "max_line_length": 88, "alphanum_fraction": 0.6080321285, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6190883022408511}} {"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 -}\nmodule Main\n\noccurences : (Eq ty) => (item : ty) -> (values : List ty) -> Nat\noccurences item [] = 0\noccurences item (x :: xs) = case item == x of\n False => occurences item xs\n True => 1 + occurences item xs\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\nrecord Album where\n constructor MkAlbum\n artist : String\n title : String\n year : Integer\n\nhelp : Album\nhelp = MkAlbum \"The Beatles\" \"Help\" 1965\n\nrubbersoul : Album\nrubbersoul = MkAlbum \"The Beatles\" \"Rubber Soul\" 1965\n\nclouds : Album\nclouds = MkAlbum \"Joni Mitchell\" \"Clouds\" 1969\n\nhunkydory : Album\nhunkydory = MkAlbum \"David Bowie\" \"Hunky Dory\" 1971\n\nheroes : Album\nheroes = MkAlbum \"David Bowie\" \"Heroes\" 1977\n\ncollection : List Album\ncollection = [help, rubbersoul, clouds, hunkydory, heroes]\n\nEq Album where\n (==) (MkAlbum artist1 title1 year1) (MkAlbum artist2 title2 year2)\n = artist1 == artist2 && title1 == title2 && year1 == year2\n\nOrd Album where\n compare (MkAlbum artist1 title1 year1) (MkAlbum artist2 title2 year2)\n = case compare artist1 artist2 of\n EQ => case compare year1 year2 of\n EQ => compare title1 title2\n diff_year => diff_year\n diff_artist => diff_artist\n\nShow Album where\n show (MkAlbum artist title year)\n = title ++ \" by \" ++ artist ++ \" (released \" ++ show year ++ \")\"\n\nmain : IO ()\nmain = do\n printLn \"Main\"\n -- Triggers a compiler like bug: https://github.com/typedefs/typedefs/issues/72\n -- print $ occurences 'b' ['a', 'a', 'b', 'b', 'b', 'c']\n printLn $ occurences 'b' ['a', 'a', 'b', 'b', 'b', 'c']\n printLn $ occurences 100 [50, 100, 100, 50]\n printLn $ occurences Liquid [Solid, Liquid, Liquid, Gas, Gas]\n printLn $ heroes > clouds\n printLn $ help <= rubbersoul\n printLn $ map title (sort collection)\n printLn $ clouds\n", "meta": {"hexsha": "5d1df51b12376d4bda096b3a016350f6b2900bc8", "size": 2283, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/tdd/chapter07/01_Interfaces.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/chapter07/01_Interfaces.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/chapter07/01_Interfaces.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": 29.6493506494, "max_line_length": 99, "alphanum_fraction": 0.6671046868, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6186170110728875}} {"text": "> module Fin.Properties\n\n> import Data.Fin\n> import Data.Vect\n> import Control.Isomorphism\n\n> import Fun.Properties\n> import Fin.Operations\n> import Basic.Operations\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n> -- %hide Prelude.List.tail\n> -- %hide Prelude.Stream.tail\n> -- %hide Data.VectType.Vect.tail\n\n\n|Fin 0| properties:\n\n> fin0Lemma : (i : Fin Z) -> (j : Fin Z) -> i = j\n> fin0Lemma i j = absurd i\n> %freeze fin0Lemma -- frozen\n\n\n|Fin 1| properties:\n\n> fin1Lemma : (i : Fin (S Z)) -> (j : Fin (S Z)) -> i = j\n> fin1Lemma FZ FZ = Refl\n> fin1Lemma FZ (FS k) = absurd k\n> fin1Lemma (FS k) FZ = absurd k\n> fin1Lemma (FS k) (FS j) = absurd k\n> %freeze fin1Lemma -- frozen\n\n\n> ||| Fin 1 is isomorphic to Unit\n> isoFin1Unit : Iso (Fin (S Z)) Unit\n> isoFin1Unit = MkIso to from toFrom fromTo where\n> to : Fin (S Z) -> Unit\n> to FZ = ()\n> to (FS k) = absurd k\n> from : Unit -> Fin (S Z)\n> from () = FZ\n> toFrom : (u : Unit) -> to (from u) = u\n> toFrom () = Refl\n> fromTo : (k : Fin (S Z)) -> from (to k) = k\n> fromTo FZ = Refl\n> fromTo (FS k) = absurd k\n> %freeze isoFin1Unit -- frozen\n\n\nInjectivity of FS\n\n> ||| FS is injective (one direction)\n> fsInjective1 : (left : Fin n) -> (right : Fin n) -> FS left = FS right -> left = right\n> fsInjective1 = FSInjective\n> %freeze fsInjective1 -- frozen\n\n\n> ||| FS is injective (the other way round)\n> fsInjective2 : (left : Fin n) -> (right : Fin n) -> Not (left = right) -> Not (FS left = FS right)\n> -- fsInjective2 left right contra = contra . (FSInjective left right)\n> fsInjective2 = injectiveLemma FS fsInjective1\n> %freeze fsInjective2 -- frozen\n\n\n> ||| FS preserves equality\n> fsPreservesEq : (left : Fin n) -> (right : Fin n) -> left = right -> FS left = FS right\n> fsPreservesEq left right = cong\n> %freeze fsPreservesEq -- frozen\n\n\n|finToNat| properties:\n\n> ||| |finToNat (k : Fin n)| is LT bounded by |n|\n> finToNatLemma : {n : Nat} -> (k : Fin n) -> LT (finToNat k) n\n> finToNatLemma {n = Z} k = absurd k\n> finToNatLemma {n = S m} FZ = LTESucc LTEZero\n> finToNatLemma {n = S m} (FS k) = LTESucc (finToNatLemma k)\n> %freeze finToNatLemma -- frozen\n\n\n|weaken| properties:\n\n> |||\n> weakenPreservesEq : (i : Fin n) -> (j : Fin n) -> (i = j) -> (weaken i = weaken j)\n> weakenPreservesEq left _ Refl = Refl\n> %freeze weakenPreservesEq -- frozen\n\n\n> |||\n> weakenInjective : (i : Fin n) -> (j : Fin n) -> (weaken i = weaken j) -> (i = j)\n> weakenInjective FZ FZ Refl = Refl\n> weakenInjective FZ (FS k) Refl impossible\n> weakenInjective (FS k) FZ Refl impossible\n> weakenInjective (FS k) (FS j) prf = s5 where\n> s1 : weaken (FS k) = weaken (FS j)\n> s1 = prf\n> s2 : FS (weaken k) = FS (weaken j)\n> s2 = s1\n> s3 : weaken k = weaken j\n> s3 = FSInjective (weaken k) (weaken j) s2\n> s4 : k = j\n> s4 = weakenInjective k j s3\n> s5 : FS k = FS j\n> s5 = cong s4\n> %freeze weakenInjective -- frozen\n\n\n> |||\n> notWeakenLemma : (i : Fin n) -> (j : Fin n) -> Not (i = j) -> Not (weaken i = weaken j)\n> notWeakenLemma i j contra = \\ prf => contra (weakenInjective i j prf)\n> %freeze notWeakenLemma -- frozen\n\n\n|tail| properties:\n\n> |||\n> tailSuccLemma : {A : Type} -> (f : Fin (S n) -> A) -> (i : Fin n) -> (tail f) i = f (FS i)\n> tailSuccLemma f i = Refl\n> %freeze tailSuccLemma -- frozen\n\n\n> |||\n> tailSuccEqLemma : {n : Nat} -> {A : Type} ->\n> (i : Fin n) -> (j : Fin n) -> (f : Fin (S n) -> A) ->\n> (tail f) i = (tail f) j ->\n> f (FS i) = f (FS j)\n> tailSuccEqLemma i j f prf = replace2 (tailSuccLemma f i) (tailSuccLemma f j) prf\n> %freeze tailSuccEqLemma -- frozen\n\n\n|toVect| properties:\n\n> ||| |toVect| representations of finite functions are complete\n> toVectComplete : {n : Nat} -> {A : Type} -> (f : Fin n -> A) -> (k : Fin n) -> Elem (f k) (toVect f)\n> toVectComplete {n = Z} _ k = void (uninhabited k)\n> toVectComplete f FZ = Here\n> toVectComplete f (FS j) = There (toVectComplete (tail f) j)\n> %freeze toVectComplete -- frozen\n\n\n> |||\n> toVectRepr : {A : Type} -> (f : Fin n -> A) -> (k : Fin n) -> index k (toVect f) = f k\n> toVectRepr {n = Z} f k = absurd k\n> toVectRepr {n = S m} f FZ = Refl\n> toVectRepr {n = S m} f (FS k) = toVectRepr (tail f) k\n> %freeze toVectRepr -- frozen\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "8aeacef002dd2f1a3583e675e97fc29aff0da744", "size": 4336, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fin/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": "Fin/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": "Fin/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": 27.9741935484, "max_line_length": 102, "alphanum_fraction": 0.5846402214, "num_tokens": 1582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6185109846601019}} {"text": "> module Rel.TotalPreorderOperations\n\n> import Rel.TotalPreorder\n\n> %default total\n\n> %access public export\n\n\n> {-\n> ||| R\n> R : {A : Type} -> {R : A -> A -> Type} -> TotalPreorder R -> (A -> A -> Type)\n> R (MkTotalPreorder R _ _ _) = R\n> -}\n\n\n> ||| reflexive\n> reflexive : {A : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R -> \n> (x : A) -> R x x\n> reflexive (MkTotalPreorder _ reflexive _ _) = reflexive\n\n\n> ||| transitive\n> transitive : {A : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R ->\n> (x : A) -> (y : A) -> (z : A) -> R x y -> R y z -> R x z\n> transitive (MkTotalPreorder _ _ transitive _) = transitive\n\n\n> ||| totalPre\n> totalPre : {A : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R ->\n> (x : A) -> (y : A) -> Either (R x y) (R y x)\n> totalPre (MkTotalPreorder _ _ _ totalPre) = totalPre\n\n\n> ||| \n> extendRight : {A, B : Type} -> \n> (A -> A -> Type) -> ((A, B) -> (A, B) -> Type)\n> extendRight R = \\ x => \\ y => R (fst x) (fst y)\n\n\n> ||| |extendRight| preserves total preorders\n> extendRightLemma : {A, B : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R -> TotalPreorder (extendRight {A} {B} R)\n> extendRightLemma {A} {B} {R} (MkTotalPreorder R reflexiveR transitiveR totalR) =\n> MkTotalPreorder S reflexiveS transitiveS totalS where\n> S : (A, B) -> (A, B) -> Type\n> S = extendRight R\n> reflexiveS : (x : (A, B)) -> S x x\n> reflexiveS = \\ x => reflexiveR (fst x)\n> transitiveS : (x : (A, B)) -> (y : (A, B)) -> (z : (A, B)) -> S x y -> S y z -> S x z\n> transitiveS = \\ x => \\ y => \\ z => \\ xRy => \\ yRz => transitiveR (fst x) (fst y) (fst z) xRy yRz\n> totalS : (x : (A, B)) -> (y : (A, B)) -> Either (S x y) (S y x)\n> totalS = \\ x => \\ y => totalR (fst x) (fst y)\n\n\n> ||| \n> extendLeft : {A, B : Type} -> \n> (B -> B -> Type) -> ((A, B) -> (A, B) -> Type)\n> extendLeft R = \\ x => \\ y => R (snd x) (snd y)\n\n\n> ||| |extendRight| preserves total preorders\n> extendLeftLemma : {A, B : Type} -> {R : B -> B -> Type} -> \n> TotalPreorder R -> TotalPreorder (extendLeft {A} {B} R)\n> extendLeftLemma {A} {B} {R} (MkTotalPreorder R reflexiveR transitiveR totalR) =\n> MkTotalPreorder S reflexiveS transitiveS totalS where\n> S : (A, B) -> (A, B) -> Type\n> S = extendLeft R\n> reflexiveS : (x : (A, B)) -> S x x\n> reflexiveS = \\ x => reflexiveR (snd x)\n> transitiveS : (x : (A, B)) -> (y : (A, B)) -> (z : (A, B)) -> S x y -> S y z -> S x z\n> transitiveS = \\ x => \\ y => \\ z => \\ xRy => \\ yRz => transitiveR (snd x) (snd y) (snd z) xRy yRz\n> totalS : (x : (A, B)) -> (y : (A, B)) -> Either (S x y) (S y x)\n> totalS = \\ x => \\ y => totalR (snd x) (snd y)\n\n\n> {-\n\n> ||| R\n> R : {A : Type} -> TotalPreorder A -> (A -> A -> Type)\n> R (MkTotalPreorder R _ _ _) = R\n\n\n> ||| reflexive\n> reflexive : {A : Type} ->\n> (tp : TotalPreorder A) ->\n> (x : A) -> (R tp) x x\n> reflexive (MkTotalPreorder _ reflexive _ _) = reflexive\n\n\n> ||| transitive\n> transitive : {A : Type} ->\n> (tp : TotalPreorder A) ->\n> (x : A) -> (y : A) -> (z : A) -> (R tp) x y -> (R tp) y z -> (R tp) x z\n> transitive (MkTotalPreorder _ _ transitive _) = transitive\n\n\n> ||| totalPre\n> totalPre : {A : Type} ->\n> (tp : TotalPreorder A) ->\n> (x : A) -> (y : A) -> Either ((R tp) x y) ((R tp) y x)\n> totalPre (MkTotalPreorder _ _ _ totalPre) = totalPre\n\n\n> ||| Total preorders on |A| induce total preorders on |(A, B)|\n> fromTotalPreorder1 : {A, B : Type} -> TotalPreorder A -> TotalPreorder (A, B)\n> fromTotalPreorder1 (MkTotalPreorder R reflexive transitive totalPre) =\n> MkTotalPreorder (\\ x => \\ y => R (fst x) (fst y))\n> (\\ x => reflexive (fst x))\n> (\\ x => \\ y => \\ z => \\ xRy => \\ yRz => transitive (fst x) (fst y) (fst z) xRy yRz)\n> (\\ x => \\ y => totalPre (fst x) (fst y))\n\n\n> from2 : {A, B : Type} -> (B -> B -> Type) -> (A, B) -> (A, B) -> Type\n> from2 R x y = R (snd x) (snd y)\n\n> ||| Total preorders on |B| induce total preorders on |(A, B)|\n> fromTotalPreorder2 : {A, B : Type} -> TotalPreorder B -> TotalPreorder (A, B)\n> fromTotalPreorder2 to =\n> MkTotalPreorder (from2 (R to))\n> (\\ x => reflexive to (snd x))\n> (\\ x => \\ y => \\ z => \\ xRy => \\ yRz => transitive to (snd x) (snd y) (snd z) xRy yRz)\n> (\\ x => \\ y => totalPre to (snd x) (snd y))\n\n> ---}\n", "meta": {"hexsha": "3e7d76c2c40a20bc0f604852c9937225795ae245", "size": 4580, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Rel/TotalPreorderOperations.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/TotalPreorderOperations.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/TotalPreorderOperations.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": 35.503875969, "max_line_length": 106, "alphanum_fraction": 0.4799126638, "num_tokens": 1694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6181683736146484}} {"text": "module ImplicitQueue\n\nimport Queue\n\n%default total\n%access private\n\ndata Digit a = Zero | One a | Two a a\n\nexport\ndata ImplicitQueue a =\n Shallow (Digit a)\n | Deep (Digit a) (Lazy (ImplicitQueue (a, a))) (Digit a)\n\nexport\nQueue ImplicitQueue where\n empty = Shallow Zero\n isEmpty (Shallow Zero) = True\n isEmpty x = False\n\n snoc (Shallow Zero) y = Shallow (One y)\n snoc (Shallow (One x)) y = Deep (Two x y) empty Zero\n snoc (Deep f m Zero) y = Deep f m (One y)\n snoc (Deep f m (One x)) y = Deep f (snoc m (x, y)) Zero\n snoc (Shallow (Two _ _)) _ = assert_unreachable\n snoc (Deep _ _ (Two _ _)) _ = assert_unreachable\n\n head (Shallow Zero ) = idris_crash \"empty queue\"\n head (Shallow (One x)) = x\n head (Deep (One x) m r) = x\n head (Deep (Two x y) m r) = x\n head (Shallow (Two _ _)) = assert_unreachable\n head (Deep Zero _ _) = assert_unreachable\n\n tail (Shallow Zero) = idris_crash \"empty queue\"\n tail (Shallow (One x)) = empty\n tail (Deep (Two x y) m r) = Deep (One y) m r\n tail (Deep (One x) m r) =\n if isEmpty m then Shallow r\n else let (y, z) = head m in Deep (Two y z) (tail m) r\n tail (Shallow (Two _ _)) = assert_unreachable\n tail (Deep Zero _ _) = assert_unreachable\n", "meta": {"hexsha": "ab0cf81a4b4f5c39f6bd44f4e5e332284a7c8960", "size": 1221, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ImplicitQueue.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/ImplicitQueue.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/ImplicitQueue.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": 28.3953488372, "max_line_length": 58, "alphanum_fraction": 0.638001638, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6177495402782873}} {"text": "module Tuple\n\nTup: Nat -> Type\nTup Z = Unit\nTup (S k) = (Nat, Tup k)\n\nct: (n: Nat) -> Tup n\nct Z = ()\nct (S k) = (S k, ct k)\n", "meta": {"hexsha": "a1b09c0aa7fc4137120bac8dc6bd333c3c2a0387", "size": 125, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/code/tuples.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/tuples.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/tuples.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": 12.5, "max_line_length": 24, "alphanum_fraction": 0.504, "num_tokens": 57, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7090191276365463, "lm_q1q2_score": 0.6172701157696562}} {"text": "module Instances.OrderZZ\n\nimport public Data.Vect\nimport public Data.Rel\nimport public Decidable.Decidable\nimport Data.ZZ\n\n%default total\n%access export\n\n||| LTE for ZZ, build on top of LTE for Nat.\npublic export\ndata LTEZ : ZZ -> ZZ -> Type where\n LtePosPos : LTE n m -> LTEZ (Pos n) (Pos m)\n LteNegNeg : LTE n m -> LTEZ (NegS m) (NegS n)\n LteNegPos : LTEZ (NegS _) (Pos _)\n\n||| Because a positive number is always greater than a negative one.\npublic export\nimplementation Uninhabited (Pos _ `LTEZ` NegS _) where\n uninhabited _ impossible\n\npublic export\nunwrapLtePosPos : LTEZ (Pos n) (Pos m) -> LTE n m\nunwrapLtePosPos (LtePosPos prf) = prf\n\npublic export\nunwrapLteNegNeg : LTEZ (NegS n) (NegS m) -> LTE m n\nunwrapLteNegNeg (LteNegNeg prf) = prf\n\n\n||| TODO. Consider import from Decidable.Order\nlteAntisymmetric : LTE n m -> LTE m n -> n = m\nlteAntisymmetric LTEZero LTEZero = Refl\nlteAntisymmetric (LTESucc p) (LTESucc q) = cong $ lteAntisymmetric p q\n\n||| Not yet in the base libraries.\npublic export\ninterface Bifunctor (f : Type -> Type -> Type) where\n bimap : (a -> b) -> (c -> d) -> f a c -> f b d\n\n||| Not yet in the base libraries.\npublic export\nimplementation Bifunctor Either where\n bimap f _ (Left a) = Left (f a)\n bimap _ g (Right b) = Right (g b)\n\n||| TODO. Consider import from Decidable.Order\nlteTotal : (n,m : Nat) -> Either (LTE n m) (LTE m n)\nlteTotal Z _ = Left LTEZero\nlteTotal _ Z = Right LTEZero\nlteTotal (S n) (S m) = bimap LTESucc LTESucc (lteTotal n m)\n\n\nlteReflZ : (x : ZZ) -> LTEZ x x\nlteReflZ (Pos _) = LtePosPos lteRefl\nlteReflZ (NegS _) = LteNegNeg lteRefl\n\nlteTransitiveZ : (x,y,z : ZZ) -> LTEZ x y -> LTEZ y z -> LTEZ x z\nlteTransitiveZ _ _ _ (LtePosPos p) (LtePosPos q) = LtePosPos (lteTransitive p q)\nlteTransitiveZ _ _ _ (LteNegNeg p) (LteNegNeg q) = LteNegNeg (lteTransitive q p)\nlteTransitiveZ _ _ _ (LteNegNeg _) LteNegPos = LteNegPos\nlteTransitiveZ _ _ _ LteNegPos (LtePosPos _) = LteNegPos\n\nlteAntisymmetricZ : (x,y : ZZ) -> LTEZ x y -> LTEZ y x -> x = y\nlteAntisymmetricZ _ _ (LtePosPos p) (LtePosPos q) = cong $ lteAntisymmetric p q\nlteAntisymmetricZ _ _ (LteNegNeg p) (LteNegNeg q) = cong $ lteAntisymmetric q p\n\nlteTotalZ : (x,y : ZZ) -> Either (LTEZ x y) (LTEZ y x)\nlteTotalZ (Pos _) (NegS _) = Right LteNegPos\nlteTotalZ (NegS _) (Pos _) = Left LteNegPos\nlteTotalZ (Pos n) (Pos m) = bimap LtePosPos LtePosPos (lteTotal n m)\nlteTotalZ (NegS n) (NegS m) = bimap LteNegNeg LteNegNeg (lteTotal m n)\n\n||| The difficulty here, is to hop over the split at zero.\nlteSuccZ : (x,y : ZZ) -> LTEZ x y -> LTEZ (Pos 1 + x) (Pos 1 + y)\nlteSuccZ _ _ (LtePosPos p) = LtePosPos (LTESucc p)\nlteSuccZ (NegS (S _)) (NegS (S _)) (LteNegNeg p) = LteNegNeg (fromLteSucc p)\nlteSuccZ (NegS (S _)) (NegS Z) _ = LteNegPos\nlteSuccZ (NegS (S _)) (Pos _) _ = LteNegPos\nlteSuccZ (NegS Z) (Pos _) _ = LtePosPos LTEZero\nlteSuccZ (NegS Z) (NegS Z) _ = LtePosPos lteRefl\nlteSuccZ (NegS Z) (NegS (S _)) (LteNegNeg _) impossible\nlteSuccZ (Pos _) (NegS _) p = absurd p\n\n||| The difficulty here, is to hop over the split at zero.\nltePredZ : (x,y : ZZ) -> LTEZ x y -> LTEZ (NegS Z + x) (NegS Z + y)\nltePredZ (Pos (S _)) (Pos (S _)) (LtePosPos p) = LtePosPos (fromLteSucc p)\nltePredZ (Pos Z) (Pos (S _)) _ = LteNegPos\nltePredZ (Pos Z) (Pos Z) _ = LteNegNeg lteRefl\nltePredZ (NegS _) (Pos (S _)) _ = LteNegPos\nltePredZ (NegS _) (Pos Z) _ = LteNegNeg LTEZero\nltePredZ (NegS n) (NegS m) (LteNegNeg p) = LteNegNeg (LTESucc p)\nltePredZ (Pos (S _)) (Pos Z) (LtePosPos _) impossible\nltePredZ (Pos _) (NegS _) p = absurd p\n\n||| Lemma\nprivate\nlteLeftTranslationInvariantPosZ : (x,y : ZZ) -> (n : Nat) ->\n LTEZ x y -> LTEZ (Pos n + x) (Pos n + y)\nlteLeftTranslationInvariantPosZ x y Z prf =\n rewrite plusZeroLeftNeutralZ x in\n rewrite plusZeroLeftNeutralZ y in prf\nlteLeftTranslationInvariantPosZ x y (S n) prf =\n rewrite sym $ plusAssociativeZ (Pos 1) (Pos n) x in\n rewrite sym $ plusAssociativeZ (Pos 1) (Pos n) y in\n lteSuccZ _ _ (lteLeftTranslationInvariantPosZ x y n prf)\n\n||| Lemma\nprivate\nlteLeftTranslationInvariantNegZ : (x,y : ZZ) -> (n : Nat) ->\n LTEZ x y -> LTEZ (NegS n + x) (NegS n + y)\nlteLeftTranslationInvariantNegZ x y Z prf = ltePredZ x y prf\nlteLeftTranslationInvariantNegZ x y (S n) prf =\n rewrite sym $ plusAssociativeZ (NegS Z) (NegS n) x in\n rewrite sym $ plusAssociativeZ (NegS Z) (NegS n) y in\n ltePredZ _ _ (lteLeftTranslationInvariantNegZ x y n prf)\n\n||| This order is translation invariant.\nlteLeftTranslationInvariantZ : (x,y,a : ZZ) ->\n LTEZ x y -> plusZ a x `LTEZ` plusZ a y\nlteLeftTranslationInvariantZ x y (Pos n) =\n lteLeftTranslationInvariantPosZ x y n\nlteLeftTranslationInvariantZ x y (NegS n) =\n lteLeftTranslationInvariantNegZ x y n\n\n||| Make ZZ into a discrete ordered group.\nlteDiscreteZ : (x : ZZ) ->\n Not (x = Pos Z) -> LTEZ x (Pos Z) -> LTEZ (Pos 1 + x) (Pos Z)\nlteDiscreteZ (Pos (S _)) _ (LtePosPos p) = absurd (succNotLTEzero p)\nlteDiscreteZ (Pos Z) notZ _ = absurd (notZ Refl)\nlteDiscreteZ (NegS Z) _ LteNegPos = LtePosPos LTEZero\nlteDiscreteZ (NegS (S _)) _ LteNegPos = LteNegPos\n\n||| Lift a decision from Nat to ZZ.\npublic export\ntoLtePosPos : Dec (LTE n m) -> Dec (LTEZ (Pos n) (Pos m))\ntoLtePosPos (Yes prf) = Yes (LtePosPos prf)\ntoLtePosPos (No contra) = No (contra . unwrapLtePosPos)\n\n||| Lift a decision from Nat to ZZ.\npublic export\ntoLteNegNeg : Dec (LTE n m) -> Dec (LTEZ (NegS m) (NegS n))\ntoLteNegNeg (Yes prf) = Yes (LteNegNeg prf)\ntoLteNegNeg (No contra) = No (contra . unwrapLteNegNeg)\n\npublic export\nisLTEZ : (x,y : ZZ) -> Dec (LTEZ x y)\nisLTEZ (Pos n) (Pos m) = toLtePosPos (isLTE n m)\nisLTEZ (NegS n) (NegS m) = toLteNegNeg (isLTE m n)\nisLTEZ (NegS _) (Pos _) = Yes LteNegPos\nisLTEZ (Pos _) (NegS _) = No absurd\n\npublic export\nimplementation Decidable [ZZ, ZZ] LTEZ where\n decide = isLTEZ\n", "meta": {"hexsha": "ec74417db209c4c0f4be0d7a2c9fdb84d1e43203", "size": 5771, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Instances/OrderZZ.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/OrderZZ.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/OrderZZ.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": 36.7579617834, "max_line_length": 80, "alphanum_fraction": 0.6932940565, "num_tokens": 2173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6171992316700918}} {"text": "-- -------------------------------------------------------------- [ Lens.idr ]\n-- Description : Idris port of Control.Lens\n-- Copyright : (c) Huw Campbell\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Control.Lens.Examples\nimport Control.Lens\n\n--\n-- Examples of interactions available with these Lenses\n--\n\nEx1 : Maybe Int\nEx1 = over mapped (+1) (Just 2)\n\nEx1Proof : Ex1 = Just 3\nEx1Proof = Refl\n\nEx2 : (Int, Int)\nEx2 = (2,3) |> over both (+1)\n\nEx2Proof : Ex2 = (3, 4)\nEx2Proof = Refl\n\nEx3 : (String, String)\nEx3 = (\"Hello\",2) |> snd_ .~ \"World!\"\n\nEx3Proof : Ex3 = (\"Hello\",\"World!\")\nEx3Proof = Refl\n\nEx4 : Either String Int\nEx4 = f (Left \"hi\")\n where f : Either String Int -> Either String Int\n f = over right_ (+1)\n\nEx4Proof : Ex4 = (Left \"hi\")\nEx4Proof = Refl\n\nEx5 : Either String Int\nEx5 = f (Right 4)\n where f : Either String Int -> Either String Int\n f = over right_ (+1)\n\nEx5Proof : Ex5 = (Right 5)\nEx5Proof = Refl\n\nEx6 : Either (String, Int) Int\nEx6 = f (Left (\"hi\", 2))\n where f : Either (String,Int) Int -> Either (String,Int) Int\n f = over (left_ . snd_) (+1)\n\nEx6Proof : Ex6 = Left (\"hi\", 3)\nEx6Proof = Refl\n\n-- Ex7 and Ex8 need to use the PlusNatMonoid named instance and I don't know how to do this yet\n[PlusNatSemi] Semigroup Nat where\n (<+>) x y = x + y\n\n[PlusNatMonoid] Monoid Nat using PlusNatSemi where\n neutral = 0\n\n[PlusNatApplicative] Applicative (Const Nat) using PlusNatMonoid where\n pure _ = MkConst neutral\n (MkConst f) <*> (MkConst v) = MkConst (f <+> v)\n\n-- f : Either (String, Nat) Int -> Nat\n-- f = view @{PlusNatApplicative} (left_ . snd_)\n\n-- Ex7 : Nat\n-- Ex7 = f (Left (\"hi\", 2)) where\n\n-- Ex7Proof : Ex7 = 2\n-- Ex7Proof = Refl\n\n-- Ex8 : Nat\n-- Ex8 = f (Right 2) where\n-- f : Either (String, Additive) Int -> Additive\n-- f = view (left_ . snd_)\n\n-- Ex8Proof : Ex8 = 0\n-- Ex8Proof = Refl\n\nEx9 : Maybe String\nEx9 = g ^? right_ . fst_ where\n g : Either String (String, Int)\n g = Right (\"x\",2)\n\nEx9Proof : Ex9 = Just \"x\"\nEx9Proof = Refl\n\nEx10 : Maybe ()\nEx10 = Just \"x\" ^? nothing_\n\nEx10Proof : Ex10 = Nothing\nEx10Proof = Refl\n\nEx11 : Maybe ()\nEx11 = n ^? nothing_ where\n n : Maybe String\n n = Nothing\n\nEx11Proof : Ex11 = Just ()\nEx11Proof = Refl\n\nEx12 : Int\nEx12 = view (to fst) (1,2)\n\nEx12Proof : Ex12 = 1\nEx12Proof = Refl\n\nEx13 : Either Int String\nEx13 = the (Either Int String) $ left_ # 4\n\nEx13Proof : Ex13 = Left 4\nEx13Proof = Refl\n\nEx14 : Either Int String\nEx14 = the (Either Int String) $ 5 ^.re left_\n\nEx14Proof : Ex14 = Left 5\nEx14Proof = Refl\n\nsansExample : Maybe Int\nsansExample = sans () (Just 4)\n\nfusingExample : Maybe (Int, Int)\nfusingExample = Just (2,3) |> over ( fusing (just_ . both)) (+1)\n\nconfusingExample : Maybe (Int, Int)\nconfusingExample = Just (2,3) |> over ( confusing (just_ . both)) (+1)\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "26f5ba5a5b70dc01f6535382ece6f7e6df33bfc1", "size": 2927, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Control/Lens/Examples.idr", "max_stars_repo_name": "shmish111/idris-lens", "max_stars_repo_head_hexsha": "0f9dd4e96ead2d012631075743ba38cdb8d80c83", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Control/Lens/Examples.idr", "max_issues_repo_name": "shmish111/idris-lens", "max_issues_repo_head_hexsha": "0f9dd4e96ead2d012631075743ba38cdb8d80c83", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Control/Lens/Examples.idr", "max_forks_repo_name": "shmish111/idris-lens", "max_forks_repo_head_hexsha": "0f9dd4e96ead2d012631075743ba38cdb8d80c83", "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.1742424242, "max_line_length": 95, "alphanum_fraction": 0.5859241544, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.616805511610408}} {"text": "module Module\n\nimport Monoid\nimport Group\nimport Ring\nimport Group_property\nimport NatUtils\n\n--(modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) ->\n-- ((*) : ring -> ring -> ring) -> (IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n--This just the data required for a module, the set modu and a ring. So, this big chunk of code will appear everywhere\n\n|||Type of operation between a ring and a moduule that distributes over addition of the ring\ntotal\ndotDistributesOverRing : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring)\n -> ((*) : ring -> ring -> ring) -> (IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu) -> Type\ndotDistributesOverRing modu ring (+) (++) (*) prfRing (.) = (r : ring) -> (s : ring) -> (m : modu) -> ((r ++ s) . m = (r . m) + (s . m))\n\n|||Type of operation between a ring and a moduuule that distributes over addition of the Module\ntotal\ndotDistributesOverModule : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring)\n -> ((*) : ring -> ring -> ring) -> (IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu) -> Type\ndotDistributesOverModule modu ring (+) (++) (*) prfRing (.) = (m : modu) -> (n : modu) -> (r : ring) -> (r . (m + n) = (r . m) + (r . n))\n\n|||Type of operation that respects ring multiplication\ntotal\ndotRespectsRingMult : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu) -> Type\ndotRespectsRingMult modu ring (+) (++) (*) prfRing (.) = (r : ring) -> (s : ring) -> (m : modu) -> ((r*s) . m = r . (s . m))\n\n|||Type of operation that maps 1.m to m.\ntotal\ndotRespectsIdentity : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu) -> Type\ndotRespectsIdentity modu ring (+) (++) (*) prfRing (.) = (m : modu) -> (e . m = m) where\n e = fst (snd (fst (snd prfRing)))\n|||The type of a Module. As the operations on the set modu determines it's abelianess property, we should only include the operation on the set modu and the operation between the set modu and the ring\ntotal\nIsleftModule : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu) -> Type\nIsleftModule modu ring (+) (++) (*) prfRing (.) = ((IsAbelianGrp modu (+)) , (dotRespectsIdentity modu ring (+) (++) (*) prfRing (.) , (dotDistributesOverRing modu ring (+) (++) (*) prfRing (.) , ( dotDistributesOverModule modu ring (+) (++) (*) prfRing (.) , dotRespectsRingMult modu ring (+) (++) (*) prfRing (.)))))\n\n--Below are a bunch of auxiliary functions to get recover dot distributing over blah from the envelope Type IsleftModule\n\n|||Gives the Abelian Group property of a module\ntotal\nAbelianAddition : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (IsleftModule modu ring (+) (++) (*) prfRing (.)) -> (IsAbelianGrp modu (+))\nAbelianAddition modu ring (+) (++) (*) prfRing (.) prfLeftModule = fst (prfLeftModule)\n\n|||Gives the Zero of the Module\ntotal\nZeroOfModule : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (IsleftModule modu ring (+) (++) (*) prfRing (.)) -> (e : modu ** ((a : modu) -> (a + e = a , e + a = a)))\nZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule = fst (snd (fst (fst (prfLeftModule))))\n\n|||Gives the dot distributes over Ring addition property of the module\ntotal\ndotOverRingAdd : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (IsleftModule modu ring (+) (++) (*) prfRing (.)) -> dotDistributesOverRing modu ring (+) (++) (*) prfRing (.)\ndotOverRingAdd modu ring (+) (++) (*) prfRing (.) prfLeftModule = fst (snd (snd (prfLeftModule)))\n\n|||Gives the dot distributes over module addition property of the module\ntotal\ndotOverModuleAdd : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (IsleftModule modu ring (+) (++) (*) prfRing (.)) -> dotDistributesOverModule modu ring (+) (++) (*) prfRing (.)\ndotOverModuleAdd modu ring (+) (++) (*) prfRing (.) prfLeftModule = fst (snd (snd (snd (prfLeftModule))))\n\n|||Gives the dot Associates with ring multiplication property of the module\ntotal\ndotAssociatesRingMult : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (IsleftModule modu ring (+) (++) (*) prfRing (.)) -> dotRespectsRingMult modu ring (+) (++) (*) prfRing (.)\ndotAssociatesRingMult modu ring (+) (++) (*) prfRing (.) prfLeftModule = snd (snd (snd (snd (prfLeftModule))))\n\n|||Gives the dot Associates with ring multiplication property of the module\ntotal\ndotRingIdentity : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (IsleftModule modu ring (+) (++) (*) prfRing (.)) -> dotRespectsIdentity modu ring (+) (++) (*) prfRing (.)\ndotRingIdentity modu ring (+) (++) (*) prfRing (.) prfLeftModule = fst (snd (prfLeftModule))\n\n|||Proof that r*0 = 0 for all r in the underlying ring\ntotal\nRingMultZeroEqualsZero : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (prfLeftModule : IsleftModule modu ring (+) (++) (*) prfRing (.))\n -> ((r : ring) -> (r . (fst (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)) = (fst (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule))))\nRingMultZeroEqualsZero modu ring (+) (++) (*) prfRing (.) prfLeftModule = k where\n e : modu\n e = fst (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)\n u : ring -> modu -> modu\n u r m = r . m\n f : (r : ring) -> (r . (e + e) = (r . e) + (r . e))\n f r = (dotOverModuleAdd modu ring (+) (++) (*) prfRing (.) prfLeftModule e e r)\n g : (r : ring) -> (r . (e + e) = r . e)\n g r = (cong (fst ((snd (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)) e)))\n h : (r : ring) -> (r . e = (r . e) + (r . e))\n h r = (trans (sym (g r)) (f r))\n i : (r : ring) -> ((r . e) + e = (r . e))\n i r = (fst ((snd (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)) (r . e)))\n j : (r : ring) -> ((r . e) + e = (r . e) + (r . e))\n j r = (trans (i r) (h r))\n k : (r : ring) -> ((r . e) = e)\n k r = (sym (Group_property_4 modu (+) (fst (fst prfLeftModule)) (r . e) e (r . e) (j r)))\n\n|||Proof that 0*m = 0 for m in the module\ntotal\nZeroMultModuleEqualsZero : (modu : Type) -> (ring : Type) -> ((+) : modu -> modu -> modu) -> ((++) : ring -> ring -> ring) -> ((*) : ring -> ring -> ring)\n -> (prfRing : IsRing_with_identity ring (++) (*)) -> ((.) : ring -> modu -> modu)\n -> (prfLeftModule : IsleftModule modu ring (+) (++) (*) prfRing (.))\n -> ((m : modu) -> ((fst (fst (snd (fst (fst prfRing))))) . m = fst (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)))\nZeroMultModuleEqualsZero modu ring (+) (++) (*) prfRing (.) prfLeftModule = k where\n e : modu\n e = fst (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)\n z : ring\n z = fst (fst (snd (fst (fst prfRing))))\n u : modu -> ring -> modu\n u m r = r . m\n f : (m : modu) -> ((z ++ z) . m = (z . m) + (z . m))\n f m = (dotOverRingAdd modu ring (+) (++) (*) prfRing (.) prfLeftModule z z m)\n g : (m : modu) -> ((z ++ z) . m = z . m)\n g m = (functionExtendsEquality2 ring modu (u m) (z ++ z) z (fst (snd (fst (snd (fst (fst prfRing)))) z)))\n h : (m : modu) -> (z . m = (z . m) + (z . m))\n h m = (trans (sym (g m)) (f m))\n i : (m : modu) -> ((z . m) + e = (z . m))\n i m = (fst ((snd (ZeroOfModule modu ring (+) (++) (*) prfRing (.) prfLeftModule)) (z . m)))\n j : (m : modu) -> ((z . m) + e = (z . m) + (z . m))\n j m = (trans (i m) (h m))\n k : (m : modu) -> ((z . m) = e)\n k m = (sym (Group_property_4 modu (+) (fst (fst prfLeftModule)) (z . m) e (z . m) (j m)))\n", "meta": {"hexsha": "18d0a01722a92692a86f8c08650ddaaff7e26e12", "size": 12359, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Module.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/Module.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/Module.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": 90.875, "max_line_length": 318, "alphanum_fraction": 0.3972004207, "num_tokens": 3133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.6893056104028799, "lm_q1q2_score": 0.6167834010478156}} {"text": "||| N-ary simple (non-dependent) functions using telescopes\n|||\n||| Compare with `base/Data.Fun` and `contrib/Data.Fun.Extra` and with:\n||| Guillaume Allais. 2019. Generic level polymorphic n-ary functions. TyDe 2019.\nmodule Data.Telescope.SimpleFun\n\nimport Data.Telescope.Telescope\nimport Data.Telescope.Segment\n\n||| An n-ary function whose codomain does not depend on its\n||| arguments. The arguments may have dependencies.\npublic export\n0 SimpleFun : (env : Left.Environment gamma) -> {n : Nat} -> (0 delta : Segment n gamma)\n -> (cod : Type) -> Type\nSimpleFun env {n = 0 } [] cod = cod\nSimpleFun env {n = S n} (ty :: delta) cod = (x : ty env) -> SimpleFun (env ** x) delta cod\n\npublic export\ntarget : {0 env : Left.Environment gamma} -> {0 delta : Segment n gamma} -> {cod : Type}\n -> SimpleFun env delta cod -> Type\ntarget {cod} _ = cod\n\npublic export\nuncurry : {n : Nat} -> {0 env : Left.Environment gamma} -> {0 delta : Segment n gamma}\n -> (f : SimpleFun env delta cod) -> Environment env delta -> cod\nuncurry {n = Z} {delta = []} f xs = f\nuncurry {n = S n} {delta = _ :: _} f (x .= xs) = uncurry (f x) xs\n\npublic export\ncurry : {n : Nat} -> {0 env : Left.Environment gamma} -> {0 delta : Segment n gamma}\n -> (f : Environment env delta -> cod)\n -> SimpleFun env delta cod\ncurry {n = 0 } {delta = [] } f = f Empty\ncurry {n = S n} {delta = ty :: delta} f = \\x => curry (\\xs => f (x .= xs))\n", "meta": {"hexsha": "c6fb21fdda93eb3184f47c7f844ad741204350c5", "size": 1449, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Telescope/SimpleFun.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/Telescope/SimpleFun.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/Telescope/SimpleFun.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": 41.4, "max_line_length": 90, "alphanum_fraction": 0.6218081435, "num_tokens": 441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6161188518604267}} {"text": "module Adder\n\nAdderType : (numargs : Nat) -> Type -> Type\nAdderType Z numType = numType\nAdderType (S k) numType = (next : numType) -> AdderType k numType\n\nadder : Num num => (numargs : Nat) -> (acc : num) -> AdderType numargs num\nadder Z acc = acc\nadder (S k) acc = \\i => adder k (i + acc)\n", "meta": {"hexsha": "70c8c831394ef2decb461a09b382f551e13e5e31", "size": 290, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Adder.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": "Adder.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": "Adder.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": 29.0, "max_line_length": 74, "alphanum_fraction": 0.6448275862, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6161188353316565}} {"text": "natElim : (p : Nat -> Type) -> p Z -> ((k : Nat) -> p k -> p (S k)) ->\n (x : Nat) -> p x\n\nnatElim2 : (p : Nat -> Type) -> p Z -> ((k : Nat) -> p k -> p (S k)) ->\n (x : Nat) -> p x\nnatElim2 p x f Z = x\nnatElim2 p x f (S k) = ?foo\n\nlistElim : (p : List a -> Type) ->\n (mnil : p []) ->\n (mcons : (x : _) -> (xs : List a) -> p xs -> p (x :: xs)) ->\n (xs : List a) -> p xs\n", "meta": {"hexsha": "25beb5fa132d68ecfffe7a3652356e8d0b926c47", "size": 417, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive011/IEdit.idr", "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/interactive011/IEdit.idr", "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/interactive011/IEdit.idr", "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": 32.0769230769, "max_line_length": 71, "alphanum_fraction": 0.3549160671, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6158913598304062}} {"text": "module Rational\nimport SignedInt\n\n%default total\n%access public export\n\n-- a/(1+b)\nrecord Rational where\n constructor MkRat\n a: SignedInt\n b: Nat\n\n\nimplementation Num Rational where\n (MkRat a1 b1) + (MkRat a2 b2) = MkRat (a1 $* (S b2) + a2 $* (S b1)) (b1 * b2 + b1 + b2)\n (MkRat a1 b1) * (MkRat a2 b2) = MkRat (a1 * a2) (b1 * b2 + b1 + b2)\n fromInteger a = MkRat (fromInteger a) 0\n\nimplementation Neg Rational where\n negate (MkRat a b) = MkRat (negate a) b\n a - b = a + negate b\n\ndata RationalEq : Rational -> Rational -> Type where\n RationalRefl : (eq : a1 $* (S b2) `SignedEq` a2 $* (S b1)) -> RationalEq (MkRat a1 b1) (MkRat a2 b2)\n", "meta": {"hexsha": "adefe81a0b577c8cde4b08563ee06f519935434a", "size": 662, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "hw6/Rational.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/Rational.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/Rational.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": 26.48, "max_line_length": 104, "alphanum_fraction": 0.6223564955, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.6893056104028797, "lm_q1q2_score": 0.6157631775873363}} {"text": "module Modulo\n\nimport Data.Fin\n\n%access export\n%default total\n\nadd : Fin k -> Fin k -> Fin k\nadd {k=S k} n m = restrict k $ finToInteger n + finToInteger m\n\nnegate : Fin k -> Fin k\nnegate {k=S k} n = restrict k $ toIntegerNat (S k) - finToInteger n\n\nsubt : Fin k -> Fin k -> Fin k\nsubt {k=S k} n m = restrict k $ finToInteger n - finToInteger m + toIntegerNat (S k)\n\nmult : Fin k -> Fin k -> Fin k\nmult {k=S k} n m = restrict k $ finToInteger n * finToInteger m\n", "meta": {"hexsha": "994ab0822b102295f5d380dc80024e15c1c05e5c", "size": 462, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codewars/Modulo.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/Modulo.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/Modulo.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": 24.3157894737, "max_line_length": 84, "alphanum_fraction": 0.6515151515, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6156897168347574}} {"text": "import Data.Vect\nimport Data.Fin\n\n-- %default total -- WHY NOT ?\n\n-- Possible types\ndata Ty = TyInt | TyBool | TyFun Ty Ty\n\n-- Types interpreted in idris\ninterpTy : Ty -> Type\ninterpTy TyInt = Integer\ninterpTy TyBool = Bool\ninterpTy (TyFun A T) = interpTy A -> interpTy T\n\n\nusing (G:Vect n Ty) -- the context\n data Expr : Vect n Ty -> Ty -> Type -- local vars Type -> Expr Type\n\n -- Representation of expressions\n data HasType : (i : Fin n) -> Vect n Ty -> Ty -> Type where \n Stop : HasType FZ (t :: G) t\n Pop : HasType k G t -> HasType (FS k) (u :: G) t\n\n data Expr : Vect n Ty -> Ty -> Type where\n Var : HasType i G t -> Expr G t\n Val : (x : Integer) -> Expr G TyInt\n Lam : Expr (a :: G) t -> Expr G (TyFun a t)\n App : Expr G (TyFun a t) -> Expr G a -> Expr G t\n Op : (interpTy a -> interpTy b -> interpTy c) -> Expr G a -> Expr G b -> Expr G c\n If : Expr G TyBool -> Lazy (Expr G a) -> Lazy (Expr G a) -> Expr G a\n \n data Env : Vect n Ty -> Type where\n Nil : Env Nil\n (::) : interpTy a -> Env G -> Env (a :: G)\n\n lookup : HasType i G t -> Env G -> interpTy t\n lookup Stop (x :: xs) = x\n lookup (Pop k) (x :: xs) = lookup k xs\n\n\n interp : Env G -> Expr G t -> interpTy t\n interp env (Var i) = lookup i env\n interp env (Val x) = x\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 interp env (If x t e) = if interp env x then interp env t\n else interp env e\n\n add : Expr G (TyFun TyInt (TyFun TyInt TyInt))\n add = Lam (Lam (Op (+) (Var Stop) (Var (Pop Stop))))\n\n fact : Expr G (TyFun TyInt TyInt)\n fact = Lam (If (Op (==) (Var Stop) (Val 0))\n (Val 1)\n (Op (*) (App fact (Op (-) (Var Stop) (Val 1)))\n (Var Stop)))\n\npartial\nmain : IO ()\nmain = do putStr \"Enter a number: \"\n x <- getLine\n printLn (interp [] fact (cast x))\n\n", "meta": {"hexsha": "1057e38ee07fbbe690456aa49b08242db8ef9e7d", "size": 2017, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Interp.idr", "max_stars_repo_name": "asmodehn/idris-playground", "max_stars_repo_head_hexsha": "d9300213e5a688c455c03fecdc3fd30417945cb9", "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": "Interp.idr", "max_issues_repo_name": "asmodehn/idris-playground", "max_issues_repo_head_hexsha": "d9300213e5a688c455c03fecdc3fd30417945cb9", "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": "Interp.idr", "max_forks_repo_name": "asmodehn/idris-playground", "max_forks_repo_head_hexsha": "d9300213e5a688c455c03fecdc3fd30417945cb9", "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.0307692308, "max_line_length": 86, "alphanum_fraction": 0.5438770451, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.6825737214979745, "lm_q1q2_score": 0.6156273490757916}} {"text": "module Data.Profunctor.Choice\n\nimport Data.Profunctor.Class\nimport Data.Morphisms\n\npublic export\ninterface Profunctor p => Choice (0 p : Type -> Type -> Type) where\n left' : p a b -> p (Either a c) (Either b c)\n left' = dimap (either Right Left) (either Right Left) . right'\n\n right' : p a b -> p (Either c a) (Either c b)\n right' = dimap (either Right Left) (either Right Left) . left'\n\npublic export\nChoice Morphism where\n left' (Mor f) = Mor g\n where g : Either a c -> Either b c\n g (Left a) = Left (f a)\n g (Right c) = Right c\n\n right' (Mor f) = Mor g\n where g : Either c a -> Either c b\n g (Left c) = Left c\n g (Right a) = Right (f a)\n", "meta": {"hexsha": "c82ade298261e34226456d768443f770ab612973", "size": 688, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Profunctor/Choice.idr", "max_stars_repo_name": "shmish111/idris-lens", "max_stars_repo_head_hexsha": "0f9dd4e96ead2d012631075743ba38cdb8d80c83", "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/Profunctor/Choice.idr", "max_issues_repo_name": "shmish111/idris-lens", "max_issues_repo_head_hexsha": "0f9dd4e96ead2d012631075743ba38cdb8d80c83", "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/Profunctor/Choice.idr", "max_forks_repo_name": "shmish111/idris-lens", "max_forks_repo_head_hexsha": "0f9dd4e96ead2d012631075743ba38cdb8d80c83", "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.52, "max_line_length": 67, "alphanum_fraction": 0.601744186, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.6548947223065754, "lm_q1q2_score": 0.6155442922265364}} {"text": "module Algebra.Solver.Prod\n\nimport public Data.List.Elem\n\n%default total\n\n||| A product of variables each represented by the exponent,\n||| to which it is raised.\n|||\n||| When normalizing arithmetic expressions, they often\n||| get converted to (sums of) products of variables\n||| (listed in index `as`), each raised to a certain\n||| exponent. This is the case for commutative monoids\n||| (a single product) as well as commutative (semi)rings\n||| (a sum of products).\npublic export\ndata Prod : (a : Type) -> (as : List a) -> Type where\n Nil : Prod a []\n (::) : (exp : Nat) -> Prod a xs -> Prod a (x :: xs)\n\n||| Multiplying two products means adding all\n||| expontents pairwise.\npublic export\nmult : Prod a as -> Prod a as -> Prod a as\nmult [] [] = []\nmult (x :: xs) (y :: ys) = (x + y) :: mult xs ys\n\n||| We sort products by lexicographically comparing\n||| the exponents.\npublic export\ncompProd : Prod a as -> Prod a as -> Ordering\ncompProd [] [] = EQ\ncompProd (x :: xs) (y :: ys) = case compare x y of\n LT => LT\n GT => GT\n EQ => compProd xs ys\n\n||| The neutral product where all exponents are zero.\npublic export\none : {as : List a} -> Prod a as\none {as = []} = []\none {as = x :: xs} = 0 :: one\n\n||| Convert a single variable to a product of variables.\npublic export\nfromVar : {as : List a} -> Elem x as -> Prod a as\nfromVar {as = x :: xs} Here = 1 :: one\nfromVar {as = x :: xs} (There y) = 0 :: fromVar y\nfromVar {as = []} Here impossible\nfromVar {as = []} (There y) impossible\n\n--------------------------------------------------------------------------------\n-- Proofs\n--------------------------------------------------------------------------------\n\nUninhabited (LT = EQ) where\n uninhabited _ impossible\n\nUninhabited (GT = EQ) where\n uninhabited _ impossible\n\nexport\n0 pcompNat : (x,y : Nat) -> (compare x y === EQ) -> x === y\npcompNat 0 0 prf = Refl\npcompNat (S k) (S j) prf = cong S $ pcompNat k j prf\npcompNat 0 (S k) Refl impossible\npcompNat (S k) 0 Refl impossible\n\nexport\n0 pcompProd : (x,y : Prod a as)\n -> (compProd x y === EQ)\n -> x === y\npcompProd [] [] prf = Refl\npcompProd (x :: xs) (y :: ys) prf with (compare x y) proof eq\n _ | EQ = cong2 (::) (pcompNat x y eq) (pcompProd xs ys prf)\n _ | LT = absurd prf\n _ | GT = absurd prf\npcompProd [] (_ :: _) Refl impossible\npcompProd (_ :: _) [] Refl impossible\n", "meta": {"hexsha": "b7ab61df15a0a0640c18590c47cfe69efdf396fb", "size": 2437, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Solver/Prod.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/Solver/Prod.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/Solver/Prod.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": 30.4625, "max_line_length": 80, "alphanum_fraction": 0.56339762, "num_tokens": 734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152325073083131, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6154312375487189}} {"text": "module Control.WellFounded\n\nimport Control.Relation\nimport Data.Nat\nimport Data.List\n\n%default total\n\npublic export\ndata Accessible : (rel : a -> a -> Type) -> (x : a) -> Type where\n Access : (rec : (y : a) -> rel y x -> Accessible rel y) ->\n Accessible rel x\n\npublic export\ninterface WellFounded a rel where\n wellFounded : (x : a) -> Accessible rel x\n\nexport\naccRec : {0 rel : (arg1 : a) -> (arg2 : a) -> Type} ->\n (step : (x : a) -> ((y : a) -> rel y x -> b) -> b) ->\n (z : a) -> (0 acc : Accessible rel z) -> b\naccRec step z (Access f) =\n step z $ \\yarg, lt => accRec step yarg (f yarg lt)\n\nexport\naccInd : {0 rel : a -> a -> Type} -> {0 P : a -> Type} ->\n (step : (x : a) -> ((y : a) -> rel y x -> P y) -> P x) ->\n (z : a) -> (0 acc : Accessible rel z) -> P z\naccInd step z (Access f) =\n step z $ \\y, lt => accInd step y (f y lt)\n\nexport\nwfRec : (0 _ : WellFounded a rel) =>\n (step : (x : a) -> ((y : a) -> rel y x -> b) -> b) ->\n a -> b\nwfRec step x = accRec step x (wellFounded {rel} x)\n\nexport\nwfInd : (0 _ : WellFounded a rel) => {0 P : a -> Type} ->\n (step : (x : a) -> ((y : a) -> rel y x -> P y) -> P x) ->\n (myz : a) -> P myz\nwfInd step myz = accInd step myz (wellFounded {rel} myz)\n\npublic export\ninterface Sized a where\n constructor MkSized\n total size : a -> Nat\n\npublic export\nSmaller : Sized a => a -> a -> Type\nSmaller = \\x, y => size x `LT` size y\n\npublic export\nSizeAccessible : Sized a => a -> Type\nSizeAccessible = Accessible Smaller\n\nexport\nsizeAccessible : Sized a => (x : a) -> SizeAccessible x\nsizeAccessible x = Access (acc $ size x)\n where\n acc : (sizeX : Nat) -> (y : a) -> (size y `LT` sizeX) -> SizeAccessible y\n acc (S x') y (LTESucc yLEx')\n = Access $ \\z, zLTy => acc x' z $ transitive {rel = LTE} zLTy yLEx'\n\nexport\nsizeInd : Sized a => {0 P : a -> Type} ->\n (step : (x : a) -> ((y : a) -> Smaller y x -> P y) -> P x) ->\n (z : a) ->\n P z\nsizeInd step z = accInd step z (sizeAccessible z)\n\nexport\nsizeRec : Sized a =>\n (step : (x : a) -> ((y : a) -> Smaller y x -> b) -> b) ->\n (z : a) -> b\nsizeRec step z = accRec step z (sizeAccessible z)\n\nexport\nSized Nat where\n size = id\n\nexport\nWellFounded Nat LT where\n wellFounded = sizeAccessible\n\nexport\nSized (List a) where\n size = length\n\nexport\n(Sized a, Sized b) => Sized (Pair a b) where\n size (x,y) = size x + size y\n", "meta": {"hexsha": "6b9af229642b7cda715e0c8ada73f0bc6c7368b8", "size": 2438, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Control/WellFounded.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/Control/WellFounded.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/Control/WellFounded.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": 26.2150537634, "max_line_length": 77, "alphanum_fraction": 0.546759639, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6149352822109918}} {"text": "module Lambdapants.Term\n\n||| In the lambda calculus, a term is one of three things:\n||| * A variable is a term;\n||| * Application of two terms is a term; and\n||| * A lambda abstraction is a term.\n|||\n||| Nothing else is a term. Application is left-associative, so the term\n||| `(s t u)` is the same as `(s t) u`. One often omits outermost parentheses.\n||| In abstractions, the body extends as far to the right as possible.\npublic export\ndata Term : Type where\n ||| Variable\n Var : String -> Term\n ||| Lambda abstraction\n Lam : String -> Term -> Term\n ||| Application\n App : Term -> Term -> Term\n\nexport\nEq Term where\n (Var a) == (Var b) = a == b\n (Lam x t) == (Lam y u) = x == y && t == u\n (App t u) == (App v w) = t == v && u == w\n _ == _ = False\n\nexport\nShow Term where\n show (Var v) = \"Var \" ++ show v\n show (App t u) = \"App (\" ++ show t ++ \") (\"\n ++ show u ++ \")\"\n show (Lam x t) = \"Lam \" ++ show x ++ \" (\"\n ++ show t ++ \")\"\n\nmutual\n lam : Term -> String\n lam (Lam x t) = \"\\x03BB\" ++ x ++ \".\" ++ lam t\n lam term = app term\n\n app : Term -> String\n app (App t u) = app t ++ \" \" ++ pretty u\n app term = pretty term\n\n ||| Translate the given term to a pretty-printed string.\n export\n pretty : Term -> String\n pretty term =\n case term of\n Lam _ _ => \"(\" ++ lam term ++ \")\"\n App _ _ => \"(\" ++ app term ++ \")\"\n Var var => var\n\n||| Return a list of all variables which appear free in the term *t*.\nexport total\nfreeVars : (t : Term) -> List String\nfreeVars (Var v) = [v]\nfreeVars (Lam v t) = delete v (freeVars t)\nfreeVars (App t u) = freeVars t `union` freeVars u\n\n||| Return a boolean to indicate whether the variable *v* appears free in the\n||| term *t*.\nexport total\nisFreeIn : (v : String) -> (t : Term) -> Bool\nisFreeIn var term = elem var (freeVars term)\n\n||| De Bruijn-indexed intermediate representation for more convenient alpha\n||| comparison of terms.\ndata Indexed : Type where\n ||| Bound variable (depth indexed)\n Bound : Nat -> Indexed\n ||| Free variable\n Free : String -> Indexed\n ||| Application\n IxApp : Indexed -> Indexed -> Indexed\n ||| Lambda abstraction\n IxLam : Indexed -> Indexed\n\nShow Indexed where\n show (Bound n) = \"Bound \" ++ show n\n show (Free v) = \"Free \" ++ show v\n show (IxApp t u) = \"IxApp (\" ++ show t ++ \") (\"\n ++ show u ++ \")\"\n show (IxLam t) = \"IxLam (\" ++ show t ++ \")\"\n\nEq Indexed where\n (Bound m) == (Bound n) = m == n\n (Free v) == (Free w) = v == w\n (IxApp t u) == (IxApp v w) = t == v && u == w\n (IxLam t) == (IxLam u) = t == u\n _ == _ = False\n\n||| Translate the term *t* to a canonical De Bruijn (depth-indexed) form.\ntotal\ntoIndexed : (t : Term) -> Indexed\ntoIndexed = indexed [] where\n indexed : List String -> Term -> Indexed\n indexed bound (Var x) = maybe (Free x) Bound (elemIndex x bound)\n indexed bound (App t u) = IxApp (indexed bound t) (indexed bound u)\n indexed bound (Lam x t) = IxLam (indexed (x :: bound) t)\n\n||| Return a boolean to indicate whether two terms are alpha equivalent; that\n||| is, whether one can be converted to the other purely by renaming of bound\n||| variables.\nexport total\nalphaEq : Term -> Term -> Bool\nalphaEq t u = toIndexed t == toIndexed u\n", "meta": {"hexsha": "b1d432c11c23d9193095e2403c683446349daf98", "size": 3343, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Lambdapants/Term.idr", "max_stars_repo_name": "laserpants/redex-reflex", "max_stars_repo_head_hexsha": "8088dd1a231f65ff0eeb24c960865a622d5a5507", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-01-16T15:04:50.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-16T15:54:56.000Z", "max_issues_repo_path": "Lambdapants/Term.idr", "max_issues_repo_name": "laserpants/lambdapants", "max_issues_repo_head_hexsha": "8088dd1a231f65ff0eeb24c960865a622d5a5507", "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": "Lambdapants/Term.idr", "max_forks_repo_name": "laserpants/lambdapants", "max_forks_repo_head_hexsha": "8088dd1a231f65ff0eeb24c960865a622d5a5507", "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.2429906542, "max_line_length": 78, "alphanum_fraction": 0.5755309602, "num_tokens": 1028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6144791031203242}} {"text": "module Dummy\n\nimport Data.Vect\n\nnamespace DList\n\n ||| A list construct for dependent types.\n |||\n ||| @aTy The type of the value contained within the list element type.\n ||| @elemTy The type of the elements within the list\n ||| @as The List used to contain the different values within the type.\n public export\n data DList : (aTy : Type)\n -> (elemTy : aTy -> Type)\n -> (as : List aTy)\n -> Type where\n ||| Create an empty List\n Nil : DList aTy elemTy Nil\n ||| Cons\n |||\n ||| @elem The element to add\n ||| @rest The list for `elem` to be added to.\n (::) : (elem : elemTy x)\n -> (rest : DList aTy elemTy xs)\n -> DList aTy elemTy (x::xs)\n\nnamespace DVect\n ||| A list construct for dependent types.\n |||\n ||| @aTy The type of the value contained within the list element type.\n ||| @elemTy The type of the elements within the list\n ||| @len The length of the list.\n ||| @as The List used to contain the different values within the type.\n public export\n data DVect : (aTy : Type)\n -> (elemTy : aTy -> Type)\n -> (len : Nat)\n -> (as : Vect len aTy)\n -> Type where\n ||| Create an empty List\n Nil : DVect aTy elemTy Z Nil\n ||| Cons\n |||\n ||| @ex The element to add\n ||| @rest The list for `elem` to be added to.\n (::) : (ex : elemTy x)\n -> (rest : DVect aTy elemTy n xs)\n -> DVect aTy elemTy (S n) (x::xs)\n\nnamespace PList\n public export\n data PList : (aTy : Type)\n -> (elemTy : aTy -> Type)\n -> (predTy : aTy -> Type)\n -> (as : List aTy)\n -> (prf : DList aTy predTy as)\n -> Type\n where\n ||| Create an empty List\n Nil : PList aTy elemTy predTy Nil Nil\n\n ||| Cons\n |||\n ||| @elem The element to add and proof that the element's type satisfies a certain predicate.\n ||| @rest The list for `elem` to be added to.\n (::) : (elem : elemTy x)\n -> {prf : predTy x}\n -> (rest : PList aTy elemTy predTy xs prfs)\n -> PList aTy elemTy predTy (x :: xs) (prf :: prfs)\n", "meta": {"hexsha": "e928847e3102e802a6bb6951910abdcd7a8cc7b0", "size": 2156, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/pkg001/Dummy.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/pkg001/Dummy.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/pkg001/Dummy.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": 30.8, "max_line_length": 99, "alphanum_fraction": 0.5398886827, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6143857544094905}} {"text": "> module Double.Properties\n\n> import Data.So\n\n> import Double.Predicates\n> import Double.Postulates\n> import Double.Operations\n> import So.Properties\n> import Ordering.Properties\n> import Rel.TotalPreorder\n> import So.Properties\n> import Interfaces.Math\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\n* Implementations\n\n> implementation Math Double where\n> exp = Prelude.Doubles.exp\n> sin = Prelude.Doubles.sin\n> cos = Prelude.Doubles.cos\n\n\n* Decidability of EQ\n\n> |||\n> decEQ : (x : Double) -> (y : Double) -> Dec (x `EQ` y)\n> decEQ x y with (decSo (x == y))\n> | Yes p = Yes (MkEQ p)\n> | No contra = No (\\ (MkEQ p) => contra p)\n\n\n* Properties of Ord methods\n\n> |||\n> LTinLTE : {x, y : Double} -> So (x < y) -> So (x <= y)\n> LTinLTE {x} {y} prf = soOrIntro1 (x < y) (x == y) prf\n> -- LTinLTE : {x, y : Double} -> x `LT` y -> x `LTE` y\n> -- LTinLTE {x} {y} (MkLT prf) = MkLTE (soOrIntro1 (x < y) (x == y) prf)\n\n> |||\n> EQinLTE : {x, y : Double} -> So (x == y) -> So (x <= y)\n> EQinLTE {x} {y} prf = soOrIntro2 (x < y) (x == y) prf\n\n> |||\n> compareLT : {x, y : Double} -> LT = compare x y -> So (x < y)\n> compareLT {x} {y} p with (compare x y)\n> compareLT {x} {y} _ | LT = Oh\n> compareLT {x} {y} p | EQ = absurd p\n> compareLT {x} {y} p | GT = absurd p\n\n> compareEQ : {x, y : Double} -> EQ = compare x y -> So (x == y)\n> compareEQ {x} {y} p with (compare x y) proof prf\n> | LT = absurd p\n> | EQ with (decSo (x == y))\n> | (Yes q) = q\n> | (No c) = void (notCompareEQ c prf)\n> | GT = absurd p\n\n> compareEQ' : {x, y : Double} -> So (x == y) -> compare x y = EQ\n> compareEQ' {x} {y} p with (x == y) proof q\n> | True = Refl\n> | False = absurd p\n\n> |||\n> compareGT : {x, y : Double} -> GT = compare x y -> So (x > y)\n> compareGT {x} {y} p with (compare x y)\n> compareGT {x} {y} p | LT = absurd p\n> compareGT {x} {y} p | EQ = absurd p\n> compareGT {x} {y} _ | GT = Oh\n\n\n* LT, LTE:\n\n> ||| LTE is total\n> totalLTE : (x, y : Double) -> Either (x `LTE` y) (y `LTE` x) \n> totalLTE x y with (compare x y) proof prf\n> | LT = Left (MkLTE (LTinLTE (compareLT prf)))\n> | EQ = Left (MkLTE (EQinLTE (compareEQ prf)))\n> | GT = Right (MkLTE (LTinLTE (gtLT (compareGT prf))))\n\n> ||| LTE is a total preorder\n> totalPreorderLTE : TotalPreorder Double.Predicates.LTE\n> totalPreorderLTE = MkTotalPreorder LTE reflexiveLTE transitiveLTE totalLTE\n\n> ||| LT is decidable\n> decLT : (x : Double) -> (y : Double) -> Dec (x `LT` y)\n> decLT x y with (decSo (x < y))\n> | Yes prf = Yes (MkLT prf)\n> | No contra = No (\\ (MkLT prf) => void (contra prf))\n\n> ||| LTE is decidable\n> decLTE : (x : Double) -> (y : Double) -> Dec (x `LTE` y)\n> decLTE x y with (decSo (x <= y))\n> | Yes prf = Yes (MkLTE prf)\n> | No contra = No (\\ (MkLTE prf) => void (contra prf))\n\n> |||\n> minusLTELemma : (x : Double) -> (y : Double) ->\n> x `LTE` y -> 0.0 `LTE` y - x \n> minusLTELemma x y xLTEy = s2 where\n> s1 : x - x `LTE` y - x\n> s1 = monotoneMinusConstLTE xLTEy\n> s2 : 0.0 `LTE` y - x\n> s2 = replace {P = \\ X => X `LTE` y - x} (minusSelfZero) s1\n\n> |||\n> divLTELemma : (x : Double) -> (y : Double) -> x `LTE` y -> \n> Positive y -> x / y `LTE` 1.0\n> divLTELemma x y xLTEy py = s2 where\n> s1 : x / y `LTE` y / y\n> s1 = monotoneDivConstLTE xLTEy py\n> s2 : x / y `LTE` 1.0\n> s2 = replace {P = \\ X => x / y `LTE` X} (divPositiveSelfOne py) s1\n \n> |||\n> divNonNegativePositiveNonNegative : (x : Double) -> (y : Double) ->\n> 0.0 `LTE` x -> Positive y ->\n> 0.0 `LTE` x / y\n> divNonNegativePositiveNonNegative x y zLTEx py = s2 where\n> s1 : 0.0 / y `LTE` x / y\n> s1 = monotoneDivConstLTE zLTEx py\n> s2 : 0.0 `LTE` x / y\n> s2 = replace {P = \\ X => X `LTE` x / y} (divZeroPositiveZero py) s1\n\n> ||| |sum| is monotone\n> monotoneSum : {A : Type} ->\n> (f : A -> Double) -> (g : A -> Double) ->\n> (p : (a : A) -> f a `LTE` g a) ->\n> (as : List A) ->\n> sum (map f as) `LTE` sum (map g as)\n> monotoneSum f g p Nil = reflexiveLTE 0.0 \n> monotoneSum f g p (a :: as) = \n> monotonePlusLTE {a = f a} {b = g a} {c = sum (map f as)} {d = sum (map g as)} (p a) (monotoneSum f g p as)\n\n\n* Non-negative double precision floating point numbers:\n\n> ||| Non-negative |Double|s are closed w.r.t. sum\n> plusPreservesNonNegativity : {x, y : Double} -> \n> NonNegative x -> NonNegative y -> NonNegative (x + y) \n> plusPreservesNonNegativity {x} {y} zeroLTEx zeroLTEy = s2 where\n> s1 : 0.0 + 0.0 `LTE` x + y\n> s1 = monotonePlusLTE {a = 0.0} {b = x} {c = 0.0} {d = y} zeroLTEx zeroLTEy\n> s2 : 0.0 `LTE` x + y\n> s2 = replace {P = \\ X => X `LTE` x + y} plusZeroLeftNeutral s1\n\n> ||| Non-negative |Double|s are closed w.r.t. multiplication\n> multPreservesNonNegativity : {x, y : Double} -> \n> NonNegative x -> NonNegative y -> NonNegative (x * y)\n> multPreservesNonNegativity {x} {y} zeroLTEx zeroLTEy = s2 where\n> s1 : 0.0 * 0.0 `LTE` x * y\n> s1 = monotoneMultLTE {a = 0.0} {b = x} {c = 0.0} {d = y} zeroLTEx zeroLTEy\n> s2 : 0.0 `LTE` x * y\n> s2 = replace {P = \\ X => X `LTE` x * y} (multZeroLeftZero {x = 0.0}) s1\n\n\n* Positive double precision floating point numbers:\n\n> |||\n> positiveImpliesNonNegative : {x : Double} -> Positive x -> NonNegative x\n> positiveImpliesNonNegative (MkLT prf) = MkLTE (LTinLTE prf) \n\n\n* Properties of constants:\n\n> ||| one is not zero\n> notOneEqZero : Not (1.0 = 0.0)\n> notOneEqZero Refl impossible\n\n> ||| zero is not positive\n> notPositiveZero : Not (Positive 0.0)\n> notPositiveZero (MkLT prf) = contra Refl prf\n\n\n* Properties of |fromNat|\n\n> |||\n> fromNatNonNegative : {n : Nat} -> NonNegative (fromNat n)\n> fromNatNonNegative {n = Z} = MkLTE Oh\n> fromNatNonNegative {n = S m} = plusPreservesNonNegativity (MkLTE Oh) fromNatNonNegative \n\n> |||\n> fromSuccPositive : {n : Nat} -> Positive (fromNat (S n))\n> fromSuccPositive {n} = positivePlusAnyPositive (MkLT Oh) fromNatNonNegative \n\n\n* Convexity\n\n> |||\n> convexLemma1 : (x1 : Double) -> (x2 : Double) -> Positive (x2 - x1) ->\n> (x : Double) -> (q : x1 `LTE` x) ->\n> 0.0 `LTE` (x - x1) / (x2 - x1)\n> convexLemma1 x1 x2 px2mx1 x x1LTEx = \n> divNonNegativePositiveNonNegative (x - x1) (x2 - x1) s1 px2mx1 where\n> s1 : 0.0 `LTE` (x - x1)\n> s1 = minusLTELemma x1 x x1LTEx\n\n> |||\n> convexLemma2 : (x1 : Double) -> (x2 : Double) -> Positive (x2 - x1) ->\n> (x : Double) -> (q : x `LTE` x2) ->\n> (x - x1) / (x2 - x1) `LTE` 1.0\n> convexLemma2 x1 x2 px2mx1 x q = divLTELemma (x - x1) (x2 - x1) s1 px2mx1 where\n> s1 : (x - x1) `LTE` (x2 - x1)\n> s1 = monotoneMinusConstLTE q \n\n> |||\n> convexLemma : (x1 : Double) -> (x2 : Double) -> (alpha : Double) ->\n> NonNegative x1 -> NonNegative x2 -> \n> 0.0 `LTE` alpha -> alpha `LTE` 1.0 ->\n> NonNegative (x1 * (1.0 - alpha) + x2 * alpha)\n> convexLemma x1 x2 alpha nnx1 nnx2 (MkLTE p1) (MkLTE p2) = s4 where\n> s1 : NonNegative alpha\n> s1 = MkLTE p1\n> s2 : alpha - alpha `LTE` 1.0 - alpha\n> s2 = monotoneMinusConstLTE (MkLTE p2)\n> s3 : NonNegative (1.0 - alpha)\n> s3 = replace {P = \\ X => X `LTE` 1.0 - alpha} minusSelfZero s2\n> s4 : NonNegative (x1 * (1.0 - alpha) + x2 * alpha)\n> s4 = plusPreservesNonNegativity {x = x1 * (1.0 - alpha)} {y = x2 * alpha}\n> (multPreservesNonNegativity nnx1 s3)\n> (multPreservesNonNegativity nnx2 s1)\n\n\n* Properties of |mkLinearStepLemma|:\n\n> |||\n> mkLinearStepLemma : (x1 : Double) -> (x2 : Double) -> Positive (x2 - x1) ->\n> (y1 : Double) -> (y2 : Double) -> \n> NonNegative y1 -> NonNegative y2 -> \n> (x : Double) -> NonNegative (mkLinearStep x1 x2 prf y1 y2 x)\n> mkLinearStepLemma x1 x2 px2mx1 y1 y2 nny1 nny2 x with (decSo (x < x1))\n> | Yes _ = nny1\n> | No _ with (decSo (x1 <= x && x <= x2))\n> | Yes prf = s3 where\n> alpha : Double\n> alpha = (x - x1) / (x2 - x1)\n> s1 : 0.0 `LTE` alpha\n> s1 = convexLemma1 x1 x2 px2mx1 x (MkLTE (soAndElim1 (x1 <= x) (x <= x2) prf))\n> s2 : alpha `LTE` 1.0\n> s2 = convexLemma2 x1 x2 px2mx1 x (MkLTE (soAndElim2 (x1 <= x) (x <= x2) prf))\n> s3 : NonNegative (y1 * (1.0 - alpha) + y2 * alpha)\n> s3 = convexLemma y1 y2 alpha nny1 nny2 s1 s2\n> | No _ = nny2\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "ba048f0eb2684ebaf92338737c7b4f112475b858", "size": 8551, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Double/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": "Double/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": "Double/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": 33.6653543307, "max_line_length": 110, "alphanum_fraction": 0.5448485557, "num_tokens": 3249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317473, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.614385746647472}} {"text": "> module PNat.Properties\n\n> import Syntax.PreorderReasoning\n\n> import PNat.PNat\n> import PNat.Operations\n> import Nat.Positive\n> import Unique.Predicates\n> import Subset.Properties\n> import Nat.LTProperties\n> import Pairs.Operations\n\n\n> %default total\n> %access export\n\n\n> ||| PNat is an implementation of DecEq\n> implementation DecEq PNat where\n> decEq (Element m pm) (Element n pn) with (decEq m n)\n> | (Yes prf) = Yes (subsetEqLemma1 (Element m pm) (Element n pn) prf PositiveUnique) \n> | (No contra) = No (\\ prf => contra (getWitnessPreservesEq prf))\n\n\n> ||| PNat is an implementation of Show\n> implementation Show PNat where\n> show = show . toNat\n\n\n> |||\n> predToNatLemma : (x : PNat) -> S (pred x) = toNat x\n> predToNatLemma (Element _ (MkPositive {n})) = Refl\n\n\n> |||\n> toNatfromNatLemma : (m : Nat) -> (zLTm : Z `LT` m) -> toNat (fromNat m zLTm) = m\n> {-\n> toNatfromNatLemma Z zLTz = absurd zLTz\n> toNatfromNatLemma (S m) _ = Refl\n> ---}\n> --{-\n> toNatfromNatLemma m zLTm = Refl\n> ---}\n\n\n> |||\n> toNatLTLemma : (x : PNat) -> Z `LT` toNat x\n> toNatLTLemma x = s2 where\n> s1 : Z `LT` (S (pred x))\n> s1 = ltZS (pred x)\n> s2 : Z `LT` (toNat x)\n> s2 = replace (predToNatLemma x) s1\n\n\n> ||| \n> toNatEqLemma : {x, y : PNat} -> (toNat x) = (toNat y) -> x = y\n> toNatEqLemma {x} {y} p = subsetEqLemma1 x y p PositiveUnique\n\n\n> ||| \n> -- toNatMultLemma : {x, y : PNat} -> toNat (x * y) = (toNat x) * (toNat y)\n> toNatMultLemma : {x, y : PNat} -> toNat (x * y) = (toNat x) * (toNat y)\n> toNatMultLemma {x = (Element m pm)} {y = (Element n pn)} = Refl\n\n\n> |||\n> multOneRightNeutral : (x : PNat) -> x * (Element 1 MkPositive) = x\n> multOneRightNeutral (Element m pm) =\n> ( (Element m pm) * (Element 1 MkPositive) )\n> ={ Refl }=\n> ( Element (m * 1) (multPreservesPositivity pm MkPositive) )\n> ={ toNatEqLemma (multOneRightNeutral m) }=\n> ( Element m pm )\n> QED\n\n\n> |||\n> multCommutative : (x : PNat) -> (y : PNat) -> x * y = y * x\n> multCommutative (Element m pm) (Element n pn) =\n> let pmn = multPreservesPositivity pm pn in\n> let pnm = multPreservesPositivity pn pm in\n> ( Element (m * n) pmn )\n> ={ toNatEqLemma (multCommutative m n) }=\n> ( Element (n * m) pnm )\n> QED\n\n\n> |||\n> multAssociative : (x : PNat) -> (y : PNat) -> (z : PNat) -> \n> x * (y * z) = (x * y) * z\n> multAssociative (Element m pm) (Element n pn) (Element o po) = \n> let pno = multPreservesPositivity pn po in\n> let pmno = multPreservesPositivity pm pno in\n> let pmn = multPreservesPositivity pm pn in\n> let pmno' = multPreservesPositivity pmn po in\n> ( (Element m pm) * ((Element n pn) * (Element o po)) )\n> ={ Refl }=\n> ( (Element m pm) * (Element (n * o) pno) )\n> ={ Refl }=\n> ( Element (m * (n * o)) pmno )\n> ={ toNatEqLemma (multAssociative m n o) }=\n> ( Element ((m * n) * o) pmno' )\n> ={ Refl }=\n> ( (Element (m * n) pmn) * (Element o po) )\n> ={ Refl }=\n> ( ((Element m pm) * (Element n pn)) * (Element o po) )\n> QED\n\n\n> {-\n \n> ---}\n", "meta": {"hexsha": "233c91c63c0b285054039e559e8f552c95696255", "size": 3030, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "PNat/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": "PNat/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": "PNat/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": 26.814159292, "max_line_length": 90, "alphanum_fraction": 0.5815181518, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764119, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6143349125178996}} {"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", "meta": {"hexsha": "1dfa8d3970975f1d3df2ce30faee6c8072a0bff8", "size": 634, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter7/Expr.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": "Chapter7/Expr.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": "Chapter7/Expr.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": 25.36, "max_line_length": 49, "alphanum_fraction": 0.5, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.6654105653819836, "lm_q1q2_score": 0.6142000121892209}} {"text": "-- Conway's Game Of Life in Idris\nmodule Conway.Conway\n\nimport Data.Vect\n\n-- | An individual Cell can either be alive or dead\npublic export\ndata CellState = Alive | Dead\n\npublic export\ndata Conway : Nat -> Nat -> Type where \n MkConway : (Vect m (Vect n CellState)) -> Conway m n\n\n-- | Neighbours of a given cell, typically has 8 neighbours \n-- (we'll count the missing neighbours from edges as dead)\ndata Neighbours : Nat -> Type where\n MkNeighbours : CellState -> (Vect n CellState) -> Neighbours n\n\n\n-- | Count number of alive neighbours, guaranteed to be <= total\n-- number of neighbours\nnumAlive : Neighbours n -> Fin (n + 1)\nnumAlive {n} nbs = case natToFin (numAlive' nbs) (n + 1) of\n Just f => f\n where\n -- | Count number of alive neighbours\n numAlive' : Neighbours n -> Nat\n numAlive' (MkNeighbours _ v) = foldl accFn 0 v\n where accFn : Nat -> CellState -> Nat\n accFn cnt Alive = (cnt + 1)\n accFn cnt Dead = (cnt + 0) \n\n\n\n-- | Count the number of dead neighbours, guaranteed to be <= total\n-- number of given neighbours\nnumDead : Neighbours n -> Fin (n + 1)\nnumDead {n} nbs = case natToFin (numDead' nbs) (n + 1) of\n Just f => f\n where\n -- | Count number of dead neighbours\n numDead' : Neighbours n -> Nat\n numDead' (MkNeighbours _ v) = foldl accFn 0 v\n where accFn : Nat -> CellState -> Nat\n accFn cnt Alive = (cnt + 0)\n accFn cnt Dead = (cnt + 1) \n\n\n\n-- | Work out the new state of a cell given its neighbours\nnewCellState : Neighbours n -> CellState\nnewCellState (MkNeighbours cs v) with (cs, finToInteger $ numAlive $ MkNeighbours cs v)\n | (Alive, 2) = Alive -- Stays alive\n | (_, 3) = Alive -- Comes to life or stays alive\n | (_, _) = Dead -- < 2 dies or stays dead and > 3 dies or stays dead\n \n\n\n-- | Generate Neighbours for a given point in the board\ngetNeighbours : Conway m n -> Fin m -> Fin n -> Neighbours 8\ngetNeighbours (MkConway v) y x = \n (MkNeighbours cs [l, topL, top, topR, r, botR, bot, botL])\n\n where\n -- Check if Cell at given position is Dead Or Alive\n -- If out of bounds the Cell is considered Dead\n getDoA : Conway a b -> Integer -> Integer -> CellState\n getDoA {a} {b} (MkConway v) y x = \n case getCell of \n Just c => c\n Nothing => Dead\n\n where getCell : Maybe CellState\n getCell = do\n row <- integerToFin y a\n col <- integerToFin x b\n return $ index col (index row v)\n \n ix : Integer\n ix = finToInteger x\n iy : Integer\n iy = finToInteger y\n \n cs = index x (index y v)\n\n l = getDoA (MkConway v) iy (ix - 1)\n topL = getDoA (MkConway v) (iy - 1) (ix - 1)\n top = getDoA (MkConway v) (iy - 1) ix\n topR = getDoA (MkConway v) (iy - 1) (ix + 1)\n r = getDoA (MkConway v) iy (ix + 1)\n botR = getDoA (MkConway v) (iy + 1) (ix + 1)\n bot = getDoA (MkConway v) (iy + 1) ix\n botL = getDoA (MkConway v) (iy + 1) (ix - 1)\n\n\n-- | Generates a List of values 0 to N - 1\n-- Guarantees that returned Vector has N values \nsequence : (n : Nat) -> Vect n Nat\nsequence n = reverse $ sequence' n\n where sequence' : (m : Nat) -> Vect m Nat\n sequence' Z = Nil \n sequence' (S n) = n::(sequence' n)\n\n\n-- | Generates a Vector of values 0 to N - 1\n-- Guarantees that returned Vector has N values\n-- and every values is < N\nexport\nsequenceFin : (n : Nat) -> Vect n (Fin n)\nsequenceFin n = map n2f (sequence n)\n where n2f : Nat -> Fin n\n n2f m = case natToFin m n of\n Just f => f\n\n-- | Get the next state from the current state\nexport\niterateGame : Conway m n -> Conway m n\niterateGame {m} {n} (MkConway v) = MkConway (map iterateRow (sequenceFin m))\n where iterateRow : Fin m -> Vect n CellState\n iterateRow y = map iteratePos (sequenceFin n)\n where iteratePos : Fin n -> CellState\n iteratePos x = newCellState (getNeighbours (MkConway v) y x) \n", "meta": {"hexsha": "d78bfb5c97d1320168398d052f304cd781c6a18a", "size": 4140, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Conway/Conway.idr", "max_stars_repo_name": "RossMeikleham/Idris-Conway", "max_stars_repo_head_hexsha": "6a114d808d2dc6bf50ca0229b0d2ec3e8832180c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-15T02:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-15T02:34:42.000Z", "max_issues_repo_path": "src/Conway/Conway.idr", "max_issues_repo_name": "RossMeikleham/Idris-Conway", "max_issues_repo_head_hexsha": "6a114d808d2dc6bf50ca0229b0d2ec3e8832180c", "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/Conway/Conway.idr", "max_forks_repo_name": "RossMeikleham/Idris-Conway", "max_forks_repo_head_hexsha": "6a114d808d2dc6bf50ca0229b0d2ec3e8832180c", "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.6585365854, "max_line_length": 87, "alphanum_fraction": 0.5862318841, "num_tokens": 1271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6141330130747593}} {"text": "data Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\ninterface Finite t where\n 0 card : Nat\n to : t -> Fin card\n\nimplementation Finite (Fin k) where\n card = k\n to = id\n\ninterface BadFinite t where\n badcard : Nat\n badto : t -> Fin card\n\nimplementation BadFinite (Fin k) where\n badcard = k\n badto = id\n\n", "meta": {"hexsha": "66a3ff1f9444c41558a5de0e24caa2a0e3ad76cc", "size": 347, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interface008/Deps.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/interface008/Deps.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/interface008/Deps.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": 16.5238095238, "max_line_length": 38, "alphanum_fraction": 0.5994236311, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.6859494550081926, "lm_q1q2_score": 0.6137803504691495}} {"text": "module Main\n\ndouble : Num ty => ty -> ty\ndouble x = x + x\n\nidentity : ty -> ty\nidentity x = x\n\nthe2 : (ty : Type) -> ty -> ty\nthe2 ty x = x\n\ntwice : (a -> a) -> a -> a\ntwice f x = f (f x)\n\n-- Shape : Type\n-- rotate : Shape -> Shape\n\nlonger : String -> String -> Nat\nlonger w1 w2\n = let l1 = length w1\n l2 = length w2\n in if l1 > l2 then l1 else l2\n\n||| Calculates the value of the pythagoras equasion.\n||| @x a value for the first side of a triangle\n||| @y a value for the second side of a triangle\npythagoras : (x : Double) -> (y : Double) -> Double\npythagoras x y = sqrt (square x + square y)\n where\n square : Double -> Double\n square x = x * x\n\nmain : IO ()\nmain = do\n putStrLn $ cast $ twice double $ the2 Int $ identity 3\n putStrLn $ cast $ longer \"Hello\" \"World!\"\n putStrLn $ cast $ pythagoras 1 3\n", "meta": {"hexsha": "ed2971b21881dbeab7b167c3cd203b058c6468b4", "size": 825, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/tdd/chapter02/03_Prelude.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/chapter02/03_Prelude.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/chapter02/03_Prelude.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": 21.7105263158, "max_line_length": 56, "alphanum_fraction": 0.6048484848, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.689305616785446, "lm_q1q2_score": 0.6136848086511323}} {"text": "\nmodule Subst\n\n\nimport FinCmp\nimport Term\n\n\n%default total\n\n\n--------------------------------------------------------------\n-- Begin: WEAKENING, I.E. ADDING UNUSED VARIABLES TO THE SCOPE\n\n-- Abbreviate the name of the function 'weakenN'\n-- from 'Data.Fin' (for better readability):\nwkN : (n : Nat) -> Fin m -> Fin (m + n)\nwkN = Data.Fin.weakenN\n\n \nweakenContext : (m : Nat) -> (n : Nat) -> Term m -> Term (m + n)\nweakenContext m n (TVar i) = TVar (wkN n i)\nweakenContext m n (TAbs x) = TAbs (weakenContext (S m) n x)\nweakenContext m n (TApp x y) = TApp (weakenContext m n x)\n (weakenContext m n y)\nweakenContext _ _ TZero = TZero\nweakenContext m n (TSucc x) = TSucc (weakenContext m n x)\nweakenContext m n (TPred x) = TPred (weakenContext m n x)\nweakenContext m n (TIfz x y z) = TIfz (weakenContext m n x)\n (weakenContext m n y)\n (weakenContext m n z)\n\n-- End: WEAKENING, I.E. ADDING UNUSED VARIABLES TO THE SCOPE\n------------------------------------------------------------\n\n\n\n \n-------------------------\n-- Begin: TECHNICAL LEMMA\n\ntightenBound : {n : Nat} ->\n (j : Fin (S n)) -> (i : Fin (S n)) -> \n j :<: i ->\n (j_ : Fin n ** (finToNat j_ = finToNat j))\n-- \ntightenBound _ FZ lt = absurd $ finNotLtZ lt\n--\ntightenBound {n = (S k)} FZ (FS i') lt = (FZ ** Refl)\n--\ntightenBound {n = (S k)} (FS j') (FS i') lt = \n let (j'_ ** eq') = tightenBound {n = k} j' i' (finLtPred lt)\n in (FS j'_ ** cong eq')\n\n-- End: TECHNICAL LEMMA\n-----------------------\n\n\n\n------------------------------------------------------------------------------\n-- Begin: SUBSTITUTION PRESERVES SCOPING OF EXPRESSIONS IN THE LAMBDA CALCULUS\n\nsubst_var : Term 0 -> -- Term that is subtituted in.\n (i : Fin (S n)) -> -- The i-th variable (Var i) is substituted for.\n (j : Fin (S n)) -> -- Substitution takes place inside the term (Var j).\n Term n\n-- An actual substitution occurs only if \"i = j\".\nsubst_var {n} ts i j = case finCmpDec i j of\n CmpEq eq => weakenContext 0 n ts\n CmpLt lt => case j of\n FZ => absurd $ finNotLtZ lt \n FS j' => TVar j'\n CmpGt gt => case i of\n FZ => absurd $ finNotLtZ gt\n FS i' => let (j_ ** _) = tightenBound j (FS i') gt\n in TVar j_\n\n\nexport subst : Term 0 -> -- Term that is substituted in.\n (i : Fin (S n)) -> -- The i-th varibale (Var i) is substituted for.\n Term (S n) -> -- Substitution takes place inside this term.\n Term n\n--\n-- The hard part is substitution in expressions that \n-- are variables, i.e. substitution in 'Var j'.\nsubst ts i (TVar j) = subst_var ts i j\n--\n-- Substitution in expressions that are not variables\n-- is handled by recursing over (and substituting in)\n-- subexpressions:\nsubst ts i (TAbs e) = TAbs (subst ts (FS i) e)\nsubst ts i (TApp e1 e2) = TApp (subst ts i e1) (subst ts i e2)\nsubst _ _ TZero = TZero\nsubst ts i (TSucc e) = TSucc (subst ts i e)\nsubst ts i (TPred e) = TPred (subst ts i e)\nsubst ts i (TIfz e1 e2 e3) = TIfz (subst ts i e1) (subst ts i e2) (subst ts i e3)\n\n-- End: SUBSTITUTION PRESERVES SCOPING OF EXPRESSIONS IN THE LAMBDA CALCULUS\n----------------------------------------------------------------------------\n", "meta": {"hexsha": "a09403819f5217c1576573a3541bf0cd187b3bf5", "size": 3561, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "untyped/src/Subst.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/Subst.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/Subst.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": 35.61, "max_line_length": 84, "alphanum_fraction": 0.49761303, "num_tokens": 1024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6136678695181425}} {"text": "module ElemsAreSame\nimport Data.Vect\n--=======================================================================================================\n--=======================================================================================================\n--Elems are same\n--=======================================================================================================\n--=======================================================================================================\npublic export data ElemsAreSame : (xs:Vect n e) -> (ys:Vect n e) -> Type where\n ||| Empty vectors are the same\n NilIsNil :\n ElemsAreSame Nil Nil\n ||| Prepending x to two vectors with the same elements\n ||| Gives two vectors which still have the same elements\n PrependXIsPrependX :\n (x:e) -> ElemsAreSame zs zs' ->\n ElemsAreSame (x::zs) (x::zs')\n ||| Given two elements x and y\n ||| and a proof that two vectors zs and zs' have the same elements\n |||\n PrependXYIsPrependYX :\n (x:e) -> (y:e) -> ElemsAreSame zs zs' ->\n ElemsAreSame (x::(y::zs)) (y::(x::(zs')))\n -- NOTE: Probably could derive this last axiom from the prior ones\n SamenessIsTransitive :\n ElemsAreSame xs zs -> ElemsAreSame zs ys ->\n ElemsAreSame xs ys\n\nexport sameListsAreSame: (xs: Vect n e) -> ElemsAreSame xs xs\nsameListsAreSame [] = NilIsNil\nsameListsAreSame (x :: xs) = PrependXIsPrependX x (sameListsAreSame xs)\n\nswap: ElemsAreSame xs ys -> ElemsAreSame ys xs\nswap NilIsNil = NilIsNil\nswap (PrependXIsPrependX x y) = PrependXIsPrependX x (swap y)\nswap (PrependXYIsPrependYX x y z) = PrependXYIsPrependYX y x (swap z)\nswap (SamenessIsTransitive x y) = SamenessIsTransitive (swap y)\n (SamenessIsTransitive y (swap (SamenessIsTransitive x y)))\n\nexport swapHeads: ElemsAreSame (x::y::zs) us -> ElemsAreSame (y::x::zs) us\nswapHeads {x} {y} {zs} {us} e = let xYIsYX = PrependXYIsPrependYX y x (sameListsAreSame zs) in\n SamenessIsTransitive xYIsYX e\n", "meta": {"hexsha": "419d53902ec8acddd48a1a20e4203b9bc4890dae", "size": 2028, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Poker/ElemsAreSame.idr", "max_stars_repo_name": "as8709/PokerHands", "max_stars_repo_head_hexsha": "873a9b646ff5f021b4af80ac3325d51397639716", "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": "Poker/ElemsAreSame.idr", "max_issues_repo_name": "as8709/PokerHands", "max_issues_repo_head_hexsha": "873a9b646ff5f021b4af80ac3325d51397639716", "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": "Poker/ElemsAreSame.idr", "max_forks_repo_name": "as8709/PokerHands", "max_forks_repo_head_hexsha": "873a9b646ff5f021b4af80ac3325d51397639716", "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": 48.2857142857, "max_line_length": 105, "alphanum_fraction": 0.5236686391, "num_tokens": 535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.7549149923816046, "lm_q1q2_score": 0.6136457250526072}} {"text": "> module NonNegDouble.Operations\n\n> import Data.So\n\n> import Double.Predicates\n> import Double.Postulates\n> import Double.Properties\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.Predicates\n> import NonNegDouble.Constants\n> import NonNegDouble.BasicOperations\n> import Pairs.Operations\n\n> %default total\n> %access public export\n\n\n> ||| Addition of positive double precision floating point numbers\n> plus : NonNegDouble -> NonNegDouble -> NonNegDouble\n> plus (Element x nnx) (Element y nny) = Element (x + y) (plusPreservesNonNegativity nnx nny)\n\n> ||| Subtraction of positive double precision floating point numbers\n> minus : (x : NonNegDouble) -> (y : NonNegDouble) -> {auto prf : y `LTE` x} -> NonNegDouble\n> minus (Element x nnx) (Element y nny) {prf} = Element (x - y) (minusPreservesNonNegativity nnx nny prf)\n\n> (-) : (x : NonNegDouble) -> (y : NonNegDouble) -> {auto prf : y `LTE` x} -> NonNegDouble\n> (-) = minus\n\n> ||| Multiplication of positive double precision floating point numbers\n> mult : NonNegDouble -> NonNegDouble -> NonNegDouble\n> mult (Element x nnx) (Element y nny) = Element (x * y) (multPreservesNonNegativity nnx nny)\n\n\n> ||| Division of positive double precision floating point numbers\n> div : NonNegDouble -> NonNegDouble -> NonNegDouble\n> div (Element x nnx) (Element y nny) = Element (x / y) (divPreservesNonNegativity nnx nny)\n\n\n> ||| \n> fromNat : (n : Nat) -> NonNegDouble\n> fromNat Z = zero\n> fromNat (S m) = one `plus` (fromNat m)\n\n\n> {-\n\n\n> ---}\n", "meta": {"hexsha": "d2919616fa9a7ce2676235c16afca89d590cde00", "size": 1495, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegDouble/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": "NonNegDouble/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": "NonNegDouble/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": 30.5102040816, "max_line_length": 105, "alphanum_fraction": 0.7076923077, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.6992544210587586, "lm_q1q2_score": 0.6135795207826429}} {"text": "infixr 5 ::\n\nnamespace List\n public export\n data List a = Nil | (::) a (List a)\n\nnamespace Stream\n public export\n data Stream a = (::) a (Inf (Stream a))\n\nones : Stream Integer\nones = num :: ones\n where\n num : Integer -- gratuitous where for a regression test!\n num = 1\n\ndata Nat = Z | S Nat\n\ntake : Nat -> Stream a -> List a\ntake Z xs = Nil\ntake (S k) (x :: xs) = List.(::) x (take k xs)\n\n", "meta": {"hexsha": "6f44919929c691a3fed49414c28a59d095e0e473", "size": 409, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/lazy001/Lazy.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/lazy001/Lazy.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/lazy001/Lazy.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": 17.7826086957, "max_line_length": 60, "alphanum_fraction": 0.5892420538, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7461390043208002, "lm_q1q2_score": 0.6134673857127767}} {"text": "import Data.Vect\n\n\n{-\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\n-}\n\ntotal\nremoveElem : (value : a) -> (xs : Vect (S n) a) -> (witn : Elem value xs) ->\n Vect n a\nremoveElem value (value :: ys) Here = ys\n{- removeElem value (y :: []) (There later) = absurd later -}\nremoveElem {n = (S k)} value (y :: ys) (There later)\n = y :: removeElem value ys later\n\n\n\nnot_in_nil : Elem value [] -> Void\nnot_in_nil Here impossible\nnot_in_nil (There _) impossible\n", "meta": {"hexsha": "33cb07c31f4f9df08e802aebcbe477e6f8f49201", "size": 543, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZPF/Slajdy19/PlikiIdrisa/removeElem.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/removeElem.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/removeElem.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.72, "max_line_length": 76, "alphanum_fraction": 0.5856353591, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7090191276365463, "lm_q1q2_score": 0.6134604242389062}} {"text": "import Data.Vect\n\ndata StackCmd : Type -> Nat -> Nat -> Type where\n Push : Integer -> StackCmd () height (S height)\n Pop : StackCmd Integer (S height) height\n Top : StackCmd Integer (S height) (S height)\n\n Pure : ty -> StackCmd ty height height\n (>>=) : StackCmd a height1 height2 ->\n (a -> StackCmd b height2 height3) ->\n StackCmd b height1 height3\n\nrunStack : (stk : Vect inHeight Integer) ->\n StackCmd ty inHeight outHeight ->\n (ty, Vect outHeight Integer)\nrunStack stk (Push val) = ((), val :: stk)\nrunStack (val :: stk) Pop = (val, stk)\nrunStack (val :: stk) Top = (val, val :: stk)\nrunStack stk (Pure x) = (x, stk)\nrunStack stk (x >>= f) = let (x', newStk) = runStack stk x in\n runStack newStk (f x')\n\ntestAdd : StackCmd Integer 0 0\ntestAdd = do Push 10\n Push 20\n val1 <- Pop\n val2 <- Pop\n Pure (val1 + val2)\n\ndoAdd : StackCmd () (S (S height)) (S height)\ndoAdd = do val1 <- Pop\n val2 <- Pop\n Push (val1 + val2)\n", "meta": {"hexsha": "7289d7f417bd5bd13af3a9ab3d7a13e94f8c1026", "size": 1090, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter13/Stack.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/typedd-book/chapter13/Stack.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/typedd-book/chapter13/Stack.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.0588235294, "max_line_length": 61, "alphanum_fraction": 0.5458715596, "num_tokens": 314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.6926419704455588, "lm_q1q2_score": 0.6134255312048624}} {"text": "import Data.Vect\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\ntri' : Vect 3 Position\ntri' = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)]\n\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": "828b019d03d935a53b051653da789b496cac2abd", "size": 319, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter06/TypeSynonyms.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": "Chapter6/TypeSynonyms.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": "Chapter6/TypeSynonyms.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": 18.7647058824, "max_line_length": 44, "alphanum_fraction": 0.5423197492, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6130650712475976}} {"text": "module Mult\n\nimport public Nat\n\npublic export\nmult : Nat -> Nat -> Nat\nmult Z y = Z\nmult (S k) y = plus y (mult k y)\n", "meta": {"hexsha": "db56ce17fd3f5160322a8fdac9c8a215c1e76b61", "size": 117, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/import001/Mult.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/import001/Mult.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/import001/Mult.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": 13.0, "max_line_length": 32, "alphanum_fraction": 0.641025641, "num_tokens": 38, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6129980491739996}} {"text": "VendState : Type\nVendState = (Nat, Nat)\n\ndata Input = COIN\n | VEND\n | CHANGE\n | REFILL Nat\n\ndata MachineCmd : Type ->\n VendState ->\n VendState ->\n Type where\n InsertCoin : MachineCmd () (pounds, chocs) (S pounds, chocs)\n Vend : MachineCmd () (S pounds, S chocs) (pounds, chocs)\n GetCoins : MachineCmd () (pounds, chocs) (Z, chocs)\n Refill : (bars : Nat) -> MachineCmd () (Z, chocs) (Z, bars + chocs)\n\n Display : String -> MachineCmd () state state\n GetInput : MachineCmd (Maybe Input) state state\n\n Pure : ty -> MachineCmd ty state state\n (>>=) : MachineCmd a state1 state2 ->\n (a -> MachineCmd b state2 state3) ->\n MachineCmd b state1 state3\n\ndata MachineIO : VendState -> Type where\n Do : MachineCmd a state1 state2 ->\n (a -> Inf (MachineIO state2)) -> MachineIO state1\n\nnamespace MachineDo\n (>>=) : MachineCmd a state1 state2 -> (a -> Inf (MachineIO state2)) ->\n MachineIO state1\n (>>=) = Do\n\n\nmutual\n vend : MachineIO (pounds, chocs)\n vend {pounds = Z} = do Display \"Insert a coin\"\n machineLoop\n vend {chocs = Z} = do Display \"Out of stock\" \n machineLoop\n vend {pounds = (S k)} {chocs = (S j)} = do Vend\n Display \"Enjoy!\"\n machineLoop\n\n refill : (num : Nat) -> MachineIO (pounds, chocs)\n refill {pounds = Z} num = do Refill num\n machineLoop\n refill _ = do Display \"Can't refill: Coins in machine\"\n machineLoop\n\n machineLoop : MachineIO (pounds, chocs)\n machineLoop = \n do Just x <- GetInput\n | Nothing => do Display \"Invalid input\"\n machineLoop\n case x of\n COIN => do InsertCoin\n machineLoop\n VEND => vend\n CHANGE => do GetCoins\n Display \"Change returned\"\n machineLoop\n REFILL num => refill num\n", "meta": {"hexsha": "3bbbb324ad208b8ddb0f9d5a2c546a84afed03be", "size": 2134, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp13/Vending.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/chp13/Vending.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/chp13/Vending.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": 32.8307692308, "max_line_length": 76, "alphanum_fraction": 0.5065604499, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.6127137122116787}} {"text": "module Solver\n\nimport Decidable.Equality\nimport Control.Monad.State\nimport Data.Vect\nimport Data.Vect.Quantifiers\nimport System\n\n-- %default total\n\n-- Solver ----------------------------------------------------------------------\n\nCell : Nat -> Type\nCell n = Maybe (Fin n)\n\ndata Board : Nat -> Type where\n MkBoard : {n : Nat} -> Vect n (Vect n (Cell n)) -> Board n\n\nemptyBoard : Board n\nemptyBoard {n=n} = MkBoard (replicate n (replicate n Nothing))\n\nshowElt : Cell n -> String\nshowElt Nothing = \".\"\nshowElt (Just x) = show (1 + (the Int (fromInteger (cast x))))\n\n-- FIXME: Inline type decl should not be necessary here\nshowRow : Vect n (Cell n) -> String\nshowRow {n=n} xs = unwords (toList (the (Vect n String) (map showElt xs)))\n\nunlines : Vect n String -> String\nunlines Nil = \"\"\nunlines (l::Nil) = l\nunlines (l::ls) = pack (foldl addLine (unpack l) (map unpack ls))\n where\n addLine : List Char -> List Char -> List Char\n addLine w s = w ++ ('\\n' :: s)\n\nShow (Board n) where\n show (MkBoard rs) = unlines (map showRow rs)\n\nupdateAt : Fin n -> Vect n a -> (a -> a) -> Vect n a\nupdateAt FZ (x::xs) f = f x :: xs\nupdateAt (FS i) (x::xs) f = x :: updateAt i xs f\n\nsetCell : Board n -> (Fin n, Fin n) -> Fin n -> Board n\nsetCell (MkBoard b) (x, y) value = MkBoard (updateAt y b (\\row => updateAt x row (const (Just value))))\n\ngetCell : Board n -> (Fin n, Fin n) -> Cell n\ngetCell (MkBoard b) (x, y) = index x (index y b)\n\nanyElim : {xs : Vect n a} -> {P : a -> Type} -> (Any P xs -> b) -> (P x -> b) -> Any P (x :: xs) -> b\nanyElim _ f (Here p) = f p\nanyElim f _ (There p) = f p\n\ngetRow : Fin n -> Board n -> Vect n (Cell n)\ngetRow i (MkBoard b) = index i b\n\ngetCol : Fin n -> Board n -> Vect n (Cell n)\ngetCol i (MkBoard b) = helper i b\n where\n helper : Fin n -> Vect m (Vect n a) -> Vect m a\n helper _ Nil = Nil\n helper i (xs::xss) = index i xs :: helper i xss\n\nLegalNeighbors : Cell n -> Cell n -> Type\nLegalNeighbors (Just x) (Just y) = Not (x = y)\nLegalNeighbors _ _ = ()\n\nlegalNeighbors : (x : Cell n) -> (y : Cell n) -> Dec (LegalNeighbors x y)\nlegalNeighbors (Just x) (Just y) with (decEq x y)\n | Yes prf = No (\\pf => pf prf)\n | No prf = Yes prf\nlegalNeighbors Nothing (Just _) = Yes ()\nlegalNeighbors (Just _) Nothing = Yes ()\nlegalNeighbors Nothing Nothing = Yes ()\n\nrowSafe : (b : Board n) -> (r : Fin n) -> (val : Fin n) -> Dec (All (LegalNeighbors (Just val)) (getRow r b))\nrowSafe b r v = all (legalNeighbors (Just v)) (getRow r b)\n\ncolSafe : (b : Board n) -> (r : Fin n) -> (val : Fin n) -> Dec (All (LegalNeighbors (Just val)) (getCol r b))\ncolSafe b r v = all (legalNeighbors (Just v)) (getCol r b)\n\nEmpty : Cell n -> Type\nEmpty {n=n} x = (the (Cell n) Nothing) = x\n\nempty : (cell : Cell n) -> Dec (Empty cell)\nempty Nothing = Yes Refl\nempty (Just _) = No nothingNotJust\n\n-- Predicate for legal cell assignments\nLegalVal : Board n -> (Fin n, Fin n) -> Fin n -> Type\nLegalVal b (x, y) val = (Empty (getCell b (x, y)), All (LegalNeighbors (Just val)) (getCol x b), All (LegalNeighbors (Just val)) (getRow y b))\n\nlegalVal : (b : Board n) -> (coord : (Fin n, Fin n)) -> (val : Fin n) -> Dec (LegalVal b coord val)\nlegalVal b (x, y) v =\n case rowSafe b y v of\n No prf => No (\\(_, _, rf) => prf rf)\n Yes prf =>\n case colSafe b x v of\n No prf' => No (\\(_, cf, _) => prf' cf)\n Yes prf' =>\n case Solver.empty (getCell b (x, y)) of\n No prf'' => No (\\(ef, _, _) => prf'' ef)\n Yes prf'' => Yes (prf'', prf', prf)\n\n\nFilled : Cell n -> Type\n--Filled {n=n} x = Not (Empty x) -- TODO: Find out why this doesn't work\nFilled {n=n} = (\\x => Not (Empty x))\n--Filled {n=n} x = the (Maybe (Fin n)) Nothing = x -> Void\n--Filled {n=n} = \\x => the (Maybe (Fin n)) Nothing = x -> Void\n\nfilled : (cell : Cell n) -> Dec (Filled cell)\nfilled Nothing = No (\\f => f Refl)\nfilled (Just _) = Yes nothingNotJust\n\nFullBoard : Board n -> Type\nFullBoard (MkBoard b) = All (All Filled) b\n\nfullBoard : (b : Board n) -> Dec (FullBoard b)\nfullBoard (MkBoard b) = all (all filled) b\n\nfins : Vect n (Fin n)\nfins {n=Z} = Nil\nfins {n=(S m)} = last :: map weaken fins\n\ndata LegalBoard : Board n -> Type where\n Base : LegalBoard (emptyBoard {n})\n Step : {b : Board n} -> {coords : (Fin n, Fin n)} -> {v : Fin n} -> LegalVal b coords v -> LegalBoard b -> LegalBoard (setCell b coords v)\n\nCompleteBoard : Board n -> Type\nCompleteBoard b = (LegalBoard b, FullBoard b)\n\nindexStep : {i : Fin n} -> {xs : Vect n a} -> {x : a} -> index i xs = index (FS i) (x::xs)\nindexStep = Refl\n\nfind : {P : a -> Type} -> ((x : a) -> Dec (P x)) -> (xs : Vect n a)\n -> Either (All (\\x => Not (P x)) xs) (y : a ** (P y, (i : Fin n ** y = index i xs)))\nfind _ Nil = Left Nil\nfind d (x::xs) with (d x)\n | Yes prf = Right (x ** (prf, (FZ ** Refl)))\n | No prf =\n case find d xs of\n Right (y ** (prf', (i ** prf''))) =>\n Right (y ** (prf', (FS i ** replace {P=(\\x => y = x)} (indexStep {x=x}) prf'')))\n Left prf' => Left (prf::prf')\n\nfindEmptyInRow : (xs : Vect n (Cell n)) -> Either (All Filled xs) (i : Fin n ** Empty (index i xs))\nfindEmptyInRow xs =\n case find {P=Empty} empty xs of\n Right (_ ** (pempty, (i ** pidx))) => Right (i ** trans pempty pidx)\n Left p => Left p\n\nemptyCell : (b : Board n) -> Either (FullBoard b) (c : (Fin n, Fin n) ** Empty (getCell b c))\nemptyCell (MkBoard rs) =\n case helper rs of\n Left p => Left p\n Right (ri ** (ci ** pf)) => Right ((ci, ri) ** pf)\n where\n helper : (rs : Vect m (Vect n (Cell n)))\n -> Either (All (All Filled) rs) (r : Fin m ** (c : Fin n ** Empty (index c (index r rs))))\n helper Nil = Left Nil\n helper (r::rs) =\n case findEmptyInRow r of\n Right (ci ** pf) => Right (FZ ** (ci ** pf))\n Left prf =>\n case helper rs of\n Left prf' => Left (prf::prf')\n Right (ri ** (ci ** pf)) => Right (FS ri ** (ci ** pf))\n\n\ntryValue : {b : Board (S n)} -> LegalBoard b -> (c : (Fin (S n), Fin (S n))) -> Empty (getCell b c) -> (v : Fin (S n))\n -> Either (Not (LegalVal b c v)) (b' : Board (S n) ** LegalBoard b')\ntryValue {b=b} l c _ v =\n case legalVal b c v of\n No prf => Left prf\n Yes prf => Right (_ ** Step prf l)\n\nnullBoardFull : (b : Board Z) -> FullBoard b\nnullBoardFull (MkBoard Nil) = Nil\n\n-- TODO: Prove complete by induction on illegal values wrt. some base state, e.g. every value is illegal for 123\\21_\\3_2\nfillBoard : (b : Board n) -> LegalBoard b -> Maybe (b' : Board n ** CompleteBoard b')\nfillBoard {n=Z} b l = Just (b ** (l, nullBoardFull b))\nfillBoard {n=(S n)} b l with (emptyCell b)\n | Left full = Just (b ** (l, full))\n | Right (coords ** p) = recurse last\n where\n %assert_total\n tryAll : (v : Fin (S n)) -> (Fin (S n), Maybe (b' : Board (S n) ** LegalBoard b'))\n tryAll v = --trace (\"Trying \" ++ show (the Int (cast v))) $\n case tryValue l coords p v of\n Right success => (v, Just success)\n Left _ => -- TODO: Prove unsolvable\n case v of\n FS k => tryAll (weaken k)\n FZ => (v, Nothing)\n\n %assert_total\n recurse : Fin (S n) -> Maybe (b' : Board (S n) ** CompleteBoard b')\n recurse start =\n case tryAll start of\n (_, Nothing) => Nothing\n (FZ, Just (b' ** l')) => fillBoard b' l'\n (FS next, Just (b' ** l')) =>\n case fillBoard b' l' of\n Just solution => Just solution\n Nothing => recurse (weaken next)\n\n-- Parser ----------------------------------------------------------------------\n\nParseErr : Type\nParseErr = String\n\nParser : Nat -> Type\nParser n = Either ParseErr (b : Board n ** LegalBoard b)\n\nmapM : Monad m => (a -> m b) -> Vect n a -> m (Vect n b)\nmapM _ Nil = pure Vect.Nil\nmapM f (x::xs) = do\n x' <- f x\n xs' <- mapM f xs\n pure (Vect.(::) x' xs')\n\nparseToken : String -> Either String (Cell n)\nparseToken \".\" = pure Nothing\nparseToken \"0\" = Left \"Got cell 0, expected 1-based numbering\"\nparseToken x = map Just (tryParseFin ((cast x) - 1))\n where\n tryParseFin : Int -> Either String (Fin n)\n tryParseFin {n=Z} _ = Left (\"Given cell \" ++ x ++ \" out of range\")\n tryParseFin {n=S k} 0 = pure FZ\n tryParseFin {n=S k} x =\n case tryParseFin {n=k} (x-1) of\n Left err => Left err\n Right fin => pure (FS fin)\n\nlength : Vect n a -> Nat\nlength {n=n} _ = n\n\nparseCols : {b : Board n} -> Fin n -> LegalBoard b -> Vect n String -> Parser n\nparseCols {n=Z} _ l _ = Right (_ ** l)\nparseCols {n=S k} row l cs = helper last l\n where\n step : {b : Board (S k)} -> LegalBoard b -> Fin (S k) -> Parser (S k)\n step {b=b} l x = do\n let here = (x, row) -- TODO: Determine why naming this makes idris smarter\n tok <- parseToken {n=S k} (index x cs)\n case tok of\n Nothing => pure (_ ** l)\n Just t =>\n case legalVal b here t of\n Yes prf => Right (_ ** Step prf l)\n No _ => Left (\"Illegal cell \" ++ index x cs)\n\n helper : {b : Board (S k)} -> Fin (S k) -> LegalBoard b -> Parser (S k)\n helper FZ l = step l FZ\n helper (FS k) l = do\n (_ ** next) <- step l (FS k)\n helper (weaken k) next\n\nparseRows : (b : Board n) -> LegalBoard b -> Vect n String -> Parser n\nparseRows {n=Z} _ l _ = Right (_ ** l)\nparseRows {n=S k} _ l rs = helper last l\n where\n step : {b : Board (S k)} -> Fin (S k) -> LegalBoard b -> Parser (S k)\n step i l =\n let cs = fromList (words (index i rs)) in\n case decEq (Parser.length cs) (S k) of\n No _ => Left \"Row length not equal to column height\"\n Yes prf => parseCols i l (replace {P=\\n => Vect n String} prf cs)\n\n helper : {b : Board (S k)} -> Fin (S k) -> LegalBoard b -> Parser (S k)\n helper FZ l = step FZ l\n helper (FS k) l = do\n (_ ** next) <- step (FS k) l\n helper (weaken k) next\n\nparse : String -> Either String (n : Nat ** (b : Board n ** LegalBoard b))\nparse str =\n let rows = fromList (lines str) in\n case parseRows {n=length rows} emptyBoard Base rows of\n Left msg => Left msg\n Right board => pure (_ ** board)\n\n-- Main ------------------------------------------------------------------------\n\nmain : IO ()\nmain = do\n args <- getArgs\n case args of\n [_, path] => do\n f <- readFile path\n case f of\n Left _err => putStrLn $ \"Error reading file: \" ++ path\n Right f' =>\n case parse f' of\n Left err => putStrLn err\n Right (_ ** (board ** legal)) => do\n putStrLn \"Got board:\"\n printLn board\n putStrLn \"Solving...\"\n case fillBoard board legal of\n Nothing => putStrLn \"No solution found\"\n Just (solved ** _) => do\n putStrLn \"Solution found:\"\n printLn solved\n [self] => putStrLn (\"Usage: \" ++ self ++ \" \")\n", "meta": {"hexsha": "be0a04f4a3a6da1455ce3dd23b05a8223305432b", "size": 10818, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Benchmarks/quasigroups.idr", "max_stars_repo_name": "timjs/iris-clean", "max_stars_repo_head_hexsha": "b2ed1f982beec936cb6fe32e8fa6b97a1da4a4f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2017-01-02T14:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-24T08:43:55.000Z", "max_issues_repo_path": "Benchmarks/quasigroups.idr", "max_issues_repo_name": "timjs/iris-clean", "max_issues_repo_head_hexsha": "b2ed1f982beec936cb6fe32e8fa6b97a1da4a4f6", "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": "Benchmarks/quasigroups.idr", "max_forks_repo_name": "timjs/iris-clean", "max_forks_repo_head_hexsha": "b2ed1f982beec936cb6fe32e8fa6b97a1da4a4f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-20T09:57:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T09:57:55.000Z", "avg_line_length": 35.0097087379, "max_line_length": 142, "alphanum_fraction": 0.5496394897, "num_tokens": 3455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6125605599284116}} {"text": "module Data.Matrix.Structural\n\n-- For structural lemmas involving matrix operations\nimport Control.Algebra\nimport Control.Algebra.VectorSpace -- definition of module\nimport Classes.Verified -- definition of verified algebras other than modules\nimport Data.Matrix\nimport Data.Matrix.Algebraic -- module instances; from Idris 0.9.20\nimport Data.Matrix.AlgebraicVerified\n\nimport Data.Vect.Structural\n\n%default total\n\n\n\ntransposeIndexChariz : {xs : Matrix n m a} -> index k $ transpose xs = getCol k xs\ntransposeIndexChariz {xs=[]} {k} = indexReplicateChariz\ntransposeIndexChariz {xs=x::xs} {k} = trans zipWithEntryChariz $ vectConsCong _ _ _ transposeIndexChariz\n\ntransposeNHead: with Data.Vect ( head $ transpose xs = map head xs )\ntransposeNHead = trans (sym indexFZIsheadValued) $ trans transposeIndexChariz $ extensionalEqToMapEq (\\xs => indexFZIsheadValued {xs=xs}) _\n\ntransposeIndicesChariz : {xs : Matrix n m a} -> (i : Fin n) -> (j : Fin m) -> indices j i $ transpose xs = indices i j xs\ntransposeIndicesChariz i j = trans (cong {f=index i} transposeIndexChariz) indexMapChariz\n\ntransposeIsInvolution : with Data.Vect ( transpose $ transpose xs = xs )\ntransposeIsInvolution {xs} = vecIndexwiseEq (\\i => vecIndexwiseEq (\\j => trans (transposeIndicesChariz j i) $ transposeIndicesChariz i j))\n\ntransposeNTail : with Data.Vect ( transpose $ tail $ transpose xs = map tail xs )\ntransposeNTail {xs} = vecIndexwiseEq $ \\i => vecIndexwiseEq $ \\j => trans (transposeIndicesChariz j i)\n\t$ trans (cong {f=(index i) . (index $ FS j)} $ sym $ headtails $ transpose xs)\n\t$ trans (transposeIndicesChariz i (FS j))\n\t$ trans (cong {f=index $ FS j} $ headtails $ index i xs)\n\t$ sym $ cong {f=index j} indexMapChariz\n\n\n\nvecMatMultIsTransposeVecMult : Ring a => (v : Vect n a) -> (xs : Matrix n m a) -> v <\\> xs = (transpose xs) v\nvecMatMultIsTransposeVecMult v xs = Refl\n\nmatVecMultIsVecTransposeMult : Ring a => (v : Vect m a) -> (xs : Matrix n m a) -> xs v = v <\\> (transpose xs)\nmatVecMultIsVecTransposeMult v xs = sym $ trans (vecMatMultIsTransposeVecMult v $ transpose xs) $ cong {f=( v)} $ transposeIsInvolution {xs=xs}\n\nheadVecMatMultChariz : Ring a => {xs : Matrix _ (S _) a} -> head $ v<\\>xs = v <:> (getCol FZ xs)\nheadVecMatMultChariz {v} {xs} = trans (sym $ indexFZIsheadValued {xs=v<\\>xs})\n\t$ trans (indexMapChariz {k=FZ} {f=(v<:>)} {xs=transpose xs})\n\t$ cong {f=(v<:>)} $ transposeIndexChariz {k=FZ} {xs=xs}\n\n\n\nmatMultIndicesChariz : Ring a => {l : Matrix _ _ a} -> {r : Matrix _ _ a} -> indices i j (l<>r) = (index i l)<:>(getCol j r)\nmatMultIndicesChariz {l} {r} {i} {j} = trans (cong {f=index j} $ indexMapChariz {f=(<\\>r)}) $ trans (indexMapChariz {f=((index i l)<:>)}) $ cong {f=((Vect.index i l)<:>)} transposeIndexChariz\n\n\n\n-- But basically from (map) being a verifiable functor.\nleadingElemExtensionFirstColReplicate : (r : a) -> getCol FZ $ map (r::) xs = replicate _ r\nleadingElemExtensionFirstColReplicate {xs=[]} r = Refl\nleadingElemExtensionFirstColReplicate {xs=x::xs} r = vecHeadtailsEq Refl $ leadingElemExtensionFirstColReplicate r\n\n-- But basically from (map) being a verifiable functor.\nleadingElemExtensionColFSId : getCol (FS i) $ map (r::) xs = getCol i xs\nleadingElemExtensionColFSId {xs} {r} {i} = trans (composeUnderMap xs (index $ FS i) (r::)) $ the (map ((index $ FS i) . (r::)) xs = map (index i) xs) $ extensionalEqToMapEq (\\v => Refl) xs\n\nleadingElemExtensionAsZipWithCons : map (r::) xs = Vect.zipWith Vect.(::) (replicate _ r) xs\nleadingElemExtensionAsZipWithCons {xs=[]} = Refl\nleadingElemExtensionAsZipWithCons {xs=x::xs} = vecHeadtailsEq Refl leadingElemExtensionAsZipWithCons\n\nnullcolExtensionEq : Monoid a => {xs : Matrix n (S predm) a} -> (getCol FZ xs=Algebra.neutral) -> map ((Algebra.neutral)::) $ map Vect.tail xs = xs\nnullcolExtensionEq {xs} prColNeut = trans leadingElemExtensionAsZipWithCons\n\t-- = zipWith (::) Algebra.neutral $ map tail xs\n\t$ trans (cong {f=zipWith (::) Algebra.neutral} $ sym $ transposeNTail)\n\t-- = zipWith (::) Algebra.neutral $ transpose $ tail $ transpose xs\n\t-- === transpose $ Algebra.neutral :: (tail $ transpose xs)\n\t$ trans (cong {f=transpose}\n\t\t$ trans (vecHeadtailsEq\n\t\t\t(trans (sym prColNeut)\n\t\t\t\t-- Algebra.neutral = getCol FZ xs\n\t\t\t\t$ trans (sym transposeIndexChariz)\n\t\t\t\t-- = index FZ $ transpose xs\n\t\t\t\t$ indexFZIsheadValued)\n\t\t\tRefl)\n\t\t-- Algebra.neutral :: (tail $ transpose xs) = head _ :: tail _\n\t\t$ sym $ headtails $ transpose xs)\n\t-- = transpose $ transpose xs\n\ttransposeIsInvolution\n\t-- = xs\n\n\n\n{-\nTheorems about the module (Matrix n m a) over a ring (a):\n* Compatibility between the Algebra.neutral of the ring (a) and of (Matrix n m a) as a module under (index).\n-}\n\n\n\nindexNeutralIsNeutral2D : Ring a => (k : Fin n) -> index k $ Algebra.neutral {a=Matrix n m a} = Algebra.neutral\nindexNeutralIsNeutral2D FZ = Refl\nindexNeutralIsNeutral2D (FS k) = indexNeutralIsNeutral2D k\n", "meta": {"hexsha": "6201eecaa9b6d7a10b6e60d5f2203960b802b6ae", "size": 4874, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Matrix/Structural.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": "Data/Matrix/Structural.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": "Data/Matrix/Structural.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": 47.7843137255, "max_line_length": 191, "alphanum_fraction": 0.7033237587, "num_tokens": 1528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451416, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.612208509198613}} {"text": "> module SequentialDecisionProblems.applications.Main\n\n> import Data.Fin\n> import Data.List\n> import Data.List.Quantifiers\n> import Data.So\n> import Control.Isomorphism\n> import Effects\n> import Effect.Exception\n> import Effect.StdIO\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.FullTheory\n> import SequentialDecisionProblems.Utils\n> import SequentialDecisionProblems.FastStochasticDefaults\n> import SequentialDecisionProblems.CoreTheoryOptDefaults\n> import SequentialDecisionProblems.FullTheoryOptDefaults\n\n> import SequentialDecisionProblems.applications.FreezeOrIncrease\n> import SequentialDecisionProblems.applications.GoodOrBad\n\n> import FastSimpleProb.SimpleProb\n> import FastSimpleProb.BasicOperations\n> import FastSimpleProb.BasicProperties\n> import FastSimpleProb.MonadicOperations\n> import FastSimpleProb.MonadicProperties\n> import FastSimpleProb.Measures\n> import FastSimpleProb.MeasuresProperties\n> import Sigma.Sigma\n> import Sigma.Operations\n> import Sigma.Properties\n> import Nat.LTProperties\n> import Double.Predicates\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.Constants\n> import NonNegDouble.BasicOperations\n> import NonNegDouble.Operations\n> import NonNegDouble.Properties\n> import NonNegDouble.Predicates\n> import NonNegDouble.LTEProperties\n> import NonNegDouble.Measures\n> import NonNegDouble.MeasureProperties\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Unique.Predicates\n> import Decidable.Predicates\n> import LocalEffect.Exception\n> import LocalEffect.StdIO\n> import Fin.Operations\n> import Fraction.Fraction\n> import Fraction.Normal\n> import Nat.Positive\n> import List.Operations\n> import Unit.Properties\n\n> -- %default total\n> %auto_implicits off\n\n> -- %logging 5\n\n\n* Introduction\n\nWe specify a first emissions game as a stochastic sequential decision\nproblem.\n\n\n* Controls\n\nAt each decision step, the decision maker has two options: freezing\nemissions or increasing emissions:\n\n> SequentialDecisionProblems.CoreTheory.Ctrl _ _ = FreezeOrIncrease\n\n\n* States\n\nThe decision maker can observe three values: the cumulated effects of\nits own decisions, of the decisions taken by \"others\", and a state of\nthe world. The latter can be either good or bad\n\n> SequentialDecisionProblems.CoreTheory.State t = (Nat, Nat, GoodOrBad)\n\nThe idea is that the world starts in a good state but, if the sum of the\ncumulated emissions of the decision maker and of the \"others\" increase\nbeyond a certain threshold, there is a non-zero probability to turn to a\nbad state. Once there, there is no chance to come back to a good state.\n\nIn this game, we assume that the decision maker and the \"others\" take\nthe same decisions in a competitive setup, see section on rewards.\n\n\n* Transition function\n\n> threshold : Nat\n> threshold = Z\n\n> p : Double\n> p = 1.0\n\n> p1 : NonNegDouble\n> p1 = cast (p / (p + 1.0))\n> p2 : NonNegDouble\n> p2 = cast (1.0 / (p + 1.0))\n\n> SequentialDecisionProblems.CoreTheory.nexts t (s1, s2, Good) Freeze =\n> if (s1 + s2 <= threshold)\n> then mkSimpleProb [((s1, s2, Good), one)]\n> else mkSimpleProb [((s1, s2, Good), p1), ((s1, s2, Bad), p2)]\n\n> SequentialDecisionProblems.CoreTheory.nexts t (s1, s2, Good) Increase = \n> if (s1 + s2 <= threshold)\n> then mkSimpleProb [((S s1, S s2, Good), one)]\n> else mkSimpleProb [((S s1, S s2, Good), p1), ((S s1, S s2, Bad), p2)]\n\n> SequentialDecisionProblems.CoreTheory.nexts t (s1, s2, Bad) Freeze = \n> mkSimpleProb [((s1, s2, Bad), one)]\n\n> SequentialDecisionProblems.CoreTheory.nexts t (s1, s2, Bad) Increase = \n> mkSimpleProb [((S s1, S s2, Bad), one)]\n\n\n* |Val| and |LTE|:\n\n> SequentialDecisionProblems.CoreTheory.Val = \n> NonNegDouble.NonNegDouble\n\n> SequentialDecisionProblems.CoreTheory.plus = \n> NonNegDouble.Operations.plus\n\n> SequentialDecisionProblems.CoreTheory.zero = \n> fromInteger @{NumNonNegDouble} 0\n\n> SequentialDecisionProblems.CoreTheory.LTE = \n> NonNegDouble.Predicates.LTE\n\n> SequentialDecisionProblems.FullTheory.reflexiveLTE = \n> NonNegDouble.LTEProperties.reflexiveLTE\n\n> SequentialDecisionProblems.FullTheory.transitiveLTE = \n> NonNegDouble.LTEProperties.transitiveLTE\n\n> SequentialDecisionProblems.FullTheory.monotonePlusLTE = \n> NonNegDouble.LTEProperties.monotonePlusLTE\n\n> SequentialDecisionProblems.CoreTheoryOptDefaults.totalPreorderLTE = \n> NonNegDouble.LTEProperties.totalPreorderLTE \n\n\n* Reward function\n\nThe idea is that, at every step, being in a good world yields more\nbenefits than being in a bad world:\n\n> benefitsGood : NonNegDouble\n> benefitsGood = one\n\n> benefitsBad : NonNegDouble\n> benefitsBad = NonNegDouble.Constants.zero\n\nFreezing emissions also brings less benefits than increasing\nemissions. However, increasing emissions in a bad world yields less\nbenefits than increasing emissions in a good world:\n\n> benefitsFreeze : NonNegDouble\n> benefitsFreeze = NonNegDouble.Constants.zero\n\n> benefitsIncreaseGood : NonNegDouble\n> benefitsIncreaseGood = one\n\n> benefitsIncreaseBad : NonNegDouble\n> benefitsIncreaseBad = cast 0.9\n\n\n> using implementation NumNonNegDouble\n> \n> SequentialDecisionProblems.CoreTheory.reward _ (_, _, _) Freeze (_, _, Good) = benefitsGood + benefitsFreeze\n> SequentialDecisionProblems.CoreTheory.reward _ (_, _, _) Increase (_, _, Good) = benefitsGood + benefitsIncreaseGood\n> SequentialDecisionProblems.CoreTheory.reward _ (_, _, _) Freeze (_, _, Bad) = benefitsBad + benefitsFreeze\n> SequentialDecisionProblems.CoreTheory.reward _ (_, _, _) Increase (_, _, Bad) = benefitsBad + benefitsIncreaseBad\n\n\n* Completing the problem specification\n\nTo be able to apply the verified, generic backwards induction algorithm\nof |CoreTheory| to compute optimal policies for our problem, we have to\nexplain how the decision maker accounts for uncertainties on rewards\ninduced by uncertainties in the transition function. We first assume\nthat the decision maker measures uncertain rewards by their expected\nvalue:\n\n> SequentialDecisionProblems.CoreTheory.meas = expectedValue\n> SequentialDecisionProblems.FullTheory.measMon = monotoneExpectedValue\n\nFurther on, we have to implement the notions of viability and\nreachability. We start by positing that all states are viable for any\nnumber of steps:\n\n> -- Viable : (n : Nat) -> State t -> Type\n> SequentialDecisionProblems.CoreTheory.Viable n x = Unit\n\nFrom this definition, it trivially follows that all elements of an\narbitrary list of states are viable for an arbitrary number of steps:\n\n> viableLemma : {t, n : Nat} -> (xs : List (State t)) -> All (Viable n) xs\n> viableLemma Nil = Nil\n> viableLemma {t} {n} (x :: xs) = () :: (viableLemma {t} {n} xs)\n\nThis fact and the (less trivial) result that simple probability\ndistributions are never empty, see |nonEmptyLemma| in\n|MonadicProperties| in |SimpleProb|, allows us to show that the above\ndefinition of |Viable| fulfills |viableSpec1|:\n\n> -- viableSpec1 : (x : State t) -> Viable (S n) x -> GoodCtrl t x \n> SequentialDecisionProblems.CoreTheory.viableSpec1 {t} {n} s v = \n> MkSigma Freeze (ne, av) where\n> ne : SequentialDecisionProblems.CoreTheory.NotEmpty (nexts t s Freeze)\n> ne = nonEmptyLemma (nexts t s Freeze)\n> av : SequentialDecisionProblems.CoreTheory.All (Viable {t = S t} n) (nexts t s Freeze)\n> av = viableLemma {t = S t} (support (nexts t s Freeze))\n\n> SequentialDecisionProblems.Utils.finiteViable n x = finiteUnit\n\n> SequentialDecisionProblems.Utils.decidableViable n x = decidableUnit\n\nFor reachability, we proceed in a similar way. We say that all states\nare reachable\n\n> -- Reachable : State t' -> Type\n> SequentialDecisionProblems.CoreTheory.Reachable x' = Unit\n\nwhich immediately implies |reachableSpec1|:\n\n> -- reachableSpec1 : (x : State t) -> Reachable {t' = t} x -> (y : Ctrl t x) -> All (Reachable {t' = S t}) (nexts t x y)\n> SequentialDecisionProblems.CoreTheory.reachableSpec1 {t} x r y = all (nexts t x y) where\n> all : (sp : SimpleProb (State (S t))) -> SequentialDecisionProblems.CoreTheory.All (Reachable {t' = S t}) sp\n> all sp = all' (support sp) where\n> all' : (xs : List (State (S t))) -> Data.List.Quantifiers.All (Reachable {t' = S t}) xs\n> all' Nil = Nil\n> all' (x :: xs) = () :: (all' xs)\n\nFinally, we have to show that controls are finite\n\n> -- finiteCtrl : {t : Nat} -> (x : State t) -> Finite (Ctrl t x) \n> SequentialDecisionProblems.Utils.finiteCtrl _ = finiteFreezeOrIncrease\n\n\n* Optimal policies, optimal decisions, ...\n\nWe can now apply the results of our |CoreTheory| and of the |FullTheory|\nto compute verified optimal policies, possible state-control sequences,\netc. To this end, we need to be able to show the outcome of the decision\nprocess. This means implemeting functions to print states and controls:\n\n> -- showState : {t : Nat} -> State t -> String\n> SequentialDecisionProblems.Utils.showState {t} (s1, s2, Good) = \n> \"(\" ++ show s1 ++ \",\" ++ show s2 ++ \",Good)\" \n> SequentialDecisionProblems.Utils.showState {t} (s1, s2, Bad) = \n> \"(\" ++ show s1 ++ \",\" ++ show s2 ++ \",Bad)\" \n\n> -- showControl : {t : Nat} -> {x : State t} -> Ctrl t x -> String\n> SequentialDecisionProblems.Utils.showCtrl {t} {x} Freeze = \"Freeze\"\n> SequentialDecisionProblems.Utils.showCtrl {t} {x} Increase = \"Increase\"\n\n\n> computation : { [STDIO] } Eff ()\n> computation =\n> do putStr (\"enter number of steps:\\n\")\n> nSteps <- getNat\n> case (decidableViable {t = Z} nSteps (Z, Z, Good)) of\n> (Yes v) => do putStrLn (\"computing optimal policies ...\")\n> ps <- pure (backwardsInduction Z nSteps)\n> putStrLn (\"computing optimal controls ...\")\n> mxys <- pure (possibleStateCtrlSeqs (Z, Z, Good) () v ps)\n> putStrLn \"possible state-control sequences:\"\n> putStr \" \"\n> putStrLn (show mxys)\n> -- mvs <- pure (possibleRewards' mxys)\n> -- putStrLn \"possible rewards:\"\n> -- putStr \" \"\n> -- putStrLn (show mvs)\n> -- mxyvs <- pure (possibleStateCtrlSeqsRewards' mxys)\n> -- putStrLn \"possible state-control sequences and rewards:\"\n> -- putStr \" \"\n> -- putStrLn (show mxyvs)\n> -- putStrLn \"measure of possible rewards: \"\n> -- putStr \" \"\n> -- putStrLn (show (meas mvs))\n> -- argmaxmax <- pure (argmaxMax {A = StateCtrlSeq Z nSteps} {B = Val} totalPreorderLTE (support mxyvs) (nonEmptyLemma mxyvs))\n> -- putStrLn \"best possible state-control sequence: \"\n> -- putStr \" \"\n> -- putStrLn (show (fst argmaxmax))\n> -- putStrLn \"best possible reward: \"\n> -- putStr \" \"\n> -- putStrLn (show (snd argmaxmax))\n> -- -- argminmin <- pure (argminMin totalPreorderLTE (support mxyvs) (nonEmptyLemma mxyvs))\n> -- -- putStrLn \"worst possible state-control sequence: \"\n> -- -- putStr \" \"\n> -- -- putStrLn (show (fst argminmin))\n> -- -- putStrLn \"worst possible reward: \"\n> -- -- putStr \" \"\n> -- -- putStrLn (show (snd argminmin))\n> putStrLn (\"done!\") \n> (No _) => putStrLn (\"initial state non viable for \" ++ cast {from = Int} (cast nSteps) ++ \" steps\")\n\n> main : IO ()\n> main = run computation\n\n\n> {-\n\n> ---}\n\n\n[1] Stanford Encyclopedia of Phylosophy, Causal Decision Theory, 2010\n\n\n-- Local Variables:\n-- idris-packages: (\"effects\")\n-- End:\n \n \n", "meta": {"hexsha": "59dd9eabb5efec5b22ad7b49559590749b258130", "size": 11797, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/EmissionsGame0.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/EmissionsGame0.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/EmissionsGame0.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.4104938272, "max_line_length": 148, "alphanum_fraction": 0.6864457065, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6116207442256014}} {"text": "{- Copied straight from the book -}\nmodule Part2.Sec6_2_2_printf\n\n{- This one is like recursive enumeration -}\ndata Format = Number Format\n | Str Format\n | Lit String Format\n | End\n\n{- Nice recursive definition that ends up resolving to a long function returning String.\n This ends up being implementable with TypeFamilies and DataKinds (for Format) in Haskell. -}\nPrintfType : Format -> Type\nPrintfType (Number fmt) = (i : Int) -> PrintfType fmt\nPrintfType (Str fmt) = (str : String) -> PrintfType fmt\nPrintfType (Lit str fmt) = PrintfType fmt\nPrintfType End = String\n\n{- CPS implemenation that still maps nicely to Haskell -}\nprintfFmt : (fmt : Format) -> (acc : String) -> PrintfType fmt\nprintfFmt (Number fmt) acc = \\i => printfFmt fmt (acc ++ show i)\nprintfFmt (Str fmt) acc = \\str => printfFmt fmt (acc ++ str)\nprintfFmt (Lit lit fmt) acc = printfFmt fmt (acc ++ lit)\nprintfFmt End acc = acc\n\n\n{- No dependent typing here -}\ntoFormat : (xs : List Char) -> Format\ntoFormat [] = End\ntoFormat ('%' :: 'd' :: chars) = Number (toFormat chars)\ntoFormat ('%' :: 's' :: chars) = Str (toFormat chars)\ntoFormat ('%' :: chars) = Lit \"%\" (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\n{- Hah, so simple! Currently no such luck in Haskell -}\nprintf : (fmt : String) -> PrintfType (toFormat (unpack fmt))\nprintf fmt = printfFmt _ \"\"\n", "meta": {"hexsha": "d01ffebd78e63fa1edc8c90c1f9656a927410e73", "size": 1515, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Part2/Sec6_2_2_printf.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/Sec6_2_2_printf.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/Sec6_2_2_printf.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": 38.8461538462, "max_line_length": 95, "alphanum_fraction": 0.6429042904, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6113153432080406}} {"text": "\nmodule Subst\n\n-- This module constructs an expressively typed substitution\n-- function 'subst' for substituting variables in the simply-typed\n-- lambda calculus.\n-- \n-- The key point is that the expressive type signature of the\n-- function 'subst' can be read as the following theorem:\n--\n-- \"Given a variable with de Bruijn index 'idx'.\n-- Given further the terms\n-- ts : Term sctx s, and\n-- tt : Term ctx t.\n-- Then 'subst ts idx tt' has type 't' in context '(remove idx ctx)++sctx'.\"\n--\n-- Note that 'subst ts idx tt' is typically written as \"tt[ts/(TVar idx)]\".\n-- \n-- Note that the theorem that is expressed by the type signature\n-- of 'subst' is usually referred to as \n--\n-- *** the substitution lemma ***\n--\n-- and casually summarized as \n-- \n-- *** substitution preserves type ***.\n--\n\n\nimport Term\n\n\n%default total\n\n\n------------------------------------------------------------\n-- Begin: SHIFTING, I.E. ADDING UNUSED VARIABLES TO CONTEXTS\n\n-- When adding variables in 'ctx' in the middle of\n-- a context 'ctx1++ctx2', de Bruijn indices must\n-- be adjusted accordingly:\nshift : (ctx : Context) -> HasType (ctx1++ctx2) t ->\n HasType (ctx1++(ctx++ctx2)) t\nshift {ctx1 = []} [] x = x\nshift {ctx1 = []} (_::ctx) x = Next $ shift {ctx1=[]} ctx x\nshift {ctx1 = (_::ctx1')} ctx First = First\nshift {ctx1 = (_::ctx1')} ctx (Next x) = Next $ shift {ctx1=ctx1'} ctx x\n\n\nshift' : (ctx : Context) -> HasType (ctx1++ctx2) t -> \n HasType ((ctx1++ctx)++ctx2) t\nshift' {ctx1} {ctx2} ctx ht = let assoc = appendAssociative ctx1 ctx ctx2 \n sh = shift {ctx1=ctx1} {ctx2=ctx2} ctx ht\n in rewrite (sym assoc) in sh\n\n\n-- Adjust terms for the (unused) variables in 'ctx':\nshiftTerm : (ctx : Context) -> Term (ctx1++ctx2) t ->\n Term (ctx1++(ctx++ctx2)) t\n--\nshiftTerm ctx (TVar ht) = let sht = shift ctx ht\n in TVar sht\n-- \nshiftTerm {ctx1} {ctx2} {t = t1:->:t2} ctx (TAbs e) = \n let e' = shiftTerm {ctx1=(t1::ctx1)} {ctx2=ctx2} ctx e\n in TAbs e'\n--\nshiftTerm {ctx1} {ctx2} ctx (TApp e1 e2) = \n let e1' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e1\n e2' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e2\n in TApp e1' e2'\n--\nshiftTerm {ctx1} {ctx2} ctx (TFix e) = \n let e' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e\n in TFix e'\n--\nshiftTerm ctx TZero = TZero\n--\nshiftTerm {ctx1} {ctx2} ctx (TSucc e) =\n let e' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e\n in TSucc e'\n--\nshiftTerm {ctx1} {ctx2} ctx (TPred e) =\n let e' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e\n in TPred e'\n--\nshiftTerm {ctx1} {ctx2} ctx (TIfz e1 e2 e3) =\n let e1' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e1\n e2' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e2\n e3' = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx e3\n in TIfz e1' e2' e3'\n\n\nshiftTerm' : (ctx : Context) -> Term (ctx1++ctx2) t -> Term ((ctx1++ctx)++ctx2) t\nshiftTerm' {ctx1} {ctx2} ctx ht = let assoc = appendAssociative ctx1 ctx ctx2 \n sh = shiftTerm {ctx1=ctx1} {ctx2=ctx2} ctx ht\n in rewrite (sym assoc) in sh\n\n\n-- Shifting a de Bruijn index 'x' with the empty\n-- context '[]' preserves the de Bruijn index 'x':\nshiftNil : {ctx1 : Context} -> {ctx2 : Context} ->\n {t : Ty} -> {x : HasType (ctx1++ctx2) t} ->\n shift [] x = x\nshiftNil {ctx1 = []} {ctx2 = ctx2} {x = x} = Refl\nshiftNil {ctx1 = _::ctx'} {ctx2 = ctx2} {x = First} = Refl\nshiftNil {ctx1 = _::ctx'} {ctx2 = ctx2} {x = (Next x)} = \n let eq = shiftNil {ctx1=ctx'} {ctx2=ctx2} {x=x}\n in cong {f = \\z => Next z} eq\n\n\n-- Shifting a term 'e' with the empty\n-- context '[]' preserves the term 'e':\nshiftTermNil : {ctx1 : Context} -> {ctx2 : Context} ->\n {t : Ty} -> {e : Term (ctx1++ctx2) t} ->\n shiftTerm [] e = e\n-- \nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {t=t} {e = (TVar ht)} = \n cong {f = \\z => TVar z} $ shiftNil {ctx1=ctx1} {ctx2=ctx2} {t=t} {x=ht}\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {t=t1:->:t2} {e = (TAbs e')} = \n let eq = shiftTermNil {ctx1=(t1::ctx1)} {ctx2=ctx2} {t=t2} {e=e'}\n in cong {f = \\z => TAbs z} eq\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {e = (TApp e1 e2)} = \n let eq1 = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e1}\n eq2 = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e2}\n c = cong {f = \\z => TApp z e2} eq1\n c' = cong {f = \\z => TApp (shiftTerm [] e1) z} eq2\n in trans c' c\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {e = (TFix e')} = \n let eq = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e'}\n in cong {f = \\z => TFix z} eq\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {e = TZero} = Refl\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {e = (TSucc e')} =\n let eq = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e'}\n in cong {f = \\z => TSucc z} eq\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {e = (TPred e')} =\n let eq = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e'}\n in cong {f = \\z => TPred z} eq\n--\nshiftTermNil {ctx1 = ctx1} {ctx2 = ctx2} {e = (TIfz e1 e2 e3)} =\n let eq1 = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e1}\n eq2 = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e2}\n eq3 = shiftTermNil {ctx1=ctx1} {ctx2=ctx2} {e=e3}\n c = cong {f = \\z => TIfz z e2 e3} eq1\n c' = cong {f = \\z => TIfz (shiftTerm [] e1) z e3} eq2\n c'' = cong {f = \\z => TIfz (shiftTerm [] e1) (shiftTerm [] e2) z} eq3\n in trans (trans c'' c') c\n\n-- End: SHIFTING, I.E. ADDING UNUSED VARIABLES TO CONTEXTS\n----------------------------------------------------------\n\n\n\n-----------------------------------------------------------------------------\n-- Begin: SUBSTITUTION PRESERVES TYPING OF EXPRESSIONS IN THE LAMBDA CALCULUS\n\nsubst_var : Term sctx s -> -- Term of type 's' is subtituted in.\n (idx : HasType ctx s) -> -- Index of the variable in 'ctx' that is subsituted for.\n -- (and hence must have type 's').\n HasType ctx t -> -- Substitution takes place inside the variable\n -- with this index.\n Term ((remove ctx idx)++sctx) t\n-- \nsubst_var {sctx} {s=s} {ctx=s::ctx'} {t=s} ts First First = \n shiftTerm' {ctx1=[]} {ctx2=sctx} ctx' ts\n--\nsubst_var {sctx} {s=s} {ctx=s::ctx'} {t=t} ts First (Next htv) = \n let anr1 = sym $ appendNilRightNeutral ctx' \n htv1 = replace {P = \\z => HasType z t} anr1 htv\n htv2 = shift {ctx1=ctx'} {ctx2=[]} sctx htv1\n anr2 = appendNilRightNeutral sctx\n htv3 = replace {P = \\z => HasType (ctx'++z) t} anr2 htv2\n in TVar htv3\n--\nsubst_var {sctx} {s=s} {ctx=u::ctx'} {t=u} ts (Next _) First = TVar First\n--\nsubst_var {sctx} {s=s} {ctx=u::ctx'} {t=t} ts (Next x) (Next y) = \n let t' = subst_var ts x y\n in shiftTerm {ctx1=[]} {ctx2=(remove ctx' x)++sctx} [u] t'\n\n\nexport subst : Term sctx s -> -- Term of type 's' is substituted in.\n (idx : HasType ctx s) -> -- Index of the variable in 'ctx' that is substituted for\n -- (and hence must have type 's').\n Term ctx t -> -- Substitution takes place inside this\n -- term of type 't'\n Term ((remove ctx idx)++sctx) t\n-- \nsubst ts ht (TVar htv) = subst_var ts ht htv\n--\nsubst {ctx} {t = t1:->:t2} ts ht (TAbs e) = \n TAbs $ subst {ctx=t1::ctx} ts (Next ht) e\n--\nsubst ts ht (TApp e1 e2) = TApp (subst ts ht e1) (subst ts ht e2) \nsubst ts ht (TFix e) = TFix (subst ts ht e)\nsubst ts ht TZero = TZero\nsubst ts ht (TSucc e) = TSucc (subst ts ht e)\nsubst ts ht (TPred e) = TPred (subst ts ht e)\nsubst ts ht (TIfz e1 e2 e3) = TIfz (subst ts ht e1)\n (subst ts ht e2)\n (subst ts ht e3)\n\n\n-- Substituting a term 'e' into a single variable 'TVar First'\n-- gives back the same term 'e' but in a shifted context:\nsubstInVar' : (e : Term sctx t) -> \n subst {ctx=(t::ctx')} {s=t} {t=t} e First (TVar First) = shiftTerm {ctx1=[]} {ctx2=sctx} ctx' e \nsubstInVar' e = Refl\n\n\n-- Specialization of the previous result to a minimal\n-- context '[t]' gives back exactly term 'e':\nsubstInVar : (e : Term sctx t) -> \n subst {ctx=[t]} {s=t} {t=t} e First (TVar First) = e \nsubstInVar {sctx} e = shiftTermNil {ctx1=[]} {ctx2=sctx} {e=e}\n\n-- End: SUBSTITUTION PRESERVES TYPING OF EXPRESSIONS IN THE LAMBDA CALCULUS\n---------------------------------------------------------------------------\n\n\n\n--------------------------------\n-- Begin: DIVERGING TERM 'omega'\n\n-- Define 'omega' to be the diverging term that\n-- is the fix-point of the identity function:\npublic export omega : Term [] TyNat\nomega = TFix (TAbs $ TVar First)\n \n \n-- To show (later) that 'omega' diverges, one needs the result that\n-- substituting 'omega' into a single variable 'TVar FZ' reproduces\n-- the term 'omega' itself: \nexport substOmega : subst {ctx=[TyNat]} {s=TyNat} {t=TyNat} Subst.omega First (TVar First) = Subst.omega\n-- Note that while 'substOmega' is a special case of the more general\n-- result 'substInVar' (see above), the general result is in fact not \n-- needed. This is because the Idris type checker can evaluate\n-- 'shiftTerm _ omega' (resulting from 'subst'), but it cannot\n-- evaluate 'shiftTerm _ e' for a variable 'e' because 'shiftTerm'\n-- is defined by recursion on the structure of 'e'.\nsubstOmega = Refl\n\n-- End: DIVERGING TERM 'omega'\n------------------------------\n", "meta": {"hexsha": "8083c70b5c0ff732fca083ebe8c8630adb806b9e", "size": 9650, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "conventional/src/Subst.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/Subst.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/Subst.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": 38.4462151394, "max_line_length": 112, "alphanum_fraction": 0.5523316062, "num_tokens": 3255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6112864324762073}} {"text": "module Addition.Absorb\n\nimport Data.Vect\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.DiscreteOrderedGroup\nimport Specifications.OrderedRing\nimport Proofs.GroupTheory\nimport Addition.Carry\nimport Addition.Scaling\nimport Addition.AbsorptionLemmas\nimport Addition.Adhoc\n\n%default total\n%access export\n\n||| This is a proof friendly semantics function. Consider a tail\n||| recursive variation for run time use.\npublic export\nphi : Ringops s => (radix : s) -> (lsdf : Vect n s) -> (msc : Carry) -> s\nphi radix (x :: xs) c = x + radix * phi radix xs c\nphi radix [] c = value c\n\n\n||| The result of absorbing carry digits:\n|||\n||| in1 in2 in3\n||| ou1 ou2 pen + unk\n||| msc abs abs unk\n|||\n||| unk = the least significant carry is still unknown\n||| pen = ouput of reduction before absorbing the unknown carry\n||| msc = most significant carry\n||| abs = carry already absorbed in the corresponding output\ndata Absorption :\n (k : Nat) ->\n (constraints : s -> Vect k s -> Type) ->\n (semantics : Vect (S k) s -> Carry -> s) ->\n (inputs : Vect (S k) s) -> Type\n where MkAbsorption :\n (msc : Carry) ->\n (pending : s) ->\n (outputs : Vect k s) ->\n (constraints pending outputs) ->\n (semantics inputs O = semantics (pending :: outputs) msc) ->\n Absorption k constraints semantics inputs\n\n\noutputs : Absorption {s} k _ _ _ -> (Carry, Vect (S k) s)\noutputs (MkAbsorption c p o _ _) = (c, reverse (p :: o))\n\n\nabsorptionBase : Ringops s =>\n DiscreteOrderedRingSpec {s} (+) Zero Ng (*) leq One ->\n (radix : s) ->\n (red : Reduction (+) Zero Ng leq One u radix) ->\n Absorption Z (Ranges leq Ng u (u + Ng One)) (phi radix) [input red]\nabsorptionBase spec radix (MkReduction i c o invariant outRange) =\n MkAbsorption c o [] (MkRanges outRange []) o3\n where\n o1 : o + radix * value c = i\n o1 = rewriteInvariant (unitalRing spec) radix i o c invariant\n o2 : i = i + radix * value O\n o2 = adhocIdentity2 (ring (unitalRing spec)) i radix\n o3 : phi radix [i] O = phi radix [o] c\n o3 = sym (o1 === o2)\n\n\narithLemma : Ringops s => UnitalRingSpec {s} (+) Zero Ng (*) One ->\n (msc : Carry) ->\n (pending : s) ->\n (outputs : Vect k s) ->\n (inputs : Vect (S k) s) ->\n (red : Reduction {s} (+) Zero Ng _ One u radix) ->\n (ih : phi radix inputs O = phi radix (pending :: outputs) msc) ->\n phi radix (input red :: inputs) O =\n phi radix (output red :: (value (carry red) + pending) :: outputs) msc\narithLemma {s} {radix} spec msc pending outputs inputs\n (MkReduction i c o invariant _) inductionHypothesis =\n let\n adhoc = adhocIdentity1 (ring spec) pending o radix (value c) o2\n shift = radix * phi radix inputs O\n shifted = cong {f = (+ shift)} o1\n in shifted @== adhoc\n where\n o1 : o + radix * value c = i\n o1 = rewriteInvariant spec radix i o c invariant\n o2 : phi radix inputs O = pending + radix * phi radix outputs msc\n o2 = inductionHypothesis\n\n\nabsorptionStep : Ringops s =>\n DiscreteOrderedRingSpec {s} (+) Zero Ng (*) leq One ->\n (radix : s) ->\n (red : Reduction (+) Zero Ng leq One u radix) ->\n Absorption k (Ranges leq Ng u (u + Ng One)) (phi radix) inputs ->\n Absorption (S k) (Ranges leq Ng u (u + Ng One))\n (phi radix) (input red :: inputs)\nabsorptionStep spec radix red@(MkReduction _ _ _ _ reducedRange)\n (MkAbsorption {inputs} msc pending outputs ranges invariant) =\n let absorb = value (carry red) + pending\n in MkAbsorption msc (output red) (absorb :: outputs)\n (rangeLemma (discreteOrderedGroup spec) ranges reducedRange (carry red))\n (arithLemma (unitalRing spec) msc pending outputs inputs red invariant)\n", "meta": {"hexsha": "cbf63fa6729d8894c324564f8417d647b39bf664", "size": 3663, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Addition/Absorb.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/Absorb.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/Absorb.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": 34.8857142857, "max_line_length": 78, "alphanum_fraction": 0.6494676495, "num_tokens": 1090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.611206590362233}} {"text": "module Leibniz\nimport Control.Monad.Identity\n\n\ndata Eq : (a : Type) -> (b : Type) -> Type where\n Subs : ({f : Type -> Type} -> f a -> f b) -> Eq a b\n\n\nrefl : Eq a a\nrefl = Subs id\n\nsubst : {f : Type -> Type} -> Eq a b -> f a -> f b\nsubst (Subs subs) fa = subs fa\n\ntrans : Eq a b -> Eq b c -> Eq a c\ntrans ab bc = subst bc ab\n\ncast : Eq a b -> a -> b\ncast eq = runIdentity . subst eq . Id\n\nFlip : (Type -> Type -> Type) -> Type -> Type -> Type\nFlip f a b = f b a\n\nsymm : Eq a b -> Eq b a\nsymm eq = subst {f = Flip Eq a} eq refl\n", "meta": {"hexsha": "25f12973c23862573e6fcb446174a3b826638a05", "size": 528, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Leibniz.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/Leibniz.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/Leibniz.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": 20.3076923077, "max_line_length": 53, "alphanum_fraction": 0.553030303, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6109300613461444}} {"text": "> module Nat.GCDEuclid\n\n\n> import Nat.GCD\n> import Nat.Divisor\n> import Nat.DivisorProperties\n> import Nat.Operations\n> import Nat.LTEProperties\n> import Nat.OperationsProperties\n> import Sigma.Sigma\n> import Pairs.Operations\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\nEuclid's greatest common divisor algorithm\n\n> euclidGCD1 : GCD m m Z\n> euclidGCD1 {m} = MkGCD (anyDivisorAny m) (anyDivisorZ m) (\\ d' => \\ d'Dm => \\ d'DZ => d'Dm)\n\n> euclidGCD2 : GCD m Z m\n> euclidGCD2 {m} = MkGCD (anyDivisorZ m) (anyDivisorAny m) (\\ d' => \\ d'DZ => \\ d'Dm => d'Dm)\n\n> euclidGCD3 : m `LTE` n -> GCD d m (n - m) -> GCD d m n\n> euclidGCD3 {m} {n} {d} p (MkGCD dDm dDnmm q) = MkGCD dDm dDn q' where\n> dDnmmpm : d `Divisor` ((n - m) + m)\n> dDnmmpm = divisorPlusLemma2 m (n - m) d dDm dDnmm\n> dDn : d `Divisor` n\n> dDn = replace {x = (n - m) + m}\n> {y = n}\n> {P = \\ ZUZU => d `Divisor` ZUZU}\n> (plusRightInverseMinus m n p)\n> dDnmmpm\n> q' : (d' : Nat) -> d' `Divisor` m -> d' `Divisor` n -> d' `Divisor` d\n> q' d' d'Dm d'Dn = q d' d'Dm d'Dnmm where\n> d'Dnmm : d' `Divisor` (n - m)\n> d'Dnmm = divisorMinusLemma m n d' d'Dm d'Dn\n\n> euclidGCD4 : Not (m `LTE` n) -> GCD d (m - n) n -> GCD d m n\n> euclidGCD4 {m} {n} {d} p (MkGCD dDmmn dDn q) = MkGCD dDm dDn q' where\n> dDmmnpn : d `Divisor` ((m - n) + n)\n> dDmmnpn = divisorPlusLemma1 (m - n) n d dDmmn dDn\n> dDm : d `Divisor` m\n> dDm = replace {x = (m - n) + n}\n> {y = m}\n> {P = \\ ZUZU => d `Divisor` ZUZU}\n> (plusRightInverseMinus n m (notLTELemma1 m n p))\n> dDmmnpn\n> q' : (d' : Nat) -> d' `Divisor` m -> d' `Divisor` n -> d' `Divisor` d\n> q' d' d'Dm d'Dn = q d' d'Dmmn d'Dn where\n> d'Dmmn : d' `Divisor` (m - n)\n> d'Dmmn = divisorMinusLemma n m d' d'Dn d'Dm\n\n> euclidGCD : (m : Nat) -> (n : Nat) -> Sigma Nat (\\ d => GCD d m n)\n> euclidGCD m Z = assert_total (MkSigma m euclidGCD1)\n> euclidGCD Z n = assert_total (MkSigma n euclidGCD2)\n> euclidGCD (S m) (S n) with (decLTE (S m) (S n))\n> | (Yes p) = assert_total (MkSigma gcd (euclidGCD3 p P)) where\n> gcdP : Sigma Nat (\\ d => GCD d (S m) (S n - S m))\n> gcdP = euclidGCD (S m) (S n - S m)\n> gcd : Nat\n> gcd = getWitness gcdP\n> P : GCD gcd (S m) (S n - S m)\n> P = getProof gcdP\n> | (No p) = assert_total (MkSigma gcd (euclidGCD4 p P)) where\n> gcdP : Sigma Nat (\\ d => GCD d (S m - S n) (S n))\n> gcdP = euclidGCD (S m - S n) (S n)\n> gcd : Nat\n> gcd = getWitness gcdP\n> P : GCD gcd (S m - S n) (S n)\n> P = getProof gcdP\n", "meta": {"hexsha": "22c6ee51619d3ce908d63e75895e35ac11bc55d5", "size": 2674, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/GCDEuclid.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/GCDEuclid.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/GCDEuclid.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": 35.6533333333, "max_line_length": 93, "alphanum_fraction": 0.5351533283, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6109096737671742}} {"text": "data BNat = BZ | O BNat | E BNat\n\ndata BLT : BNat -> BNat -> Type where\n BLT_ZO : BLT BZ (O bn)\n BLT_ZE : BLT BZ (E bn)\n BLT_OO : BLT bn bm -> BLT (O bn) (O bm)\n BLT_OE : BLT bn bm -> BLT (O bn) (E bm)\n BLT_OE_Eq : BLT (O bn) (E bn)\n BLT_EO : BLT bn bm -> BLT (E bn) (O bm)\n BLT_EE : BLT bn bm -> BLT (E bn) (E bm)\n\nnotLtz : BLT bn BZ -> Void\nnotLtz x = ?notLtz_rhs\n", "meta": {"hexsha": "680070624a6b4b8f73480d04b3780aeaa6e1e61b", "size": 373, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/reg024/split.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/reg024/split.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/reg024/split.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": 26.6428571429, "max_line_length": 41, "alphanum_fraction": 0.5683646113, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.6825737279551494, "lm_q1q2_score": 0.6107597777825131}} {"text": "module Utils.ComplexAddon\n\nimport Data.Complex\n\n%default total\n%access public export\n\nimplementation (Fractional a, Neg a) => Fractional (Complex a) where\n (/) (a:+b) (c:+d) = let\n real = (a*c+b*d)/(c*c+d*d)\n imag = (b*c-a*d)/(c*c+d*d)\n in\n (real:+imag)\n\nimplementation (Cast a b) => Cast (Complex a) (Complex b) where\n cast (x :+ y) = (cast x :+ cast y) \n", "meta": {"hexsha": "4363e558639ea782edfb741f657367fb5fbb8922", "size": 458, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Utils/ComplexAddon.idr", "max_stars_repo_name": "GrandArchTemplar/QuantumProgramming", "max_stars_repo_head_hexsha": "54da87cc4471ad6b8d510dc35095edc74efa9ec4", "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/Utils/ComplexAddon.idr", "max_issues_repo_name": "GrandArchTemplar/QuantumProgramming", "max_issues_repo_head_hexsha": "54da87cc4471ad6b8d510dc35095edc74efa9ec4", "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/Utils/ComplexAddon.idr", "max_forks_repo_name": "GrandArchTemplar/QuantumProgramming", "max_forks_repo_head_hexsha": "54da87cc4471ad6b8d510dc35095edc74efa9ec4", "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.9411764706, "max_line_length": 68, "alphanum_fraction": 0.4890829694, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.6825737214979745, "lm_q1q2_score": 0.6107597777498464}} {"text": "Ty : Type\nTy = (Ty : Type)\n ->(empty : Ty)\n ->(arr : Ty -> Ty -> Ty)\n -> Ty\n\nempty : Ty\nempty = \\ _, empty, _ => empty\n\narr : Ty -> Ty -> Ty\narr = \\ a, b, ty, empty, arr => arr (a ty empty arr) (b ty empty arr)\n\nCon : Type\nCon = (Con : Type)\n ->(nil : Con)\n ->(snoc : Con -> Ty -> Con)\n -> Con\n\nnil : Con\nnil = \\ con, nil, snoc => nil\n\nsnoc : Con -> Ty -> Con\nsnoc = \\ g, a, con, nil, snoc => snoc (g con nil snoc) a\n\nVar : Con -> Ty -> Type\nVar = \\ g, a =>\n (Var : Con -> Ty -> Type)\n -> (vz : (g : _)-> (a : _) -> Var (snoc g a) a)\n -> (vs : (g : _)-> (b : _) -> (a : _) -> Var g a -> Var (snoc g b) a)\n -> Var g a\n\nvz : {g : _}-> {a : _} -> Var (snoc g a) a\nvz = \\ var, vz, vs => vz _ _\n\nvs : {g : _} -> {B : _} -> {a : _} -> Var g a -> Var (snoc g B) a\nvs = \\ x, var, vz, vs => vs _ _ _ (x var vz vs)\n\nTm : Con -> Ty -> Type\nTm = \\ g, a =>\n (Tm : Con -> Ty -> Type)\n -> (var : (g : _) -> (a : _) -> Var g a -> Tm g a)\n -> (lam : (g : _) -> (a : _) -> (B : _) -> Tm (snoc g a) B -> Tm g (arr a B))\n -> (app : (g : _) -> (a : _) -> (B : _) -> Tm g (arr a B) -> Tm g a -> Tm g B)\n -> Tm g a\n\nvar : {g : _} -> {a : _} -> Var g a -> Tm g a\nvar = \\ x, tm, var, lam, app => var _ _ x\n\nlam : {g : _} -> {a : _} -> {B : _} -> Tm (snoc g a) B -> Tm g (arr a B)\nlam = \\ t, tm, var, lam, app => lam _ _ _ (t tm var lam app)\n\napp : {g:_}->{a:_}->{B:_} -> Tm g (arr a B) -> Tm g a -> Tm g B\napp = \\ t, u, tm, var, lam, app => app _ _ _ (t tm var lam app) (u tm var lam app)\n\nv0 : {g:_}->{a:_} -> Tm (snoc g a) a\nv0 = var vz\n\nv1 : {g:_}->{a:_}-> {B:_}-> Tm (snoc (snoc g a) B) a\nv1 = var (vs vz)\n\nv2 : {g:_}-> {a:_}-> {B:_}-> {C:_} -> Tm (snoc (snoc (snoc g a) B) C) a\nv2 = var (vs (vs vz))\n\nv3 : {g:_}-> {a:_}-> {B:_}-> {C:_}-> {D:_} -> Tm (snoc (snoc (snoc (snoc g a) B) C) D) a\nv3 = var (vs (vs (vs vz)))\n\nv4 : {g:_}-> {a:_}-> {B:_}-> {C:_}-> {D:_}-> {E:_}-> Tm (snoc (snoc (snoc (snoc (snoc g a) B) C) D) E) a\nv4 = var (vs (vs (vs (vs vz))))\n\ntest : {g:_}-> {a:_} -> Tm g (arr (arr a a) (arr a a))\ntest = lam (lam (app v1 (app v1 (app v1 (app v1 (app v1 (app v1 v0)))))))\n", "meta": {"hexsha": "ccadcb2a0d5f5d80e4ac9686a72a835f39eedf61", "size": 2096, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "bench/stlc_small.idr", "max_stars_repo_name": "Kha/smalltt", "max_stars_repo_head_hexsha": "3d4a20a6d80ac524325cf2d8d0a48095ded08eb6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 377, "max_stars_repo_stars_event_min_datetime": "2017-11-26T16:57:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T21:31:01.000Z", "max_issues_repo_path": "bench/stlc_small.idr", "max_issues_repo_name": "Kha/smalltt", "max_issues_repo_head_hexsha": "3d4a20a6d80ac524325cf2d8d0a48095ded08eb6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-03-16T09:14:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T21:51:10.000Z", "max_forks_repo_path": "bench/stlc_small.idr", "max_forks_repo_name": "Kha/smalltt", "max_forks_repo_head_hexsha": "3d4a20a6d80ac524325cf2d8d0a48095ded08eb6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-12-05T21:11:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T19:46:54.000Z", "avg_line_length": 29.1111111111, "max_line_length": 104, "alphanum_fraction": 0.4231870229, "num_tokens": 955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.6859494485880928, "lm_q1q2_score": 0.6106968374828992}} {"text": "data Vect: Nat -> Type -> Type where\n Nil : Vect Z a\n Cons : a -> Vect x a -> Vect (S x) a\n\ninsert : a -> Vect x a -> Vect (S x) a\ninsert = Cons\n\n", "meta": {"hexsha": "422a0071e7928d7cf8181540ba8009efbf2ad724", "size": 148, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-structures/MyVector.idr", "max_stars_repo_name": "LucasTornai/pgc-ufabc", "max_stars_repo_head_hexsha": "ae38058644363daa39e6fb44e831d26b27d810ea", "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-structures/MyVector.idr", "max_issues_repo_name": "LucasTornai/pgc-ufabc", "max_issues_repo_head_hexsha": "ae38058644363daa39e6fb44e831d26b27d810ea", "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-structures/MyVector.idr", "max_forks_repo_name": "LucasTornai/pgc-ufabc", "max_forks_repo_head_hexsha": "ae38058644363daa39e6fb44e831d26b27d810ea", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.5, "max_line_length": 38, "alphanum_fraction": 0.5472972973, "num_tokens": 52, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.6959583187272712, "lm_q1q2_score": 0.6106872697380691}} {"text": "-- HOF.idr\n-- Higher order functions\n\ntwice : (a -> a) -> a -> a\ntwice f x = f (f x)\n\nShape : Type\nrotate : Shape -> Shape\n\n-- taken from Generic.idr:\ndouble : Num ty => ty -> ty\ndouble x = x + x\n\nquadruple : Num a => a -> a\nquadruple = twice double\n\nturn_around : Shape -> Shape\nturn_around = twice rotate\n\n\n", "meta": {"hexsha": "957f090c950710f9393d12c20fc174b693d1416c", "size": 309, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_2/HOF.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_2/HOF.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_2/HOF.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": 14.7142857143, "max_line_length": 28, "alphanum_fraction": 0.6181229773, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152325073083131, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6106802469401159}} {"text": "\ndata PowerSource = Petrol | Pedal | Electric\n\n-- 4.2.4 Exercises\n-- Extend the Vehicle data type so that it supports unicycles and motorcycles, and wheels and refuel\ndata Vehicle : PowerSource -> Type where\n Bicycle : Vehicle Pedal\n Unicycle : Vehicle Pedal\n Car : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n Motorcycle : (fuel : Nat) -> Vehicle Petrol\n Tram : (charge : Nat) -> Vehicle Electric\n ElectricCar : (charge : Nat) -> Vehicle Electric\n\nwheels : Vehicle power -> Nat\nwheels Bicycle = 2\nwheels Unicycle = 1\nwheels (Car fuel) = 4\nwheels (Bus fuel) = 4\nwheels (Tram charge) = 40\nwheels (ElectricCar charge) = 4\n\nrefuel : Vehicle Petrol -> Vehicle Petrol\nrefuel (Car fuel) = Car 100\nrefuel (Bus fuel) = Bus 120\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a\n%name Vect xs, ys, zs\n", "meta": {"hexsha": "00fb0ee09577e7a3dbf6af29151c503dc869b9bd", "size": 902, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "starting/vehicle.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/vehicle.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/vehicle.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": 29.0967741935, "max_line_length": 100, "alphanum_fraction": 0.6541019956, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6106802176307794}} {"text": "module RingProperties\n\nimport Ring\nimport Monoid\nimport Group\nimport Group_property\n\n%access public export\n\n|||Auxiliary function that provzs that if a+a=a thzn a=0\ntotal\naplusaZ: (r: Type) -> (pfr: Ring r) -> (a: r) -> ((Ring_Add r pfr a a) =a) -> (a = (DPair.fst(RingAdditive_id r pfr)))\naplusaZ r (MkRing r (+) (*) pfr) a prf = (Group_property_4 r (+) (Basics.fst (Basics.fst pfr)) a a z (trans prf (sym (Basics.fst (pfz a))) )) where\n z: r\n z = (DPair.fst(RingAdditive_id r (MkRing r (+) (*) pfr)))\n pfz: (a: r) -> (a+z=a, z+a=a)\n pfz = DPair.snd (RingAdditive_id r (MkRing r (+) (*) pfr))\n\n|||Proof that 0*a = 0\ntotal\nZmultleft: (r: Type) -> (pfr: Ring r) -> (a: r) -> ((Ring_Mult r pfr (DPair.fst(RingAdditive_id r pfr)) a) = (DPair.fst(RingAdditive_id r pfr)))\nZmultleft r (MkRing r (+) (*) pfr) a = (aplusaZ r (MkRing r (+) (*) pfr) (z*a) (\n trans (sym (pfd a z z)) (cong {f= \\p => p*a} (pfz z))\n ) ) where\n z: r\n z = (DPair.fst(RingAdditive_id r (MkRing r (+) (*) pfr)))\n pfz: (a: r) -> (a+z=a)\n pfz a = Basics.fst ((DPair.snd (RingAdditive_id r (MkRing r (+) (*) pfr))) a)\n pfd: (a: r) -> (b: r) -> (c: r) -> ((b+c)*a = (b*a) + (c*a))\n pfd a b c = Basics.snd ((Basics.snd (Basics.snd pfr)) a b c)\n\n|||Proof that a*0 = 0\ntotal\nZmultright: (r: Type) -> (pfr: Ring r) -> (a: r) -> ((Ring_Mult r pfr a (DPair.fst(RingAdditive_id r pfr))) = (DPair.fst(RingAdditive_id r pfr)))\nZmultright r (MkRing r (+) (*) pfr) a = (aplusaZ r (MkRing r (+) (*) pfr) (a*z) (\n trans (sym (pfd a z z)) (cong {f= \\p => a*p} (pfz z))\n ) ) where\n z: r\n z = (DPair.fst(RingAdditive_id r (MkRing r (+) (*) pfr)))\n pfz: (a: r) -> (a+z=a)\n pfz a = Basics.fst ((DPair.snd (RingAdditive_id r (MkRing r (+) (*) pfr))) a)\n pfd: (a: r) -> (b: r) -> (c: r) -> (a*(b+c) = (a*b) + (a*c))\n pfd a b c = Basics.fst ((Basics.snd (Basics.snd pfr)) a b c)\n\n|||Proof that for a ring homomorphism f between rings with identity, f(0) = 0\ntotal\nRHomZtoZ: (r1: Type) -> (pf1: Ring r1) -> (r2: Type) -> (pf2: Ring r2) -> (f: r1 -> r2) -> RHom r1 pf1 r2 pf2 f -> f(fst(RingAdditive_id r1 pf1)) = fst (RingAdditive_id r2 pf2)\nRHomZtoZ r1 (MkRing r1 ((+)) (m) pf1) r2 (MkRing r2 (*) m1 pf2) f pfhom = aplusaZ r2 (MkRing r2 (*) m1 pf2) (f z1) (\n trans\n (sym (Basics.fst(pfhom z1 z1)))\n (cong (Basics.fst(pfid1 z1)))\n ) where\n z1: r1\n z1 = fst(RingAdditive_id r1 (MkRing r1 ((+)) (m) pf1))\n pfid1: (a : r1) -> ((a+z1) = a, (z1+a) = a)\n pfid1 = snd(RingAdditive_id r1 (MkRing r1 ((+)) (m) pf1))\n\n|||Proof that for a ring homomorphism f, f(0) = 0\ntotal\nIRHomZtoZ: (r1: Type) -> (pf1: Ring_with_identity r1) -> (r2: Type) -> (pf2: Ring_with_identity r2) -> (f: r1 -> r2) -> IRHom r1 pf1 r2 pf2 f -> f(fst(RingAdditive_id r1 (Ring_with_identity_isRing r1 pf1))) = fst (RingAdditive_id r2 (Ring_with_identity_isRing r2 pf2))\nIRHomZtoZ r1 (MkRing_with_identity r1 ((((+)))) (m) (a, b)) r2 (MkRing_with_identity r2 (((*))) (m1) (a', b')) f pfhom = aplusaZ r2 prf2 (f z1) (\n trans\n (sym (Basics.fst(pfhom z1 z1)))\n (cong (Basics.fst(pfid1 z1)))\n ) where\n prf1: Ring r1\n prf1 = MkRing r1 (+) (m) (a, ((Basics.fst (Basics.fst b)), (Basics.snd b)))\n prf2: Ring r2\n prf2 = MkRing r2 (*) (m1) (a', ((Basics.fst (Basics.fst b')), (Basics.snd b')))\n z1: r1\n z1 = fst(RingAdditive_id r1 prf1)\n pfid1: (a : r1) -> ((a + z1) = a, (z1 + a) = a)\n pfid1 a = snd(RingAdditive_id r1 prf1) a\n", "meta": {"hexsha": "9cc5c1fe40af03633462e77729db73d83c287c15", "size": 3397, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/RingProperties.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/RingProperties.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/RingProperties.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.9054054054, "max_line_length": 268, "alphanum_fraction": 0.5784515749, "num_tokens": 1506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.6757645879592641, "lm_q1q2_score": 0.6104142391584855}} {"text": "data Direction = North\n | East\n | South\n | West\n\nturn_clockwise : Direction -> Direction\nturn_clockwise North = East\nturn_clockwise East = South\nturn_clockwise South = West\nturn_clockwise West = North\n\ndata Shape = ||| A triangle, with base length and height\n Triangle Double Double\n | ||| A rectangle with 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\ntest_pic : Picture\ntest_pic = 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\npicture_area : Picture -> Double\npicture_area (Primitive shape) = area shape\npicture_area (Combine pic pic1) = picture_area pic + picture_area pic1\npicture_area (Rotate x pic) = picture_area pic\npicture_area (Translate x y pic) = picture_area pic\n\ndata Tree a = Empty\n | Node (Tree a) a (Tree a)\n\n%name Tree tree, tree1\n\ninsert : Ord a =>\n 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\n GT => Node left y (insert x right)\n\nlistToTree : Ord a => List a -> Tree a\nlistToTree xs = foldr insert Empty xs\n\nfoldrTree : (a -> as -> as) -> as -> Tree a -> as\nfoldrTree f x Empty = x\nfoldrTree f x (Node lft y rgt) = let rgt' = (foldrTree f x rgt) in\n foldrTree f (f y rgt') lft\n\ntreeToList : Tree a -> List a\ntreeToList tree = foldrTree (::) [] tree\n\ndata Expr = PrimInt Int\n | Add Expr Expr\n | Sub Expr Expr\n | Mult Expr Expr\n\nevaluate : Expr -> Int\nevaluate (PrimInt 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 x = x\nmaxMaybe x Nothing = x\nmaxMaybe (Just x) (Just y) = Just (max x y)\n\ntriangleSize : Shape -> Maybe Double\ntriangleSize tri@(Triangle _ _) = Just (area tri)\ntriangleSize _ = Nothing\n\nbiggestFound : Maybe Double -> Picture -> Maybe Double\nbiggestFound x (Primitive p) = maxMaybe x (triangleSize p)\nbiggestFound x (Combine pic pic1) = biggestFound (biggestFound x pic) pic1\nbiggestFound x (Rotate y pic) = biggestFound x pic\nbiggestFound x (Translate y z pic) = biggestFound x pic\n\nbiggestTriangle : Picture -> Maybe Double\nbiggestTriangle pic = biggestFound Nothing pic\n\n\ndata PowerSource = Petrol | Pedal\n\ndata Vehicle : PowerSource -> Type where\n Bicycle : Vehicle Pedal\n Unicycle : Vehicle Pedal\n Car : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n\nwheels : Vehicle p -> Nat\nwheels Bicycle = 2\nwheels Unicycle = 1\nwheels (Car fuel) = 4\nwheels (Bus fuel) = 4\n\nrefuel : Vehicle Petrol -> Vehicle Petrol\nrefuel (Car fuel) = Car 100\nrefuel (Bus fuel) = Car 200\n", "meta": {"hexsha": "724160433e10026e36a000dcb1f62cba11eaa4e2", "size": 3586, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-04/main.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-04/main.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-04/main.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.1544715447, "max_line_length": 74, "alphanum_fraction": 0.6413831567, "num_tokens": 932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6102143894159786}} {"text": "maybeAdd : Maybe Int -> Maybe Int -> Maybe Int\nmaybeAdd x y = case x of\n Nothing => Nothing\n Just x_val => case y of\n Nothing => Nothing\n Just y_val => Just (x_val + y_val)\n\nmaybeAdd' : Maybe Int -> Maybe Int -> Maybe Int\nmaybeAdd' x y = x >>= \\x_val =>\n y >>= \\y_val =>\n Just (x_val + y_val)\n\nmaybeAdd'' : Maybe Int -> Maybe Int -> Maybe Int\nmaybeAdd'' x y = do x_val <- x\n y_val <- y\n Just (x_val + y_val)\n", "meta": {"hexsha": "07ea08068b0a39c0c0fe426e441d4a27b94d4bc4", "size": 590, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter06/Maybe.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": "Chapter6/Maybe.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": "Chapter6/Maybe.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": 34.7058823529, "max_line_length": 73, "alphanum_fraction": 0.4305084746, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426303, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6101656818211535}} {"text": "-- data MyNat = Z | S MyNat\n\n-- Z\n-- S Z\n-- S (S Z)\n-- S (S (S Z))\n\n-- myPlus : MyNat -> MyNat -> MyNat\n-- myPlus Z j = j\n-- myPlus (S x) j = S (myPlus x j)\n", "meta": {"hexsha": "e107a84b6f48e8236430914a3b652a5376c0f5f4", "size": 157, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "myNat.idr", "max_stars_repo_name": "fthomas/tdd-talk", "max_stars_repo_head_hexsha": "988657bc2055e2b0d270198a58b1af0531eb8413", "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": "myNat.idr", "max_issues_repo_name": "fthomas/tdd-talk", "max_issues_repo_head_hexsha": "988657bc2055e2b0d270198a58b1af0531eb8413", "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": "myNat.idr", "max_forks_repo_name": "fthomas/tdd-talk", "max_forks_repo_head_hexsha": "988657bc2055e2b0d270198a58b1af0531eb8413", "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": 14.2727272727, "max_line_length": 35, "alphanum_fraction": 0.4713375796, "num_tokens": 69, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.6723316926137812, "lm_q1q2_score": 0.6100147665717094}} {"text": "{- \n SnocList and fast reverse examples from 10.2.1 and 10.2.2 \n \"snoc\" == reverse \"cons\"\n The book claims linear cost but my experiments suggest quadratic.\n I think the cost of snocListHelp append proofs causes it.\n-}\n\nmodule Part2.Sez10_2a_snoc\n\n%default total \n\npublic export\ndata SnocList : List a -> Type where\n Empty : SnocList []\n Snoc : (rec : SnocList xs) -> SnocList (xs ++ [x])\n\nexport\nsnocList : (xs : List a) -> SnocList xs\n\nsnocListHelp : (snoc : SnocList input) -> (rest : List a) ->\n 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 = snocListHelp Empty xs\n\n||| reverse based on SnocList view, implementation that avoids using Helper function\nexport\nmyReverse : List a -> List a\n-- with argument is not recreated in recursive step\nmyReverse input with (snocList input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (Snoc rec) = x :: myReverse xs | rec -- passed with argument\n\ntest1 : List Int\ntest1 = myReverse [1..50]\n\ntest2 : List Int\ntest2 = myReverse [1..100]\n\n{-\nidris repl:\n*Part2/Sec10_2a> myReverse [1..10]\n[10, 9, 8, 7, 6, 5, 4, 3, 2, 1] : List Integer\n*Part2/Sec10_2a> :t appendNilRightNeutral\nappendNilRightNeutral : (l : List a) -> l ++ [] = l\n*Part2/Sec10_2a> :t appendAssociative\nappendAssociative : (l : List a) ->\n (c : List a) -> (r : List a) -> l ++ c ++ r = (l ++ c) ++ r\n-}\n", "meta": {"hexsha": "5cc7d0e1e560410c991dc37de05641aea2a8e2e5", "size": 1557, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Part2/Sez10_2a_snoc.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_2a_snoc.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_2a_snoc.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": 29.9423076923, "max_line_length": 86, "alphanum_fraction": 0.65253693, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6099621073174128}} {"text": "module Conway\n\nimport Data.Vect\nimport Data.Fin\n\n-- Local Variables:\n-- idris-load-packages: (\"prelude\" \"effects\" \"contrib\" \"base\")\n-- End:\n\nboard : Nat -> Nat -> Type\nboard n m = Vect n (Vect m Bool)\n\nprintChar : Bool -> String\nprintChar False = \"x\"\nprintChar True = \"o\"\n\nprintRow : Vect m Bool -> String\nprintRow [] = \"\\n\"\nprintRow (x :: xs) = (printChar x) ++ (printRow xs)\n\nprintBoard : board n m -> String\nprintBoard = concat . map printRow \n\nlistFins : (n : Nat) -> Vect n (Fin n)\nlistFins Z = []\nlistFins (S k) = FZ :: (map FS (listFins k))\n\nboardAux : Fin n -> Vect m (Fin n, Fin m)\nboardAux {n} {m} f = map (\\x => (f,x)) (listFins m) \n\nboardCoords : (n : Nat) -> (m : Nat) -> Vect n (Vect m (Fin n, Fin m))\nboardCoords n m = map boardAux (listFins n)\n\npromote : Fin k -> Fin (S k)\npromote FZ = FZ\npromote (FS x) = (FS (promote x))\n\nsafeDec : Fin n -> Fin n\nsafeDec FZ = FZ\nsafeDec (FS x) = promote x\n\nmaxFin : (n : Nat) -> Fin (S n) \nmaxFin Z = FZ\nmaxFin (S k) = FS (maxFin k)\n\n-- this should return the maximum element in the finite set\nsafeInc : Fin n -> Fin n\nsafeInc {n = Z} FZ impossible\nsafeInc {n = Z} (FS _) impossible\nsafeInc {n = (S k)} f = case (strengthen f) of\n Left same => same\n Right f' => (FS f')\n\nmyStrengthen : Fin (S n) -> Either (Fin (S n)) (Fin n)\nmyStrengthen {n = Z} f = Left FZ\nmyStrengthen {n = (S k)} FZ = Right FZ\nmyStrengthen {n = (S k)} (FS x) = case (myStrengthen x) of\n Left same => Left (FS x)\n Right decked => Right (FS decked)\n\nlastV : Vect (S n) a -> a\nlastV (x :: []) = x\nlastV (x :: (y :: xs)) = lastV (y :: xs)\n\nfilterV : (a -> Bool) -> Vect n a -> (m ** (Vect m a))\nfilterV f [] = (0 ** [])\nfilterV f (x :: xs) = case (f x) of\n True => let (n ** xs') = filterV f xs in (S n ** (x :: xs'))\n False => filterV f xs\n\nnubV : Eq a => Vect n a -> (m ** (Vect m a))\nnubV [] = (Z ** [])\nnubV (x :: xs) = let (n ** xs') = filterV (\\y => y /= x) xs \n (n' ** xs'') = nubV xs'\n in (S n' ** (x :: xs''))\n\nneighCoords : Fin n -> Fin m -> List (Fin n, Fin m)\nneighCoords fx fy = [(safeInc fx , fy),\n (safeInc fx , safeInc fy),\n (fx , safeInc fy),\n (safeDec fx, safeInc fy),\n (safeInc fx , safeDec fy),\n (safeDec fx, fy),\n (fx , safeDec fy),\n (safeDec fx, safeDec fy)]\n \nixer : board n m -> (Fin n, Fin m) -> Lazy Bool\nixer b (fx, fy) = index fy (index fx b)\n\nrhs : Vect n (Vect m (Fin n, Fin m)) -> (b : Vect n (Vect m Bool)) -> (Fin n, Fin m) -> Bool\nrhs coords b f = let neigh = uncurry neighCoords f in and $ map (ixer b) neigh\n\ngameStep : board n m -> board n m\ngameStep {n} {m} b = let coords = boardCoords n m in map (map (rhs coords b)) coords \n\n\nrepeatF : Nat -> (a -> a) -> a -> a\nrepeatF Z f = id\nrepeatF (S k) f = f . (repeatF k f)\n\n-- this is way too specific, but I'm getting bored\nplaceBoard : board n m -> Fin n -> Fin m -> board n m\nplaceBoard b fx fy = updateAt fx (\\v => updateAt fy (const True) v) b\n\nblankBoard : board n m\nblankBoard {n} {m} = map (map (const False)) (boardCoords n m)\n\nmkBoard : (List (Fin n, Fin m)) -> board n m\nmkBoard l = foldr (\\f,b => uncurry (placeBoard b) f) blankBoard l\n", "meta": {"hexsha": "15df48d24fd6768bcd4ef5d0d6510f177a35b0bc", "size": 3410, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Conway.idr", "max_stars_repo_name": "clarissalittler/idris-practice", "max_stars_repo_head_hexsha": "e307a93fa4ab7bce9f6cf7fef9973c398b3d65ea", "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": "Conway.idr", "max_issues_repo_name": "clarissalittler/idris-practice", "max_issues_repo_head_hexsha": "e307a93fa4ab7bce9f6cf7fef9973c398b3d65ea", "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": "Conway.idr", "max_forks_repo_name": "clarissalittler/idris-practice", "max_forks_repo_head_hexsha": "e307a93fa4ab7bce9f6cf7fef9973c398b3d65ea", "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.0, "max_line_length": 92, "alphanum_fraction": 0.5263929619, "num_tokens": 1117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6097667787068731}} {"text": "import Data.Fin\nimport Data.Vect\n\ntail : (Fin (S n) -> a) -> (Fin n -> a)\ntail f = f . FS\n\ntoVectFun : {n : Nat} -> (Fin n -> a) -> Vect n a\ntoVectFun {n = Z} _ = Nil\ntoVectFun {n = S m} f = (f FZ) :: (toVectFun (tail f))\n\nN : Nat\nN = 500\n\nxs : Vect (S N) Nat\nxs = toVectFun {n = S N} finToNat\n\nmain : IO ()\nmain = putStrLn $\n \"xs(\" ++ show N ++ \") = \" ++ show (index (fromInteger (natToInteger N)) xs)\n", "meta": {"hexsha": "6aac14b8c484f7f2a8b85ac991a54f1242c0919b", "size": 406, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/perf008/FinPerf.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/perf008/FinPerf.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/perf008/FinPerf.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": 20.3, "max_line_length": 77, "alphanum_fraction": 0.5418719212, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6095647422529614}} {"text": "> data 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\n> append : Vect n a -> Vect m a -> Vect (n + m) a\n> append xs ys\n> = case xs of\n> [] => ?bar_3\n> (x :: zs) => ?bar_4\n\n", "meta": {"hexsha": "0be28fbf2be874d3313405785d66001fef625841", "size": 276, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/literate002/IEdit2.lidr", "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/literate002/IEdit2.lidr", "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/literate002/IEdit2.lidr", "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": 21.2307692308, "max_line_length": 49, "alphanum_fraction": 0.4239130435, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6095180632155301}} {"text": "> module SequentialDecisionProblems.examples.Main\n\n> import Decidable.Order\n\n> import Data.List\n> import Data.List.Quantifiers\n> import Effects\n> import Effect.Exception\n> import Effect.StdIO\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.FullTheory\n> import SequentialDecisionProblems.Utils\n> import SequentialDecisionProblems.NonDeterministicDefaults\n> import SequentialDecisionProblems.CoreTheoryOptDefaults\n> import SequentialDecisionProblems.FullTheoryOptDefaults\n> import SequentialDecisionProblems.ViabilityDefaults\n\n> import SequentialDecisionProblems.examples.LeftAheadRight\n\n> import List.Operations\n> import List.Properties\n> import BoundedNat.BoundedNat\n> import BoundedNat.Operations\n> import BoundedNat.Properties\n> import Sigma.Sigma\n> import Nat.LTEProperties\n> import Nat.LTProperties\n> import Nat.OperationsProperties\n> import LocalEffect.Exception\n> import LocalEffect.StdIO\n\n> -- %default total\n> %auto_implicits off\n\n> -- %logging 5\n\n\nWe reimplement \"Example1.lidr\", this time with |M = List|.\n\n* The decision process:\n\n> maxColumn : Nat\n> maxColumn = 10\n\n> nColumns : Nat\n> nColumns = S maxColumn\n\n** States:\n\n> SequentialDecisionProblems.CoreTheory.State t = LTB nColumns\n\n** Controls:\n\n> SequentialDecisionProblems.CoreTheory.Ctrl t x = LeftAheadRight\n\n** Transition function:\n\n> SequentialDecisionProblems.CoreTheory.nexts t (MkSigma Z prf) Left =\n> [MkSigma maxColumn (ltIdS maxColumn)]\n> SequentialDecisionProblems.CoreTheory.nexts t (MkSigma (S n) prf) Left =\n> [MkSigma n (ltLemma1 n nColumns prf)]\n> SequentialDecisionProblems.CoreTheory.nexts t x Ahead = [x]\n> SequentialDecisionProblems.CoreTheory.nexts t (MkSigma n prf) Right with (decLT n maxColumn)\n> | (Yes p) = [MkSigma (S n) (LTESucc p)]\n> | (No contra) = [MkSigma Z (LTESucc LTEZero)]\n\n** |Val| and |LTE|:\n\n> SequentialDecisionProblems.CoreTheory.Val = \n> Nat\n\n> SequentialDecisionProblems.CoreTheory.plus = \n> Prelude.Nat.plus\n\n> SequentialDecisionProblems.CoreTheory.zero = \n> Z\n\n> SequentialDecisionProblems.CoreTheory.LTE = \n> Prelude.Nat.LTE\n\n> SequentialDecisionProblems.FullTheory.reflexiveLTE = \n> Nat.LTEProperties.reflexiveLTE\n\n> SequentialDecisionProblems.FullTheory.transitiveLTE = \n> Nat.LTEProperties.transitiveLTE\n\n> SequentialDecisionProblems.FullTheory.monotonePlusLTE = \n> Nat.LTEProperties.monotoneNatPlusLTE\n\n> SequentialDecisionProblems.CoreTheoryOptDefaults.totalPreorderLTE = \n> Nat.LTEProperties.totalPreorderLTE \n\n** Reward function:\n\n> SequentialDecisionProblems.CoreTheory.reward t x y (MkSigma c _) =\n> if c == Z\n> then (S Z)\n> else if (S c) == nColumns\n> then (S (S Z))\n> else Z\n\n** Measure:\n\n> SequentialDecisionProblems.CoreTheory.meas = sum\n> SequentialDecisionProblems.FullTheory.measMon = sumMon\n\n** |Ctrl| is finite:\n\n> SequentialDecisionProblems.Utils.finiteCtrl _ = \n> finiteLeftAheadRight\n\n** Reachability\n\n> SequentialDecisionProblems.CoreTheory.Reachable x' = Unit\n> SequentialDecisionProblems.CoreTheory.reachableSpec1 {t} x r y = all (nexts t x y) where\n> all : (xs : List (State (S t))) -> SequentialDecisionProblems.CoreTheory.All (Reachable {t' = S t}) xs\n> all Nil = Nil\n> all (x :: xs) = () :: (all xs)\n\n\n* The computation:\n\n> SequentialDecisionProblems.Utils.showState = show @{ShowLTB}\n> SequentialDecisionProblems.Utils.showCtrl = show\n\n> computation : { [STDIO] } Eff ()\n> computation =\n> do putStr (\"enter number of steps:\\n\")\n> nSteps <- getNat\n> putStr (\"enter initial column:\\n\")\n> x0 <- getLTB nColumns\n> case (decidableViable {t = Z} nSteps x0) of\n> (Yes v0) => do putStrLn (\"computing optimal policies ...\")\n> ps <- pure (backwardsInduction Z nSteps)\n> putStrLn (\"computing optimal controls ...\")\n> mxys <- pure (possibleStateCtrlSeqs x0 () v0 ps)\n> putStrLn (show mxys)\n> putStrLn (\"done!\") \n> (No _) => putStrLn (\"initial column non viable for \" ++ cast {from = Int} (cast nSteps) ++ \" steps\")\n\n> main : IO ()\n> main = run computation\n\n\n> {-\n\n> ---}\n\n\n-- Local Variables:\n-- idris-packages: (\"effects\")\n-- End:\n", "meta": {"hexsha": "ff4554343d5b5db9b727345c92f8ce3799078f36", "size": 4230, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/examples/Example2.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/Example2.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/Example2.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": 27.4675324675, "max_line_length": 111, "alphanum_fraction": 0.709929078, "num_tokens": 1111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6095074749046273}} {"text": "> module Vect.Operations\n\n\n> import Data.Vect\n> import Data.Fin\n> import Data.So\n\n> import Decidable.Predicates\n> import Rel.TotalPreorder\n> import Rel.TotalPreorderOperations\n> import Nat.LTProperties\n> import Sigma.Sigma\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\nLookup\n\n> ||| Lookup the index of an element of a vector\n> lookup : {A : Type} -> .(a : A) -> .(as : Vect n A) -> Elem a as -> Fin n\n> lookup {n = Z} a Nil Here impossible\n> lookup {n = Z} a Nil (There p) impossible\n> lookup {n = S m} a (a :: as) Here = FZ\n> lookup {n = S m} a (a' :: as) (There prf) = FS (lookup a as prf)\n\n> ||| Lookup the index of an element of a vector\n> -- lookup' : {n : Nat} -> {A : Type} -> (DecEq A) => (a : A) -> (as : Vect n A) -> Maybe (Fin n)\n> lookup' : {n : Nat} -> {A : Type} -> (DecEq A) -> (a : A) -> (as : Vect n A) -> Maybe (Fin n)\n> lookup' {n = Z} _ _ Nil = Nothing\n> lookup' {n = S m} d a (a' :: as) with (decEq a a')\n> | (Yes _) = Just FZ\n> | (No _) with (lookup' d a as)\n> | Nothing = Nothing\n> | (Just k) = Just (FS k)\n\n\nContainer monad operations\n\n...\n\n\nFiltering\n\n> ||| Filters a vector on a decidable property\n> filter : {A : Type} ->\n> {P : A -> Type} ->\n> Dec1 P ->\n> Vect n A -> \n> Sigma Nat (\\ m => Vect m A)\n> filter d1P Nil = MkSigma Z Nil\n> filter d1P (a :: as) with (filter d1P as)\n> | (MkSigma n as') with (d1P a)\n> | (Yes _) = MkSigma (S n) (a :: as')\n> | (No _) = MkSigma n as'\n\n\n> ||| Filters a vector on a decidable property and pairs elements with proofs\n> filterTagSigma : {A : Type} ->\n> {P : A -> Type} ->\n> Dec1 P ->\n> Vect n A -> \n> Sigma Nat (\\ m => Vect m (Sigma A P))\n> filterTagSigma d1P Nil = MkSigma _ Nil\n> filterTagSigma d1P (a :: as) with (filterTagSigma d1P as)\n> | (MkSigma _ tail) with (d1P a)\n> | (Yes p) = MkSigma _ ((MkSigma a p) :: tail)\n> | (No _) = MkSigma _ tail\n\n\n> ||| Filters a vector on a decidable property and pairs elements with proofs\n> filterTagExists : {A : Type} ->\n> {P : A -> Type} ->\n> Dec1 P ->\n> Vect n A -> \n> Sigma Nat (\\ m => Vect m (Exists {a = A} P))\n> filterTagExists d1P Nil = MkSigma _ Nil\n> filterTagExists d1P (a :: as) with (filterTagExists d1P as)\n> | (MkSigma _ tail) with (d1P a)\n> | (Yes p) = MkSigma _ ((Evidence a p) :: tail)\n> | (No _) = MkSigma _ tail\n\n\n> ||| Filters a vector on a decidable property and pairs elements with proofs\n> filterTagSubset : {A : Type} ->\n> {P : A -> Type} ->\n> Dec1 P ->\n> Vect n A -> \n> Sigma Nat (\\ m => Vect m (Subset A P))\n> filterTagSubset d1P Nil = MkSigma _ Nil\n> filterTagSubset d1P (a :: as) with (filterTagSubset d1P as)\n> | (MkSigma _ tail) with (d1P a)\n> | (Yes p) = MkSigma _ ((Element a p) :: tail)\n> | (No _) = MkSigma _ tail\n\nSearching\n\n> |||\n> argmaxMax : {A : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R -> Vect n A -> .(LT Z n) -> (Fin n, A)\n> argmaxMax {n = Z} tp Nil p = absurd p\n> argmaxMax {n = S Z} tp (a :: Nil) _ = (FZ, a)\n> argmaxMax {n = S (S m)} tp (a' :: (a'' :: as)) _ with (argmaxMax tp (a'' :: as) (ltZS m))\n> | (k, max) with (totalPre tp a' max)\n> | (Left _) = (FS k, max)\n> | (Right _) = (FZ, a')\n\n\n> |||\n> argmax : {A : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R -> Vect n A -> .(LT Z n) -> Fin n\n> argmax tp as p = fst (argmaxMax tp as p)\n\n\n> |||\n> max : {A : Type} -> {R : A -> A -> Type} -> \n> TotalPreorder R -> Vect n A -> .(LT Z n) -> A\n> max tp as p = snd (argmaxMax tp as p)\n\n\n> {-\n\n> |||\n> argmaxMax : {A : Type} ->\n> TotalPreorder A -> Vect n A -> .(LT Z n) -> (Fin n, A)\n> argmaxMax {n = Z} tp Nil p = absurd p\n> argmaxMax {n = S Z} tp (a :: Nil) _ = (FZ, a)\n> argmaxMax {n = S (S m)} tp (a' :: (a'' :: as)) _ with (argmaxMax tp (a'' :: as) (ltZS m))\n> | (k, max) with (totalPre tp a' max)\n> | (Left _) = (FS k, max)\n> | (Right _) = (FZ, a')\n\n\n> |||\n> argmax : {A : Type} ->\n> TotalPreorder A -> Vect n A -> .(LT Z n) -> Fin n\n> argmax tp as p = fst (argmaxMax tp as p)\n\n\n> |||\n> max : {A : Type} ->\n> TotalPreorder A -> Vect n A -> .(LT Z n) -> A\n> max tp as p = snd (argmaxMax tp as p)\n\n> -}\n\n\nShow\n\n> implementation Show (Elem a as) where\n> show = show' where\n> show' : {n : Nat} -> {A : Type} -> {a : A} -> {as : Vect n A} -> Elem a as -> String \n> show' Here = \"Here\"\n> show' (There p) = \"There\" ++ show' p\n\n\nPointwise modify\n\n> |||\n> modifyVect : {n : Nat} -> {a : Type} ->\n> Vect n a -> Fin n -> a -> Vect n a\n> modifyVect {n = Z} Nil k _ = absurd k\n> modifyVect {n = S m} (a :: as) FZ a' = a' :: as\n> modifyVect {n = S m} (a :: as) (FS k) a' = a :: (modifyVect as k a')\n\n\nFold:\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z A\n Cons : A -> Vect n A -> Vect (S n) A\n\nx0 : X 0\nf : A -> X n -> X (S n)\n\n\n> foldVect : {X : Nat -> Type} -> \n> {A : Type} ->\n> X 0 ->\n> ((n : Nat) -> A -> X n -> X (S n)) ->\n> Vect n A ->\n> X n\n> foldVect {n = Z} x0 f Nil = x0\n> foldVect {n = S m} x0 f (a :: as) = f m a (foldVect x0 f as)\n\n\n> {-\n\n> |||\n> argmaxMax : {A : Type} -> {TO : A -> A -> Type} -> Preordered A TO =>\n> Vect (S n) A -> (Fin (S n), A)\n> argmaxMax {n = Z} (a :: Nil) = (FZ, a)\n> argmaxMax {A} {n = S m} (a :: (a' :: as)) with (preorder a (snd (argmaxMax (a' :: as))))\n> | (Left _) = (FS (fst ka), snd ka) where\n> ka : (Fin (S m), A)\n> ka = argmaxMax (a' :: as)\n> | (Right _) = (FZ, a)\n\n\n> |||\n> argmax : {A : Type} -> {TO : A -> A -> Type} -> Preordered A TO =>\n> Vect (S n) A -> Fin (S n)\n> argmax = fst . argmaxMax\n\n\n> |||\n> max : {A : Type} -> {TO : A -> A -> Type} -> Preordered A TO =>\n> Vect (S n) A -> A\n> max = snd . argmaxMax\n\n> -}\n\n\n> {-\n\n> |||\n> argmaxMax : {A, F : Type} -> {TO : F -> F -> Type} -> Ordered F TO =>\n> Vect (S n) (A,F) -> (A,F)\n> argmaxMax {n = Z} (af :: Nil) = af\n> argmaxMax {n = S m} (af :: (af' :: afs)) with (order (snd af) (snd (argmaxMax (af' :: afs))))\n> | (Left _) = argmaxMax (af' :: afs)\n> | (Right _) = af\n\n\n> |||\n> argmax : {A, F : Type} -> {TO : F -> F -> Type} -> Ordered F TO =>\n> Vect (S n) (A,F) -> A\n> argmax = fst . argmaxMax\n\n\n> |||\n> max : {A, F : Type} -> {TO : F -> F -> Type} -> Ordered F TO =>\n> Vect (S n) (A,F) -> F\n> max = snd . argmaxMax\n\n> ---}\n \n> ---}\n\n \n", "meta": {"hexsha": "fbf04548ba0ba8223cfe7be053444e32c106ac3e", "size": 6719, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Vect/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": "Vect/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": "Vect/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": 27.6502057613, "max_line_length": 98, "alphanum_fraction": 0.4676291115, "num_tokens": 2434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6094026481229103}} {"text": "module Eval\n\nimport Syntax\n\nexport\neval : Expression -> Integer\neval (Numeral i) = i\neval (Plus e1 e2) = (eval e1) + (eval e2)\neval (Minus e1 e2) = (eval e1) - (eval e2)\neval (Times e1 e2) = (eval e1) * (eval e2)\neval (Divide e1 e2) = (eval e1) `div` (eval e2) -- Note: a bit evil - will fail with RTS exception.\neval (Negate e) = -(eval e)\n", "meta": {"hexsha": "a634954e25a8833dc0ba5d57569ad091f14050c9", "size": 352, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Eval.idr", "max_stars_repo_name": "steshaw/idris-calc", "max_stars_repo_head_hexsha": "7bb1d7761e8f0d2764fb2bd8713a57bec06f5fba", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-17T08:24:59.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-24T09:02:16.000Z", "max_issues_repo_path": "src/Eval.idr", "max_issues_repo_name": "steshaw/idris-calc", "max_issues_repo_head_hexsha": "7bb1d7761e8f0d2764fb2bd8713a57bec06f5fba", "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": "src/Eval.idr", "max_forks_repo_name": "steshaw/idris-calc", "max_forks_repo_head_hexsha": "7bb1d7761e8f0d2764fb2bd8713a57bec06f5fba", "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": 27.0769230769, "max_line_length": 99, "alphanum_fraction": 0.6164772727, "num_tokens": 135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.6893056104028799, "lm_q1q2_score": 0.6093732451478012}} {"text": "module Injective\n\n%default total\n\ninterface Injective (op : t -> t) where\n inj : (a : t) -> (b : t) -> op a = op b -> a = b\n\n inj' : {a : t} -> {b : t} -> op a = op b -> a = b\n inj' {a} {b} = inj a b\n\nInjective S where\n inj = succInjective\n", "meta": {"hexsha": "a67fac50681058c938a1c8b0ed52be4a92d44932", "size": 244, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Injective.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": "Injective.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": "Injective.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": 18.7692307692, "max_line_length": 51, "alphanum_fraction": 0.512295082, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6093688814031517}} {"text": "module Linear.Types\n\npublic export\n(-<>) : Type -> Type -> Type\n(-<>) a b = (1 x : a) -> b\n\ninfixr 0 -<>\n\npublic export\nvoid1 : Void -<> a\nvoid1 x impossible\n\npublic export\ninterface LBifunctor f where\n bimap : (a -<> c) -> (b -<> d) -> f a b -<> f c d\n\nnamespace LPair\n\n public export\n 0 fst : LPair a b -> a\n fst (x # y) = x\n\n public export\n 0 snd : LPair a b -> b\n snd (x # y) = y\n\n public export\n 0 surjPairing : (w : LPair a b) -> fst w # snd w = w\n surjPairing (x # y) = Refl\n\npublic export\nLBifunctor LPair where\n bimap f g (x # y) = (f x) # (g y)\n\npublic export\ndata I : Type where\n Star : I\n\nnamespace Sigma1\n public export\n data Sigma1 : (a : Type) -> (b : a -> Type) -> Type where\n (#) : (1 x : a) -> (1 y : b x) -> Sigma1 a b\n\nnamespace Sigma0\n public export\n data Sigma0 : (a : Type) -> (b : a -> Type) -> Type where\n (#): (0 x : a) -> (1 y : b x) -> Sigma0 a b\n\n public export\n 0 fst : Sigma0 a b -<> a\n fst (x # y) = x\n\n public export\n snd : (1 x : Sigma0 a b) -> b (fst x)\n snd (x # y) = y\n\npublic export\ndata Sum : (a : Type) -> (b : Type) -> Type where\n Inl : (1 x : a) -> Sum a b\n Inr : (1 y : b) -> Sum a b\n\npublic export\nUninhabited (Inl x = Inr y) where\n uninhabited p impossible\n\npublic export\nLBifunctor Sum where\n bimap f g (Inl x) = Inl $ f x\n bimap f g (Inr y) = Inr $ g y\n\nnamespace With\n public export\n 0 With : Type -> Type -> Type\n With a b = (1 x : Bool) -> if x then a else b\n\n public export\n bimap : (a -<> c) -> (b -<> d) -> With a b -<> With c d\n bimap f g x True = f (x True)\n bimap f g x False = g (x False)\n\n\nnamespace DWith\n public export\n 0 DWith : (a : Type) -> (b : a -> Type) -> Type\n DWith a b = Sigma0 a (\\x => With (Sigma1 a (\\z => z = x)) (b x))\n\n public export\n fstW : DWith a b -<> a\n fstW (_ # w) = let (z # Refl) = (w True) in z\n\n public export\n sndW : (1 w : DWith a b) -> b (fstW {b = b} w)\n sndW (x # w) = replace {p = b} (eq (x # w)) (w False)\n where\n eq : (w : DWith a b) -> fst w = fstW {b = b} w\n eq (x # w) with (w True)\n eq (z # w) | (z # Refl) = Refl\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "b6bd4d83bd2c049266e584fbcb40ee4b36405c60", "size": 2083, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Linear/Types.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": "Linear/Types.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": "Linear/Types.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": 19.1100917431, "max_line_length": 66, "alphanum_fraction": 0.5352856457, "num_tokens": 825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.609368866136464}} {"text": "totalLen : List String -> Nat\ntotalLen xs = foldr (\\elem, acc => length elem + acc ) 0 xs\n", "meta": {"hexsha": "878417947abefed93184fcf39d992da30cb1a577", "size": 90, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "totalLen.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": "totalLen.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": "totalLen.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.0, "max_line_length": 59, "alphanum_fraction": 0.6555555556, "num_tokens": 28, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6093688611746813}} {"text": "module Proofs.TranslationInvarianceTheory\n\nimport Common.Util\nimport Specifications.TranslationInvariance\nimport Proofs.GroupTheory\nimport Proofs.GroupCancelationLemmas\nimport Symmetry.Opposite\n\n%default total\n%access export\n\ninfixl 8 #\n\ncomposeOrder : {(#) : Binop s} -> {(<=) : Binrel s} ->\n PartiallyOrderedMagmaSpec (#) (<=) -> (a,b,c,d : s) ->\n a <= b -> c <= d -> a # c <= b # d\ncomposeOrder spec a b c d ab cd =\n let pp = translationInvariantR spec a b c ab\n qq = translationInvariantL spec c d b cd\n in transitive (order spec) (a # c) (b # c) (b # d) pp qq\n\n\norderInverseL : {(#) : Binop s} -> {(<=) : Binrel s} ->\n PartiallyOrderedGroupSpec (#) e inv (<=) -> (a,b,c : s) ->\n a # c <= b -> c <= inv a # b\norderInverseL spec a b c given = rewrite sym o2 in o1 where\n o1 : inv a # (a # c) <= inv a # b\n o1 = translationInvariantL (invariantOrder spec) (a # c) b _ given\n o2 : inv a # (a # c) = c\n o2 = groupCancel1bis (group spec) a c\n\n\norderInverseR : {(#) : Binop s} -> {(<=) : Binrel s} ->\n PartiallyOrderedGroupSpec (#) e inv (<=) -> (a,b,c : s) ->\n a # c <= b -> a <= b # inv c\norderInverseR spec a b c = orderInverseL (opposite spec) c b a\n\n\ninverseReversesOrder : {(#) : Binop s} ->\n PartiallyOrderedGroupSpec (#) _ inv leq ->\n leq a b -> inv b `leq` inv a\ninverseReversesOrder spec {a} {b} given = rewriteRelation leq o3 o4 o2 where\n o1 : inv a # a `leq` inv a # b\n o1 = translationInvariantL (invariantOrder spec) _ _ (inv a) given\n o2 : inv a # a # inv b `leq` inv a # b # inv b\n o2 = translationInvariantR (invariantOrder spec) (inv a # a) (inv a # b) _ o1\n o3 : inv a # a # inv b = inv b\n o3 = groupCancel1 (group spec) a _\n o4 : inv a # b # inv b = inv a\n o4 = groupCancel3bis (group spec) _ b\n\n\ngroupInverseAndOrder : {(#) : Binop s} ->\n PartiallyOrderedGroupSpec (#) e inv leq -> (a,b : s) ->\n a `leq` b -> a # inv b `leq` e\ngroupInverseAndOrder spec a b given = rewrite sym o2 in o1 where\n o1 : a # inv b `leq` b # inv b\n o1 = translationInvariantR (invariantOrder spec) a b _ given\n o2 : b # inv b = e\n o2 = inverseR (group spec) b\n\n\ninvertNegative : {(<=) : Binrel s} ->\n PartiallyOrderedGroupSpec _ zero neg (<=) -> (a : s) ->\n a <= zero -> zero <= neg a\ninvertNegative spec a negative = rewrite sym o2 in o1 where\n o1 : neg zero <= neg a\n o1 = inverseReversesOrder spec negative\n o2 : neg zero = zero\n o2 = groupInverseNeutral (group spec)\n", "meta": {"hexsha": "816cfdbcef3c1669b5500359bced67e22d801be0", "size": 2417, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Proofs/TranslationInvarianceTheory.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/Proofs/TranslationInvarianceTheory.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/Proofs/TranslationInvarianceTheory.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": 34.0422535211, "max_line_length": 79, "alphanum_fraction": 0.6239139429, "num_tokens": 842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6093688611746813}} {"text": "data BNat = BZ | O BNat | E BNat\n\nbnat_ind : {0 p : BNat -> Type}\n -> p BZ\n -> ((bn : BNat) -> p bn -> p (O bn))\n -> ((bn : BNat) -> p bn -> p (E bn))\n -> (bn : BNat) -> p bn\nbnat_ind pbz po pe = go\n where\n go : (bn : BNat) -> p bn\n go BZ = ?pbz_hole\n go (O x) = po x (go x)\n go (E x) = pe x (go x)\n", "meta": {"hexsha": "bd1b333fb1522f8457f4c14f22d641d150093ff9", "size": 331, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/reg025/lift.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/reg025/lift.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/reg025/lift.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": 23.6428571429, "max_line_length": 44, "alphanum_fraction": 0.4259818731, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6090755570965558}} {"text": "module Entscheidbar\n\ndata Entscheidbar : (behauptung:Type) -> Type where\n Ja : (beweis : behauptung) -> Entscheidbar behauptung\n Nein : (widerspruch : behauptung -> Void) -> Entscheidbar behauptung\n\n\nNullUngleichNachfolger : Nat -> (Z = S k) -> Void\nNullUngleichNachfolger _ Refl impossible\n\n\nNachfolgerUngleichNull : Nat -> (S k = Z) -> Void\nNachfolgerUngleichNull _ Refl impossible\n\n\nauchNichtGleich : (a = b -> Void) -> (S a = S b) -> Void\nauchNichtGleich wid Refl = wid Refl\n\n\nsindGleich : (n : Nat) -> (m : Nat) -> Entscheidbar (n = m)\nsindGleich Z Z = Ja Refl\nsindGleich Z (S k) = Nein (NullUngleichNachfolger k)\nsindGleich (S k) Z = Nein (NachfolgerUngleichNull k)\nsindGleich (S k) (S j) =\n case sindGleich k j of\n Ja prf => Ja (cong prf)\n Nein wid => Nein (auchNichtGleich wid)\n\n\nsindGleich' : (n : Nat) -> (m : Nat) -> Dec (n = m)\nsindGleich' Z Z = Yes Refl\nsindGleich' Z (S k) = No (NullUngleichNachfolger k)\nsindGleich' (S k) Z = No (NachfolgerUngleichNull k)\nsindGleich' (S k) (S j) =\n case sindGleich' k j of\n Yes prf => Yes (cong prf)\n No wid => No (auchNichtGleich wid)\n", "meta": {"hexsha": "a5b9d608cf0f255761cbd223fb376e18c683e2cd", "size": 1101, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Beispiele/Entscheidbar.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/Entscheidbar.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/Entscheidbar.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": 28.9736842105, "max_line_length": 70, "alphanum_fraction": 0.6721162579, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.66192288918838, "lm_q1q2_score": 0.6087324397999032}} {"text": "module Chapter3\n\nimport Data.Vect\n\ninvert : Bool -> Bool\ninvert False = True\ninvert True = False\n\ndescribe_list : List Int -> String\ndescribe_list [] = \"Empty List\"\ndescribe_list (x :: xs) = \"Non-empty, tail = \" ++ show xs\n\nword_lengths : List String -> List Nat\nword_lengths [] = []\nword_lengths (word :: words) = length word :: word_lengths words\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) = not (isEven k)\n\n isOdd : Nat -> Bool\n isOdd Z = False\n isOdd (S k) = isEven k\n\nfourInts : Vect 4 Int\nfourInts = [0, 1, 2, 3]\n\nword_lengths_vec : Vect len String -> Vect len Nat\nword_lengths_vec [] = []\nword_lengths_vec (word :: words) = length word :: word_lengths_vec words\n\ninsert : Ord elem => (x : elem) -> (xs_sorted : Vect k elem) -> Vect (S k) elem\ninsert x [] = [x]\ninsert x (y :: xs) = if x < y then x :: y :: xs\n else y :: insert x xs\n\nins_sort : Ord elem => Vect n elem -> Vect n elem\nins_sort [] = []\nins_sort (x :: xs) = let xs_sorted = ins_sort xs in\n insert x xs_sorted\n\nlist_length : List a -> Nat\nlist_length [] = 0\nlist_length (x :: xs) = 1 + list_length xs\n\nlist_reverse : List a -> List a\nlist_reverse [] = []\nlist_reverse (x :: xs) = (list_reverse xs) ++ [x]\n\nlist_map : (a -> b) -> List a -> List b\nlist_map _ [] = []\nlist_map f (x :: xs) = f x :: list_map f xs\n\nvec_map : (a -> b) -> Vect n a -> Vect n b\nvec_map _ [] = []\nvec_map f (x :: xs) = f x :: vec_map f xs\n", "meta": {"hexsha": "001ea045b4a2124d5a4180a400d55b9d1b86eb3e", "size": 1523, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter3.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": "Chapter3.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": "Chapter3.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.564516129, "max_line_length": 79, "alphanum_fraction": 0.6007879186, "num_tokens": 472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.608640578464333}} {"text": "module Issue893\n\n%default total\n\nfoo : (a, b : Nat) -> Bool\nfoo Z b = False\nfoo (S _) b = False\n\nnotFoo : (a, b : Nat) -> Not (foo a b = True)\nnotFoo Z _ = uninhabited\nnotFoo (S _) _ = uninhabited\n\nbar : (a, b : Nat) -> (foo a b) && c = foo a b\nbar a b with (foo a b) proof ab\n bar a b | True = absurd $ notFoo a b ab\n bar a b | False = Refl\n\ngoo : (a, b : Nat) -> Bool -> Bool\ngoo a b True = True\ngoo a b False = foo a b || foo a b\n\nbar2 : (a, b : Nat) -> goo a b (foo a b) = foo a b\nbar2 a b with (foo a b) proof ab\n bar2 a b | True = Refl\n bar2 a b | False = rewrite ab in Refl\n", "meta": {"hexsha": "bb5f4b02fd99994c3c74c3e501882ed860e2b19e", "size": 594, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/with005/Issue893.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/with005/Issue893.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/with005/Issue893.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": 22.8461538462, "max_line_length": 50, "alphanum_fraction": 0.563973064, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.6791786861878392, "lm_q1q2_score": 0.6077219397188122}} {"text": "import Data.Primitives.Views\n\ndata Face = Head | Tail\n\ngetFace : Int -> Face\ngetFace x with (divides x 2)\n getFace ((2 * div) + rem) | (DivBy prf)\n = case rem of\n 0 => Head\n other => Tail\n\ncoinFlips : (count : Nat) -> Stream Int -> List Face\ncoinFlips Z xs = []\ncoinFlips (S k) (x :: xs) = getFace x :: coinFlips k xs\n", "meta": {"hexsha": "c2f9a11890924dd3039bfe2faaeea36cd193919c", "size": 342, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-11/Face.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/Face.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/Face.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": 22.8, "max_line_length": 55, "alphanum_fraction": 0.5877192982, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.6825737279551494, "lm_q1q2_score": 0.6076914449273797}} {"text": "import Data.Vect\n\ntotal allLengths : Vect len String -> Vect len Nat\nallLengths [] = []\nallLengths (x :: xs) = length x :: allLengths xs\n", "meta": {"hexsha": "d182473757d4e962ebb10da5ed2f7862ba69b593", "size": 137, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "WordLength_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": "WordLength_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": "WordLength_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": 22.8333333333, "max_line_length": 50, "alphanum_fraction": 0.6861313869, "num_tokens": 41, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6076766821487813}} {"text": "module HOAS\n\n\n\ndata Expr : Type -> Type where\n Val : a -> Expr a\n Op : (a -> b -> c) -> Expr a -> Expr b -> Expr c\n If : Expr Bool -> Expr a -> Expr a -> Expr a\n Lam : (Expr a -> Expr b) -> Expr (a -> b)\n App : Expr (a -> b) -> Expr a -> Expr b\n Fix : Expr ((a -> b) -> (a -> b)) -> Expr (a -> b)\n\n\neval : Expr a -> a\neval (Val x) = x\neval (Op f x y) = f (eval x) (eval y)\neval (If p x y) = if (eval p) then (eval x) else (eval y)\neval (Lam f) = \\x => eval (f (Val x))\neval (App f x) = (eval f) (eval x)\neval (Fix f) = \\x => loop f x\n where\n loop : Expr ((a -> b) -> (a -> b)) -> a -> b\n loop f a = (eval f) (loop f) a\n\n\nexample : Expr (Int -> Int)\nexample = Fix (Lam (\\f => (Lam (\\x =>\n If (Op (==) x (Val 0))\n (Val 1)\n (Op (*) x (App f (Op (-) x (Val 1))))))))\n\ntest : Int\ntest = eval example 5\n", "meta": {"hexsha": "11ba1447b8012db5e0205f6bfca88e331953032a", "size": 871, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/HOAS.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/HOAS.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/HOAS.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": 25.6176470588, "max_line_length": 63, "alphanum_fraction": 0.4431687715, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.6757645879592642, "lm_q1q2_score": 0.6075943906895539}} {"text": "||| Fresh lists, a variant of Catarina Coquand's contexts in \"A\n||| Formalised Proof of the Soundness and Completeness of a Simply\n||| Typed Lambda-Calculus with Explicit Substitutions\"\n|||\n||| Based directly on Agda's fresh lists:\n||| http://agda.github.io/agda-stdlib/Data.List.Fresh.html\nmodule FreshList\n\nimport public Data.So\n\n%default total\n\n-- Boolean \"relation\"\npublic export\nBRel : Type -> Type\nBRel a = a -> a -> Bool\n\ninfix 4 #, ##, #?\n\npublic export\ndata FreshVect : Nat -> (a : Type) -> (neq : BRel a) -> Type\n\n-- The boolean version\npublic export\n(##) : {neq : BRel a} -> (x : a) -> (xs : FreshVect l a neq) -> Bool\n-- The type version\npublic export\n(#) : {neq : BRel a} -> (x : a) -> (xs : FreshVect l a neq) -> Type\n\npublic export\ndata FreshVect : Nat -> (a : Type) -> (neq : BRel a) -> Type where\n Nil : FreshVect Z a neq\n (::) : (x : a) -> (xs : FreshVect l a neq) ->\n {auto 0 fresh : x # xs} ->\n FreshVect (S l) a neq\n\n%name FreshVect xs, ys, zs\n\nx ## [] = True\nx ## (y :: xs) = (x `neq` y) && (x ## xs)\n\nx # xs = So (x ## xs)\n\nexport\ntoList : FreshVect l a p -> List a\ntoList [] = []\ntoList (x :: xs) = x :: toList xs\n\nexport\nShow a => Show (FreshVect l a p) where\n show = show . toList\n\nparameters\n {0 A : Type} {0 Aneq : BRel A}\n {0 B : Type} {0 Bneq : BRel B}\n (F : A -> B)\n (Injectivity : (x,y : A) -> So (x `Aneq` y) -> So (F x `Bneq` F y))\n\n public export\n map : FreshVect l A Aneq -> FreshVect l B Bneq\n\n public export\n 0 mapFreshness : {x : A} -> (ys : FreshVect l A Aneq) ->\n x # ys -> F x # map ys\n\n map [] = []\n map ((x :: xs) {fresh}) = (F x :: map xs) {fresh = mapFreshness xs fresh}\n\n mapFreshness [] _\n = Oh\n mapFreshness (y :: ys) p\n = let (x_fresh_y, x_fresh_ys) = soAnd p in\n andSo (Injectivity _ _ x_fresh_y, mapFreshness ys x_fresh_ys)\n\nnamespace View\n public export\n data Empty : FreshVect Z a neq -> Type where\n Nil : Empty Nil\n\n public export\n data NonEmpty : FreshVect (S l) a neq -> Type where\n IsNonEmpty : NonEmpty ((x :: xs) {fresh})\n\npublic export\nlength : FreshVect l a neq -> Nat\nlength [] = 0\nlength (x :: xs) = 1 + length xs\n\npublic export\nfromMaybe : Maybe a -> (l ** FreshVect l a neq)\nfromMaybe Nothing = (Z ** [])\nfromMaybe (Just x) = (1 ** [x])\n\n-- I don't include replicate since freshness ought not to be\n-- reflexive, but feel free to add it if you need it\n\npublic export\nuncons : FreshVect (S l) a neq -> (a , FreshVect l a neq)\nuncons (x :: xs) = (x, xs)\n\npublic export\nhead : (xs : FreshVect (S l) a neq) -> a\nhead (x :: xs) = x\n\npublic export\ntail : (xs : FreshVect (S l) a neq) -> FreshVect l a neq\ntail (x :: xs) = xs\n\npublic export\n0 (.freshness) : (xs : FreshVect (S l) a neq) ->\n head xs # tail xs\n(((x :: xs) {fresh}).freshness) = fresh\n\n-- Freshness lemmata\nparameters (0 x : a) (ys : FreshVect (S l) a neq)\n public export\n 0 headFreshness : x # ys -> So (x `neq` head ys)\n\n public export\n 0 tailFreshness : x # ys -> x # (tail ys)\n\nheadFreshness x (y :: ys) freshness\n = fst (soAnd freshness)\ntailFreshness x (y :: ys) freshness\n = snd (soAnd freshness)\n\npublic export\ntake : (n : Nat) -> FreshVect (n + m) a neq -> FreshVect n a neq\npublic export\n0 takeFreshness : (n : Nat) -> (xs : FreshVect (n + m) a neq) -> y # xs -> y # take n {m} xs\n\ntake 0 xs = []\ntake (S n) ((x :: xs) {fresh}) = (x :: take n xs) {fresh = takeFreshness {m} n xs fresh}\n\ntakeFreshness 0 xs fresh = Oh\ntakeFreshness (S n) (x :: xs) fresh =\n let (y_neq_x, y_fresh_xs) = soAnd fresh in\n andSo (y_neq_x, takeFreshness n xs y_fresh_xs)\n\npublic export\ndrop : (n : Nat) -> FreshVect (n + m) a neq -> FreshVect m a neq\ndrop 0 xs = xs\ndrop (S n) (x :: xs) = drop n xs\n\n-- The Agda lib has more general takeWhile, dropWhile, filter\n-- involving decidable predicts, but we follow the Idris stdlib and\n-- use the special case for Bool\n\n-- public export\n-- takeWhile : (pred : a -> Bool) -> FreshVect l a neq -> (m ** FreshVect m a neq)\n-- public export\n-- 0 takeWhileFreshness : (pred : a -> Bool) -> (xs : FreshVect l a neq) ->\n-- y # xs -> y # (takeWhile pred xs).snd\n--\n-- takeWhile pred [] = (Z ** [])\n-- takeWhile pred ((x :: xs) {fresh}) = case pred x of\n-- True => let (n ** rec) = takeWhile pred xs\n-- ; res = (x :: rec) {fresh = takeWhileFreshness pred xs fresh} in\n-- (S n ** res)\n-- False => (Z ** [])\n\n-- takeWhileFreshness pred [] fresh\n-- = Oh\n-- takeWhileFreshness pred (x :: xs) fresh with (pred x)\n-- takeWhileFreshness pred (x :: xs) fresh | True\n-- = let (y_fresh_x, y_fresh_xs) = soAnd fresh in\n-- andSo (y_fresh_x, takeWhileFreshness pred xs y_fresh_xs)\n-- takeWhileFreshness pred (x :: xs) fresh | False\n-- = Oh\n--\n-- public export\n-- dropWhile : (pred : a -> Bool) -> FreshVect a neq -> FreshVect a neq\n--\n-- public export\n-- 0 dropWhileFreshness : (pred : a -> Bool) -> (xs : FreshVect a neq) ->\n-- y # xs -> y # dropWhile pred xs\n--\n--\n-- dropWhile pred [] = []\n-- dropWhile pred ((x :: xs) {fresh}) = case pred x of\n-- True => (x :: dropWhile pred xs) {fresh = dropWhileFreshness pred xs fresh}\n-- False => []\n--\n-- dropWhileFreshness pred [] fresh = Oh\n-- dropWhileFreshness pred (x :: xs) fresh with (pred x)\n-- dropWhileFreshness pred (x :: xs) fresh | False\n-- = Oh\n-- dropWhileFreshness pred (x :: xs) fresh | True\n-- = let (y_neq_x, y_fresh_xs) = soAnd fresh in\n-- andSo (y_neq_x, dropWhileFreshness pred xs y_fresh_xs)\n--\n-- public export\n-- filter : (pred : a -> Bool) -> FreshVect a neq -> FreshVect a neq\n-- public export\n-- 0 filterFreshness : (pred : a -> Bool) -> (xs : FreshVect a neq) ->\n-- y # xs -> y # filter pred xs\n--\n-- filter pred [] = []\n-- filter pred ((x :: xs) {fresh}) = case pred x of\n-- False => filter pred xs\n-- True => (x :: filter pred xs) {fresh = filterFreshness pred xs fresh}\n--\n-- filterFreshness pred [] fresh = Oh\n-- filterFreshness pred (x :: xs) fresh with (pred x)\n-- filterFreshness pred (x :: xs) fresh | False\n-- = let (y_neq_x, y_fresh_xs) = soAnd fresh in\n-- filterFreshness pred xs y_fresh_xs\n-- filterFreshness pred (x :: xs) fresh | True\n-- = let (y_neq_x, y_fresh_xs) = soAnd fresh in\n-- andSo (y_neq_x, filterFreshness pred xs y_fresh_xs)\n\n-- Todo: move `decSo : (b : Bool) -> Dec (So b)` to base\npublic export\ndecideFreshness : {neq : BRel a} ->\n (x : a) -> (ys : FreshVect l a neq) ->\n Dec (x # ys)\ndecideFreshness x ys with (x ## ys)\n decideFreshness x ys | True = Yes Oh\n decideFreshness x ys | False = No absurd\n\npublic export\nfoldl : (f : b -> a -> b) -> b -> FreshVect l a neq -> b\nfoldl f x [] = x\nfoldl f x (y :: ys) = foldl f (x `f` y) ys\n\npublic export\nfoldr : (f : a -> b -> b) -> b -> FreshVect l a neq -> b\nfoldr f x [] = x\nfoldr f x (val :: vals) = (val `f` foldr f x vals)\n\nnamespace String\n public export\n (##) : BRel String\n s ## t = (s /= t)\n\n", "meta": {"hexsha": "27372651fdfa76489e44e1d1c23c63972a15443e", "size": 7068, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "programs/permutations/src/FreshList.idr", "max_stars_repo_name": "andrevidela/dev-notes", "max_stars_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": "programs/permutations/src/FreshList.idr", "max_issues_repo_name": "andrevidela/dev-notes", "max_issues_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": "programs/permutations/src/FreshList.idr", "max_forks_repo_name": "andrevidela/dev-notes", "max_forks_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": 29.9491525424, "max_line_length": 92, "alphanum_fraction": 0.5836162988, "num_tokens": 2378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6069052788741184}} {"text": "module Data.Matrix.AlgebraicVerified\n\nimport Control.Algebra\nimport Control.Algebra.VectorSpace -- definition of module\nimport Classes.Verified -- definition of verified algebras other than modules\nimport Control.Algebra.DiamondInstances\nimport Data.Matrix\nimport Data.Matrix.Algebraic -- module instances; from Idris 0.9.20\n\nimport Data.Vect.Structural\n\n-- Style & syntax\nimport Syntax.PreorderReasoning\n\n-- Support\nimport Control.Algebra.DiamondInstances\n\n%default total\n\n\n\n{-\nDefinitions:\n* Verified module\n* Verified vector space\n\nRipped from comments of Classes.Verified, commenting out there coincides with definition of module being in the separate module Control.Algebra.VectorSpace from Control.Algebra.\n-}\n\n\n\nclass (VerifiedRingWithUnity a, VerifiedAbelianGroup b, Module a b) => VerifiedModule a b where\n total moduleScalarMultiplyComposition : (x,y : a) -> (v : b) -> x <#> (y <#> v) = (x <.> y) <#> v\n total moduleScalarUnityIsUnity : (v : b) -> unity {a} <#> v = v\n total moduleScalarMultDistributiveWRTVectorAddition : (s : a) -> (v, w : b) -> s <#> (v <+> w) = (s <#> v) <+> (s <#> w)\n total moduleScalarMultDistributiveWRTModuleAddition : (s, t : a) -> (v : b) -> (s <+> t) <#> v = (s <#> v) <+> (t <#> v)\n\n--class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}\n\n-- As desired in Data.Matrix.Algebraic\ninstance [vectModule] Module a b => Module a (Vect n b) where\n\t(<#>) r = map (r <#>)\n\n\n\n{-\nDefinitions:\n* Verified module instance for Matrix n m ZZ.\n* A verified module instance for Vect n ZZ will prevent you from writing one for Matrix,\n\tthe proof of which depends on (Vect n ZZ) being a (VerifiedModule) in all but name.\n-}\n\n\n\nsemigroupOpIsAssociative_Vect : (VerifiedRingWithUnity a) => (l, c, r : Vect n a) -> l <+> (c <+> r) = l <+> c <+> r\nsemigroupOpIsAssociative_Vect [] [] [] = Refl\nsemigroupOpIsAssociative_Vect (l::ls) (c::cs) (r::rs) = vecHeadtailsEq (semigroupOpIsAssociative _ _ _) (semigroupOpIsAssociative_Vect _ _ _)\n\nmonoidNeutralIsNeutralL_Vect : (VerifiedRingWithUnity a) => (l : Vect n a) -> l <+> Algebra.neutral = l\nmonoidNeutralIsNeutralL_Vect [] = Refl\nmonoidNeutralIsNeutralL_Vect (l::ls) = vecHeadtailsEq (monoidNeutralIsNeutralL _) $ monoidNeutralIsNeutralL_Vect _\n\nmonoidNeutralIsNeutralR_Vect : (VerifiedRingWithUnity a) => (r : Vect n a) -> Algebra.neutral <+> r = r\nmonoidNeutralIsNeutralR_Vect [] = Refl\nmonoidNeutralIsNeutralR_Vect (r::rs) = vecHeadtailsEq (monoidNeutralIsNeutralR _) $ monoidNeutralIsNeutralR_Vect _\n\ngroupInverseIsInverseL_Vect : (VerifiedRingWithUnity a) => (l : Vect n a) -> l <+> inverse l = Algebra.neutral\ngroupInverseIsInverseL_Vect [] = Refl\ngroupInverseIsInverseL_Vect (l::ls) = vecHeadtailsEq (groupInverseIsInverseL _) $ groupInverseIsInverseL_Vect _\n\ngroupInverseIsInverseR_Vect : (VerifiedRingWithUnity a) => (r : Vect n a) -> inverse r <+> r = Algebra.neutral\ngroupInverseIsInverseR_Vect [] = Refl\ngroupInverseIsInverseR_Vect (r::rs) = vecHeadtailsEq (groupInverseIsInverseR _) $ groupInverseIsInverseR_Vect _\n\nabelianGroupOpIsCommutative_Vect : (VerifiedRingWithUnity a) => (l, r : Vect n a) -> l <+> r = r <+> l\nabelianGroupOpIsCommutative_Vect [] [] = Refl\nabelianGroupOpIsCommutative_Vect (l::ls) (r::rs) = vecHeadtailsEq (abelianGroupOpIsCommutative _ _) $ abelianGroupOpIsCommutative_Vect _ _\n\nmoduleScalarMultiplyComposition_Vect : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> ( x, y : a ) -> ( v : Vect n a )\n\t-> x <#> (y <#> v) = x <.> y <#> v\nmoduleScalarMultiplyComposition_Vect x y [] = Refl\nmoduleScalarMultiplyComposition_Vect {ok} x y (v::vs) =\n\tvecHeadtailsEq\n\t\t(rewrite ok in ringOpIsAssociative x y v)\n\t$ moduleScalarMultiplyComposition_Vect x y vs\n\n{-\nThis doesn't exist because of a diamond inheritance problem.\n\nmoduleScalarUnityIsUnity_Vect : (VerifiedRingWithUnity a) => ( v : Vect n a ) -> (Algebra.unity {a=a}) <#> v = v\nmoduleScalarUnityIsUnity_Vect [] = Refl\nmoduleScalarUnityIsUnity_Vect (v::vs) = ?moduleScalarUnityIsUnity_Vect'\n\n---\n\nSo we use this instead,\nwhere the equality between (<.>)s coming from different instances is\nan automatically solved assumption.\n-}\n\nmoduleScalarUnityIsUnity_Vect : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> ( v : Vect n a )\n\t-> (Algebra.unity {a=a}) <#> v = v\nmoduleScalarUnityIsUnity_Vect [] = Refl\nmoduleScalarUnityIsUnity_Vect {ok} (v::vs) =\n\tvecHeadtailsEq (\n\t\ttrans (cong {f=\\t => t Algebra.unity v} ok)\n\t\t$ ringWithUnityIsUnityR v)\n\t$ moduleScalarUnityIsUnity_Vect vs\n\nmoduleScalarMultDistributiveWRTVectorAddition_Vect : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> (s : a) -> (v, w : Vect n a)\n\t-> s <#> v <+> w = (s <#> v) <+> (s <#> w)\nmoduleScalarMultDistributiveWRTVectorAddition_Vect s [] [] = Refl\nmoduleScalarMultDistributiveWRTVectorAddition_Vect {ok} s (v::vs) (w::ws) =\n\tvecHeadtailsEq\n\t\t(rewrite ok in ringOpIsDistributiveL s v w)\n\t$ moduleScalarMultDistributiveWRTVectorAddition_Vect s vs ws\n\nmoduleScalarMultDistributiveWRTModuleAddition_Vect : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> (s, t : a) -> (v : Vect n a)\n\t-> s <+> t <#> v = (s <#> v) <+> (t <#> v)\nmoduleScalarMultDistributiveWRTModuleAddition_Vect s t [] = Refl\nmoduleScalarMultDistributiveWRTModuleAddition_Vect {ok} s t (v::vs) =\n\tvecHeadtailsEq\n\t\t(rewrite ok in ringOpIsDistributiveR s t v)\n\t$ moduleScalarMultDistributiveWRTModuleAddition_Vect s t vs\n\n{-\ninstance (VerifiedRingWithUnity a) => VerifiedSemigroup (Vect n a) where\n\tsemigroupOpIsAssociative = ?semigroupOpIsAssociative_Vect\n\ninstance (VerifiedRingWithUnity a) => VerifiedMonoid (Vect n a) where {\n\tmonoidNeutralIsNeutralL = ?monoidNeutralIsNeutralL_Vect\n\tmonoidNeutralIsNeutralR = ?monoidNeutralIsNeutralR_Vect\n}\n\ninstance (VerifiedRingWithUnity a) => VerifiedGroup (Vect n a) where {\n\tgroupInverseIsInverseL = ?groupInverseIsInverseL_Vect\n\tgroupInverseIsInverseR = ?groupInverseIsInverseR_Vect\n}\n\ninstance (VerifiedRingWithUnity a) => VerifiedAbelianGroup (Vect n a) where {\n\tabelianGroupOpIsCommutative = ?abelianGroupOpIsCommutative_Vect\n}\n\ninstance (VerifiedRingWithUnity a) => VerifiedModule a (Vect n a) where {\n\tmoduleScalarMultiplyComposition = ?moduleScalarMultiplyComposition_Vect\n\tmoduleScalarUnityIsUnity = ?moduleScalarUnityIsUnity_Vect\n\tmoduleScalarMultDistributiveWRTVectorAddition = ?moduleScalarMultDistributiveWRTVectorAddition_Vect\n\tmoduleScalarMultDistributiveWRTModuleAddition = ?moduleScalarMultDistributiveWRTModuleAddition_Vect\n}\n-}\n\n\n\nsemigroupOpIsAssociative_Mat : (VerifiedRingWithUnity a) => (l, c, r : Matrix n m a) -> l <+> (c <+> r) = l <+> c <+> r\nsemigroupOpIsAssociative_Mat [] [] [] = Refl\nsemigroupOpIsAssociative_Mat (l::ls) (c::cs) (r::rs) = vecHeadtailsEq (semigroupOpIsAssociative_Vect _ _ _) (semigroupOpIsAssociative_Mat _ _ _)\n\nmonoidNeutralIsNeutralL_Mat : (VerifiedRingWithUnity a) => (l : Matrix n m a) -> l <+> Algebra.neutral = l\nmonoidNeutralIsNeutralL_Mat [] = Refl\nmonoidNeutralIsNeutralL_Mat (l::ls) = vecHeadtailsEq (monoidNeutralIsNeutralL_Vect _) $ monoidNeutralIsNeutralL_Mat _\n\nmonoidNeutralIsNeutralR_Mat : (VerifiedRingWithUnity a) => (r : Matrix n m a) -> Algebra.neutral <+> r = r\nmonoidNeutralIsNeutralR_Mat [] = Refl\nmonoidNeutralIsNeutralR_Mat (r::rs) = vecHeadtailsEq (monoidNeutralIsNeutralR_Vect _) $ monoidNeutralIsNeutralR_Mat _\n\ngroupInverseIsInverseL_Mat : (VerifiedRingWithUnity a) => (l : Matrix n m a) -> l <+> inverse l = Algebra.neutral\ngroupInverseIsInverseL_Mat [] = Refl\ngroupInverseIsInverseL_Mat (l::ls) = vecHeadtailsEq (groupInverseIsInverseL_Vect _) $ groupInverseIsInverseL_Mat _\n\ngroupInverseIsInverseR_Mat : (VerifiedRingWithUnity a) => (r : Matrix n m a) -> inverse r <+> r = Algebra.neutral\ngroupInverseIsInverseR_Mat [] = Refl\ngroupInverseIsInverseR_Mat (r::rs) = vecHeadtailsEq (groupInverseIsInverseR_Vect _) $ groupInverseIsInverseR_Mat _\n\nabelianGroupOpIsCommutative_Mat : (VerifiedRingWithUnity a) => (l, r : Matrix n m a) -> l <+> r = r <+> l\nabelianGroupOpIsCommutative_Mat [] [] = Refl\nabelianGroupOpIsCommutative_Mat (l::ls) (r::rs) = vecHeadtailsEq (abelianGroupOpIsCommutative_Vect _ _) $ abelianGroupOpIsCommutative_Mat _ _\n\nmoduleScalarMultiplyComposition_Mat : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> ( x, y : a ) -> ( v : Matrix n m a )\n\t-> x <#> (y <#> v) = x <.> y <#> v\nmoduleScalarMultiplyComposition_Mat x y [] = Refl\nmoduleScalarMultiplyComposition_Mat x y (v::vs) = vecHeadtailsEq (moduleScalarMultiplyComposition_Vect _ _ _) $ moduleScalarMultiplyComposition_Mat _ _ _\n\nmoduleScalarUnityIsUnity_Mat : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> ( v : Matrix n m a )\n\t-> (Algebra.unity {a=a}) <#> v = v\nmoduleScalarUnityIsUnity_Mat [] = Refl\nmoduleScalarUnityIsUnity_Mat (v::vs) = vecHeadtailsEq (moduleScalarUnityIsUnity_Vect _)\n\t$ moduleScalarUnityIsUnity_Mat _\n\nmoduleScalarMultDistributiveWRTVectorAddition_Mat : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> (s : a) -> (v, w : Matrix n m a)\n\t-> s <#> v <+> w = (s <#> v) <+> (s <#> w)\nmoduleScalarMultDistributiveWRTVectorAddition_Mat s [] [] = Refl\nmoduleScalarMultDistributiveWRTVectorAddition_Mat s (v::vs) (w::ws) = vecHeadtailsEq (moduleScalarMultDistributiveWRTVectorAddition_Vect _ _ _) $ moduleScalarMultDistributiveWRTVectorAddition_Mat _ _ _\n\nmoduleScalarMultDistributiveWRTModuleAddition_Mat : (VerifiedRingWithUnity a)\n\t=> {auto ok :\n\t\t((<.>) @{vrwuRingByRWU $ the (VerifiedRingWithUnity a) %instance})\n\t\t= ((<.>) @{vrwuRingByVR $ the (VerifiedRingWithUnity a) %instance})\n\t\t}\n\t-> (s, t : a) -> (v : Matrix n m a)\n\t-> s <+> t <#> v = (s <#> v) <+> (t <#> v)\nmoduleScalarMultDistributiveWRTModuleAddition_Mat s t [] = Refl\nmoduleScalarMultDistributiveWRTModuleAddition_Mat s t (v::vs) = vecHeadtailsEq (moduleScalarMultDistributiveWRTModuleAddition_Vect _ _ _) $ moduleScalarMultDistributiveWRTModuleAddition_Mat _ _ _\n\n\ninstance (VerifiedRingWithUnity a) => VerifiedSemigroup (Matrix n m a) where\n\tsemigroupOpIsAssociative = semigroupOpIsAssociative_Mat\n\ninstance (VerifiedRingWithUnity a) => VerifiedMonoid (Matrix n m a) where {\n\tmonoidNeutralIsNeutralL = monoidNeutralIsNeutralL_Mat\n\tmonoidNeutralIsNeutralR = monoidNeutralIsNeutralR_Mat\n}\n\ninstance (VerifiedRingWithUnity a) => VerifiedGroup (Matrix n m a) where {\n\tgroupInverseIsInverseL = groupInverseIsInverseL_Mat\n\tgroupInverseIsInverseR = groupInverseIsInverseR_Mat\n}\n\ninstance (VerifiedRingWithUnity a) => VerifiedAbelianGroup (Matrix n m a) where {\n\tabelianGroupOpIsCommutative = abelianGroupOpIsCommutative_Mat\n}\n\n\n\n{-\nTrivial identities about (unital) rings.\n-}\n\n\n\n-- Actually theorems about quasigroups\ngroupOpIsCancellativeL : VerifiedGroup a => (left, right1, right2 : a) -> left<+>right1 = left<+>right2 -> right1=right2\ngroupOpIsCancellativeL left right1 right2 pr = trans (sym $ trans (cong {f=(<+>right1)} $ groupInverseIsInverseR left) $ monoidNeutralIsNeutralR right1) $ trans (trans (sym $ semigroupOpIsAssociative (inverse left) left right1) $ trans (cong {f=((inverse left)<+>)} pr) $ semigroupOpIsAssociative (inverse left) left right2) $ trans (cong {f=(<+>right2)} $ groupInverseIsInverseR left) $ monoidNeutralIsNeutralR right2\n\ngroupOpIsCancellativeR : VerifiedGroup a => (left1, left2, right : a) -> left1<+>right = left2<+>right -> left1=left2\ngroupOpIsCancellativeR left1 left2 right pr = trans (sym $ trans (cong {f=(left1<+>)} $ groupInverseIsInverseL right) $ monoidNeutralIsNeutralL left1) $ trans (trans (semigroupOpIsAssociative left1 right (inverse right)) $ trans (cong {f=(<+>(inverse right))} pr) $ sym $ semigroupOpIsAssociative left2 right (inverse right)) $ trans (cong {f=(left2<+>)} $ groupInverseIsInverseL right) $ monoidNeutralIsNeutralL left2\n\ngroupOpIsCancellativeL_Vect : VerifiedRingWithUnity a =>\n\t(left, right1, right2 : Vect n a)\n\t-> left<+>right1 = left<+>right2 -> right1=right2\ngroupOpIsCancellativeL_Vect left right1 right2 pr =\n\ttrans (sym $ trans (cong {f=(<+>right1)} $ groupInverseIsInverseR_Vect left)\n\t\t$ monoidNeutralIsNeutralR_Vect right1)\n\t$ trans (trans (sym $ semigroupOpIsAssociative_Vect (inverse left) left right1)\n\t\t$ trans (cong {f=((inverse left)<+>)} pr)\n\t\t$ semigroupOpIsAssociative_Vect (inverse left) left right2)\n\t$ trans (cong {f=(<+>right2)} $ groupInverseIsInverseR_Vect left)\n\t$ monoidNeutralIsNeutralR_Vect right2\n\ngroupOpIsCancellativeR_Vect : VerifiedRingWithUnity a =>\n\t(left1, left2, right : Vect n a)\n\t-> (left1 <+> right = left2 <+> right) -> left1 = left2\ngroupOpIsCancellativeR_Vect left1 left2 right pr =\n\ttrans (sym $ trans (cong {f=(left1<+>)} $ groupInverseIsInverseL_Vect right)\n\t\t$ monoidNeutralIsNeutralL_Vect left1)\n\t$ trans (trans (semigroupOpIsAssociative_Vect left1 right (inverse right))\n\t\t$ trans (cong {f=(<+>(inverse right))} pr)\n\t\t$ sym $ semigroupOpIsAssociative_Vect left2 right (inverse right))\n\t$ trans (cong {f=(left2<+>)} $ groupInverseIsInverseL_Vect right)\n\t$ monoidNeutralIsNeutralL_Vect left2\n\n-- Not used for the below, but for elsewhere.\nneutralSelfInverse : VerifiedGroup a => inverse $ the a $ Algebra.neutral = the a $ Algebra.neutral\nneutralSelfInverse = groupOpIsCancellativeL _ _ _ $ trans (groupInverseIsInverseL _) $ sym $ monoidNeutralIsNeutralL _\n\ngroupElemOwnDoubleImpliesNeut : VerifiedGroup a => (x : a) -> x<+>x=x -> x = Algebra.neutral\ngroupElemOwnDoubleImpliesNeut x pr = groupOpIsCancellativeL x x Algebra.neutral $ trans pr $ sym $ monoidNeutralIsNeutralL x\n\ngroupSubtractionIsRDivision : VerifiedGroup t\n\t=> {auto ok :\n\t\t((<+>) @{vgrpSemigroupByGrp $ the (VerifiedGroup t) %instance})\n\t\t= ((<+>) @{vgrpSemigroupByVMon $ the (VerifiedGroup t) %instance})\n\t\t}\n\t-> (a, b : t)\n\t-> (a <-> b) <+> b = a\ngroupSubtractionIsRDivision {ok} a b = rewrite ok in\n\ttrans (sym $ semigroupOpIsAssociative a (inverse b) b)\n\t$ trans (cong $ groupInverseIsInverseR b)\n\t$ monoidNeutralIsNeutralL a\n\ngroupSubtractionIsRDivision_Vect : VerifiedGroup t\n\t=> {auto ok :\n\t\t((<+>) @{vgrpSemigroupByGrp $ the (VerifiedGroup t) %instance})\n\t\t= ((<+>) @{vgrpSemigroupByVMon $ the (VerifiedGroup t) %instance})\n\t\t}\n\t-> (a, b : Vect n t)\n\t-> (a <-> b) <+> b = a\ngroupSubtractionIsRDivision_Vect [] [] = Refl\ngroupSubtractionIsRDivision_Vect (a::as) (b::bs)\n\t= vecHeadtailsEq (groupSubtractionIsRDivision a b)\n\t$ groupSubtractionIsRDivision_Vect as bs\n\ngroupDivisionAddLToSubR : VerifiedGroup t\n\t=> {auto ok :\n\t\t((<+>) @{vgrpSemigroupByGrp $ the (VerifiedGroup t) %instance})\n\t\t= ((<+>) @{vgrpSemigroupByVMon $ the (VerifiedGroup t) %instance})\n\t\t}\n\t-> (x, y, z : t)\n\t-> x <+> y = z\n\t-> x = z <-> y\ngroupDivisionAddLToSubR {ok} x y z pr\n\t= groupOpIsCancellativeR x (z <-> y) y\n\t$ trans pr\n\t$ sym $ groupSubtractionIsRDivision {ok=ok} z y\n\ninverseIsInvolution : VerifiedGroup t\n\t=> (r : t)\n\t-> inverse $ inverse r = r\ninverseIsInvolution r = groupOpIsCancellativeR (inverse $ inverse r) r (inverse r)\n\t$ trans (groupInverseIsInverseR _)\n\t$ sym $ groupInverseIsInverseL _\n\n\n\nringNeutralIsMultZeroL : VerifiedRing a => (x : a) -> Algebra.neutral <.> x = Algebra.neutral\nringNeutralIsMultZeroL x = groupElemOwnDoubleImpliesNeut (Algebra.neutral <.> x) $ trans (sym $ ringOpIsDistributiveR Algebra.neutral Algebra.neutral x) $ cong {f=(<.>x)} $ monoidNeutralIsNeutralL Algebra.neutral\n\nringNeutralIsMultZeroR : VerifiedRing a => (x : a) -> x <.> Algebra.neutral = Algebra.neutral\nringNeutralIsMultZeroR x = groupElemOwnDoubleImpliesNeut (x <.> Algebra.neutral) $ trans (sym $ ringOpIsDistributiveL x Algebra.neutral Algebra.neutral) $ cong {f=(x<.>)} $ monoidNeutralIsNeutralL Algebra.neutral\n\nringNegationCommutesWithLeftMult : VerifiedRing a => (left, right : a) -> left<.>(inverse right) = inverse $ left<.>right\nringNegationCommutesWithLeftMult left right = groupOpIsCancellativeR (left<.>(inverse right)) (inverse $ left<.>right) (left<.>right) $ trans (trans (sym $ ringOpIsDistributiveL left (inverse right) right) $ trans (cong {f=(left<.>)} $ groupInverseIsInverseR right) $ ringNeutralIsMultZeroR left) $ sym $ groupInverseIsInverseR $ left<.>right\n\nringNegationCommutesWithRightMult : VerifiedRing a => (left, right : a) -> (inverse left)<.>right = inverse $ left<.>right\nringNegationCommutesWithRightMult left right = groupOpIsCancellativeR ((inverse left)<.>right) (inverse $ left<.>right) (left<.>right) $ trans (trans (sym $ ringOpIsDistributiveR (inverse left) left right) $ trans (cong {f=(<.>right)} $ groupInverseIsInverseR left) $ ringNeutralIsMultZeroL right) $ sym $ groupInverseIsInverseR $ left<.>right\n\nringNegationCancelsWithMult : VerifiedRing t\n\t=> (x, y : t) -> inverse x <.> inverse y = x <.> y\nringNegationCancelsWithMult x y =\n\ttrans (ringNegationCommutesWithRightMult x (inverse y))\n\t$ trans (cong {f=inverse} $ ringNegationCommutesWithLeftMult x y)\n\t$ inverseIsInvolution (x <.> y)\n\nringOpIsDistributiveSubR : VerifiedRing a\n\t=> {auto ok :\n\t\t((<+>) @{vrSemigroupByGrp $ the (VerifiedRing a) %instance})\n\t\t= ((<+>) @{vrSemigroupByVMon $ the (VerifiedRing a) %instance})\n\t\t}\n\t-> (l, c, r : a)\n\t-> (l <-> c) <.> r = l <.> r <-> c <.> r\nringOpIsDistributiveSubR {ok} l c r =\n\t( (l <-> c) <.> r )\n\t\t={ rewrite ok in Refl }=\n\t( (l <+> inverse c) <.> r )\n\t\t={ ringOpIsDistributiveR l (inverse c) r }=\n\t( l <.> r <+> (inverse c) <.> r )\n\t\t={ rewrite sym ok\n\t\t\tin cong $ ringNegationCommutesWithRightMult c r }=\n\t( l <.> r <-> c <.> r )\n\t\tQED\n-- (but true by divisibility of addition even without associativity)\n\nringOpIsDistributiveSubL : VerifiedRing a\n\t=> {auto ok :\n\t\t((<+>) @{vrSemigroupByGrp $ the (VerifiedRing a) %instance})\n\t\t= ((<+>) @{vrSemigroupByVMon $ the (VerifiedRing a) %instance})\n\t\t}\n\t-> (l, c, r : a)\n\t-> l <.> (c <-> r) = l <.> c <-> l <.> r\nringOpIsDistributiveSubL {ok} l c r =\n\ttrans (rewrite ok in ringOpIsDistributiveL l c (inverse r))\n\t$ rewrite sym ok in cong $ ringNegationCommutesWithLeftMult l r\n-- (but true by divisibility of addition even without associativity)\n", "meta": {"hexsha": "823f574108dc0c6c5ae692d8c60574a654a697b9", "size": 18700, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Matrix/AlgebraicVerified.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": "Data/Matrix/AlgebraicVerified.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": "Data/Matrix/AlgebraicVerified.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": 46.9849246231, "max_line_length": 418, "alphanum_fraction": 0.728342246, "num_tokens": 6116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6068640286654498}} {"text": "module Tensor\n\n-- Based on https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/aplicative.pdf\nimport src.GenericArity\nimport Data.Vect\nimport Data.HVect\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\ntoVectT' : Vect n Nat -> Type -> Type\ntoVectT' [] a = a\ntoVectT' (x :: xs) a = Vect x (toVectT' xs 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\nfinToInt : Fin n -> Int\nfinToInt FZ = 0\nfinToInt (FS k) = 1 + finToInt k\n\nindex' : {xs : Vect n Nat} -> HVect (map (\\n => Fin n) xs) -> toVectT' xs a -> a\nindex' {xs = []} [] x = x\nindex' {xs = (x :: xs)} (fin :: fins) vs = index' fins (Data.Vect.index fin vs)\n\nindex : Fin n -> Fin m -> Vect n (Vect m a) -> a\nindex {n} {m} fn fm xss = index' {xs = [n, m]} [fn, fm] xss\n\npositions' : (n : Nat) -> Vect n (Fin n)\npositions' Z = []\npositions' (S n) = FZ :: map FS (positions' n)\n\ntabulate' : {xs : Vect n Nat} -> (Arrows n (map (\\n => Fin n) xs) a) -> toVectT' xs a\ntabulate' {n = Z} {xs = []} x = x\ntabulate' {n = S n} {xs = (x :: xs)} f = [tabulate' (f fn) | fn <- positions' x]\n\ntabulate : (Fin n -> a) -> Vect n a\ntabulate {n} f = tabulate' {xs = [n]} f\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": "2ccbb633429432382a880e2ae93def494a1d7132", "size": 2797, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Tensor.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/Tensor.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/Tensor.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": 31.0777777778, "max_line_length": 85, "alphanum_fraction": 0.5609581695, "num_tokens": 1059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6068148520030454}} {"text": "-- pass parameters in bulk to types and functions\n\nmodule ParameterisedBlocks\n\nimport Data.Vect\n\nparameters (x: Nat, y : Nat) \n addAll : Nat -> Nat\n addAll z = x + y + z\n\nparameters (y : Nat, xs : Vect x a)\n data Vects : Type -> Type where\n MkVects : Vect y a -> Vects a\n\n append : Vects a -> Vect (x + y) a\n append (MkVects ys) = xs ++ ys\n\n\n\n", "meta": {"hexsha": "c2f4cf169ff434e8311d0211e6c5f8638fc90e00", "size": 351, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "modules_and_namespaces/ParameterisedBlocks.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": "modules_and_namespaces/ParameterisedBlocks.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": "modules_and_namespaces/ParameterisedBlocks.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": 17.55, "max_line_length": 49, "alphanum_fraction": 0.6239316239, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6068148493476632}} {"text": "module Linear.Vect\n\nimport Data.List\nimport Data.Vect\n\ninfixl 6 ^+^, ^-^\ninfixl 7 ^*, *^, ^/\n\npublic export\nV2 : a -> a -> Vect 2 a\nV2 x y = x :: y :: Nil\n\npublic export\nV3 : a -> a -> a -> Vect 3 a\nV3 x y z = x :: y :: z :: Nil\n\npublic export\nV4 : a -> a -> a -> a -> Vect 4 a\nV4 a b c d = a :: b :: c :: d :: Nil\n\npublic export\nimplementation Semigroup a => Semigroup (Vect n a) where\n (<+>) = zipWith (<+>)\n\npublic export\nimplementation {n : Nat} -> Monoid a => Monoid (Vect n a) where\n neutral = pure neutral\n\npublic export\nimplementation {n : Nat} -> Num a => Num (Vect n a) where\n (+) = zipWith (+)\n (*) = zipWith (*)\n fromInteger = pure . fromInteger\n\n||| Compute the negation of a vector\n|||\n||| ```idris example\n||| negated (V2 2 4)\n||| ```\nexport\nnegated : (Functor f, Neg a) => f a -> f a\nnegated = map negate\n\n||| Compute the left scalar product\n|||\n||| ```idris example\n||| 2 *^ V2 3 4\n||| ```\nexport\n(*^) : (Functor f, Neg a) => a -> f a -> f a\n(*^) a = map (a *)\n\n||| Compute the right scalar product\n|||\n||| ```idris example\n||| the (Vect ? ?) [3, 4] ^* 2\n||| ```\nexport\n(^*) : (Functor f, Neg a) => f a -> a -> f a\nf ^* a = map (* a) f\n\n||| Compute division by a scalar on the right.\nexport\n(^/) : (Functor f, Fractional a) => f a -> a -> f a\nf ^/ a = map (/a) f\n\npublic export\ninterface Functor f => Additive f where\n ||| The zero vector\n zero : Num a => f a\n\n ||| Compute the sum of two vectors\n |||\n ||| ```idris example\n ||| V2 1 2 ^+^ V2 3 4\n (^+^) : Num a => f a -> f a -> f a\n (^+^) = liftU2 (+)\n\n ||| Compute the difference between two vectors\n |||\n ||| ```idris example\n ||| V2 4 5 ^-^ V2 3 1\n ||| ```\n (^-^) : Neg a => f a -> f a -> f a\n x ^-^ y = x ^+^ negated y\n\n ||| Linearly interpolate between two vectors.\n lerp : Neg a => a -> f a -> f a -> f a\n lerp alpha u v = alpha *^ u ^+^ (1 - alpha) *^ v\n\n ||| Apply a function to merge the 'non-zero' components of two vectors, unioning the rest of the values.\n |||\n ||| * For a dense vector this is equivalent to 'liftA2'.\n |||\n ||| * For a sparse vector this is equivalent to 'unionWith'.\n liftU2 : (a -> a -> a) -> f a -> f a -> f a\n\n ||| Apply a function to the components of two vectors.\n |||\n ||| * For a dense vector this is equivalent to 'liftA2'.\n |||\n ||| * For a sparse vector this is equivalent to 'intersectionWith'.\n liftI2 : (a -> b -> c) -> f a -> f b -> f c\n\n||| Sum over multiple vectors\n|||\n||| ```idris example\n||| sumV [V2 1 1, V2 3 4]\n||| ```\nexport\nsumV : (Foldable f, Additive v, Num a) => f (v a) -> v a\nsumV = foldl (^+^) zero\n\npublic export\ninterface (Num a, Fractional a, Cast a Double, Cast Double a) => Floating a where\n\nliftA2 : Applicative f => (a -> b -> c) -> f a -> f b -> f c\nliftA2 f x = (<*>) (map f x)\n\npublic export\nimplementation Applicative f => Additive f where\n zero = pure 0\n liftU2 = liftA2\n liftI2 = liftA2\n\npublic export\nimplementation Additive Maybe where\n zero = Nothing\n liftU2 f (Just a) (Just b) = Just (f a b)\n liftU2 _ Nothing ys = ys\n liftU2 _ xs Nothing = xs\n liftI2 = liftA2\n\n{-\n||| Produce a default basis for a vector space from which the\n||| argument is drawn.\nbasisFor : (Traversable t, Num a) => t b -> List (t a)\n-- basisFor = \\t ->\n-- ifoldMapOf traversed ?? t $ \\i _ ->\n-- return $\n-- iover traversed ?? t $ \\j _ ->\n-- if i == j then 1 else 0\n\nbasis : (Additive t, Traversable t, Num a) => List (t a)\nbasis = basisFor zero'\n where\n zero' : Additive v => v Int\n zero' = zero\n\nscaled : (Traversable t, Num a) => t a -> t (t a)\n\nunit : (Additive t, Num a) => ASetter' (t a) a -> t a\n-}\n\n||| Outer (tensor) product of two vectors\nexport\nouter : (Functor f, Functor g, Num a) => f a -> g a -> f (g a)\nouter a b = map (\\x => map (*x) b) a\n", "meta": {"hexsha": "a2cb437cc8a19f62387668eaee612703ee50e7ce", "size": 3766, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Linear/Vect.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/Vect.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/Vect.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": 23.6855345912, "max_line_length": 106, "alphanum_fraction": 0.5597450876, "num_tokens": 1343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6068148362163224}} {"text": "module SQLiteTypes\n\nimport Decidable.Equality\n\n%default total\n\n\npublic export data SQLiteType = TEXT | INTEGER | REAL\n | NULLABLE SQLiteType\n\npublic export interpSql : SQLiteType -> Type\ninterpSql TEXT = String\ninterpSql INTEGER = Integer\ninterpSql REAL = Double\ninterpSql (NULLABLE x) = Maybe (interpSql x)\n\nequalSql : (t : SQLiteType) -> (x, y : interpSql t) -> Bool\nequalSql TEXT x y = x == y\nequalSql INTEGER x y = x == y\nequalSql REAL x y = x == y\nequalSql (NULLABLE ty) (Just x) (Just y) = equalSql ty x y\nequalSql (NULLABLE ty) Nothing Nothing = True\nequalSql (NULLABLE ty) _ _ = False\n\nexport showSql : (t : SQLiteType) -> (x : interpSql t) -> String\nshowSql TEXT x = show x\nshowSql INTEGER x = show x\nshowSql REAL x = show x\nshowSql (NULLABLE ty) (Just x) = showSql ty x\nshowSql (NULLABLE ty) Nothing = \"null\"\n\n\nintegerNotText : INTEGER = TEXT -> Void\nintegerNotText Refl impossible\n\nrealNotText : REAL = TEXT -> Void\nrealNotText Refl impossible\n\nnullableNotText : NULLABLE t = TEXT -> Void\nnullableNotText Refl impossible\n\nrealNotInteger : REAL = INTEGER -> Void\nrealNotInteger Refl impossible\n\nnullableNotInteger : NULLABLE t = INTEGER -> Void\nnullableNotInteger Refl impossible\n\nnullableNotReal : NULLABLE t = REAL -> Void\nnullableNotReal Refl impossible\n\nexport implementation DecEq SQLiteType where\n decEq TEXT TEXT = Yes Refl\n decEq INTEGER TEXT = No integerNotText\n decEq REAL TEXT = No realNotText\n decEq (NULLABLE x) TEXT = No nullableNotText\n decEq TEXT INTEGER = No $ integerNotText . sym\n decEq INTEGER INTEGER = Yes Refl\n decEq REAL INTEGER = No realNotInteger\n decEq (NULLABLE x) INTEGER = No nullableNotInteger\n decEq TEXT REAL = No $ realNotText . sym\n decEq INTEGER REAL = No $ realNotInteger . sym\n decEq REAL REAL = Yes Refl\n decEq (NULLABLE x) REAL = No nullableNotReal\n decEq TEXT (NULLABLE x) = No $ nullableNotText . sym\n decEq INTEGER (NULLABLE x) = No $ nullableNotInteger . sym\n decEq REAL (NULLABLE x) = No $ nullableNotReal . sym\n decEq (NULLABLE y) (NULLABLE x) with (decEq y x)\n decEq (NULLABLE x) (NULLABLE x) | (Yes Refl) = Yes Refl\n decEq (NULLABLE y) (NULLABLE x) | (No prf) = No $ prf . inside\n where inside : NULLABLE a = NULLABLE b -> a = b\n inside Refl = Refl\n", "meta": {"hexsha": "2f0a1a7a6e2e8f0235f074cbdf3c5a4b2ab73dfe", "size": 2353, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type-provider/SQLiteTypes.idr", "max_stars_repo_name": "ethansr/IdrisSqlite", "max_stars_repo_head_hexsha": "72a3c934401ccc08f27cd1ea32e4beedc994de65", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2015-01-22T10:54:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:18:05.000Z", "max_issues_repo_path": "type-provider/SQLiteTypes.idr", "max_issues_repo_name": "ethansr/IdrisSqlite", "max_issues_repo_head_hexsha": "72a3c934401ccc08f27cd1ea32e4beedc994de65", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-09-20T17:40:14.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-07T20:03:24.000Z", "max_forks_repo_path": "type-provider/SQLiteTypes.idr", "max_forks_repo_name": "ethansr/IdrisSqlite", "max_forks_repo_head_hexsha": "72a3c934401ccc08f27cd1ea32e4beedc994de65", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-09-30T20:53:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-07T13:41:23.000Z", "avg_line_length": 32.6805555556, "max_line_length": 66, "alphanum_fraction": 0.6872078198, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6066398584101446}} {"text": "module ExtEq\n\ninfix 9 =~=\n\n-- Universal (of any order) extensional equality\npublic export\n(=~=) : {ty : Type} -> ty -> ty -> Type\n(=~=) {ty = s -> _} a b = (x : s) -> a x =~= b x\n(=~=) a b = a = b\n\npublic export\ninterface Functor m => FunctorExt m where\n 0 map_ext : {f, g : a -> b} -> f =~= g -> map {f=m} f =~= map g\n\nexport\nFunctorExt List where\n map_ext fg [] = ?foo_1\n map_ext fg (x::xs) = let fgx = fg x\n sub = map_ext fg xs in\n ?foo_2\n", "meta": {"hexsha": "e98576be960aa525fc8ceab51ec7cdb30a7ef62d", "size": 522, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ExtEq.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": "ExtEq.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": "ExtEq.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": 24.8571428571, "max_line_length": 65, "alphanum_fraction": 0.4731800766, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.6757646010190476, "lm_q1q2_score": 0.6066307027571659}} {"text": "module CFT\n\nimport Data.List\nimport Data.Fin\nimport Data.Maybe\nimport Data.Nat\nimport Data.Vect\n\ninfixr 1 ~>\n\nnamespace Telescope\n\n public export\n data Tel : Nat -> (f : Nat -> Type) -> Type where\n Nil : Tel 0 f\n (::) : (t : f n) -> Tel n f -> Tel (S n) f\n\npublic export\ndata CFT : Nat -> Type where\n --- variables\n VZ : CFT (S n)\n VS : CFT n -> CFT (S n)\n\n -- Void\n Zero : CFT n\n\n -- Unit\n One : CFT n\n\n -- fixpoint\n Mu : CFT (S n) -> CFT n\n\n -- Algebraic definitions\n (+) : (a, b : CFT n) -> CFT n\n (*) : (a, b : CFT n) -> CFT n\n -- (~>) : (a, b : CFT n) -> CFT n\n App : CFT (S n) -> CFT n -> CFT n\n\n%inline\npublic export\nµ : CFT (S n) -> CFT n\nµ = Mu\n\npublic export\nvar : Fin n -> CFT n\nvar FZ = VZ\nvar (FS x) = VS (var x)\n\npublic export\nTyFromNat : Nat -> CFT n\nTyFromNat 0 = Zero\nTyFromNat (S k) = One + TyFromNat k\n\ninterface Universe u where\n El : u -> Type\n\npublic export\ndata Ty : CFT n -> Tel n CFT -> Type where\n Top : Ty t t' -> Ty VZ (t :: t')\n Pop : Ty t t' -> Ty (VS t) (s :: t')\n Left : Ty s t' -> Ty (s + t) t'\n Right : Ty t t' -> Ty (s + t) t'\n Def : Ty f (a :: t) -> Ty (App f a) t\n -- Fun : {k : CFT n} -> (k -> Ty t t') -> Ty (k ~> t) t'\n Unit : Ty One t\n Pair : Ty s t' -> Ty t t' -> Ty (s * t) t'\n In : Ty f (Mu f :: t') -> Ty (Mu f) t'\n\ndata Morph : (s, t : Tel n f) -> Type where\n\n ML : Morph s s\n\n MF : (f : Ty s s' -> Ty t t')\n -> (phi : Morph s' t')\n ----------------------------\n -> Morph (s :: s') (t :: t')\n\n Mµ : Morph s' t' -> Morph (t :: s') (t :: t')\n\ngMap : Morph s' t' -> Ty t s' -> Ty t t'\ngMap ML (Top x) = Top x\ngMap (MF f phi) (Top x) = Top (f x)\ngMap (Mµ phi) (Top x) = Top (gMap phi x)\ngMap ML (Pop x) = Pop x\ngMap (MF f phi) (Pop x) = Pop (gMap phi x)\ngMap (Mµ phi) (Pop x) = Pop (gMap phi x)\ngMap phi (Left x) = Left (gMap phi x)\ngMap phi (Right x) = Right (gMap phi x)\ngMap phi (Def x) = Def (gMap (Mµ phi) x)\ngMap phi Unit = Unit\ngMap phi (Pair x y) = Pair (gMap phi x) (gMap phi y)\ngMap phi (In x) = In (gMap (Mµ phi) x)\n\n", "meta": {"hexsha": "04901cb7b81b7acc450050294f4be7807f542719", "size": 2088, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "programs/CFT/src/CFT.idr", "max_stars_repo_name": "andrevidela/dev-notes", "max_stars_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": "programs/CFT/src/CFT.idr", "max_issues_repo_name": "andrevidela/dev-notes", "max_issues_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": "programs/CFT/src/CFT.idr", "max_forks_repo_name": "andrevidela/dev-notes", "max_forks_repo_head_hexsha": "baa6e10e4123ce785ae0ad402e86893306d94ecf", "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": 22.2127659574, "max_line_length": 59, "alphanum_fraction": 0.4942528736, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.6757646075489392, "lm_q1q2_score": 0.6066306993711824}} {"text": "module ArithExp.Types\n\nimport ArithExp.AST\nimport ArithExp.SmallStep\n\n||| Types for the ArithBool language\ndata SimpleType = TBool | TNum\n\n-- syntax to make writing out types more natural.\nsyntax \"[\" [x] \":\" [t] \"]\" = TypeOf x t\n\n||| The ArithBool typing relation. There is no need to include a `gamma`-like\n||| parameter here, as we don't have any variables.\ndata TypeOf : ArithBool -> SimpleType -> Type where\n ZeroT : [ Zero : TNum ]\n SuccT : [ n : TNum ] -> [ (Succ n) : TNum ]\n PredT : [ n : TNum ] -> [ (Pred n) : TNum ]\n TruT : [ Tru : TBool ]\n FalsT : [ Fals : TBool ]\n IfT : [ c : TBool ] -> [ tcase : a ] -> [ fcase : a ]\n -> [ (IF c tcase fcase) : a ]\n IsZeroT : [ n : TNum ] -> [ (IsZero n) : TBool ]\n\n||| Predicate for values in the language. Needed for defining progress\ndata IsValue : ArithBool -> Type where\n NumsValues : NV s -> IsValue s\n TruValue : IsValue Tru\n FalsValue : IsValue Fals\n\n-- Boilerplate uninhabitted instances needed below.\n--\n-- These were all generated automatically with the idris-specific commands in\n-- my editor, so the compiler should be able to infer it in principle. These\n-- first two instances are just proofs that booleans cannot be typed as numbers.\nUninhabited [Fals : TNum] where\n uninhabited ZeroT impossible\n uninhabited (SuccT _) impossible\n uninhabited (PredT _) impossible\n uninhabited TruT impossible\n uninhabited FalsT impossible\n uninhabited (IfT _ _ _) impossible\n uninhabited (IsZeroT _) impossible\n\nUninhabited [Tru : TNum] where\n uninhabited ZeroT impossible\n uninhabited (SuccT _) impossible\n uninhabited (PredT _) impossible\n uninhabited TruT impossible\n uninhabited FalsT impossible\n uninhabited (IfT _ _ _) impossible\n uninhabited (IsZeroT _) impossible\n\n||| Numbers are not booleans\nboolNotNum : [c : TBool] -> NV c -> Void\nboolNotNum TruT NvZero impossible\nboolNotNum TruT (NvSucc _) impossible\nboolNotNum FalsT NvZero impossible\nboolNotNum FalsT (NvSucc _) impossible\nboolNotNum (IfT _ _ _) NvZero impossible\nboolNotNum (IfT _ _ _) (NvSucc _) impossible\nboolNotNum (IsZeroT _) NvZero impossible\nboolNotNum (IsZeroT _) (NvSucc _) impossible\n\n||| Preservation lemma for type soundness\npreservation : (a =>> b) -> [a : t] -> [b : t]\npreservation IfTrue (IfT x y z) = y\npreservation IfFalse (IfT x y z) = z\npreservation (IfStep x) (IfT y z w) = IfT (preservation x y) z w\npreservation (SuccStep x) (SuccT y) = SuccT (preservation x y)\npreservation (IsZeroStep x) (IsZeroT y) = IsZeroT (preservation x y)\npreservation IsZeroZero (IsZeroT x) = TruT\npreservation IsZeroSucc (IsZeroT x) = FalsT\npreservation (PredStep x) (PredT y) = PredT (preservation x y)\npreservation PredZero (PredT x) = ZeroT\npreservation PredSucc (PredT (SuccT x)) = x\n\n||| Progress lemma for type soundness.\n|||\n||| This was more difficult to write, mostly because there are more cases\n||| to consider. Each individual case is fairly straight-forward, so some\n||| elaborator reflection should be able to automate this.\nprogress : [a : t] -> Either (IsValue a) (b ** (a =>> b))\nprogress ZeroT = Left (NumsValues NvZero)\nprogress (SuccT x) = case progress x of\n Left (NumsValues nv) => Left $ NumsValues (NvSucc nv)\n -- booleans are not numbers\n Left TruValue => absurd x\n Left FalsValue => absurd x\n Right (red ** step) => Right ((Succ red) ** (SuccStep step))\nprogress (PredT x) =\n case progress x of\n Left (NumsValues NvZero) => Right (Zero ** PredZero)\n Left (NumsValues (NvSucc k {n=n})) => Right (n ** PredSucc {prf=k})\n Left TruValue => absurd x\n Left FalsValue => absurd x\n Right (red ** step) => Right ((Pred red) ** (PredStep step))\nprogress TruT = Left TruValue\nprogress FalsT = Left FalsValue\nprogress (IfT {tcase=tcase} {fcase=fcase} x y z) =\n case progress x of\n Left TruValue => Right (tcase ** IfTrue)\n Left FalsValue => Right (fcase ** IfFalse)\n Left (NumsValues nv) => absurd (boolNotNum x nv)\n Right (red ** step) => Right ((IF red tcase fcase) ** IfStep step)\nprogress (IsZeroT x) =\n case progress x of\n Left TruValue => absurd x\n Left FalsValue => absurd x\n Left (NumsValues NvZero) => Right (Tru ** IsZeroZero)\n Left (NumsValues (NvSucc k)) => Right (Fals ** IsZeroSucc)\n Right (red ** step) => Right (IsZero red ** IsZeroStep step)\n", "meta": {"hexsha": "1c42db26b75b8e863380c7db8ca7a746d3c08580", "size": 4594, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ArithExp/Types.idr", "max_stars_repo_name": "ezrosent/TAPL-idris", "max_stars_repo_head_hexsha": "edc7b1383456aaf4a47588ae2a4e5b48199be972", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-21T09:47:00.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-21T15:37:15.000Z", "max_issues_repo_path": "ArithExp/Types.idr", "max_issues_repo_name": "ezrosent/TAPL-idris", "max_issues_repo_head_hexsha": "edc7b1383456aaf4a47588ae2a4e5b48199be972", "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": "ArithExp/Types.idr", "max_forks_repo_name": "ezrosent/TAPL-idris", "max_forks_repo_head_hexsha": "edc7b1383456aaf4a47588ae2a4e5b48199be972", "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.0178571429, "max_line_length": 88, "alphanum_fraction": 0.6458424031, "num_tokens": 1389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6063279288159019}} {"text": "module Data.LengthMatch\n\n%default total\n\npublic export\ndata LengthMatch : List a -> List b -> Type where\n NilMatch : LengthMatch [] []\n ConsMatch : LengthMatch xs ys -> LengthMatch (x :: xs) (y :: ys)\n\nexport\ncheckLengthMatch : (xs : List a) -> (ys : List b) -> Maybe (LengthMatch xs ys)\ncheckLengthMatch [] [] = Just NilMatch\ncheckLengthMatch [] (x :: xs) = Nothing\ncheckLengthMatch (x :: xs) [] = Nothing\ncheckLengthMatch (x :: xs) (y :: ys)\n = Just (ConsMatch !(checkLengthMatch xs ys))\n", "meta": {"hexsha": "bebde240c3a11db7407e667360fe12bd6109a978", "size": 501, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/src/Data/LengthMatch.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/src/Data/LengthMatch.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/src/Data/LengthMatch.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": 29.4705882353, "max_line_length": 78, "alphanum_fraction": 0.6586826347, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6060834321405446}} {"text": "module BiNat.Properties.Plus\n\nimport BiNat\n\n%access public export\n%default total\n\nsuccDashAppendsAcc : (n : BiNat) -> (acc : List Bit) -> succ' n acc = foldl (-:) (succ' n []) acc\nsuccDashAppendsAcc J acc = Refl\nsuccDashAppendsAcc (n -: O) acc = Refl\nsuccDashAppendsAcc (n -: I) acc =\n rewrite succDashAppendsAcc n (O :: acc) in\n rewrite succDashAppendsAcc n [O] in Refl\n\npredDashAppendsAcc : (n : BiNat) -> (acc : List Bit) -> pred' n acc = foldl (-:) (pred' n []) acc\npredDashAppendsAcc J acc = Refl\npredDashAppendsAcc (n -: I) acc = Refl\npredDashAppendsAcc (J -: O) acc = Refl\npredDashAppendsAcc (ns -: n -: O) acc =\n rewrite predDashAppendsAcc (ns -: n) (I :: acc) in\n rewrite predDashAppendsAcc (ns -: n) [I] in Refl\n\npredOfSucc : (n : BiNat) -> pred (succ n) = n\npredOfSucc J = Refl\npredOfSucc (n -: O) = Refl\npredOfSucc (J -: I) = Refl\npredOfSucc (ns -: O -: I) = Refl\npredOfSucc (ns -: I -: I) =\n rewrite succDashAppendsAcc ns [O, O] in\n rewrite predDashAppendsAcc (succ' ns [] -: O) [I] in\n rewrite sym $ succDashAppendsAcc ns [O] in\n rewrite predOfSucc (ns -: I) in Refl\n\nsuccOfPred : (n : BiNat) -> Not (n = J) -> succ (pred n) = n\nsuccOfPred J notJ = absurd (notJ Refl)\nsuccOfPred (n -: I) _ = Refl\nsuccOfPred (J -: O) _ = Refl\nsuccOfPred (ns -: I -: O) _ = Refl\nsuccOfPred (ns -: O -: O) _ =\n rewrite predDashAppendsAcc (ns -: O) [I] in\n rewrite succDashAppendsAcc (pred' (ns -: O) []) [O] in\n rewrite succOfPred (ns -: O) uninhabited in Refl\n\nsuccInjective : (m, n : BiNat) -> succ m = succ n -> m = n\nsuccInjective m n eq =\n rewrite sym $ predOfSucc m in\n rewrite eq in\n predOfSucc n\n\nplusJIsSucc : (n : BiNat) -> plus n J = succ n\nplusJIsSucc J = Refl\nplusJIsSucc (ns -: n) = Refl\n\njPlusIsSucc : (n : BiNat) -> plus J n = succ n\njPlusIsSucc J = Refl\njPlusIsSucc (ns -: n) = Refl\n\nnextCarrySymmetric : (a, b, c : Bit) -> nextCarry a b c = nextCarry b a c\nnextCarrySymmetric O O O = Refl\nnextCarrySymmetric O O I = Refl\nnextCarrySymmetric O I O = Refl\nnextCarrySymmetric O I I = Refl\nnextCarrySymmetric I O O = Refl\nnextCarrySymmetric I O I = Refl\nnextCarrySymmetric I I O = Refl\nnextCarrySymmetric I I I = Refl\n\nnextAccSymmetric : (a, b, c : Bit) -> nextAcc a b c = nextAcc b a c\nnextAccSymmetric O O O = Refl\nnextAccSymmetric O O I = Refl\nnextAccSymmetric O I O = Refl\nnextAccSymmetric O I I = Refl\nnextAccSymmetric I O O = Refl\nnextAccSymmetric I O I = Refl\nnextAccSymmetric I I O = Refl\nnextAccSymmetric I I I = Refl\n\nplusDashSymmetric : (m, n : BiNat) -> (carry : Bit) -> (acc : List Bit) ->\n plus' m n carry acc = plus' n m carry acc\nplusDashSymmetric J J carry acc = Refl\nplusDashSymmetric J (ns -: n) O acc = Refl\nplusDashSymmetric J (ns -: n) I acc = Refl\nplusDashSymmetric (ms -: m) J O acc = Refl\nplusDashSymmetric (ms -: m) J I acc = Refl\nplusDashSymmetric (ms -: m) (ns -: n) carry acc =\n rewrite nextCarrySymmetric n m carry in\n rewrite nextAccSymmetric n m carry in\n plusDashSymmetric ms ns (nextCarry m n carry) (nextAcc m n carry :: acc)\n\nplusSymmetric : (m, n : BiNat) -> plus m n = plus n m\nplusSymmetric m n = plusDashSymmetric m n O []\n\nplusDashAppendsAcc : (m, n : BiNat) -> (carry : Bit) -> (acc : List Bit) ->\n plus' m n carry acc = foldl (-:) (plus' m n carry []) acc\nplusDashAppendsAcc J J carry acc = Refl\nplusDashAppendsAcc J (ns -: n) O acc = succDashAppendsAcc (ns -: n) acc\nplusDashAppendsAcc J (ns -: n) I acc =\n rewrite succDashAppendsAcc ns [n] in\n rewrite succDashAppendsAcc ns (n :: acc) in Refl\nplusDashAppendsAcc (ms -: m) J O acc = succDashAppendsAcc (ms -: m) acc\nplusDashAppendsAcc (ms -: m) J I acc =\n rewrite succDashAppendsAcc ms [m] in\n rewrite succDashAppendsAcc ms (m :: acc) in Refl\nplusDashAppendsAcc (ms -: m) (ns -: n) carry acc =\n rewrite plusDashAppendsAcc ms ns (nextCarry m n carry) (nextAcc m n carry :: acc) in\n rewrite plusDashAppendsAcc ms ns (nextCarry m n carry) [nextAcc m n carry] in Refl\n\nsuccGoesToCarry : (m, n : BiNat) -> (acc : List Bit) ->\n succ' (plus' m n O []) acc = plus' m n I acc\nsuccGoesToCarry J J acc = Refl\nsuccGoesToCarry (ms -: O) J acc = Refl\nsuccGoesToCarry (ms -: I) J acc =\n rewrite succDashAppendsAcc ms [O] in\n rewrite succDashAppendsAcc ms (I :: acc) in Refl\nsuccGoesToCarry J (ns -: O) acc = Refl\nsuccGoesToCarry J (ns -: I) acc =\n rewrite succDashAppendsAcc ns [O] in\n rewrite succDashAppendsAcc ns (I :: acc) in Refl\nsuccGoesToCarry (ms -: O) (ns -: O) acc =\n rewrite plusDashAppendsAcc ms ns O [O] in\n rewrite plusDashAppendsAcc ms ns O (I :: acc) in Refl\nsuccGoesToCarry (ms -: O) (ns -: I) acc =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite succGoesToCarry ms ns (O :: acc) in Refl\nsuccGoesToCarry (ms -: I) (ns -: O) acc =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite succGoesToCarry ms ns (O :: acc) in Refl\nsuccGoesToCarry (ms -: I) (ns -: I) acc =\n rewrite plusDashAppendsAcc ms ns I [O] in\n rewrite plusDashAppendsAcc ms ns I (I :: acc) in Refl\n\nsuccDashCommutesToPlusDashSnd : (m, n : BiNat) -> (acc : List Bit) ->\n succ' (plus m n) acc = plus' m (succ n) O acc\nsuccDashCommutesToPlusDashSnd J J acc = Refl\nsuccDashCommutesToPlusDashSnd J (ns -: O) acc = Refl\nsuccDashCommutesToPlusDashSnd J (ns -: I) acc =\n rewrite succDashAppendsAcc (succ' ns [O]) acc in\n rewrite plusDashAppendsAcc J (succ' ns [O]) O acc in\n rewrite jPlusIsSucc (succ' ns [O]) in Refl\nsuccDashCommutesToPlusDashSnd (ms -: O) J acc =\n rewrite succDashAppendsAcc ms (O :: acc) in\n rewrite plusDashAppendsAcc ms J O (O :: acc) in\n rewrite plusJIsSucc ms in Refl\nsuccDashCommutesToPlusDashSnd (ms -: I) J acc =\n rewrite succDashAppendsAcc ms [O] in\n rewrite sym $ plusJIsSucc ms in\n rewrite plusDashAppendsAcc ms J O (I :: acc) in Refl\nsuccDashCommutesToPlusDashSnd (ms -: O) (ns -: O) acc =\n rewrite plusDashAppendsAcc ms ns O [O] in\n rewrite plusDashAppendsAcc ms ns O (I :: acc) in Refl\nsuccDashCommutesToPlusDashSnd (ms -: O) (ns -: I) acc =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite succDashCommutesToPlusDashSnd ms ns (O :: acc) in\n rewrite succDashAppendsAcc ns [O] in Refl\nsuccDashCommutesToPlusDashSnd (ms -: I) (ns -: O) acc =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite succGoesToCarry ms ns (O :: acc) in Refl\nsuccDashCommutesToPlusDashSnd (ms -: I) (ns -: I) acc =\n rewrite plusDashAppendsAcc ms ns I [O] in\n rewrite sym $ succGoesToCarry ms ns [] in\n rewrite succDashAppendsAcc ns [O] in\n rewrite sym $ succDashCommutesToPlusDashSnd ms ns (I :: acc) in\n rewrite succDashAppendsAcc (plus' ms ns O []) (I :: acc) in Refl\n\nsuccDashCommutesToPlusDashFst : (m, n : BiNat) -> (acc : List Bit) ->\n succ' (plus m n) acc = plus' (succ m) n O acc\nsuccDashCommutesToPlusDashFst m n acc =\n rewrite plusSymmetric m n in\n rewrite succDashCommutesToPlusDashSnd n m acc in\n rewrite plusDashSymmetric n (succ m) O acc in Refl\n\nplusAssociative : (l, m, n : BiNat) -> plus l (plus m n) = plus (plus l m) n\nplusAssociative J J J = Refl\nplusAssociative J J (ns -: O) =\n rewrite succDashAppendsAcc ns [O] in\n rewrite plusDashAppendsAcc J ns O [O] in\n rewrite jPlusIsSucc ns in Refl\nplusAssociative J J (ns -: I) =\n rewrite succDashAppendsAcc ns [O] in\n rewrite plusDashAppendsAcc J ns O [I] in\n rewrite jPlusIsSucc ns in Refl\nplusAssociative J (ms -: O) J = Refl\nplusAssociative J (ms -: I) J = plusDashSymmetric J (succ' ms [O]) O []\nplusAssociative (ls -: O) J J =\n rewrite succDashAppendsAcc ls [O] in\n rewrite plusDashAppendsAcc ls J O [O] in\n rewrite plusJIsSucc ls in Refl\nplusAssociative (ls -: I) J J =\n rewrite succDashAppendsAcc ls [O] in\n rewrite plusDashAppendsAcc ls J O [I] in\n rewrite plusJIsSucc ls in Refl\nplusAssociative J (ms -: O) (ns -: O) =\n rewrite plusDashAppendsAcc ms ns O [O] in\n rewrite plusDashAppendsAcc ms ns O [I] in Refl\nplusAssociative J (ms -: O) (ns -: I) =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite sym $ succGoesToCarry ms ns [O] in Refl\nplusAssociative J (ms -: I) (ns -: O) =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite succDashAppendsAcc (plus' ms ns O []) [O] in\n rewrite sym $ jPlusIsSucc (plus' ms ns O []) in\n rewrite succDashAppendsAcc ms [O] in\n rewrite plusDashAppendsAcc (succ' ms []) ns O [O] in\n rewrite sym $ jPlusIsSucc ms in\n rewrite plusAssociative J ms ns in Refl\nplusAssociative J (ms -: I) (ns -: I) =\n rewrite plusDashAppendsAcc ms ns I [O] in\n rewrite sym $ succGoesToCarry ms ns [] in\n rewrite succDashAppendsAcc ms [O] in\n rewrite plusDashAppendsAcc (succ' ms []) ns O [I] in\n rewrite sym $ jPlusIsSucc ms in\n rewrite sym $ jPlusIsSucc (plus' ms ns O []) in\n rewrite plusAssociative J ms ns in Refl\nplusAssociative (ls -: O) J (ns -: O) = Refl\nplusAssociative (ls -: O) J (ns -: I) =\n rewrite succDashAppendsAcc ns [O] in\n rewrite plusDashAppendsAcc ls (succ' ns []) O [O] in\n rewrite sym $ plusJIsSucc ns in\n rewrite sym $ succGoesToCarry ls ns [O] in\n rewrite succDashAppendsAcc (plus' ls ns O []) [O] in\n rewrite sym $ plusJIsSucc (plus' ls ns O []) in\n rewrite plusAssociative ls ns J in Refl\nplusAssociative (ls -: I) J (ns -: O) =\n rewrite sym $ succGoesToCarry ls ns [O] in\n rewrite succDashAppendsAcc (plus' ls ns O []) [O] in\n rewrite sym $ jPlusIsSucc (plus' ls ns O []) in\n rewrite succDashAppendsAcc ls [O] in\n rewrite plusDashAppendsAcc (succ' ls []) ns O [O] in\n rewrite sym $ jPlusIsSucc ls in\n rewrite plusAssociative J ls ns in Refl\nplusAssociative (ls -: I) J (ns -: I) =\n rewrite succDashAppendsAcc ns [O] in\n rewrite plusDashAppendsAcc ls (succ' ns []) O [I] in\n rewrite sym $ jPlusIsSucc ns in\n rewrite succDashAppendsAcc ls [O] in\n rewrite plusDashAppendsAcc (succ' ls []) ns O [I] in\n rewrite sym $ plusJIsSucc ls in\n rewrite plusAssociative ls J ns in Refl\nplusAssociative (ls -: O) (ns -: O) J =\n rewrite plusDashAppendsAcc ls ns O [O] in\n rewrite plusDashAppendsAcc ls ns O [I] in Refl\nplusAssociative (ls -: O) (ns -: I) J =\n rewrite succDashAppendsAcc ns [O] in\n rewrite sym $ plusJIsSucc ns in\n rewrite plusDashAppendsAcc ls (plus' ns J O []) O [O] in\n rewrite plusDashAppendsAcc ls ns O [I] in\n rewrite succDashAppendsAcc (plus' ls ns O []) [O] in\n rewrite sym $ plusJIsSucc (plus' ls ns O []) in\n rewrite plusAssociative ls ns J in Refl\nplusAssociative (ls -: I) (ns -: O) J =\n rewrite plusDashAppendsAcc ls ns I [O] in\n rewrite sym $ succGoesToCarry ls ns [] in\n rewrite sym $ plusJIsSucc (plus' ls ns O []) in\n rewrite plusDashAppendsAcc ls ns O [I] in\n rewrite succDashAppendsAcc (plus' ls ns O []) [O] in\n rewrite sym $ plusJIsSucc (plus' ls ns O []) in Refl\nplusAssociative (ls -: I) (ns -: I) J =\n rewrite succDashAppendsAcc ns [O] in\n rewrite plusDashAppendsAcc ls (succ' ns []) O [I] in\n rewrite sym $ plusJIsSucc ns in\n rewrite plusDashAppendsAcc ls ns I [O] in\n rewrite sym $ succGoesToCarry ls ns [] in\n rewrite sym $ plusJIsSucc (plus' ls ns O []) in\n rewrite plusAssociative ls ns J in Refl\nplusAssociative (ls -: O) (ms -: O) (ns -: O) =\n rewrite plusDashAppendsAcc ms ns O [O] in\n rewrite plusDashAppendsAcc ls (plus' ms ns O []) O [O] in\n rewrite plusDashAppendsAcc ls ms O [O] in\n rewrite plusDashAppendsAcc (plus' ls ms O []) ns O [O] in\n rewrite plusAssociative ls ms ns in Refl\nplusAssociative (ls -: O) (ms -: O) (ns -: I) =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite plusDashAppendsAcc ls (plus' ms ns O []) O [I] in\n rewrite plusDashAppendsAcc ls ms O [O] in\n rewrite plusDashAppendsAcc (plus' ls ms O []) ns O [I] in\n rewrite plusAssociative ls ms ns in Refl\nplusAssociative (ls -: O) (ms -: I) (ns -: O) =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite plusDashAppendsAcc ls (plus' ms ns O []) O [I] in\n rewrite plusDashAppendsAcc ls ms O [I] in\n rewrite plusDashAppendsAcc (plus' ls ms O []) ns O [I] in\n rewrite plusAssociative ls ms ns in Refl\nplusAssociative (ls -: O) (ms -: I) (ns -: I) =\n rewrite plusDashAppendsAcc ms ns I [O] in\n rewrite sym $ succGoesToCarry ms ns [] in\n rewrite plusDashAppendsAcc ls ms O [I] in\n rewrite sym $ succGoesToCarry (plus' ls ms O []) ns [O] in\n rewrite sym $ plusAssociative ls ms ns in\n rewrite succDashCommutesToPlusDashSnd ls (plus' ms ns O []) [O] in Refl\nplusAssociative (ls -: I) (ms -: O) (ns -: O) =\n rewrite plusDashAppendsAcc ms ns O [O] in\n rewrite plusDashAppendsAcc ls (plus' ms ns O []) O [I] in\n rewrite plusDashAppendsAcc ls ms O [I] in\n rewrite plusDashAppendsAcc (plus' ls ms O []) ns O [I] in\n rewrite plusAssociative ls ms ns in Refl\nplusAssociative (ls -: I) (ms -: O) (ns -: I) =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite sym $ succGoesToCarry ls (plus' ms ns O []) [O] in\n rewrite plusDashAppendsAcc ls ms O [I] in\n rewrite sym $ succGoesToCarry (plus' ls ms O []) ns [O] in\n rewrite plusAssociative ls ms ns in Refl\nplusAssociative (ls -: I) (ms -: I) (ns -: O) =\n rewrite plusDashAppendsAcc ms ns O [I] in\n rewrite sym $ succGoesToCarry ls (plus' ms ns O []) [O] in\n rewrite plusDashAppendsAcc ls ms I [O] in\n rewrite sym $ succGoesToCarry ls ms [] in\n rewrite sym $ succDashCommutesToPlusDashFst (plus' ls ms O []) ns [O] in\n rewrite plusAssociative ls ms ns in Refl\nplusAssociative (ls -: I) (ms -: I) (ns -: I) =\n rewrite plusDashAppendsAcc ms ns I [O] in\n rewrite sym $ succGoesToCarry ms ns [] in\n rewrite sym $ succDashCommutesToPlusDashSnd ls (plus' ms ns O []) [I] in\n rewrite plusDashAppendsAcc ls ms I [O] in\n rewrite sym $ succGoesToCarry ls ms [] in\n rewrite sym $ succDashCommutesToPlusDashFst (plus' ls ms O []) ns [I] in\n rewrite plusAssociative ls ms ns in Refl\n\nshiftLeftDoubles : (n : BiNat) -> n -: O = plus n n\nshiftLeftDoubles J = Refl\nshiftLeftDoubles (ns -: O) =\n rewrite plusDashAppendsAcc ns ns O [O] in\n rewrite shiftLeftDoubles ns in Refl\nshiftLeftDoubles (ns -: I) =\n rewrite plusDashAppendsAcc ns ns I [O] in\n rewrite sym $ succGoesToCarry ns ns [] in\n rewrite sym $ shiftLeftDoubles ns in Refl\n\nsuccIsNotJ : (n : BiNat) -> Not (succ n = J)\nsuccIsNotJ J eq = uninhabited eq\nsuccIsNotJ (ns -: O) eq = uninhabited eq\nsuccIsNotJ (ns -: I) eq = uninhabited $ replace {P = \\z => z = J} (succDashAppendsAcc ns [O]) eq\n\npredOfDoubled : (n : BiNat) -> Not (n = J) -> pred (n -: O) = pred n -: I\npredOfDoubled J notJ = absurd $ notJ Refl\npredOfDoubled (ns -: O) _ = predDashAppendsAcc (ns -: O) [I]\npredOfDoubled (ns -: I) _ = Refl\n\npredCommutesToPlusSnd : (m, n : BiNat) -> Not (n = J) ->\n pred (plus m n) = plus m (pred n)\npredCommutesToPlusSnd J n notJ =\n rewrite jPlusIsSucc n in\n rewrite predOfSucc n in\n rewrite jPlusIsSucc (pred n) in\n rewrite succOfPred n notJ in Refl\npredCommutesToPlusSnd (ms -: m) n notJ =\n rewrite sym $ succOfPred (ms -: m) uninhabited in\n rewrite sym $ jPlusIsSucc (pred (ms -: m)) in\n rewrite sym $ plusAssociative J (pred (ms -: m)) n in\n rewrite jPlusIsSucc (plus (pred (ms -: m)) n) in\n rewrite predOfSucc (plus (pred (ms -: m)) n) in\n rewrite plusSymmetric J (pred (ms -: m)) in\n rewrite sym $ plusAssociative (pred (ms -: m)) J (pred n) in\n rewrite jPlusIsSucc (pred n) in\n rewrite succOfPred n notJ in Refl\n", "meta": {"hexsha": "5e162fe192977df3732c8da4f8689dff90324ee8", "size": 15569, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "BiNat/Properties/Plus.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/Plus.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/Plus.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": 43.8563380282, "max_line_length": 97, "alphanum_fraction": 0.6624702935, "num_tokens": 5431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6060028318398645}} {"text": "module Vect\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\nappend : Vect n a -> Vect m a -> Vect (n + m) a\nappend [] ys = ys\nappend (x :: xs) ys = x :: (append xs ys)\n\nvzipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\nvzipWith f [] [] = []\nvzipWith f (x :: xs) (y :: ys) = f x y :: (vzipWith f xs ys)\n\n\n", "meta": {"hexsha": "dbbdb7a26c204dae9a7d88423ad428d3aff1eba0", "size": 445, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Intro/Vect.idr", "max_stars_repo_name": "silky/idris-demos", "max_stars_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-27T11:33:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T11:33:51.000Z", "max_issues_repo_path": "Intro/Vect.idr", "max_issues_repo_name": "silky/idris-demos", "max_issues_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Intro/Vect.idr", "max_forks_repo_name": "silky/idris-demos", "max_forks_repo_head_hexsha": "1cda10e07d9c8205b9dd56048b1c2cc96f8e3e04", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1904761905, "max_line_length": 60, "alphanum_fraction": 0.595505618, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6058455474359522}} {"text": "module Adder\n\n%default total\n\n||| Calculate the type of an adder function \n||| that expected `numargs` arguments (in addition\n||| to the initial value argument)\nAdderType : (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 (acc + next)\n", "meta": {"hexsha": "77c90b8b72af757e1859fb3b5d7fda19a37bb4eb", "size": 388, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter6/Adder.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": "chapter6/Adder.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": "chapter6/Adder.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": 25.8666666667, "max_line_length": 59, "alphanum_fraction": 0.6675257732, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6053768321705422}} {"text": "module Hands\nimport Data.Vect\n\nimport InsertionSort\nimport Card\nimport ElemsAreSame\nimport Sorted\nimport SlideWise\n\npublic export HAND_SIZE : Nat\nHAND_SIZE = 5\n\n\n--=======================================================================================================\n--=======================================================================================================\n--Utility proof data structures\n--=======================================================================================================\n--=======================================================================================================\ndata ForAll : Vect n elem -> (elem -> Type) -> Type where\n ForVect : prf x -> ForAll xs prf -> ForAll (x::r) prf\n End : ForAll [] pred\n\ndata AllSame : Vect n elem -> (elem -> elem -> Type) -> Type where\n EmptyIsSame: AllSame [] prf\n SingleIsSame: AllSame [x] prf\n Same: prf x y -> AllSame (y::ys) prf -> AllSame (x::y::ys) prf\n\ndata SameValue: Card -> Card -> Type where\n ValueMatch: SameValue (MkCard v _) (MkCard v _)\n\ndata SameSuit: Card -> Card -> Type where\n SuitMatch: SameSuit (MkCard _ s) (MkCard _ s)\n\n--=======================================================================================================\n--=======================================================================================================\n--Hand Proof data structures\n--=======================================================================================================\n--=======================================================================================================\ndata PairH: Vect 2 Card -> Type where\n MkPair: PairH [(MkCard v _), (MkCard v _)]\n\ndata TwoPair: Vect HAND_SIZE Card -> Type where\n MkTwoPair: Sorted hand -> (firstpair: SlideWise2 hand PairH) -> (secondPair:SlideWise2 (getRest2 hand firstpair) PairH) -> TwoPair hand\n\ndata ThreeOfAKind : Vect 3 Card -> Type where\n MkThree: AllSame x SameValue -> ThreeOfAKind x\n\ndata Straight: Vect HAND_SIZE Card -> Type where\n MkStraight: Sorted x -> Consecutive x -> Straight x\n\ndata Flush: Vect HAND_SIZE Card -> Type where\n MkFlush: AllSame x SameSuit -> Flush x\n\ndata FullHouse: (hand:Vect HAND_SIZE Card) -> Type where\n MkFullHouse: Sorted hand -> (three: SlideWise3 hand ThreeOfAKind) -> (pair: PairH (getRest3 hand three)) -> FullHouse hand\n\ndata FourOfAKind : Vect 4 Card -> Type where\n MkFour: AllSame x SameValue -> FourOfAKind x\n\ndata StraightFlush: Vect HAND_SIZE Card -> Type where\n MkStraightFlush: Straight x -> Flush x -> StraightFlush x\n\n--=======================================================================================================\n--=======================================================================================================\n--Hand\n--=======================================================================================================\n--=======================================================================================================\nexport data Hand: Vect HAND_SIZE Card -> Type where\n StraightFlushHand:\n StraightFlush x -> Hand x\n FourOfAKindHand:\n {auto p:Sorted y} -> SlideWise4 y FourOfAKind -> Hand y\n FullHouseHand:\n FullHouse y -> Hand y\n FlushHand:\n Flush x -> Hand x\n StraightHand:\n Straight x -> Hand x\n ThreeOfAKindHand:\n {auto p:Sorted y} -> SlideWise3 y ThreeOfAKind -> Hand y\n TwoPairHand:\n {auto p:Sorted y} -> TwoPair y -> Hand y\n PairHand:\n {auto p:Sorted y} -> SlideWise2 y PairH -> Hand y\n HighCardHand:\n {auto p:Sorted kickers} -> (kickers: Vect HAND_SIZE Card) -> Hand kickers\n\n--=======================================================================================================\n--=======================================================================================================\n-- Utility proofs\n--=======================================================================================================\n--=======================================================================================================\n--=======================================================================================================\n-- hasSameSuit\n--=======================================================================================================\nnotSameSuit : (contra : (s1 = s2) -> Void) -> SameSuit (MkCard value s1) (MkCard value1 s2) -> Void\nnotSameSuit contra SuitMatch = contra Refl\n\nhasSameSuit: (c1: Card) -> (c2: Card) -> Dec (SameSuit c1 c2)\nhasSameSuit (MkCard _ s1) (MkCard _ s2) = case decEq s1 s2 of\n (Yes prf) => Yes (rewrite prf in SuitMatch)\n (No contra) => No (notSameSuit contra)\n\n--=======================================================================================================\n-- hasSameValue\n--=======================================================================================================\nnotSameValue : (contra : (v1 = v2) -> Void) -> SameValue (MkCard v1 suit) (MkCard v2 suit1) -> Void\nnotSameValue contra ValueMatch = contra Refl\n\nhasSameValue: (c1: Card) -> (c2: Card) -> Dec (SameValue c1 c2)\nhasSameValue (MkCard v1 _) (MkCard v2 _) = case decEq v1 v2 of\n (Yes prf) => Yes (rewrite prf in ValueMatch)\n (No contra) => No (notSameValue contra)\n--=======================================================================================================\n-- allSameSuit\n--=======================================================================================================\nrestNotSameSuit : (contra : AllSame (x2 :: xs) SameSuit -> Void) -> AllSame (x1 :: (x2 :: xs)) SameSuit -> Void\nrestNotSameSuit contra (Same x y) = contra y\n\nsingleNotSameSuit : (contra : SameSuit x1 x2 -> Void) -> AllSame (x1 :: (x2 :: xs)) SameSuit -> Void\nsingleNotSameSuit contra (Same x y) = contra x\n\nallSameSuit: (x: Vect n Card) -> Dec (AllSame x SameSuit)\nallSameSuit [] = Yes EmptyIsSame\nallSameSuit [x] = Yes SingleIsSame\nallSameSuit (x1 :: x2 :: xs) = case allSameSuit (x2 :: xs) of\n (Yes prf_rest) => case hasSameSuit x1 x2 of\n (Yes prf_single) => Yes (Same prf_single prf_rest)\n (No contra) => No (singleNotSameSuit contra)\n (No contra) => No (restNotSameSuit contra)\n\n--=======================================================================================================\n-- isNoOfKind\n--=======================================================================================================\nrestNotSame: (contra : AllSame (x2 :: xs) SameValue -> Void) -> AllSame (x1 :: (x2 :: xs)) SameValue -> Void\nrestNotSame contra (Same x y) = contra y\n\nsingleNotSame : (contra : SameValue x1 x2 -> Void) -> AllSame (x1 :: (x2 :: xs)) SameValue -> Void\nsingleNotSame contra (Same x y) = contra x\n\nisNoOfKind: (x: Vect n Card) -> Dec (AllSame x SameValue)\nisNoOfKind [] = Yes EmptyIsSame\nisNoOfKind [x] = Yes SingleIsSame\nisNoOfKind (x1 :: x2 :: xs) = case isNoOfKind (x2 :: xs) of\n (Yes prf_rest) => (case hasSameValue x1 x2 of\n (Yes prf_single) => Yes (Same prf_single prf_rest)\n (No contra) => No (singleNotSame contra))\n (No contra) => No (restNotSame contra)\n\n\n--=======================================================================================================\n--=======================================================================================================\n--Hand Proofs\n--=======================================================================================================\n--=======================================================================================================\n--=======================================================================================================\n-- Pair\n--=======================================================================================================\nisNotPair : (contra : (v1 = v2) -> Void) -> PairH [(MkCard v1 suit), (MkCard v2 suit1)] -> Void\nisNotPair contra MkPair = contra Refl\n\nisPair: (p: Vect 2 Card) -> Dec (PairH p)\nisPair [(MkCard v1 _), (MkCard v2 _)] = case decEq v1 v2 of\n (Yes prf) => Yes (rewrite prf in MkPair)\n (No contra) => No (isNotPair contra)\n\nisPairHand: (hand: Vect HAND_SIZE Card) -> {auto sort_prf: Sorted hand }-> Dec (SlideWise2 hand PairH)\nisPairHand hand {sort_prf} = isSlideWise2 hand isPair\n--=======================================================================================================\n-- Two Pair\n--=======================================================================================================\npairInRest: {hand: Vect HAND_SIZE Card} -> (firstPair: SlideWise2 hand PairH) -> Dec (SlideWise2 (getRest2 hand firstPair) PairH)\npairInRest (HeadMatches2 searched match rest x) = isSlideWise2 (getRest2 (match ++ rest) (HeadMatches2 searched match rest x)) isPair\npairInRest (RestMatches2 x rest y) = isSlideWise2 (getRest2 (x :: rest) (RestMatches2 x rest y)) isPair\n\n\n||| TODO return Dec instead\nisTwoPairHand: (hand: Vect HAND_SIZE Card) -> {auto sort_prf: Sorted hand} -> Maybe (TwoPair hand)\nisTwoPairHand hand {sort_prf} = case isPairHand hand of\n (Yes first_prf) => (case pairInRest first_prf of\n (Yes snd_prf) => Just (MkTwoPair sort_prf first_prf snd_prf)\n (No contra) => Nothing)\n (No contra) => Nothing\n\n--=======================================================================================================\n-- Three of a Kind\n--=======================================================================================================\nnotThreeOfAKind : (contra : AllSame x SameValue -> Void) -> ThreeOfAKind x -> Void\nnotThreeOfAKind contra (MkThree x) = contra x\n\nisThreeOfAKind: (x: Vect 3 Card) -> Dec (ThreeOfAKind x)\nisThreeOfAKind x = case isNoOfKind x of\n (Yes prf) => Yes (MkThree prf)\n (No contra) => No (notThreeOfAKind contra)\n\nisThreeOfAKindHand: (hand: Vect 5 Card) -> {auto sort_prf: Sorted hand} -> Dec (SlideWise3 hand ThreeOfAKind)\nisThreeOfAKindHand hand = isSlideWise3 hand isThreeOfAKind\n--=======================================================================================================\n-- Straight\n--=======================================================================================================\nnotConsecSoNotStraight : (contra : Consecutive x -> Void) -> Straight x -> Void\nnotConsecSoNotStraight contra (MkStraight x y) = contra y\n\nisStraight: (x: Vect HAND_SIZE Card) -> {auto sort_prf:Sorted x} -> Dec (Straight x)\nisStraight {sort_prf} x = case isConsecutive x of\n (Yes prf) => Yes (MkStraight sort_prf prf)\n (No contra) => No (notConsecSoNotStraight contra)\n\n--=======================================================================================================\n-- Flush\n--=======================================================================================================\nnotFlush : (contra : AllSame x SameSuit -> Void) -> Flush x -> Void\nnotFlush contra (MkFlush (Same z w)) = contra (Same z w)\n\n\nisFlush: (x: Vect HAND_SIZE Card) -> Dec (Flush x)\nisFlush x = case allSameSuit x of\n (Yes prf) => Yes (MkFlush prf)\n (No contra) => No (notFlush contra)\n--=======================================================================================================\n-- Full House\n--=======================================================================================================\nisFullHouse: (hand: Vect HAND_SIZE Card) -> (sort_prf: Sorted hand) -> Maybe (FullHouse hand)\nisFullHouse hand sort_prf = case isThreeOfAKindHand hand of\n (No contra) => Nothing\n (Yes three_prf) => (case isPair (getRest3 hand three_prf) of\n (Yes pair_prf) => Just (MkFullHouse sort_prf three_prf pair_prf)\n (No contra) => Nothing)\n\n\n\n--=======================================================================================================\n-- Four of a Kind\n--=======================================================================================================\nnotFourOfAKind : (contra : AllSame x SameValue -> Void) -> FourOfAKind x -> Void\nnotFourOfAKind contra (MkFour x) = contra x\n\nisFourOfAKind: (x: Vect 4 Card) -> Dec (FourOfAKind x)\nisFourOfAKind x = case isNoOfKind x of\n (Yes prf) => Yes (MkFour prf)\n (No contra) => No (notFourOfAKind contra)\n\n\nisFourOfAKindHand: (hand: Vect 5 Card) -> Sorted hand -> Dec (SlideWise4 hand FourOfAKind)\nisFourOfAKindHand hand sort_prf = isSlideWise4 hand isFourOfAKind\n\n--=======================================================================================================\n-- Straight Flush\n--=======================================================================================================\nnotStraightSoNotSF : (contra : Straight x -> Void) -> StraightFlush x -> Void\nnotStraightSoNotSF contra (MkStraightFlush straight flush) = contra straight\n\nnotFlushSoNotSF : (contra : Flush x -> Void) -> StraightFlush x -> Void\nnotFlushSoNotSF contra (MkStraightFlush straight flush) = contra flush\n\nisStraightFlush: (x: Vect HAND_SIZE Card) -> {auto sort_prf:Sorted x} -> Dec (StraightFlush x)\nisStraightFlush x = case isStraight x of\n (Yes straight_prf) => (case isFlush x of\n (Yes flush_prf) => Yes (MkStraightFlush straight_prf flush_prf)\n (No contra) => No (notFlushSoNotSF contra))\n (No contra) => No (notStraightSoNotSF contra)\n\n\n--=======================================================================================================\n--=======================================================================================================\n-- Hand evaluator\n--=======================================================================================================\n--=======================================================================================================\n\nevalRestHand : (hand: Vect HAND_SIZE Card) -> (sort_prf : Sorted hand) -> (contra_4 : SlideWise4 hand FourOfAKind -> Void) -> (contra_sf : StraightFlush hand -> Void) -> Hand hand\nevalRestHand hand sort_prf contra_4 contra_sf = case isFlush hand of\n (Yes prf) => FlushHand prf\n (No contra_flush) => (case isStraight hand of\n (Yes prf) => StraightHand prf\n (No contra) => (case isThreeOfAKindHand hand of\n (Yes prf) => ThreeOfAKindHand prf\n (No contra) => (case isTwoPairHand hand of\n (Just prf) => TwoPairHand prf\n Nothing => (case isPairHand hand of\n (Yes prf) => PairHand prf\n (No contra) => HighCardHand hand))))\n\n\nexport evalHand: (hand: Vect HAND_SIZE Card) -> Sorted hand -> Hand hand\nevalHand hand sort_prf = case isStraightFlush hand of\n (Yes prf) => StraightFlushHand prf\n (No contra_sf) => (case isFourOfAKindHand hand sort_prf of\n Yes prf => FourOfAKindHand prf\n No contra_4 => (case isFullHouse hand sort_prf of\n Just prf => FullHouseHand prf\n Nothing => evalRestHand hand sort_prf contra_4 contra_sf))\n\n\n\ncompareStraightFlushes : (x : StraightFlush h1) -> (y : StraightFlush h2) -> Ordering\ncompareStraightFlushes {h1 = (x1 :: xs1)} {h2 = (x2:: xs2)} x y = compare (cardValue x1) (cardValue x2)\n\ncompareFourOfAKinds : (x : SlideWise4 h1 FourOfAKind) -> (y : SlideWise4 h2 FourOfAKind) -> Ordering\ncompareFourOfAKinds {h1} {h2} x y = let ((x1::xs), kicker1::[]) = getMatchAndRest4 h1 x\n ((y1::ys), kicker2::[]) = getMatchAndRest4 h2 y in\n (case compare (cardValue x1) (cardValue y1) of\n LT => LT\n EQ => compare (cardValue kicker1) (cardValue kicker2)\n GT => GT)\n\ncompareHighCards : (h1 : Vect n Card) -> (h2 : Vect n Card) -> Ordering\ncompareHighCards [] [] = EQ\ncompareHighCards (x :: xs) (y :: ys) = case compare (cardValue x) (cardValue y) of\n LT => LT\n EQ => compareHighCards xs ys\n GT => GT\n\ncompareFlushes : (x : Flush h1) -> (y : Flush h2) -> Ordering\ncompareFlushes {h1} {h2} x y = compareHighCards h1 h2\n\ncomparePairs : {h1, h2: Vect (S(S n)) Card} -> (x : SlideWise2 h1 PairH) -> (y : SlideWise2 h2 PairH) -> Ordering\ncomparePairs {h1} {h2} x y = let ((x1::xs), kickers1) = getMatchAndRest2 h1 x\n ((y1::ys), kickers2) = getMatchAndRest2 h2 y in\n (case compare (cardValue x1) (cardValue y1) of\n LT => LT\n EQ => compareHighCards kickers1 kickers2\n GT => GT)\n\n\ngetHighLowPair: Card -> Card -> (Card, Card)\ngetHighLowPair x y = case compare (cardValue x) (cardValue y) of\n LT => (y, x)\n gtOrEq => (x, y)\n\ncompareTwoPairs : {h1, h2: Vect HAND_SIZE Card} -> (x : TwoPair h1) -> (y : TwoPair h2) -> Ordering\ncompareTwoPairs {h1} {h2} (MkTwoPair x firstPair1 secondPair1)\n (MkTwoPair y firstPair2 secondPair2) = let (firstmatch1::f1) = getMatch2 h1 firstPair1\n (secondmatch1::s1, kicker1::[]) = getMatchAndRest2 (getRest2 h1 firstPair1) secondPair1\n (firstmatch2::f2) = getMatch2 h2 firstPair2\n (secondmatch2::s2, kicker2::[]) = getMatchAndRest2 (getRest2 h2 firstPair2) secondPair2\n (highestPair1, lowestPair1) = getHighLowPair firstmatch1 secondmatch1\n (highestPair2, lowestPair2) = getHighLowPair firstmatch2 secondmatch2\n in\n (case compare (cardValue highestPair1) (cardValue highestPair2) of\n LT => LT\n GT => GT\n EQ => (case compare (cardValue lowestPair1) (cardValue lowestPair2) of\n LT => LT\n EQ => compare (cardValue kicker1) (cardValue kicker2)\n GT => GT))\n\ncompareThreeOfAKinds : {h1, h2: Vect (S(S(S n))) Card} -> (x : SlideWise3 h1 ThreeOfAKind) -> (y : SlideWise3 h2 ThreeOfAKind) -> Ordering\ncompareThreeOfAKinds {h1} {h2} x y = let ((x1::xs), kickers1) = getMatchAndRest3 h1 x\n ((y1::ys), kickers2) = getMatchAndRest3 h2 y in\n (case compare (cardValue x1) (cardValue y1) of\n LT => LT\n EQ => compareHighCards kickers1 kickers2\n GT => GT)\n\ncomparePairHs : (pair_prf1 : PairH h1) -> (pair_prf2 : PairH h2) -> Ordering\ncomparePairHs {h1} {h2} pair_prf1 pair_prf2 = compareHighCards h1 h2\n\ncompareFullHouseHands : (x : FullHouse h1) -> (y : FullHouse h2) -> Ordering\ncompareFullHouseHands {h1} (MkFullHouse x three_prf1 pair_prf1)\n {h2} (MkFullHouse y three_prf2 pair_prf2) = let (threeCard1::_) = (getMatch3 h1 three_prf1)\n (threeCard2::_) = (getMatch3 h2 three_prf2) in\n (case compare (cardValue threeCard1) (cardValue threeCard2) of\n LT => LT\n EQ => comparePairHs pair_prf1 pair_prf2\n GT => GT)\n\n\ncompareStraights : {h1, h2: Vect HAND_SIZE Card} -> (x : Straight h1) -> (y : Straight h2) -> Ordering\ncompareStraights {h1} {h2} x y = compareHighCards h1 h2\n\nexport compareHands: {h1, h2: Vect HAND_SIZE Card} -> (hand1: Hand h1) -> (hand2: Hand h2) -> Ordering\ncompareHands (StraightFlushHand x) (StraightFlushHand y) = compareStraightFlushes x y\ncompareHands (StraightFlushHand x) hand2 = GT\ncompareHands (FourOfAKindHand x) (StraightFlushHand y) = LT\ncompareHands (FourOfAKindHand x) (FourOfAKindHand y) = compareFourOfAKinds x y\ncompareHands (FourOfAKindHand x) hand2 = GT\ncompareHands (FullHouseHand x) (StraightFlushHand y) = LT\ncompareHands (FullHouseHand x) (FourOfAKindHand y) = LT\ncompareHands (FullHouseHand x) (FullHouseHand y) = compareFullHouseHands x y\ncompareHands (FullHouseHand x) hand2 = GT\ncompareHands (FlushHand x) (StraightFlushHand y) = LT\ncompareHands (FlushHand x) (FourOfAKindHand y) = LT\ncompareHands (FlushHand x) (FullHouseHand y) = LT\ncompareHands (FlushHand x) (FlushHand y) = compareFlushes x y\ncompareHands (FlushHand x) hand2 = GT\ncompareHands (StraightHand x) (StraightFlushHand y) = LT\ncompareHands (StraightHand x) (FourOfAKindHand y) = LT\ncompareHands (StraightHand x) (FullHouseHand y) = LT\ncompareHands (StraightHand x) (FlushHand y) = LT\ncompareHands (StraightHand x) (StraightHand y) = compareStraights x y\ncompareHands (StraightHand x) hand2 = GT\ncompareHands (ThreeOfAKindHand x) (StraightFlushHand y) = LT\ncompareHands (ThreeOfAKindHand x) (FourOfAKindHand y) = LT\ncompareHands (ThreeOfAKindHand x) (FullHouseHand y) = LT\ncompareHands (ThreeOfAKindHand x) (FlushHand y) = LT\ncompareHands (ThreeOfAKindHand x) (StraightHand y) = LT\ncompareHands (ThreeOfAKindHand x) (ThreeOfAKindHand y) = compareThreeOfAKinds x y\ncompareHands (ThreeOfAKindHand x) hand2 = GT\ncompareHands (TwoPairHand x) (HighCardHand h2) = GT\ncompareHands (TwoPairHand x) (PairHand y) = GT\ncompareHands (TwoPairHand x) (TwoPairHand y) = compareTwoPairs x y\ncompareHands (TwoPairHand x) hand2 = LT\ncompareHands (PairHand x) (HighCardHand h2) = GT\ncompareHands (PairHand x) (PairHand y) = comparePairs x y\ncompareHands (PairHand x) hand2 = LT\ncompareHands (HighCardHand h1) (HighCardHand h2) = compareHighCards h1 h2\ncompareHands (HighCardHand h1) hand2 = LT\n\nshowHighCard : (h : Vect HAND_SIZE Card) -> String\nshowHighCard (x :: xs) = \"High Card: \" ++ (show (cardValue x))\n\n\nshowPair :{h: Vect HAND_SIZE Card} -> (x : SlideWise2 h PairH) -> String\nshowPair {h} x = let (m::ms, r::rs) = getMatchAndRest2 h x in\n \"Pair: \" ++ (show (cardValue m)) ++ \"s with a \" ++ (show (cardValue r)) ++ \" kicker\"\n\nshowTwoPair : (x : TwoPair h)-> String\nshowTwoPair {h} (MkTwoPair x firstPair secondPair) = let (m1::ms1) = getMatch2 h firstPair\n (m2::ms2, [kicker]) = getMatchAndRest2 (getRest2 h firstPair) secondPair in\n \"Two Pair: \" ++ (show (cardValue m1)) ++ \"s and \" ++ (show (cardValue m2)) ++ \"s with a \" ++ (show (cardValue kicker)) ++ \" kicker\"\n\nshowThreeOfAKind : (x : SlideWise3 h ThreeOfAKind) -> String\nshowThreeOfAKind {h} x = let (m::ms, r::rs) = getMatchAndRest3 h x in\n \"Three of a kind: \" ++ (show (cardValue m)) ++ \"s with a \" ++ (show (cardValue r)) ++ \" kicker\"\n\nshowStraight : (x : Straight h) -> String\nshowStraight {h = (z :: xs)} (MkStraight x y) = \"Straight: \" ++ (show (cardValue z)) ++ \" high\"\n\nshowFlush : (x : Flush h) -> String\nshowFlush {h = (y :: xs)} x = \"Flush: \" ++ (show (cardValue y)) ++ \" high\"\n\n\n\nshowFullHouse : (x : FullHouse h) -> String\nshowFullHouse {h} (MkFullHouse x three pair) = let (m1::m1s) = getMatch3 h three\n (m2::m2s) = (getRest3 h three) in\n \"Full house: \" ++ (show (cardValue m1)) ++ \"s over \" ++ (show (cardValue m2)) ++ \"s\"\n\nshowFourOfAKind : (x : SlideWise4 h FourOfAKind) -> String\nshowFourOfAKind {h} x = let (m::ms, [kicker]) = getMatchAndRest4 h x in\n \"Four of a kind: \" ++ (show (cardValue m)) ++ \"s with a \" ++ (show (cardValue kicker)) ++ \" kicker\"\n\nshowStraightFlush : (x : StraightFlush h) -> String\nshowStraightFlush {h = (y :: xs)} x = \"Straight flush: \" ++ (show (cardValue y)) ++ \" high\"\n\nexport Show (Hand h) where\n show (StraightFlushHand x) = showStraightFlush x\n show (FourOfAKindHand x) = showFourOfAKind x\n show (FullHouseHand x) = showFullHouse x\n show (FlushHand x) = showFlush x\n show (StraightHand x) = showStraight x\n show (ThreeOfAKindHand x) = showThreeOfAKind x\n show (TwoPairHand x) = showTwoPair x\n show (PairHand x) = showPair x\n show (HighCardHand h) = showHighCard h\n", "meta": {"hexsha": "82dc60998876efdd7059132233ba3b8c13dfa6fb", "size": 26877, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Poker/Hands.idr", "max_stars_repo_name": "as8709/PokerHands", "max_stars_repo_head_hexsha": "873a9b646ff5f021b4af80ac3325d51397639716", "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": "Poker/Hands.idr", "max_issues_repo_name": "as8709/PokerHands", "max_issues_repo_head_hexsha": "873a9b646ff5f021b4af80ac3325d51397639716", "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": "Poker/Hands.idr", "max_forks_repo_name": "as8709/PokerHands", "max_forks_repo_head_hexsha": "873a9b646ff5f021b4af80ac3325d51397639716", "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": 58.9407894737, "max_line_length": 188, "alphanum_fraction": 0.4476318041, "num_tokens": 6007, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6043910650535241}} {"text": "module Issue833\n\nimport Data.Fin\n\n%default total\n\ndata Singleton : Nat -> Type where\n Sing : {n : Nat} -> Singleton n\n\nf : (n : Singleton Z) -> n === Sing\nf = \\ Sing => Refl\n\ng : (k : Fin 1) -> k === FZ\ng = \\ FZ => Refl\n\nsym : {t, u : a} -> t === u -> u === t\nsym = \\Refl => Refl\n", "meta": {"hexsha": "35c3e27d9d5c4b3871522be934e528ba201adac8", "size": 281, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/basic051/Issue833.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/basic051/Issue833.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/basic051/Issue833.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": 15.6111111111, "max_line_length": 38, "alphanum_fraction": 0.5160142349, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267118111485245, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6043747664389887}} {"text": "> module Pairs.Operations\n\n> import Sigma.Sigma\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n> -- %hide getWitness\n> -- %hide getProof\n\n> {-\n\n> namespace Exists\n> getWitness : {P : a -> Type} -> Exists {a} P -> a\n> getWitness (Evidence x pf) = x\n> getProof : {P : a -> Type} -> (x : Exists {a} P) -> P (getWitness x)\n> getProof (Evidence x pf) = pf\n\n\n> namespace Subset\n> getWitness : {P : a -> Type} -> Subset a P -> a\n> getWitness (Element x pf) = x\n> getProof : {P : a -> Type} -> (x : Subset a P) -> P (getWitness x)\n> getProof (Element x pf) = pf\n\n> ---}\n\n> namespace Sigma\n> getWitness : {P : a -> Type} -> Sigma a P -> a\n> getWitness (MkSigma x pf) = x\n> getProof : {P : a -> Type} -> (x : Sigma a P) -> P (getWitness x)\n> getProof (MkSigma x pf) = pf\n\n\n", "meta": {"hexsha": "92e9acce0ade189f14025b9fba2accd7411ad728", "size": 804, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Pairs/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": "Pairs/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": "Pairs/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": 22.3333333333, "max_line_length": 72, "alphanum_fraction": 0.5671641791, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.604195066162131}} {"text": "import Data.Vect\n\nappend_nil : Vect m elem -> Vect (plus m 0) elem\nappend_nil xs = rewrite plusZeroRightNeutral m in xs\n\nappend_xs : Vect (S (m + len)) elem -> Vect (m + (S len)) elem\nappend_xs xs = rewrite sym (plusSuccRightSucc m len) in xs\n\n-- by \"carelessly\" changing `n + m` to `m + n` we need use a few rewrites\n-- to prove to idris that the definition is valid\nappend : Vect n elem -> Vect m elem -> Vect (m + n) elem\nappend [] ys = append_nil ys\nappend (x :: xs) ys = append_xs (x :: append xs ys)", "meta": {"hexsha": "68b56828765c2adc8f45d6be10a84e94fb145b75", "size": 505, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch8/AppendVec.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/AppendVec.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/AppendVec.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": 38.8461538462, "max_line_length": 73, "alphanum_fraction": 0.6772277228, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6040469203966895}} {"text": "module Cursor\n\nimport Data.Fin\n\n%default total\n\npublic export\ndata Cursor : Nat -> Type where\n MkCursor : Nat -> Fin n -> Cursor n\n\nexport\nright : Cursor n -> Cursor n\nright (MkCursor x y) = MkCursor (S x) y\n\nexport\nleft : Cursor n -> Cursor n\nleft (MkCursor (S x) y) = MkCursor x y\nleft (MkCursor Z y) = MkCursor Z y\n\ndec : Fin n -> Fin n\ndec FZ = FZ\ndec (FS k) = weaken k\n\nexport\nup : Cursor n -> Cursor n\nup (MkCursor x y) = MkCursor x (dec y)\n\nexport\ndown : Cursor n -> Cursor (S n)\ndown (MkCursor x y) = MkCursor x (shift 1 y)\n\nexport\ndownInBounds : Cursor n -> Cursor n\ndownInBounds originalCursor@(MkCursor x y) =\n case strengthen $ shift 1 y of\n Left _ => originalCursor\n Right newY => MkCursor x newY\n\n--todo: is it possible to use something like strengthenN and shift?\nexport\ndownWithnInBounds : Nat -> Cursor n -> Cursor n\ndownWithnInBounds d originalCursor@(MkCursor x y) {n} =\n case natToFin ((finToNat y) + d) n of\n Nothing => originalCursor\n Just newY => MkCursor x newY\n\nexport\nlineStart : Cursor n -> Cursor n\nlineStart (MkCursor _ y) = MkCursor Z y\n", "meta": {"hexsha": "b64a3a6a1320baf0c9a8de61de33034a3dd0bedc", "size": 1082, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Cursor.idr", "max_stars_repo_name": "PeterHajdu/peti", "max_stars_repo_head_hexsha": "bd1ba3b4ea805b645348d9c11f5c3d85ee835e72", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-10T09:23:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-10T09:23:10.000Z", "max_issues_repo_path": "Cursor.idr", "max_issues_repo_name": "PeterHajdu/peti", "max_issues_repo_head_hexsha": "bd1ba3b4ea805b645348d9c11f5c3d85ee835e72", "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": "Cursor.idr", "max_forks_repo_name": "PeterHajdu/peti", "max_forks_repo_head_hexsha": "bd1ba3b4ea805b645348d9c11f5c3d85ee835e72", "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": 21.64, "max_line_length": 67, "alphanum_fraction": 0.6866913124, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6040469203966894}} {"text": "module Main\n\nimport Data.Vect\n\ndata Box = X | O | Empty\n\nisEmpty : Box -> Bool\nisEmpty Empty = True\nisEmpty _ = False\n\nBoard : (size : Nat) -> Type\nBoard size = Vect size (Vect size Box)\n\nnewBoard : (size : Nat) -> Board size\nnewBoard size = replicate size (replicate size Empty)\n\nmarkColumn : Box -> Vect x Box -> Fin x -> Maybe (Vect x Box)\nmarkColumn mark (x :: xs) FZ = case x of\n Empty => Just (mark :: xs)\n _ => Nothing\nmarkColumn mark (x :: xs) (FS y) = case markColumn mark xs y of\n Nothing => Nothing\n Just rest => Just (x :: rest)\n\nmarkSquare : Vect x (Vect y Box) -> Box -> Fin x -> Fin y -> Maybe (Vect x (Vect y Box))\nmarkSquare (x :: xs) mark FZ j = case markColumn mark x j of\n Nothing => Nothing\n Just new_x => Just (new_x :: xs)\nmarkSquare (x :: xs) mark (FS i) j = case markSquare xs mark i j of\n Nothing => Nothing\n Just rest => Just (x :: rest)\n\ncheckVect : Vect x Box -> Maybe Box\ncheckVect [] = Just Empty\ncheckVect (x :: xs) = let rest = checkVect xs in\n match x rest where\n match : Box -> Maybe Box -> Maybe Box\n match x Nothing = Nothing\n match X (Just X) = Just X\n match X (Just O) = Nothing\n match X (Just Empty) = Just X\n match O (Just X) = Nothing\n match O (Just O) = Just O\n match O (Just Empty) = Just O\n match Empty (Just y) = Nothing\n\ncheckRows : Vect x (Vect y Box) -> Maybe Box\ncheckRows [] = Nothing\ncheckRows (x :: xs) = case checkVect x of\n Just X => Just X\n Just Y => Just Y\n _ => checkRows xs\n\n\ncheckCols : Vect x (Vect y Box) -> Maybe Box\ncheckCols board = checkRows (transpose board)\n\ncheckDiags : Board size -> Maybe Box\ncheckDiags {size} board = case checkVect (diag board) of\n Just a => Just a\n Nothing => case checkVect (diag (reverse board)) of\n Just a => Just a\n Nothing => Nothing\n\nfindLegalMoves : Vect x (Vect y Box) -> Nat -> List (Nat, Nat)\nfindLegalMoves [] i = []\nfindLegalMoves (x :: xs) i = let hits = the (List Nat) (findIndices isEmpty (toList x)) in\n (zip (replicate (length hits) i) hits) ++ (findLegalMoves xs (i+1))\n\n\ncheckDraw : Board size -> Bool\ncheckDraw board = (length (findLegalMoves board 0)) == 0\n\n\ncheckVictory : Board size -> Maybe Box\ncheckVictory b = case checkRows b of\n Just X => Just X\n Just O => Just O\n Nothing => case checkCols b of\n Just X => Just X\n Just O => Just O\n Nothing => case checkDiags b of\n Just X => Just X\n Just O => Just O\n Nothing => case checkDraw b of\n True => Just Empty\n False => Nothing\nreadNumber : IO (Maybe Nat)\nreadNumber = do input <- getLine\n if all isDigit (unpack input)\n then pure (Just (cast input))\n else pure Nothing\n\ngetMove : Board size -> IO (Fin size, Fin size)\ngetMove board {size} = do putStr \"Enter row: \"\n Just row <- readNumber | Nothing => getMove board\n let fRow = natToFin row size\n putStr \"Enter col: \"\n Just col <- readNumber | Nothing => getMove board\n let fCol = natToFin col size\n case finalizeMove fRow fCol of\n Nothing => getMove board\n Just move => pure move\n where\n finalizeMove : Maybe (Fin b) -> Maybe (Fin b) -> Maybe (Fin b, Fin b)\n finalizeMove Nothing y = Nothing\n finalizeMove (Just x) Nothing = Nothing\n finalizeMove (Just x) (Just y) = Just (x, y)\n\n\nformattedRow : Vect n String -> String\nformattedRow [] = \"\"\nformattedRow (x :: xs) = x ++ (formattedRow xs)\n\nstringify : Box -> String\nstringify X = \"X\"\nstringify O = \"O\"\nstringify Empty = \" \"\n\nshowBoard : Vect n (Vect m Box) -> String\nshowBoard [] = \"\"\nshowBoard (x :: xs) {m} = (formattedRow (intersperse \"|\" (map stringify x))) ++ \"\\n\" ++\n rest xs where\n rest : Vect n' (Vect m Box) -> String\n rest [] = showBoard xs\n rest xs = (formattedRow (replicate (2 * m) \"-\")) ++ \"\\n\" ++ (showBoard xs)\n\n\nflipPlayer : Box -> Box\nflipPlayer X = O\nflipPlayer O = X\nflipPlayer Empty = Empty\n\nrunGame : Board size -> Box -> IO ()\nrunGame [] player = putStrLn \"weird board!\"\nrunGame board player = do putStrLn (showBoard board)\n putStrLn ((stringify player) ++ \"'s turn: \")\n move <- getMove board\n case markSquare board player (fst move) (snd move) of\n Nothing => runGame board player\n Just new_board => case checkVictory new_board of\n Nothing => runGame new_board (flipPlayer player)\n Just Empty => putStrLn \"Draw\"\n Just b => putStrLn ((stringify b) ++ \" wins!\")\n\nmain : IO ()\nmain = do runGame (newBoard 3) X\n", "meta": {"hexsha": "77aa4dd6fbe151c6ac88fe276cd07b703070b3d9", "size": 6198, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TicTacToe.idr", "max_stars_repo_name": "scotthellman/tictactoe", "max_stars_repo_head_hexsha": "359bb316062a1da27221b1dc058ffb9125e9d873", "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": "TicTacToe.idr", "max_issues_repo_name": "scotthellman/tictactoe", "max_issues_repo_head_hexsha": "359bb316062a1da27221b1dc058ffb9125e9d873", "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": "TicTacToe.idr", "max_forks_repo_name": "scotthellman/tictactoe", "max_forks_repo_head_hexsha": "359bb316062a1da27221b1dc058ffb9125e9d873", "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.8783783784, "max_line_length": 102, "alphanum_fraction": 0.4498225234, "num_tokens": 1278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6037303851362766}} {"text": "module IndProp\n\nimport Logic\n\n%access public export\n\n%default total\n\ndata Reflect : (p : Type) -> Bool -> Type where\n ReflectT : p -> (b=True) -> Reflect p b\n ReflectF : (Not p) -> (b=False) -> Reflect p b\n\niff_reflect : (p ↔ (b=True)) -> Reflect p b\niff_reflect {b = False} (pb, _) = ReflectF (uninhabited . pb) Refl\niff_reflect {b = True} (_, bp) = ReflectT (bp Refl) Refl\n\nreflect_iff : Reflect p b -> (p ↔ (b=True))\nreflect_iff (ReflectT p b_true) = (\\_ => b_true, \\_ => p)\nreflect_iff (ReflectF not_p b_false) =\n ( \\p => void (not_p p)\n , \\b_true => void . uninhabited $\n the (False = True) $ rewrite sym b_false in b_true)\n", "meta": {"hexsha": "ecc3bbf1fac425f4518f48d4cf63ffca3e73117f", "size": 638, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "IndProp.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": "IndProp.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": "IndProp.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": 27.7391304348, "max_line_length": 66, "alphanum_fraction": 0.6300940439, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.6757646140788307, "lm_q1q2_score": 0.603666889874178}} {"text": "> module Void.Properties\n\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Sigma.Sigma\n\n\n> %default total\n\n> %access public export\n\n\n> ||| Mapping |Void|s to |Fin|s\n> toFin : Void -> Fin Z\n> toFin = void\n> %freeze toFin\n\n\n> ||| Mapping |Fin Z|s to |Void|s\n> fromFin : Fin Z -> Void\n> fromFin k = absurd k\n> %freeze fromFin \n\n\n> ||| |toFin| is the left-inverse of |fromFin|\n> toFinFromFinLemma : (k : Fin Z) -> toFin (fromFin k) = k\n> toFinFromFinLemma k = absurd k\n> %freeze toFinFromFinLemma\n\n\n> ||| |fromFin| is the left-inverse of |toFin|\n> fromFinToFinLemma : (e : Void) -> fromFin (toFin e) = e\n> fromFinToFinLemma e = void e\n> %freeze fromFinToFinLemma\n\n\n> ||| Void is finite\n> finiteVoid : Finite Void\n> finiteVoid = MkSigma Z iso where\n> iso : Iso Void (Fin Z)\n> iso = MkIso toFin fromFin toFinFromFinLemma fromFinToFinLemma\n\n\n> ||| Void is decidable\n> decidableVoid : Dec Void\n> decidableVoid = No void\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "ffcdca0568becc26a3edd4f03b03fbd9ae181423", "size": 967, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Void/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": "Void/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": "Void/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": 17.5818181818, "max_line_length": 65, "alphanum_fraction": 0.6659772492, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.6791787056691698, "lm_q1q2_score": 0.6036260510186379}} {"text": "-- Exercises.idr\n-- Solutions for exercises of chapter 2\n\nmodule Exercises\n\nimport Data.Vect\n\n-- length function\nmyLength : List a -> Nat\nmyLength [] = 0\nmyLength (x :: xs) = 1 + myLength xs\n\n\n-- reverse function\nmyReverse : List a -> List a\nmyReverse [] = []\nmyReverse (x :: xs) = (myReverse xs) ++ [x]\n\n-- myVectReverse : Vect n a -> Vect n a\n-- myVectReverse [] = []\n-- myVectReverse (x :: xs) = (?myVectReverse_rhs xs) ++ (the (Vect 1 _) [x])\n\n\n-- map function\nmyMap : (a -> b) -> List a -> List b\nmyMap f [] = []\nmyMap f (x :: xs) = f x :: myMap f xs\n\nmyVectMap : (a -> b) -> Vect n a -> Vect n b\nmyVectMap f [] = []\nmyVectMap f (x :: xs) = f x :: myVectMap f xs\n\n", "meta": {"hexsha": "98ecaf6d413f19a4b05a9a4092968a4f21d6ac28", "size": 669, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_3/Exercise_3_2_3.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/Exercise_3_2_3.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/Exercise_3_2_3.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": 20.2727272727, "max_line_length": 76, "alphanum_fraction": 0.5919282511, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6034887552224161}} {"text": "module GenericAdder\n\n%default total\n\nAdderType : (numargs : Nat) -> (elemType : Type) -> Type\nAdderType Z ty = ty\nAdderType (S k) ty = (next : ty) -> AdderType k ty\n\nadder : Num elemType => (numargs : Nat) -> (acc : elemType) -> AdderType numargs elemType\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (acc + next)\n", "meta": {"hexsha": "cef39328baa62e810ff178511573279216af1789", "size": 322, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter6/GenericAdder.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": "chapter6/GenericAdder.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": "chapter6/GenericAdder.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": 26.8333333333, "max_line_length": 89, "alphanum_fraction": 0.652173913, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6034281197169146}} {"text": "\nmodule Part2.Sec9_2_hangman\nimport Data.Vect\nimport Part2.Sec9_1_elem\n\n%default total \n\ndata WordState : (guesses_remaining : Nat) -> (letters : Nat) -> Type where\n MkWordState : (word : String) ->\n (missing : Vect letters Char) ->\n WordState guesses_remaining letters\n\ndata Finished : Type where\n Lost : (game : WordState 0 (S letters)) -> Finished\n Won : (game : WordState (S guesses) 0) -> Finished\n\nprocessGuess : (letter : Char) -> WordState (S guesses) (S letters) -> Either (WordState guesses (S letters)) (WordState (S guesses) letters)\nprocessGuess letter (MkWordState word missing) = case isElem letter missing of\n Yes prf => Right (MkWordState word (removeElem_auto letter missing)) \n No contra => Left (MkWordState word missing)\n\n{- the rest is user interface code -}\n\ndata ValidInput : List Char -> Type where\n Letter : (c : Char) -> ValidInput [c]\n\ninvalidNil : ValidInput [] -> Void\ninvalidNil (Letter _) impossible\n\ninvalidTwo : ValidInput (x :: y :: xs) -> Void\ninvalidTwo (Letter _) impossible\n\nisValidInput : (cs : List Char) -> Dec (ValidInput cs)\nisValidInput [] = No invalidNil\nisValidInput (x :: []) = Yes (Letter x)\nisValidInput (x :: (y :: xs)) = No invalidTwo\n\nisValidString : (s : String) -> Dec (ValidInput (unpack s))\nisValidString s = isValidInput (unpack s)\n\ncovering\nreadGuess : IO (x ** ValidInput x)\nreadGuess = do putStr \"Guess:\"\n x <- getLine\n case isValidString (toUpper x) of\n Yes prf => pure (_ ** prf)\n No contra => do putStrLn \"Invalid guess\"\n readGuess\n\ncovering\ngame : WordState (S guesses) (S letters) -> IO Finished\ngame {guesses} {letters} st\n = do (_ ** Letter letter) <- readGuess\n case processGuess letter st of\n Left l => do putStrLn \"Wrong!\"\n case guesses of\n Z => pure (Lost l)\n S k => game l\n Right r => do putStrLn \"Right!\"\n case letters of\n Z => pure (Won r)\n S k => game r\n\n{- To execute in repl, idrs repl from src folder, :l this file and use :exec sec_9_2 -}\ncovering\nsec_9_2 : IO ()\nsec_9_2 = do result <- game {guesses=2} (MkWordState \"Test\" ['T', 'E', 'S'])\n case result of\n Lost (MkWordState word missing) =>\n putStrLn (\"You lose. The word was \" ++ word)\n Won game =>\n putStrLn \"You win!\"\n", "meta": {"hexsha": "46c94755f8c500a51cc4336bb79f5cc490d0c6a3", "size": 2691, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Part2/Sec9_2_hangman.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/Sec9_2_hangman.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/Sec9_2_hangman.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": 36.8630136986, "max_line_length": 141, "alphanum_fraction": 0.5510962467, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6030045650529025}} {"text": "module Data.Map\n\n%default total\n\nexport\ndata Map : (key : Type) -> (VF : key -> Type) -> Type where\n MNil : .{VF : key -> Type} -> Map key VF\n MBranch : (DecEq key, Ord key) =>\n .{VF : key -> Type}\n -> (k : key)\n -> (val : VF k )\n -> (l : Map key VF)\n -> (r : Map key VF)\n -> Map key VF\n\n%name Map map, map2, map3\n\nempty : Map k p\nempty = MNil\n\ninsert : (DecEq key, Ord key) => (k : key) -> p k -> Map key p -> Map key p\ninsert k x MNil = MBranch k x MNil MNil\ninsert k x (MBranch kr val l r) =\n case compare k kr of\n LT => MBranch kr val (insert k x l) r\n EQ => MBranch k x l r\n GT => MBranch kr val l (insert k x r)\n\nlookup : (DecEq key, Ord key) => (k : key) -> Map key p -> Maybe (p k)\nlookup _ MNil = Nothing\nlookup k (MBranch kr val l r) =\n case decEq k kr of\n Yes prf => rewrite prf in Just val\n No _ => case compare k kr of\n LT => lookup k l\n _ => lookup k r\n\ninsertWith : (DecEq key, Ord key) => (k : key) -> p k -> (p k -> p k -> p k) -> Map key p -> Map key p\ninsertWith k x f m =\n case lookup k m of\n Just v => insert k (f x v) m\n Nothing => insert k x m\n-- it would be nice to implement this with one traversal,\n-- but having a hard time rewriting some types\n-- insertWith k x f MNil = MBranch k x MNil MNil\n-- insertWith {p} k x f (MBranch kr val l r) =\n-- case decEq kr k of\n-- Yes prf => MBranch k (f x val) l r\n-- No _ => case compare k kr of\n-- LT => insertWith k x f l\n-- _ => insertWith k x f r\n\nfromList : (DecEq key, Ord key) => List (k : key ** p k) -> Map key p\nfromList [] = MNil\nfromList ((k ** v) :: xs) = insert k v $ fromList xs\n", "meta": {"hexsha": "6a8ece5c288faf197eb372a5c3ec5057502e3e23", "size": 1800, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "dependent-map/lib/Data/Map.idr", "max_stars_repo_name": "jhmcstanton/idris-sandbox", "max_stars_repo_head_hexsha": "f10e53fca354c27286daaf71bd4377b773426cad", "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": "dependent-map/lib/Data/Map.idr", "max_issues_repo_name": "jhmcstanton/idris-sandbox", "max_issues_repo_head_hexsha": "f10e53fca354c27286daaf71bd4377b773426cad", "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": "dependent-map/lib/Data/Map.idr", "max_forks_repo_name": "jhmcstanton/idris-sandbox", "max_forks_repo_head_hexsha": "f10e53fca354c27286daaf71bd4377b773426cad", "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.1428571429, "max_line_length": 102, "alphanum_fraction": 0.515, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.6992544273261176, "lm_q1q2_score": 0.6024344072552676}} {"text": "module Basic.Types.Qubit\n\nimport Data.Complex\nimport Data.Vect\nimport Effects\nimport Effect.Random\nimport Utils.Accomodation\nimport Utils.ComplexAddon\n\n%default total\n%access public export\n\nrecord QuantumState a where\n constructor QS\n amplitude : Complex a\n label : String\n\n%name QuantumState qs, qs1, qs2, qs3\nimplementation (Num a, Neg a, Show a, Eq a, Ord a) \n => Show (QuantumState a) where\n show (QS amplitude label) = complexShow amplitude ++ \"|\" ++ label ++ \">\" where\n complexShow : Complex a -> String \n complexShow (x :+ y) = \n if x == x + x \n then imShow y\n else if y <= y + y\n then show x ++ \"+\" ++ imShow y\n else show x ++ imShow y where\n imShow : a -> String\n imShow y = \n if y > y + y \n then \"-\" ++ imPosShow (negate y)\n else imPosShow y where\n imPosShow : (y : a) -> String\n imPosShow y = if y /= y + y \n then if y * y == y\n then \"i\"\n else show y ++ \"i\"\n else \"0\"\n \n\nqMap : (f : Complex a -> Complex b) -> QuantumState a -> QuantumState b\nqMap f (QS amplitude label) = QS (f amplitude) label\n\nimplementation Eq a => Eq (QuantumState a) where\n (QS amplitude1 label1) == (QS amplitude2 label2) = \n (amplitude1 == amplitude2) && (label1 == label2)\nimplementation [vectorization] Eq a => Ord (QuantumState a) where\n compare (QS amplitude1 label1) (QS amplitude2 label2) = compare label1 label2\n\nqPredicate : (p : Complex a -> Bool) -> QuantumState a -> Bool\nqPredicate p (QS amplitude label) = p amplitude\n\nconjugateQS : Neg a => QuantumState a -> QuantumState a\nconjugateQS = qMap conjugate\n\nrecord Qubit a where\n constructor QB\n states : List (QuantumState a)\n%name Qubit qb, qb1, qb2, qb3\npartial\nimplementation (Num a, Neg a, Show a, Eq a, Ord a) \n => Show (Qubit a) where\n show (QB []) = \"\" \n show (QB (x :: [])) = show x \n show (QB (x :: qb@(y :: xs))) = show x ++ \" + \" \n ++ show (QB qb)\n\ntoAmplList : Qubit a -> List (Complex a)\ntoAmplList (QB states) = map amplitude states\n\ntoLabelList : Qubit a -> List String\ntoLabelList (QB states) = map label states\n\nfromList : List (Complex a) -> List String -> Qubit a\nfromList xs ys = QB (zipWith QS xs ys)\n\nrefine : Ord a => Qubit a -> List (QuantumState a)\nrefine (QB states) = sort @{vectorization} states\n\ntoFineList : Eq a => Qubit a -> List (Complex a)\ntoFineList (QB states) = map amplitude (sort @{vectorization} states)\n\nfromFineList : List (Complex a) -> Qubit a \nfromFineList xs = QB (zipWith QS xs (accomod \"01\" (degree (length xs) 2)))\n\nliftQubit : (f : List (QuantumState a) -> List (QuantumState b)) \n -> Qubit a -> Qubit b\nliftQubit f (QB states) = QB (f states)\n\ninfix 2 <~>\n(<~>) : Neg a => QuantumState a -> QuantumState a -> QuantumState a\n(QS amplitude1 label1) <~> (QS amplitude2 label2) = \n QS (amplitude1 * amplitude2) (label1 ++ label2)\n\nentangle : Neg a => Qubit a -> Qubit a -> Qubit a\nentangle (QB states1) (QB states2) = QB [|states1 <~> states2|]\n\nconjugateQubit : Neg a => Qubit a -> Qubit a\nconjugateQubit = liftQubit (map conjugateQS)\n\nscalarProduct : (Neg a, Eq a) => Qubit a -> Qubit a -> a\nscalarProduct qb1 qb2 = realPart \n (sum \n (Prelude.List.zipWith (*) \n (toFineList qb1) \n (toFineList qb2)))\n\nnorm : (Cast a Double, Cast Double a, Neg a, Eq a) => Qubit a -> a\nnorm qb = (cast . sqrt . cast) (scalarProduct qb (conjugateQubit qb))\n\nnormalize : (Cast a Double, Cast Double a, Neg a, Eq a, Fractional a) => \n Qubit a -> Qubit a\nnormalize qb = liftQubit ((map . qMap) \n (cast . \n (\\x => x / (((sqrt . cast) \n (scalarProduct qb (conjugateQubit qb))):+0)) . \n cast)) qb\n\nextract : (Cast a Double, Cast Double a, Neg a, Eq a) => \n Qubit a -> Eff String [RND]\nextract qb = helper (map cast (toAmplList qb)) (toLabelList qb) where\n helper : List (Complex Double) -> List String-> Eff String [RND]\n helper ampl labels = help (part 0 ampl) labels where\n part : Double -> List (Complex Double) -> List Double\n part prev [] = []\n part prev ((x :+ y) :: xs) = curr :: part curr xs where\n curr : Double\n curr = prev + x * x + y * y\n help : List Double -> List String -> Eff String [RND]\n help [] _ = pure \"Nothing\"\n help ds@(x :: xs) ys = \n do rand <- assert_total (rndInt 0 (transmute (last ds)))\n findAns (zip (map transmute ds) ys) rand\n where\n transmute : Double -> Integer\n transmute x = cast (1000000000 * x)\n findAns : List (Integer, String) -> Integer -> Eff String [RND]\n findAns [] _ = pure \"Nothing\"\n findAns ((p, label) :: xs) r = case p < r of\n False => findAns xs r\n True => pure label\n\n\nqubitZero : Qubit Double\nqubitZero = QB ([(QS (1 :+ 0) \"0\"), \n (QS (0 :+ 0) \"1\")])\n\nqubitOne : Qubit Double\nqubitOne = QB ([(QS (0 :+ 0) \"0\"), \n (QS (1 :+ 0) \"1\")])\n\nqubitPlus : Qubit Double\nqubitPlus = QB ([(QS ((1 / sqrt 2) :+ 0) \"0\"), \n (QS ((1 / sqrt 2) :+ 0) \"1\")])\n\nqubitMinus : Qubit Double\nqubitMinus = QB ([(QS ((1 / sqrt 2) :+ 0) \"0\"), \n (QS (((-1) / sqrt 2) :+ 0) \"1\")])\n\nqubitPhiPlus : Qubit Double\nqubitPhiPlus = QB ([(QS ((1 / sqrt 2) :+ 0) \"00\"), \n (QS ((1 / sqrt 2) :+ 0) \"11\")])\n\nqubitPhiMinus : Qubit Double\nqubitPhiMinus = QB ([(QS ((1 / sqrt 2) :+ 0) \"00\"), \n (QS (((-1) / sqrt 2) :+ 0) \"11\")])\n\nqubitPsiPlus : Qubit Double\nqubitPsiPlus = QB ([(QS ((1 / sqrt 2) :+ 0) \"01\"), \n (QS ((1 / sqrt 2) :+ 0) \"10\")])\n\nqubitPsiMinus : Qubit Double\nqubitPsiMinus = QB ([(QS ((1 / sqrt 2) :+ 0) \"01\"), \n (QS (((-1) / sqrt 2) :+ 0) \"10\")])\n\n\n", "meta": {"hexsha": "d176ffaf349a8dcef0e2138c64aec5d0862bbc26", "size": 6444, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Basic/Types/Qubit.idr", "max_stars_repo_name": "GrandArchTemplar/QuantumProgramming", "max_stars_repo_head_hexsha": "54da87cc4471ad6b8d510dc35095edc74efa9ec4", "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/Basic/Types/Qubit.idr", "max_issues_repo_name": "GrandArchTemplar/QuantumProgramming", "max_issues_repo_head_hexsha": "54da87cc4471ad6b8d510dc35095edc74efa9ec4", "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/Basic/Types/Qubit.idr", "max_forks_repo_name": "GrandArchTemplar/QuantumProgramming", "max_forks_repo_head_hexsha": "54da87cc4471ad6b8d510dc35095edc74efa9ec4", "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.202247191, "max_line_length": 80, "alphanum_fraction": 0.5136561142, "num_tokens": 1854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.6619228758499942, "lm_q1q2_score": 0.6022882589584984}} {"text": "module Data.Scientific\n\nimport Data.Fin\nimport Data.List\nimport Data.Vect\n\n||| Arbitrary precision coefficient for scientific notation in base b.\n||| Representants are unique regarding (==) and there are no trailing zeros.\n||| For a coefficient x this holds:\n||| 1 <= x < b\npublic export\ndata Coefficient : (b : Nat) -> Type where\n CoeffInt : Fin (S b) ->\n Coefficient (S (S b))\n CoeffFloat : Fin (S b) ->\n List (Fin (S (S b))) ->\n Fin (S b) ->\n Coefficient (S (S b))\n\npublic export\nUninhabited (Coefficient 0) where\n uninhabited _ impossible\npublic export\nUninhabited (Coefficient 1) where\n uninhabited _ impossible\n\npublic export\nEq (Coefficient b) where\n (CoeffInt x) == (CoeffInt y) = x == y\n (CoeffFloat x xs x') == (CoeffFloat y ys y') = x == y && xs == ys && x' == y'\n _ == _ = False\n\npublic export\nOrd (Coefficient b) where\n compare (CoeffInt x) (CoeffInt y) = compare x y\n compare (CoeffInt x) (CoeffFloat y ys y') = case compare x y of\n EQ => LT\n comp => comp\n compare (CoeffFloat x xs x') (CoeffInt y) = case compare x y of\n EQ => GT\n comp => comp\n compare (CoeffFloat x xs x') (CoeffFloat y ys y') =\n compare (FS x :: xs `snoc` FS x') (FS y :: ys `snoc` FS y')\n\nprivate\nprettyShowDigit : Fin 10 -> Char\nprettyShowDigit x =\n case x of\n 0 => '0'\n 1 => '1'\n 2 => '2'\n 3 => '3'\n 4 => '4'\n 5 => '5'\n 6 => '6'\n 7 => '7'\n 8 => '8'\n 9 => '9'\n\nprivate\nprettyShowCoefficient : Coefficient 10 -> String\nprettyShowCoefficient (CoeffInt x) = pack [ prettyShowDigit (FS x) ]\nprettyShowCoefficient (CoeffFloat x xs x') =\n pack $ [ prettyShowDigit (FS x), '.' ] ++ map prettyShowDigit xs ++ [ prettyShowDigit (FS x') ]\n\npublic export\ndata Sign = Positive\n | Negative\n\npublic export\nEq Sign where\n Positive == Positive = True\n Negative == Negative = True\n _ == _ = False\n\npublic export\nOrd Sign where\n compare Positive Positive = EQ\n compare Positive Negative = GT\n compare Negative Positive = LT\n compare Negative Negative = EQ\n\nprivate\nprettyShowSign : Sign -> String\nprettyShowSign s = case s of\n Positive => \"\"\n Negative => \"-\"\n\n||| A scientific notation numeral in base b.\n||| Representants are unique, as this type is built on top of Coefficient.\n||| The numbers x represented are those which can be written as a finite sum of powers of b:\n||| x = \\Sigma_{i=n}^m a_i * b^i , {n,m : Integer; a_i : Fin b}\npublic export\ndata Scientific : (b : Nat) -> Type where\n SciZ : Scientific (S (S b))\n Sci : Sign ->\n Coefficient b ->\n Integer ->\n Scientific b\n\npublic export\nUninhabited (Scientific 0) where\n uninhabited (Sci _ _ _) impossible\n\npublic export\nUninhabited (Scientific 1) where\n uninhabited (Sci _ _ _) impossible\n\npublic export\nEq (Scientific b) where\n SciZ == SciZ = True\n (Sci s c e) == (Sci s' c' e') = s == s' && c == c' && e == e'\n _ == _ = False\n\npublic export\nOrd (Scientific b) where\n compare SciZ SciZ = EQ\n compare SciZ (Sci s _ _) = case s of\n Positive => LT\n Negative => GT\n compare (Sci s _ _) SciZ = case s of\n Positive => GT\n Negative => LT\n compare (Sci s c e) (Sci s' c' e') =\n case (s, s') of\n (Positive, Positive) => case compare e e' of\n EQ => compare c c'\n comp => comp\n (Positive, Negative) => GT\n (Negative, Positive) => LT\n (Negative, Negative) => case compare e' e of\n EQ => compare c' c\n comp => comp\n\ninfixl 9 ^\nprivate\n(^) : Nat -> Nat -> Nat\nx ^ Z = 1\nx ^ (S k) = x * (x ^ k)\n\nprivate\ndigitsToNat : {b : _} -> List (Fin (S (S b))) -> Nat\ndigitsToNat [] = 0\ndigitsToNat (x::xs) = finToNat x + (S (S b)) * digitsToNat xs\n\nexport\ntoInteger : {b : _} -> Scientific b -> Maybe Integer\ntoInteger SciZ = Just 0\ntoInteger (Sci s c e) =\n if e >= 0\n then case c of\n CoeffInt x => Just $ withSign $ finToNat (FS x) * (b ^ integerToNat e)\n CoeffFloat x xs x' => let digits = reverse $ (FS x) :: xs ++ [FS x']\n e' = e - natToInteger (length (xs ++ [FS x']))\n in if e' >= 0\n then Just $ withSign $ digitsToNat digits * (b ^ integerToNat e')\n else Nothing\n else Nothing\nwhere\n withSign : Nat -> Integer\n withSign = case s of\n Negative => negate . natToInteger\n Positive => natToInteger\n\nexport\nnegate : Scientific b -> Scientific b\nnegate SciZ = SciZ\nnegate (Sci s c e) = let s' = case s of\n Positive => Negative\n Negative => Positive\n in Sci s' c e\n\nexport\nabs : Scientific b -> Scientific b\nabs SciZ = SciZ\nabs (Sci _ c e) = Sci Positive c e\n\n-- TODO: What happens, when Integer is negative? Low priority, since this is private.\n||| The digits of an Integer, least significant first.\nprivate\nintegerDigits : {b : _} -> Integer -> List (Fin (S (S b)))\nintegerDigits 0 = []\nintegerDigits x = d :: integerDigits r where\n d : Fin (S (S b))\n d = restrict (S b) x\n r : Integer\n r = x `div` natToInteger (S (S b))\n\n||| Remove the zeros near the head of a list.\nprivate\nremoveLeadingZeros : List (Fin (S (S b))) -> Maybe (Fin (S b), List (Fin (S (S b))))\nremoveLeadingZeros [] = Nothing\nremoveLeadingZeros (FZ :: xs) = removeLeadingZeros xs\nremoveLeadingZeros (FS x :: xs) = Just (x, xs)\n\nprivate\nfromDigits : List (Fin (S (S b))) -> Scientific (S (S b))\nfromDigits ys =\n case removeLeadingZeros $ reverse ys of\n Nothing => SciZ\n Just (x, ys') => case removeLeadingZeros $ reverse ys' of\n Nothing => Sci Positive (CoeffInt x) (cast $ length ys')\n Just (x', xs) => Sci Positive (CoeffFloat x (reverse xs) x') (cast $ length ys')\n\nexport\nfromFin : Fin (S (S b)) -> Scientific (S (S b))\nfromFin FZ = SciZ\nfromFin (FS x) = Sci Positive (CoeffInt x) 0\n\nexport\nfromInteger : {b : _} -> Integer -> Scientific (S (S b))\nfromInteger x = if x < 0\n then negate $ fromIntegerPositive x\n else fromIntegerPositive x\nwhere\n fromIntegerPositive : Integer -> Scientific (S (S b))\n fromIntegerPositive = fromDigits . integerDigits . abs\n\nexport\nfromNat : {b : _} -> Nat -> Scientific (S (S b))\nfromNat = fromInteger . natToInteger\n\n||| Single bit full adder in base (S (S b)).\nprivate\nplusBit : (op : Sign) ->\n {b : _} ->\n (carry : Bool) ->\n Fin (S (S b)) ->\n Fin (S (S b)) ->\n ((Fin (S (S b))), Bool)\nplusBit op False x FZ = (x, False)\nplusBit Positive True x FZ = case strengthen $ FS FZ of\n Nothing => (FZ, True)\n Just z => (z, False)\nplusBit Negative True x FZ = case x of\n FZ => (last, True)\n FS z => (weaken z, False)\nplusBit Positive carry x (FS y) = case strengthen $ FS x of\n Nothing => (fst $ plusBit Positive carry FZ (weaken y), True)\n Just z => plusBit Positive carry z (weaken y)\nplusBit Negative carry x (FS y) = case x of\n FZ => (fst $ plusBit Negative carry last (weaken y), True)\n FS z => plusBit Negative carry (weaken z) (weaken y)\n\n||| N bit full adder in base (S (S b)).\nexport\nplusBits : (op : Sign) ->\n {b : _} ->\n (carry : Bool) ->\n Vect n (Fin (S (S b))) ->\n Vect n (Fin (S (S b))) ->\n (Vect n (Fin (S (S b))), Bool)\nplusBits op carry [] [] = ([], carry)\nplusBits op carry (x :: xs) (y :: ys) =\n let (z, carry') = plusBit op carry x y\n (zs, sign) = plusBits op carry' xs ys\n in (z :: zs, sign)\n\n-- TODO: Add NonEmpty to result type.\n||| All bits of a Coefficient, least significant first.\nexport\ncoefficientBits : Coefficient (S (S b)) -> List (Fin (S (S b)))\ncoefficientBits (CoeffInt x) = [FS x]\ncoefficientBits (CoeffFloat x xs x') = reverse $ FS x :: xs ++ [FS x']\n\n-- TODO: get a definiton like this working:\n--equalizeLength : a ->\n-- (xs : List a) ->\n-- (ys : List a) ->\n-- (Vect (max (length xs) (length ys)) a, Vect (max (length xs) (length ys)) a)\nprivate\nequalizeLength : a ->\n (n : _) ->\n (xs : List a) ->\n (ys : List a) ->\n (Vect n a, Vect n a)\nequalizeLength a Z _ _ = ([],[])\nequalizeLength a (S k) [] [] = let (ps, qs) = equalizeLength a k [] []\n in (a :: ps, a :: qs)\nequalizeLength a (S k) [] (y::ys) = let (ps, qs) = equalizeLength a k [] ys\n in (a :: ps, y :: qs)\nequalizeLength a (S k) (x::xs) [] = let (ps, qs) = equalizeLength a k xs []\n in (x :: ps, a :: qs)\nequalizeLength a (S k) (x::xs) (y::ys) = let (ps, qs) = equalizeLength a k xs ys\n in (x :: ps, y :: qs)\n\n||| Wrapper for plusBits, adding padding regarding the exponent and trailing zeros.\nprivate\nplusBits' : (op : Sign) ->\n {b : _} ->\n (List (Fin (S (S b))), Integer) ->\n (List (Fin (S (S b))), Integer) ->\n (List (Fin (S (S b))), Bool)\nplusBits' op (xs,xe) (ys,ye) =\n let n = max (length xs) (length ys)\n (xs'', ys'') = equalizeLength FZ n xs' ys'\n (zs, overflow) = plusBits op False (reverse xs'') (reverse ys'')\n in (toList zs, overflow) where\n xs' : List (Fin (S (S b)))\n xs' = reverse $ xs ++ replicate (integerToNat ye `minus` integerToNat xe) FZ\n ys' : List (Fin (S (S b)))\n ys' = reverse $ ys ++ replicate (integerToNat xe `minus` integerToNat ye) FZ\n\n-- TODO: remove this or removeLeadingZeros\nprivate\nremoveLeadingZeros' : List (Fin (S (S b))) -> (Nat, Maybe (Fin (S b), List (Fin (S (S b)))))\nremoveLeadingZeros' [] = (Z, Nothing)\nremoveLeadingZeros' (FZ :: xs) = let (n, res) = removeLeadingZeros' xs\n in (S n, res)\nremoveLeadingZeros' (FS x :: xs) = (Z, Just (x, xs))\n\n||| Requires the digits to be ordered, least significant first.\n||| Returns Coefficient and number of significant zeros.\nprivate\nfromDigits' : List (Fin (S (S b))) -> (Maybe (Coefficient (S (S b))), Nat)\nfromDigits' ys =\n let (n, removedLeading) = removeLeadingZeros' $ reverse ys\n in case removedLeading of\n Nothing => (Nothing, n)\n Just (x, ys') => case removeLeadingZeros $ reverse ys' of\n Nothing => (Just (CoeffInt x), n)\n Just (x', xs) => (Just (CoeffFloat x (reverse xs) x'), n)\n\nexport\n(+) : {b : _} -> Scientific (S (S b)) -> Scientific (S (S b)) -> Scientific (S (S b))\nSciZ + y = y\nx + SciZ = x\nx@(Sci s c e) + y@(Sci s' c' e') =\n let (zs, bit) = plusBits' op (xs, e) (ys, e')\n in case op of\n Positive => let s'' = s\n bits = if bit then [FS FZ] else [FZ]\n in case fromDigits' $ zs ++ bits of\n (Nothing, _) => SciZ\n (Just c'', bitShift) => let e'' = max e e' + 1 - natToInteger bitShift\n in Sci s'' c'' e''\n Negative => let s'' = if bit then s' else s\n in case fromDigits' zs of\n (Nothing, _) => SciZ\n (Just c'', bitShift) => let e'' = max e e' - natToInteger bitShift\n in Sci s'' c'' e''\nwhere\n op : Sign\n op = if s == s'\n then Positive\n else Negative\n xs : List (Fin (S (S b)))\n xs = coefficientBits c\n ys : List (Fin (S (S b)))\n ys = coefficientBits c'\n\n(-) : {b : _} -> Scientific (S (S b)) -> Scientific (S (S b)) -> Scientific (S (S b))\nx - y = x + negate y\n\n-- TODO\n||| Multiply two Coefficients and return True in the Bool, when the product is greater than the base.\nprivate\nmultCoefficents : {b : _} -> Coefficient (S (S b)) -> Coefficient (S (S b)) -> (Coefficient (S (S b)), Bool)\nmultCoefficents (CoeffInt x) (CoeffInt y) =\n case integerToFin res (S b) of\n Nothing => (CoeffInt $ restrict b res, True)\n Just fin => (CoeffInt fin, False)\nwhere\n res : Integer\n res = (finToInteger x + 1) * (finToInteger y + 1) - 1\nmultCoefficents a@(CoeffInt x) b@(CoeffFloat y ys y') = multCoefficents b a\n-- TODO: finish multCoefficents\nmultCoefficents (CoeffFloat x xs x') (CoeffInt y) = ?multCoefficents_rhs_2\nmultCoefficents (CoeffFloat x xs x') (CoeffFloat y ys y') = ?multCoefficents_rhs_3\n\nexport\n(*) : {b : _} -> Scientific (S (S b)) -> Scientific (S (S b)) -> Scientific (S (S b))\nSciZ * y = SciZ\nx * SciZ = SciZ\n(Sci s c e) * (Sci s' c' e') = Sci s'' c'' e'' where\n coefficientPair : (Coefficient (S (S b)), Bool)\n coefficientPair = multCoefficents c c'\n s'' : Sign\n s'' = if s == s'\n then Positive\n else Negative\n c'' : Coefficient (S (S b))\n c'' = fst coefficientPair\n e'' : Integer\n e'' = if snd coefficientPair\n then e + e' + 1\n else e + e'\n\n-- -- TODO: implementations don't work because the base (S (S b)) isn't accessible in the method's context.\n-- -- TODO: consider other implementations:\n-- -- - Fractional might not terminate, because of infinite representation\n-- -- - Integral doesn't sound like it would fit, but mod and div make still make sense\n-- public export\n-- Num (Scientific b) where\n-- -- (+) = (+)\n-- -- (*) = (*)\n-- -- fromInteger = fromInteger\n\n-- public export\n-- Neg (Scientific b) where\n-- -- negate = negate\n-- -- (-) = (-)\n\n-- public export\n-- Abs (Scientific b) where\n-- -- abs = abs\n\n||| Create string representing using scientific notation.\nexport\nprettyShowScientific : Scientific 10 -> String\nprettyShowScientific SciZ = \"0\"\nprettyShowScientific (Sci s c e) = prettyShowSign s ++ prettyShowCoefficient c ++ prettyExponent where\n prettyExponent : String\n prettyExponent = case e of\n 0 => \"\"\n x => \"e\" ++ show x\n", "meta": {"hexsha": "a4cb066b4851510f63958a50a834dbe86652fe77", "size": 14683, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Scientific.idr", "max_stars_repo_name": "jumper149/idris2-scientific", "max_stars_repo_head_hexsha": "da1ebb8bd5a261c426d3108cf47a2d4120ab13f1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-01-21T06:52:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-11T02:00:51.000Z", "max_issues_repo_path": "src/Data/Scientific.idr", "max_issues_repo_name": "jumper149/idris2-scientific", "max_issues_repo_head_hexsha": "da1ebb8bd5a261c426d3108cf47a2d4120ab13f1", "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/Scientific.idr", "max_forks_repo_name": "jumper149/idris2-scientific", "max_forks_repo_head_hexsha": "da1ebb8bd5a261c426d3108cf47a2d4120ab13f1", "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.2110311751, "max_line_length": 108, "alphanum_fraction": 0.5306817408, "num_tokens": 4117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6022622694502895}} {"text": "module Metamorphic\n\n-- Based on https://bitbucket.org/josh-hs-ko/MetamorphismsInAgda/raw/master/MetamorphismsInAgda.pdf\n\ndata AlgList : (a : Type) -> {s : Type} -> (f : a -> s -> s) -> (e : s) -> s -> Type where\n Nil : AlgList a f e e\n (::) : (x : a) -> {st : s} -> AlgList a f e st -> AlgList a f e (f x st)\n\n\ncodata CoAlgList : (b : Type) -> {s : Type} -> (g : s -> Maybe (b, s)) -> s -> Type where\n Empty : {st : s} -> g st = Nothing -> CoAlgList b g st\n Cons : (x : b) -> {st, st' : s} -> g st = Just (x, st') -> CoAlgList b g st' -> CoAlgList b g st\n\n\ntestAlgList : AlgList Nat (\\x, s => x + s) 0 3\ntestAlgList = 1 :: 1 :: 1 :: Nil\n\ntestCoAlgList : (st : Nat) -> CoAlgList Nat (\\x => Just (x, S x)) st\ntestCoAlgList st = Cons st Refl (testCoAlgList (S st))\n\nfromLeftAlg : {a, s : Type} -> (s -> a -> s) -> a -> (s -> s) -> (s -> s)\nfromLeftAlg f a s = s . flip f a\n\nparameters (a : Type, b : Type, s : Type, f : s -> a -> s, g : s -> Maybe (b, s),\n sc : {x : a} -> {y : b} -> {st, st' : s} -> g st = Just (y, st') -> g (f st x) = Just (y, f st' x))\n\n cbp : (st : s) -> {h : s -> s} -> AlgList a (fromLeftAlg f) (\\x => x) h -> CoAlgList b g (h st)\n cbp s [] with (g s) proof prf\n cbp s [] | Nothing = Empty (sym prf)\n cbp s [] | Just (y, s') = Cons y (sym prf) (cbp s' [])\n cbp s (a :: as) = cbp (f s a) as\n\n lemma : {st : s} -> {y : b} -> {st' : s} -> {h : s -> s} -> AlgList a (fromLeftAlg f) (\\x => x) h -> g st = Just (y, st') -> g (h st) = Just (y, h st')\n lemma [] eq = eq\n lemma (a :: as) eq = lemma as (sc eq)\n\n stream : (st : s) -> {h : s -> s} -> AlgList a (fromLeftAlg f) (\\x => x) h -> CoAlgList b g (h st)\n stream s as with (g s) proof prf\n stream s [] | Nothing = Empty (sym prf)\n stream s (a :: as) | Nothing = stream (f s a) as\n stream s as | Just (y, s') = Cons y (lemma as (sym prf)) (stream s' as)\n", "meta": {"hexsha": "4797ecd9fe9de29ba5150930078d6b339ae802a6", "size": 1861, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Metamorphic.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/Metamorphic.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/Metamorphic.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": 44.3095238095, "max_line_length": 153, "alphanum_fraction": 0.5002686728, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6021304604381821}} {"text": "import Data.Vect\nimport Data.Fin\nimport Language.Reflection\n\n%language ElabReflection\n\ndata Ty : Type where\n Base : Type -> Ty\n Arrow : Ty -> Ty -> Ty\n\n-- Ty can be translated to a host language type\n\ninterpTy : Ty -> Type\ninterpTy (Base t) = t\ninterpTy (Arrow s t) = (argTy : interpTy s) -> interpTy t\n\ndata HasType : Fin k -> Ty -> Vect k Ty -> Type where\n Stop : HasType FZ t (t :: gam)\n Pop : HasType i t gam -> HasType (FS i) t (u :: gam)\n\ndata Lang : Vect k Ty -> Ty -> Type where\n Var : HasType i t gam -> Lang gam t\n Val : (x : interpTy a) -> Lang gam a\n Lam : (scope : Lang (s :: gam) t) -> Lang gam (Arrow s t)\n App : Lang gam (Arrow s t) -> Lang gam s -> Lang gam t;\n Op : (interpTy a -> interpTy b -> interpTy c) ->\n Lang gam a -> Lang gam b -> Lang gam c\n\ndata Env : Vect n Ty -> Type where\n Nil : Env Nil\n (::) : (x : interpTy a) -> Env xs -> Env (a :: xs)\n\n-- Find a value in an environment\nlookupEnv : HasType i t gam -> Env gam -> Elab (interpTy t)\nlookupEnv Stop (x :: xs) = pure x\nlookupEnv (Pop var) (x :: env) = lookupEnv var env\n\ninterp : Env gam -> Lang gam t -> Elab (interpTy t)\ninterp env (Var x)\n = do res <- lookupEnv x env\n pure res\ninterp env (Val x) = pure x\ninterp env (Lam scope)\n = lambda _ (\\val => interp (val :: env) scope)\ninterp env (App f a)\n = interp env f <*> interp env a\ninterp env (Op f x y) = f <$> interp env x <*> interp env y\n\n%macro\neval : Env gam -> Lang gam t -> Elab (interpTy t)\neval = interp\n\ntestAdd : Lang gam (Arrow (Base Nat) (Arrow (Base Nat) (Base Nat)))\ntestAdd = Lam (Lam (Op plus (Var Stop) (Var (Pop Stop))))\n\nevalAdd : Nat -> Nat -> Nat\nevalAdd x y =let add = eval [] testAdd in add x y\n\ntestBlock : Lang gam (Base Nat)\ntestBlock = Op {a=Base Nat} {b=Base Nat} plus (Val 3) (Val 4)\n\nevalBlock : Nat\nevalBlock = eval [] testBlock\n", "meta": {"hexsha": "172e9d0eeeff0d40d4db7044c858c7f4726f8407", "size": 1868, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/reflection008/Interp.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/reflection008/Interp.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/reflection008/Interp.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": 29.1875, "max_line_length": 67, "alphanum_fraction": 0.6027837259, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6019090095344123}} {"text": "module PLFI.Part1.Connectives\n\nimport Data.Fin\nimport PLFI.Part1.Isomorphism\nimport Syntax.PreorderReasoning.Generic\n\n-- data _×_ (A B : Set) : Set where\n\n-- ⟨_,_⟩ :\n-- A\n-- → B\n-- -----\n-- → A × B\n\ntest : (Int,Nat)\ntest = (0,0)\n\ntotal\ntest2 : (Void,Nat)\ntest2 = (?x,0)\n\n-- data TT : Type where\n-- MkTT : TT\n\n-- data TF : Type where\n\n-- test3 : TF\n-- test3 = ?x1\n\n-- test4 : (TT, TT)\n-- test4 = (MkTT, MkTT)\n\n-- test5 : (TF, TT)\n-- test5 = (?test5_rhs_1, MkTT)\n\n-- test6 : (,) Nat Nat\n-- test6 = (3,3)\n\ndata Sx : Nat -> Type where\n MkSx : Sx n\n\ntest7 : (x : Nat ** Sx x)\ntest7 = (3 ** MkSx)\n\ntest8 : DPair Nat (\\x => Sx x)\ntest8 = MkDPair 3 MkSx\n\n-- test8 : Sigma Nat (\\x => Sx x)\n-- test8 = MkSigma 3 MkSx\n\n-- η-× : ∀ {A B : Set} (w : A × B) → ⟨ proj₁ w , proj₂ w ⟩ ≡ w\netaTuple : {a,b : Type} -> (w : (a, b)) -> (fst w, snd w) === w\netaTuple (x, y) = Refl\n\n-- data Bool : Set where\n-- true : Bool\n-- false : Bool\n\n-- data Tri : Set where\n-- aa : Tri\n-- bb : Tri\n-- cc : Tri\n\ndata B : Type where\n True : B\n False : B\n\nenumB : B -> Fin 2\nenumB True = 0\nenumB False = 1\n\n-- data T : Type where\n-- AA, BB, CC : T\n\n-- enumT : T -> Fin 3\n-- enumT AA = 0\n-- enumT BB = 1\n-- enumT CC = 2\n\ntupleX : (a -> Fin n) -> (b -> Fin m) -> (a,b) -> Fin (n * m)\ntupleX f s x = ?xy\n\n-- timesCountBetween1and6 : (x: (Bool, Tri)) -> (timesCount x <= 6 && timesCount x >= 1) = True\n-- timesCountBetween1and6 (False, Aa) = Refl\n-- timesCountBetween1and6 (False, Bb) = Refl\n-- timesCountBetween1and6 (False, Cc) = Refl\n-- timesCountBetween1and6 (True, Aa) = Refl\n-- timesCountBetween1and6 (True, Bb) = Refl\n-- timesCountBetween1and6 (True, Cc) = Refl\n\n-- ×-comm : ∀ {A B : Set} → A × B ≃ B × A\n-- ×-comm =\n-- record\n-- { to = λ{ ⟨ x , y ⟩ → ⟨ y , x ⟩ }\n-- ; from = λ{ ⟨ y , x ⟩ → ⟨ x , y ⟩ }\n-- ; from∘to = λ{ ⟨ x , y ⟩ → refl }\n-- ; to∘from = λ{ ⟨ y , x ⟩ → refl }\n-- }\n\nprodComm : Iso (a,b) (b,a)\nprodComm =\n MkIso \n { to = (\\(x,y) => (y,x))\n , from = (\\(y,x) => (x,y))\n , fromTo = (\\(x,y) => Refl)\n , toFrom = (\\(y,x) => Refl)\n }\n\n-- ×-assoc : ∀ {A B C : Set} → (A × B) × C ≃ A × (B × C)\n-- ×-assoc =\n-- record\n-- { to = λ{ ⟨ ⟨ x , y ⟩ , z ⟩ → ⟨ x , ⟨ y , z ⟩ ⟩ }\n-- ; from = λ{ ⟨ x , ⟨ y , z ⟩ ⟩ → ⟨ ⟨ x , y ⟩ , z ⟩ }\n-- ; from∘to = λ{ ⟨ ⟨ x , y ⟩ , z ⟩ → refl }\n-- ; to∘from = λ{ ⟨ x , ⟨ y , z ⟩ ⟩ → refl }\n-- }\n\nprodAssoc : Iso ((a,b),c) (a,(b,c))\nprodAssoc = MkIso\n { to = \\((x,y),z) => (x,(y,z))\n , from = \\(x,(y,z)) => ((x,y),z)\n , fromTo = \\((x,y),z) => Refl\n , toFrom = \\(x,(y,z)) => Refl\n }\n\n-- data ⊤ : Set where\n-- tt :\n-- --\n-- ⊤\n\ndata T : Type where\n TT : T\n \n-- ------ T-I\n-- TT : T\n\n-- T , c\n-- ------- T-E\n-- c\n\n-- elim:\n-- c -> (T -> c)\n-- c -> T -> c\n-- c -> c\n\n-- ⊤-identityˡ : ∀ {A : Set} → ⊤ × A ≃ A\n-- ⊤-identityˡ =\n-- record\n-- { to = λ{ ⟨ tt , x ⟩ → x }\n-- ; from = λ{ x → ⟨ tt , x ⟩ }\n-- ; from∘to = λ{ ⟨ tt , x ⟩ → refl }\n-- ; to∘from = λ{ x → refl }\n-- }\n\nttIdentityL : {a : Type} -> Iso (T, a) a\nttIdentityL = MkIso\n { to = \\(TT,y) => y\n , from = \\x => (TT, x)\n , fromTo = \\(TT,y) => Refl\n , toFrom = \\y => Refl\n }\n\n-- ⊤-identityʳ : ∀ {A : Set} → (A × ⊤) ≃ A\n-- ⊤-identityʳ {A} =\n-- ≃-begin\n-- (A × ⊤)\n-- ≃⟨ ×-comm ⟩\n-- (⊤ × A)\n-- ≃⟨ ⊤-identityˡ ⟩\n-- A\n-- ≃-∎\n\n-- 0\ntest3 : {a,b,c : Type} -> Iso a b -> Iso b c -> Iso a c\ntest3 ab bc = CalcWith {leq = Iso} $\n |~ a\n <~ b ... (ab)\n <~ c ... (bc)\n\nttIdentityR : {a : Type} -> Iso (a,T) a\nttIdentityR = CalcWith {leq = Iso} $\n |~ (a, T)\n <~ (T, a) ... prodComm\n <~ a ... ttIdentityL\n\n-- Same as Either, we are going to use Either\ndata Sum : Type -> Type -> Type where\n L : a -> Sum a b\n R : b -> Sum a b\n\n-- the first introduces a formula for the connective, which appears in the conclusion but not in the hypotheses\n-- x : a\n-- ------------- Sum-I1\n-- L x : Sum a b\n--\n-- x : b\n-- ------------- Sum-I2\n-- R x : Sum a b\n\n-- the second eliminates a formula for the connective, which appears in a hypothesis but not in the conclusion\n-- Sum a b , (a -> c) , (b -> c)\n-- ----------------------------- Sum-E\n-- c \n\n-- case-⊎ : ∀ {A B C : Set}\n-- → (A → C)\n-- → (B → C)\n-- → A ⊎ B\n-- -----------\n-- → C\n-- case-⊎ f g (inj₁ x) = f x\n-- case-⊎ f g (inj₂ y) = g y\n\n-- either\n\n-- η-⊎ : ∀ {A B : Set} (w : A ⊎ B) → case-⊎ inj₁ inj₂ w ≡ w\n\neither2 : (b -> c) -> (a -> c) -> Either a b -> c\neither2 f g (Left x) = g x\neither2 f g (Right x) = f x\n\netaEither : {a,b : Type} -> (w : Either a b) -> either Left Right w = w\netaEither (Left x) = Refl\netaEither (Right x) = Refl\n\n\ntestData1 : Either () Nat\ntestData1 = Right 1\n\ntest1 : Bool\ntest1 = either Left Right testData1 == (Right 1)\n\ntestData2 : Either Nat ()\ntestData2 = Left 2\n\ntest4 : Bool\ntest4 = either Left Right testData2 == (Left 2)\n\n-- uniq-⊎ : ∀ {A B C : Set} (h : A ⊎ B → C) (w : A ⊎ B) →\nuniqEither\n : {a,b,c : Type} -> (h : Either a b -> c) -> (w : Either a b)\n -> either (h . Left) (h . Right) w = h w\nuniqEither h (Left x) = Refl\nuniqEither h (Right x) = Refl\n\n-- test5 : let t = Nat = Nat in Either t t\n-- test5 = Left Refl\n\ncommEither : Iso (Either a b) (Either b a)\ncommEither = MkIso\n { to = either Right Left\n , from = either Right Left\n , fromTo = \\case\n (Left x) => Refl\n (Right x) => Refl\n , toFrom = \\case\n (Left x) => Refl\n (Right x) => Refl\n }\n\nassocEither : Iso (Either (Either a b) c) (Either a (Either b c))\nassocEither = MkIso\n { to = either (either Left (Right . Left)) (Right . Right)\n , from = either (Left . Left) (either (Left . Right) Right)\n , fromTo = \\case\n (Left (Left x)) => Refl\n (Left (Right x)) => Refl\n (Right x) => Refl\n , toFrom = \\case\n (Left x) => Refl\n (Right (Left x)) => Refl\n (Right (Right x)) => Refl\n }\n\n-- Couldn't parse any alternatives:\n-- 1: Expected name.\n-- ... (1 others)idris2\n-- data G : Type where\n-- { MkG : G\n-- } -- c)\n\n-- Without where clause it means something else, we declare this type, but we don't define it yet.\n-- data F : Type a)\n-- declare data F : Type a)\n\n-- Suggestions for definition of empty type\n-- data F : Type where -- b)\n\n-- data F : Type where -- c)\n-- impossible\n\n-- data F : Type empty -- d)\n\n-- data F : Type impossible -- e)\n\n-- data F : Type where {}\n\ndata F : Type where -- c)\n\nfElim : {0 a : Type} -> F -> a\nfElim x impossible\n\nfElim' : {a : Type} -> F -> a\nfElim' = \\x => case x of {} -- \\case leads to a parse error\n\n-- uniq-⊥ : ∀ {C : Set} (h : ⊥ → C) (w : ⊥) → ⊥-elim w ≡ h w\n-- uniq-⊥ h ()\n\nuniqF : {c : Type} -> (h : F -> c) -> (w : F) -> fElim w = h w\nuniqF h w impossible\n\n-- ⊥-identityˡ\n\nfIdentityL : Iso (Either F a) a\nfIdentityL = MkIso\n { to = either fElim id\n , from = Right\n , fromTo = \\case\n (Left x) => fElim x\n (Right x) => Refl\n , toFrom = \\y => Refl\n }\n\nfIdentityR : Iso (Either a F) a\nfIdentityR = isoTrans commEither fIdentityL\n\n-- η-→ : ∀ {A B : Set} (f : A → B) → (λ (x : A) → f x) ≡ f\n-- η-→ f = refl\n\n\n-- TODO: Ask\n-- a : Type\n-- b : Type\n-- f : a -> b\n-- ------------------------------\n-- xx : (\\x => f x) = f\netaFun : {a,b : Type} -> (f : a -> b) -> (\\x => f x) = f\netaFun f = Refl\n\n-- a : Type\n-- b : Type\n-- f : a -> b\n-- ------------------------------\n-- xRefl : (\\x => f x) = (\\y => f y)\nalphaFun : {a,b : Type} -> (f : a -> b) -> (\\x => f x) = (\\y => f y)\nalphaFun f = Refl\n\n-- Under the hood terms are normalized for alpha/eta equivalence?\nalphaFun2 : {a,b,c : Type} -> (f : a -> b -> c) -> (z : b) -> (\\x => f x z) = (\\y => f y z)\nalphaFun2 f z = Refl\n\nbetaFun : (y : Nat) -> (\\x => x * x) y = y * y\nbetaFun y = Refl\n\nnamespace Newtype12\n\n export\n Person : Type\n Person = (String, Int)\n\n public export\n mkPerson : (String, Int) -> Person\n mkPerson = id\n\n public export\n unPerson : Person -> (String, Int)\n unPerson = id\n\n export\n 0\n samePersonLemma : (p : Person) -> (mkPerson (unPerson p)) = p\n samePersonLemma p = Refl\n\n -- export\n -- samePersonLemma\n\ntest5 : Person\ntest5 = mkPerson (\"Andor\", 23)\n\n-- samePersonLemma : (p : Person) -> (mkPerson (unPerson p)) = p\n-- samePersonLemma p = Refl\n\nsamePersonLemmaR : (p : (String, Int)) -> (unPerson (mkPerson p) = p)\nsamePersonLemmaR p = ?h1_0\n\nhandwaving : {t : Type} -> (a : t) -> (b : t) -> (a = b)\nhandwaving a b = believe_me (the (a=a) Refl)\n\nnamespace Postulate\n\n export\n extensionality : {a,b : Type} -> {f,g : a -> b} -> ((x : a) -> f x = g x) -> f = g\n extensionality _ = handwaving f g\n\n-- currying : ∀ {A B C : Set} → (A → B → C) ≃ (A × B → C)\ncurrying : {a,b,c : Type} -> Iso (a -> b -> c) ((a,b) -> c)\ncurrying = MkIso\n { to = \\f => \\(x,y) => f x y\n , from = \\f => \\x => \\y => f (x, y)\n , fromTo = \\f => Refl\n , toFrom = \\g => extensionality (\\(x,y) => Refl)\n }\n\n-- c ^ (a + b) ~ c ^ a * c ^ b\n-- →-distrib-⊎ : ∀ {A B C : Set} → (A ⊎ B → C) ≃ ((A → C) × (B → C))\ndistribFunOverSumR : {a,b,c : Type} -> Iso (Either a b -> c) (a -> c, b -> c)\ndistribFunOverSumR = MkIso\n { to = \\f => (f . Left, f . Right)\n , from = \\(f,g) => either f g\n , fromTo = \\f => extensionality (\\case { Left x => Refl ; Right y => Refl })\n , toFrom = \\(f,g) => Refl\n }\n\n-- →-distrib-× : ∀ {A B C : Set} → (A → B × C) ≃ (A → B) × (A → C)\n-- (p * n) ^ m = (p ^ m) * (n ^ m)\ndistribFunOverProdL : {a,b,c : Type} -> Iso (a -> (b,c)) (a -> b, a -> c)\ndistribFunOverProdL = MkIso\n { to = \\f => (fst . f, snd . f)\n , from = \\(f,g) => \\x => (f x, g x)\n , fromTo = \\f => extensionality (\\x => etaTuple (f x)) -- TODO: Next time cong\n , toFrom = \\(f,g) => Refl\n }\n\n-- →-distrib-× : ∀ {A B C : Set} → (A → B × C) ≃ (A → B) × (A → C)\n-- (p * n) ^ m = (p ^ m) * (n ^ m)\ndistribFunOverProdL2 : {a,b,c : Type} -> Iso (a -> (b,c)) (a -> b, a -> c)\ndistribFunOverProdL2 = MkIso\n { to = \\f => (fst . f, snd . f)\n , from = \\(f,g) => \\x => (f x, g x)\n , fromTo = \\f => extensionality (\\x => cong id (cong id (cong id (etaTuple (f x)))))\n , toFrom = \\(f,g) => Refl\n }\n\n-- ×-distrib-⊎ : ∀ {A B C : Set} → (A ⊎ B) × C ≃ (A × C) ⊎ (B × C)\ndistribProdOverSum : {a,b,c : Type} -> Iso (Either a b, c) (Either (a,c) (b,c))\ndistribProdOverSum = MkIso\n { to = \\(x,y) => bimap (,y) (,y) x\n , from = either (mapFst Left) (mapFst Right)\n -- , fromTo = \\(x, y) => either (\\z => ?h1) ?h2 x -- (const Refl) (const Refl) x\n , fromTo = \\(x, y) => case x of\n (Left z) => Refl\n (Right z) => Refl\n , toFrom = \\case\n (Left (x, y)) => Refl\n (Right (x, y)) => Refl\n }\n\n-- ⊎-distrib-× : ∀ {A B C : Set} → (A × B) ⊎ C ≲ (A ⊎ C) × (B ⊎ C)\nweakDistribSumOverProd : {a,b,c : Type} -> (Either (a,b) c) <= (Either a c, Either b c)\nweakDistribSumOverProd = MkEmb\n { to = \\case\n (Left (x, y)) => (Left x, Left y)\n (Right x) => (Right x, Right x)\n , from = \\case\n ((Right x), y ) => Right x\n ((Left x) , (Right y)) => Right y\n ((Left x) , (Left y) ) => Left (x, y)\n , fromTo = \\case\n (Left (x, y)) => Refl\n (Right x) => Refl\n }\n", "meta": {"hexsha": "33485f6ddb5fb7cb35adc8dbfd83118fa97c7b02", "size": 11335, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "PLFI/Part1/Connectives.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/Connectives.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/Connectives.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": 24.5346320346, "max_line_length": 111, "alphanum_fraction": 0.462814292, "num_tokens": 4485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.60157266706722}} {"text": "module Main\n\nimport Effect.Random\nimport Effect.StdIO\nimport Effects\nimport Data.Vect\n\n-- import Probability.Core\n-- import Probability.Monad\n\n%default total\n\n{- Probabilistic programming -}\n\ndata Prob : Type -> Type where\n Binomial : Nat -> Double -> Prob Nat\n Certainly : a -> Prob a\n Bind : (Prob a) -> (a -> Prob b) -> Prob b\n CustomDist : Vect (S n) (a, Double) -> Prob a\n\nShow a => Show (Prob a) where\n show (Binomial n p) = \"Binomial \" ++ (show n) ++ \" \" ++ (show p)\n show (Certainly a) = \"Certainly \" ++ (show a)\n show (Bind (Binomial n p) _) = \"Bind (\" ++ (show $ Binomial n p) ++ \") \"\n show (Bind a _) = \"Bind \"\n show (CustomDist d) = \"CustomDist \" ++ (show d)\n\n-- NOTE: It seems Idris won't accept this as total unless I handle the\n-- 'impossible' case (that's also why choose wasn't reducing at compile time).\nzeroSum : {a: Nat} -> {b: Nat} -> (a + b = 0) -> Either Void ((a = 0), (b = 0))\nzeroSum {a = Z} Refl = Right (Refl, Refl)\nzeroSum {a} {b = Z} prf = Right (replace {P = \\x => x = 0} (plusZeroRightNeutral a) prf, Refl)\nzeroSum {a = S a} {b = S b} prf = Left $ SIsNotZ prf\n\nfactNZ : {k: Nat} -> Not (fact k = Z)\nfactNZ {k = Z} p = SIsNotZ p\nfactNZ {k = (S k)} p = case zeroSum p of\n Left v => v\n Right (q1, _) => factNZ q1\n\n-- factBetween : Nat -> Nat -> Nat\n-- factBetween n m = if n == m then n else if n > m then 0 else (factBetween n (pred m)) * (m)\n\ntotal\nchoose : Nat -> Nat -> Nat\nchoose _ Z = 1\nchoose (S n) (S Z) = S n\nchoose Z (S _) = 0\n-- if n < k then n `choose` k = 0\nchoose n k = divNatNZ (divNatNZ (fact n) (fact (n `minus` k)) factNZ) (fact k) factNZ\n\nchooseZero : {n: Nat} -> choose n Z = 1\nchooseZero = Refl\n\nchooseOne : {n: Nat} -> choose (S n) 1 = S n\nchooseOne = Refl\n\n-- chooseNLessK : choose n (n + m + 1) = 0\n-- chooseNLessK = ?csdvsd\n\ntotal\nbinomialPMF : Nat -> Double -> Nat -> Double\nbinomialPMF n p k = cast (n `choose` k) * (p `pow` k) * ((1.0 - p) `pow` (n `minus` k))\n\nsplitBy : (a -> Bool) -> List a -> (List a, List a)\nsplitBy _ [] = ([], [])\nsplitBy pred (x::xs) = let (s, t) = splitBy pred xs in\n if pred x then (x::s, t) else (s, x::t)\n\ngatherer : (Eq a, Eq p, Num p) => List (a,p) -> List (a,p) -- copied from https://github.com/lambdacasserole/probability/blob/master/src/Probability/Core.idr\ngatherer [] = []\ngatherer ((x,p) :: xs) = assert_total $ -- why is assert_total needed?\n let lyln = splitBy (\\(z,_) => z == x) xs\n newp = (+) p . sum $ map snd (fst lyln)\n in (x,newp) :: gatherer (snd lyln)\n\n-- vectNatEnumFromTo : (a, b: Nat) -> {auto prf: LTE a b} -> Vect (b - a + 1) Nat\n-- vectNatEnumFromTo a b = vectNatEnumFromTo' a (b - a) where\n-- vectNatEnumFromTo' a Z = [a]\n-- vectNatEnumFromTo' a (S n) = a :: vectNatEnumFromTo' (a + 1) n\n\n-- cartesianProduct : Vect n a -> (a -> Vect m b) -> Vect (n * m) (a, b)\n-- cartesianProduct [] _ = []\n-- cartesianProduct {n} {m = Z} _ _ = rewrite multZeroRightZero n in []\n-- cartesianProduct (x::xs) fys = ((\\y => (x, y)) <$> fys x) ++ cartesianProduct xs fys\n--\n-- cartesianProduct' : Vect n a -> (a -> (m: Nat ** Vect m b)) -> Vect (n * m) (a, b)\n-- cartesianProduct' xs fys = cartesianProduct xs (DPair.snd . fys)\n\nconcatNonempty' : Vect n (m: Nat ** Vect (S m) a) -> (k: Nat ** Vect k a)\nconcatNonempty' [] = (_ ** [])\nconcatNonempty' (x1::xs) = (_ ** (snd x1) ++ (snd (concatNonempty' xs)))\n\nconcatNonempty : Vect (S n) (m: Nat ** Vect (S m) a) -> (k: Nat ** Vect (S k) a)\nconcatNonempty [x] = x\n-- concatNonempty [x1, x2] = (_ ** (snd x1) ++ (snd x2))\nconcatNonempty (x1::xs) = (_ ** (snd x1) ++ (snd (concatNonempty' xs)))\n\ntotal\nrunProb : Prob a -> (k: Nat ** Vect (S k) (a, Double))\nrunProb (Binomial n p) = (_ ** (\\k => (k, binomialPMF n p k)) <$> 0 :: fromList [1..n])\nrunProb (Certainly a) = (_ ** [(a, 1.0)])\n-- runProb {a} (Bind probA f) = (_ ** (\\((_,w),(y,q)) => (y, q*w)) <$> cartesianProduct {m = m} (DPair.snd {x = runProb probA}) f'') where\n-- f' : (a: Type) -> (b, Double) -> (l: Nat ** Vect (S l) (a, Double))\n-- f' a (y,_) = runProb {a = a} ?dxdv --(f x)\n-- f'' y' = DPair.snd {x = (f' a y')}\n-- m = S $ DPair.fst (f' (head (DPair.snd (runProb probA))))\nrunProb {a} (Bind probA f) =\n concatNonempty (snd joinedPartly) -- unjoined = (\\(pA,p) => (runProb pA, p)) <$> probfAs in\n where\n probfAs : (k: Nat ** Vect (S k) ((l: Nat ** Vect (S l) (a, Double)), Double))\n probfAs = assert_total (_ ** (\\(x,p) => (runProb (f x), p)) <$> snd (runProb (assert_smaller (Bind probA f) probA)))\n joinedPartly : (k: Nat ** Vect (S k) (l: Nat ** Vect (S l) (a, Double)))\n joinedPartly = (_ ** (\\((_**dist),p) => (_ ** (\\(x,q) => (x, p*q)) <$> dist)) <$> snd probfAs)\n -- joinedPartly = (_ ** ?cbfdbdb <$> probfAs)\nrunProb (CustomDist d) = (_ ** d)\n\nFunctor Prob where\n map f (Certainly a) = Certainly $ f a\n map f (Bind a g) = Bind a (\\x => f <$> g x)\n map f (CustomDist d) = CustomDist $ (\\(x, p) => (f x, p)) <$> d\n map f p = CustomDist $ (\\(x, p) => (f x, p)) <$> (snd $ runProb p)\n\nApplicative Prob where\n pure = Certainly\n (Certainly f) <*> p = f <$> p\n (Bind pa f) <*> p = Bind pa (\\a => (f a) <*> p)\n -- (CustomDist d) <*> p = CustomDist [ (f x, q*w) | (f,w) <- d, (x,q) <- runProb p ] -- copied from https://github.com/lambdacasserole/probability/blob/master/src/Probability/Core.idr\n (CustomDist d) <*> p = Bind (CustomDist d) (\\f => Bind p (pure . f))\n\nMonad Prob where\n (Certainly a) >>= f = f a\n (Bind fa f) >>= g = fa >>= (\\a => (f a) >>= g)\n fa >>= f = Bind fa f\n\ngather : (Eq a) => Prob a -> Prob a\n-- FIXME: Adapt this function for vects\n-- gather (CustomDist d) = CustomDist (gatherer d)\n-- gather (Bind pa f) = pa >>= (\\a => gather $ f a) -- FIXME: Might not gather completely because pa not gathered\ngather p = p\n\nmortalityRate : Double\nmortalityRate = 0.03\n\nbinomial : Nat -> Double -> Prob Nat\nbinomial = Binomial\n\nkill : (population: Nat) -> Double -> Prob Nat\nkill = binomial\n\nreplace : Nat -> Nat -> Prob (Nat, Nat)\nreplace n1 n2 = gather $ replace' <$> binomial (n1 + n2) ((cast n1) / (cast (n1 + n2))) where\n replace' n1' = (n1', (n1 + n2) `minus` n1')\n\nstep : Nat -> Nat -> Prob (Nat, Nat)\nstep n1 n2 = gather $ do\n dead1 <- kill n1 mortalityRate\n dead2 <- kill n2 mortalityRate\n gather $ (\\(new1,new2) => ((n1 `minus` dead1) + new1, (n2 `minus` dead2) + new2)) <$> replace dead1 dead2\n\nsimulate : Nat -> Nat -> Nat -> Prob (Nat, Nat)\nsimulate species1Initial species2Initial Z = pure (species1Initial, species2Initial)\nsimulate species1Initial species2Initial (S k) = gather $ do\n (n1, n2) <- step species1Initial species2Initial\n gather $ simulate n1 n2 k\n\n{- Error propagation -}\n\ndata Uncertain value = MkUncertain value value\n\ninterface SquareRootable a where\n sqrt : a -> a\n\nSquareRootable Double where\n sqrt = Doubles.sqrt\n\nsquare : Num a => a -> a\nsquare a = a * a\n\nnorm : (Num a, SquareRootable a) => List a -> a\nnorm values = sqrt $ sum (square <$> values)\n\n(Fractional value, SquareRootable value) => Num (Uncertain value) where\n -- FIXME: Account for correlation\n (+) (MkUncertain a aUncertainty) (MkUncertain b bUncertainty) = MkUncertain (a + b) (norm [aUncertainty, bUncertainty])\n (*) (MkUncertain a aUncertainty) (MkUncertain b bUncertainty) = (MkUncertain (a * b) (a * b * norm [aUncertainty/a, bUncertainty/b]))\n fromInteger i = MkUncertain (fromInteger i) 0\n\n(SquareRootable value, Fractional value) => Fractional (Uncertain value) where\n (MkUncertain a aUncertainty) / (MkUncertain b bUncertainty) = MkUncertain (a / b) (a / b * norm [aUncertainty/a, bUncertainty/b])\n\nShow value => Show (Uncertain value) where\n show (MkUncertain a aUncertainty) = show a ++ \" +- \" ++ show aUncertainty\n\ninterface Scalable a where\n (*) : a -> Double -> a\n\nScalable Double where\n (*) = Interfaces.(*)\n\nmean : (Scalable a, Num a) => (prob: Prob a) -> a\nmean (Binomial n p) = (Main.(*) n p) -- probably not what you want\nmean (Certainly a) = a\nmean (CustomDist d) = sum [x * p | (x, p) <- d]\nmean (Bind pa f) = sum [x * p | (x, p) <- snd $ runProb (pa >>= f)]\n\n-- population standardDeviation (QUESTION: should it be sample instead?)\nstandardDeviation : (SquareRootable a, Scalable a, Neg a) => (prob: Prob a) -> a\nstandardDeviation (Binomial n p) = sqrt (Main.(*) (Main.(*) n p) (1.0 - p)) -- probably not what you want\nstandardDeviation (Certainly _) = 0\nstandardDeviation (CustomDist d) = let mu = mean (CustomDist d) in\n sqrt $ sum [square (mu - x) * p | (x, p) <- d]\nstandardDeviation (Bind pa f) = let mu = mean (Bind pa f) in\n sqrt $ sum [square (mu - x) * p | (x, p) <- snd $ runProb (pa >>= f)]\n\nprobToUncertain : (SquareRootable a, Scalable a, Neg a, Fractional a) => (prob: Prob a) -> Uncertain a\nprobToUncertain dist = MkUncertain (mean dist) (Main.(*) (standardDeviation dist) 0.5)\n\n{- Estimate distributions by sampling (Monte Carlo) -}\n\nselect : Double -> Vect (S n) (a, Double) -> Double -> a\nselect _ [(x, p)] _ = x\nselect target ((x, p)::xps) current =\n if target >= current + p\n then x\n else case xps of\n [] => x\n (xp::xps') => select target (xp::xps') (current + p)\n\n-- Copied from https://bl.ocks.org/justinmanley/f2e169feb32e06e06c2f\n||| Naively generate a (pseudo)-random float between 0 and 1.\nrndDouble : Integer -> Eff Double [RND]\nrndDouble max = do\n\trnd <- assert_total $ rndInt 0 max\n\tpure (fromInteger rnd / fromInteger max)\n\nsample : Prob a -> Eff a [RND, STDIO]\nsample (Bind prob f) = do\n observedFromProb <- sample prob\n putStrLn \"Bind: sampled prob\"\n result <- sample (f observedFromProb)\n putStrLn \"Bind: sampled f _\"\n pure result\nsample prob = do\n putStrLn \"Sampling from an arbitrary distribution\"\n probability <- rndDouble (2 `pow` 20)\n (_ ** dist) <- pure (runProb prob)\n pure $ select probability dist 0.0\n\nApplicative (Pair Int) where\n pure a = (0, a)\n\n f <*> fa = (fst fa, (snd f) (snd fa))\n\nmain : IO ()\nmain = do\n dist <- pure (simulate 1 1 3)\n putStrLn \"dist\"\n printLn dist\n printLn (gatherer $ toList (snd (runProb dist)))\n printLn $ (MkUncertain 0.172807 0.000008) / ((MkUncertain 13.7 0.3) * (MkUncertain 1.0 0.1)) -- 0.013 ± 0.001 (https://chem.libretexts.org/Bookshelves/Analytical_Chemistry/Supplemental_Modules_(Analytical_Chemistry)/Quantifying_Nature/Significant_Digits/Propagation_of_Error)\n printLn $ probToUncertain (cast {to=Double} <$> binomial 5 0.5) -- 2.5 +- 0.559\n -- printLn (run $ sample (simulate 1 1 3))\n", "meta": {"hexsha": "0dc455f026a3f6a9432f9e9cd991d2de1627d9a7", "size": 10356, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/src/Main.idr", "max_stars_repo_name": "jmanuel1/sust-modeling", "max_stars_repo_head_hexsha": "dafe5899272e08cf0c0d26265ce5fbe709c79842", "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/src/Main.idr", "max_issues_repo_name": "jmanuel1/sust-modeling", "max_issues_repo_head_hexsha": "dafe5899272e08cf0c0d26265ce5fbe709c79842", "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/src/Main.idr", "max_forks_repo_name": "jmanuel1/sust-modeling", "max_forks_repo_head_hexsha": "dafe5899272e08cf0c0d26265ce5fbe709c79842", "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.2272727273, "max_line_length": 277, "alphanum_fraction": 0.612784859, "num_tokens": 3627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.6791787121629466, "lm_q1q2_score": 0.6015020397384323}} {"text": "module FieldAxioms\n\nimport ZZ\nimport ZZUtils\nimport GCDZZ\nimport Divisors\nimport Rationals\n\n%default total\n\n-- The field axioms which require the custom equality EqRat type are verified here.\n\nEqRatAddInvLeft: (x: ZZPair) -> (a: NotZero (snd x))\n-> (EqRat (AddRationals x a (AddInverse x a) (xAndInverseNotZeroPlus x a)) (productNonZero a (xAndInverseNotZeroPlus x a)) ((Pos 0), (snd x)*(snd x)) (productNonZero a a))\nEqRatAddInvLeft x a = eqMeansEqRat (AddRationals x a (AddInverse x a) (xAndInverseNotZeroPlus x a)) (productNonZero a (xAndInverseNotZeroPlus x a)) ((Pos 0), (snd x)*(snd x)) (productNonZero a a) (addInverseLeft x a)\n\nEqRatAddInvRight: (x: ZZPair) -> (a: NotZero (snd x))\n-> (EqRat (AddRationals (AddInverse x a) (xAndInverseNotZeroPlus x a) x a) (productNonZero a (xAndInverseNotZeroPlus x a)) ((Pos 0), (snd x)*(snd x)) (productNonZero a a))\nEqRatAddInvRight x a = eqMeansEqRat (AddRationals (AddInverse x a) (xAndInverseNotZeroPlus x a) x a) (productNonZero a (xAndInverseNotZeroPlus x a)) ((Pos 0), (snd x)*(snd x)) (productNonZero a a) (addInverseRight x a)\n\nEqRatMultInvLeft: (x: ZZPair) -> (a: NotZero (fst x)) -> (b: NotZero (snd x))\n-> (EqRat (MultiplyRationals x b (MultInverse x a b) (xAndInverseNotZeroMult x a b)) (productNonZero b (xAndInverseNotZeroMult x a b)) ((fst x)*(snd x), (fst x)*(snd x)) (productNonZero a b))\nEqRatMultInvLeft x a b = eqMeansEqRat (MultiplyRationals x b (MultInverse x a b) (xAndInverseNotZeroMult x a b)) (productNonZero b (xAndInverseNotZeroMult x a b)) ((fst x)*(snd x), (fst x)*(snd x)) (productNonZero a b) (multInverseLeft x a b)\n\nEqRatMultInvRight: (x: ZZPair) -> (a: NotZero (fst x)) -> (b: NotZero (snd x))\n-> (EqRat (MultiplyRationals (MultInverse x a b) (xAndInverseNotZeroMult x a b) x b) (productNonZero (xAndInverseNotZeroMult x a b) b) ((snd x)*(fst x), (snd x)*(fst x)) (productNonZero b a))\nEqRatMultInvRight x a b = eqMeansEqRat (MultiplyRationals (MultInverse x a b) (xAndInverseNotZeroMult x a b) x b) (productNonZero (xAndInverseNotZeroMult x a b) b) ((snd x)*(fst x), (snd x)*(fst x)) (productNonZero b a) (multInverseRight x a b)\n\n-- All of the following proofs involve the use of EqRat and its associated properties which are\n-- reflexvity, symmetry, transitivity, and the fact that two elements being equal is enough to construct\n-- an element of EqRat.\n\n|||Constructs an equality between (a,b) + (c,d) and (c,d) + (a,b)\nplusCommQEqRat: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) ->\n(EqRat (AddRationals x a y b) (productNonZero a b) (AddRationals y b x a) (productNonZero b a))\nplusCommQEqRat x a y b = eqMeansEqRat (AddRationals x a y b) (productNonZero a b) (AddRationals y b x a) (productNonZero b a) (plusCommutativeQ x a y b)\n\n|||Constructs an equality between (a,b)*(c,d) and (c,d)*(a,b)\nmultCommQEqRat: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) ->\n(EqRat (MultiplyRationals x a y b) (productNonZero a b) (MultiplyRationals y b x a) (productNonZero b a))\nmultCommQEqRat x a y b = eqMeansEqRat (MultiplyRationals x a y b) (productNonZero a b) (MultiplyRationals y b x a) (productNonZero b a) (multCommutativeQ x a y b)\n\n|||Constructs an equality between (a,b) + (0,1) and (a,b).\naddIdRightEqRat: (x: ZZPair) -> (a: NotZero (snd x)) ->\n(EqRat (AddRationals x a (0,1) PositiveZ) (productNonZero a (PositiveZ)) x a)\naddIdRightEqRat x a = eqMeansEqRat (AddRationals x a (0,1) PositiveZ) (productNonZero a (PositiveZ)) (x) (a) (zeroAddIdentityRight x a)\n\n|||Constructs an equality between (a,b) and (a,b) + (0,1).\naddIdLeftEqRat: (x: ZZPair) -> (a: NotZero (snd x)) ->\n(EqRat (AddRationals (0,1) PositiveZ x a) (productNonZero (PositiveZ) a) x a)\naddIdLeftEqRat x a = eqMeansEqRat (AddRationals (0,1) PositiveZ x a) (productNonZero (PositiveZ) a) (x) (a) (zeroAddIdentityLeft x a)\n\n|||Constructs an equality between (a,b)*(1,1) and (a,b).\nmultIdRightEqRat: (x: ZZPair) -> (a: NotZero (snd x)) ->\n(EqRat (MultiplyRationals x a (1,1) PositiveZ) (productNonZero a (PositiveZ)) x a)\nmultIdRightEqRat x a = eqMeansEqRat (MultiplyRationals x a (1,1) PositiveZ) (productNonZero a (PositiveZ)) (x) (a) (oneMultIdentityRight x a)\n\n|||Constructs an equality between (a,b)*(1,1) and (a,b).\nmultIdLeftEqRat: (x: ZZPair) -> (a: NotZero (snd x)) ->\n(EqRat (MultiplyRationals (1,1) PositiveZ x a) (productNonZero (PositiveZ) a) x a)\nmultIdLeftEqRat x a = eqMeansEqRat (MultiplyRationals (1,1) PositiveZ x a) (productNonZero (PositiveZ) a) (x) (a) (oneMultIdentityLeft x a)\n\n|||Constructs an equality between ((a,b)+(-a,b)) and 0.\naddInverseLeftEqRat: (x: ZZPair) -> (a: NotZero (snd x)) ->\n(EqRat (AddRationals x a (AddInverse x a) (xAndInverseNotZeroPlus x a) ) (productNonZero a (xAndInverseNotZeroPlus x a)) (0,1) PositiveZ)\naddInverseLeftEqRat x a = EqRatTrans (AddRationals x a (AddInverse x a) (xAndInverseNotZeroPlus x a)) (productNonZero a (xAndInverseNotZeroPlus x a)) ((Pos 0), (snd x)*(snd x)) (productNonZero a a) (0,1) (PositiveZ) (EqRatAddInvLeft x a) (reducedFormZeroRight ((snd x)*(snd x)) (productNonZero a a))\n\n|||Constructs an equality between 0 and ((a,b)+(-a,b)).\naddInverseRightEqRat: (x: ZZPair) -> (a: NotZero (snd x)) ->\n(EqRat (AddRationals (AddInverse x a) (xAndInverseNotZeroPlus x a) x a) (productNonZero a (xAndInverseNotZeroPlus x a)) (0,1) PositiveZ)\naddInverseRightEqRat x a = EqRatTrans (AddRationals (AddInverse x a) (xAndInverseNotZeroPlus x a) x a) (productNonZero a (xAndInverseNotZeroPlus x a)) ((Pos 0), (snd x)*(snd x)) (productNonZero a a) (0,1) (PositiveZ) (EqRatAddInvRight x a) (reducedFormZeroRight ((snd x)*(snd x)) (productNonZero a a))\n\n|||Constructs an equality between (a,b)*(b,a) and (1,1).\nmultInverseLeftEqRat: (x: ZZPair) -> (a: NotZero (fst x)) -> (b: NotZero (snd x)) ->\n(EqRat (MultiplyRationals x b (MultInverse x a b) (xAndInverseNotZeroMult x a b)) (productNonZero b (xAndInverseNotZeroMult x a b)) (1,1) (PositiveZ))\nmultInverseLeftEqRat x a b = EqRatTrans (MultiplyRationals x b (MultInverse x a b) (xAndInverseNotZeroMult x a b)) (productNonZero b (xAndInverseNotZeroMult x a b)) ((fst x)*(snd x), (fst x)*(snd x)) (productNonZero a b) (1,1) (PositiveZ) (EqRatMultInvLeft x a b) (reducedFormOneRight ((fst x)*(snd x)) (productNonZero a b))\n\n|||Constructs an equality between (1,1) and (a,b)*(b,a).\nmultInverseRightEqRat: (x: ZZPair) -> (a: NotZero (fst x)) -> (b: NotZero (snd x)) ->\n(EqRat (MultiplyRationals (MultInverse x a b) (xAndInverseNotZeroMult x a b) x b) (productNonZero (xAndInverseNotZeroMult x a b) b) (1,1) (PositiveZ))\nmultInverseRightEqRat x a b = EqRatTrans (MultiplyRationals (MultInverse x a b) (xAndInverseNotZeroMult x a b) x b) (productNonZero (xAndInverseNotZeroMult x a b) b) ((snd x)*(fst x), (snd x)*(fst x)) (productNonZero b a) (1,1) (PositiveZ) (EqRatMultInvRight x a b) (reducedFormOneRight ((snd x)*(fst x)) (productNonZero b a))\n\n|||Constructs an EqRat element of associativity for addition.\nplusAssocQEqRat: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (z: ZZPair) -> (c: NotZero (snd z)) ->\n(EqRat (AddRationals (AddRationals x a y b) (productNonZero a b) z c) (productNonZero (productNonZero a b) c) (AddRationals x a (AddRationals y b z c) (productNonZero b c)) (productNonZero a (productNonZero b c)))\nplusAssocQEqRat x a y b z c = eqMeansEqRat (AddRationals (AddRationals x a y b) (productNonZero a b) z c) (productNonZero (productNonZero a b) c) (AddRationals x a (AddRationals y b z c) (productNonZero b c)) (productNonZero a (productNonZero b c)) (plusAssociativeQ x a y b z c)\n\n|||Constructs an EqRat element of associativity for multiplication.\nmultAssocQEqRat: (x: ZZPair) -> (a: NotZero (snd x)) -> (y: ZZPair) -> (b: NotZero (snd y)) -> (z: ZZPair) -> (c: NotZero (snd z)) ->\n(EqRat (MultiplyRationals (MultiplyRationals x a y b) (productNonZero a b) z c) (productNonZero (productNonZero a b) c) (MultiplyRationals x a (MultiplyRationals y b z c) (productNonZero b c)) (productNonZero a (productNonZero b c)))\nmultAssocQEqRat x a y b z c = eqMeansEqRat (MultiplyRationals (MultiplyRationals x a y b) (productNonZero a b) z c) (productNonZero (productNonZero a b) c) (MultiplyRationals x a (MultiplyRationals y b z c) (productNonZero b c)) (productNonZero a (productNonZero b c)) (multAssociativeQ x a y b z c)\n", "meta": {"hexsha": "85aa2a6cca800d1f324f0fbd702e413965a9b2e6", "size": 8289, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/FieldAxioms.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/FieldAxioms.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/FieldAxioms.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": 90.097826087, "max_line_length": 326, "alphanum_fraction": 0.711304138, "num_tokens": 3014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.679178699175393, "lm_q1q2_score": 0.6015020261860579}} {"text": "module PatternMatching\n\nzahlen : List Nat\nzahlen = [1,2,3,4,5]\n\nperson : (String, Nat)\nperson = (\"Max\", 40)\n\ndata Farbe \n = Rot\n | Blau\n \ndata Expression : Type -> Type where\n Falsch : Expression Bool\n Wahr : Expression Bool\n Zahl : Nat -> Expression Nat\n Plus : Expression Nat -> Expression Nat -> Expression Nat\n Gleich : Expression Nat -> Expression Nat -> Expression Bool\n Falls : Expression Bool -> Expression a -> Expression a -> Expression a\n\nistLeer : List a -> Bool\nistLeer [] = True\nistLeer (x :: xs) = False\n\nname : (String, Nat) -> String\nname (n, _) = n\n\neval : Expression a -> a\neval Falsch = False\neval Wahr = True\neval (Zahl k) = k\neval (Plus x y) = eval x + eval y\neval (Gleich x y) = eval x == eval y\neval (Falls b t e) = if (eval b) then eval t else eval e\n", "meta": {"hexsha": "4a8db3f4cb5439c64023d6fd594dcf5405efca8e", "size": 785, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Beispiele/PatternMatching.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/PatternMatching.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/PatternMatching.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": 22.4285714286, "max_line_length": 73, "alphanum_fraction": 0.6535031847, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.6688802735722128, "lm_q1q2_score": 0.6014045455706521}} {"text": "module Verified.Functor\n\n%default total\n\nclass Functor f => VerifiedFunctor (f : Type -> Type) where\n functorIdentity : {a : Type} -> (x : f a) -> map id x = id x\n functorComposition : {a : Type} -> {b : Type} -> (x : f a) ->\n (g1 : a -> b) -> (g2 : b -> c) ->\n map (g2 . g1) x = (map g2 . map g1) x\n", "meta": {"hexsha": "c75d288b55b3d90035f48830cce1bf40386f60ab", "size": 338, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Verified/Functor.idr", "max_stars_repo_name": "yurrriq/idris-verified", "max_stars_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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/Verified/Functor.idr", "max_issues_repo_name": "yurrriq/idris-verified", "max_issues_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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/Verified/Functor.idr", "max_forks_repo_name": "yurrriq/idris-verified", "max_forks_repo_head_hexsha": "10dd99e43824421be94138b5547fed5a294c9cd1", "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.8, "max_line_length": 63, "alphanum_fraction": 0.4881656805, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.6893056040203135, "lm_q1q2_score": 0.6013139248676755}} {"text": "module Vec\n\nimport Data.Fin\n\n%default total\n\n%logging 1\n%logging declare.def 2\n\nVec : Type -> Nat -> Type\nVec a n = Fin n -> a\n\nNil : Vec a Z\nNil = absurd\n\n(::) : a -> Vec a n -> Vec a (S n)\n(x :: xs) FZ = x\n(x :: xs) (FS i) = xs i\n\ntest : Vec (List Nat) 2\ntest = [[], [0]]\n", "meta": {"hexsha": "4452446f44f577f5f530a2875cec2ba3533491df", "size": 274, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic044/Vec.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/basic044/Vec.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/basic044/Vec.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": 12.4545454545, "max_line_length": 34, "alphanum_fraction": 0.5401459854, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7090191214879992, "lm_q1q2_score": 0.6012253496469933}} {"text": "> module SequentialDecisionProblems.applications.Main\n\n> import Data.Fin\n> import Data.List\n> import Data.List.Quantifiers\n> import Data.Vect\n> import Data.So\n> import Effects\n> import Effect.Exception\n> import Effect.StdIO\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.FullTheory\n> import SequentialDecisionProblems.TabBackwardsInduction1\n> import SequentialDecisionProblems.Utils\n> import SequentialDecisionProblems.FastStochasticDefaults\n> import SequentialDecisionProblems.CoreTheoryOptDefaults\n> import SequentialDecisionProblems.FullTheoryOptDefaults\n> import SequentialDecisionProblems.TabBackwardsInductionOptDefaults1\n\n> import SequentialDecisionProblems.applications.LowHigh\n> import SequentialDecisionProblems.applications.AvailableUnavailable\n> import SequentialDecisionProblems.applications.GoodBad\n\n> import FastSimpleProb.SimpleProb\n> import FastSimpleProb.BasicOperations\n> import FastSimpleProb.BasicProperties\n> import FastSimpleProb.MonadicOperations\n> import FastSimpleProb.MonadicProperties\n> import FastSimpleProb.Measures\n> import FastSimpleProb.MeasuresProperties\n> import FastSimpleProb.Operations\n> import Sigma.Sigma\n> import Double.Predicates\n> import Double.Postulates\n> import Double.Operations\n> import Double.Properties\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.Constants\n> import NonNegDouble.BasicOperations\n> import NonNegDouble.Operations\n> import NonNegDouble.Properties\n> import NonNegDouble.Predicates\n> import NonNegDouble.LTEProperties\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Decidable.Predicates\n> import Decidable.Properties\n> import LocalEffect.Exception\n> import LocalEffect.StdIO\n> import Fin.Operations\n> import List.Operations\n> import Vect.Operations\n> import Unit.Properties\n\n> -- %default total\n> %auto_implicits off\n\n> -- %logging 5\n\n\n* Introduction\n\nWe specify a second emissions game as a stochastic sequential decision\nproblem with a single decision maker.\n\nThe idea is that \"best\" decisions on levels of greenhouse gases (GHG)\nemissions (that is, how much GHG shall be allowed to be emitted in a\ngiven time period) are affected by three major sources of uncertainty:\n\n1) uncertainty about the (typically negative) effects of high GHG\nconcentrations in the atmosphere,\n\n2) uncertainty about the availability of effective (cheap, efficient)\ntechnologies for reducing GHG emissions,\n\n3) uncertainty about the capability of actually implementing a decision\non a given GHG emission level.\n\nWe study the effects of 1), 2) and 3) on optimal sequences of emission\npolicies. The idea is to design an emission game that accounts for all\nthree sources of uncertainty and yet is simple enough to support\ninvestigating the logical consequences of different assumptions through\ncomparisons and parametric studies.\n\n\n* Controls\n\nWe consider a game in which, at each decision step, the decision maker\ncan select between low and high GHG emissions\n\n> SequentialDecisionProblems.CoreTheory.Ctrl _ _ = LowHigh\n\nLow emissions, if implemented, increase the cumulated GHG emissions less\nthan high emissions.\n\n\n* States\n\nAt each decision step, the decision maker has to choose an option on the\nbasis of four data: the cumulated GHG emissions, the current emission\nlevel (low or high), the availability of effective technologies for\nreducing GHG emissions and the state of the world. Effective\ntechnologies for reducing GHG emissions can be either available or\nunavailable. The state of the world can be either good or bad:\n\n> CumulatedEmissions : (t : Nat) -> Type\n> CumulatedEmissions t = Fin (S t)\n\n> SequentialDecisionProblems.CoreTheory.State t \n> = (CumulatedEmissions t, LowHigh, AvailableUnavailable, GoodBad)\n\nThe idea is that the game starts with zero cumulated emissions, high\nemission levels, unavailable GHG technologies and with the world in a\ngood state. \n\nIn these conditions, the probability to turn to the bad state is\nlow. But if the cumulated emissions increase beyond a fixed critical\nthreshold, the probability that the state of the world turns bad\nincreases. If the world is the bad state, there is no chance to come\nback to the good state.\n\nSimilarly, the probability that effective technologies for reducing GHG\nemissions become available increases after a fixed number of decision\nsteps. Once available, effective technologies stay available for ever.\n\nThe capability of actually implementing a decision on a given GHG\nemission level in general depends on many factors. In our simplified\nsetup, we just investigate the effect of inertia: implementing low\nemissions is easier when low emission policies are already in place than\nwhen the current emission policies are high emission\npolicies. Similarly, implementing high emission policies is easier under\nhigh emissions policies than under low emissions policies.\n\n\n* Transition function\n\n> -- The critical cumulated emissions threshold\n> crE : Double\n> crE = 4.0\n\n> -- The critical number of decision steps\n> crN : Nat\n> crN = 2\n\n> -- The probability of staying in a good world when the cumulated\n> -- emissions are |<=| the critical threshold |crE|\n> pS1 : NonNegDouble\n> pS1 = cast 0.9 -- cast 0.8 -- cast 1.0 -- cast 0.9\n\n> -- The probability of staying in a good world when the cumulated\n> -- emissions are |>=| the critical threshold |crE|\n> pS2 : NonNegDouble\n> pS2 = cast 0.1 -- cast 0.2 -- cast 0.0 -- cast 0.1\n\n> -- Sanity check\n> pS2LTEpS1 : pS2 `NonNegDouble.Predicates.LTE` pS1\n> pS2LTEpS1 = MkLTE Oh\n\n> -- The probability of effective technologies for reducing GHG\n> -- emissions becoming available when the number of decision steps is\n> -- below |crN|\n> pA1 : NonNegDouble\n> pA1 = cast 0.1 -- cast 0.0 -- cast 0.1\n\n> -- The probability of effective technologies for reducing GHG\n> -- emissions becoming available when the number of decision steps is\n> -- above |crN|\n> pA2 : NonNegDouble\n> pA2 = cast 0.9 -- cast 1.0 -- cast 0.9\n\n> -- Sanity check\n> pA1LTEpA2 : pA1 `NonNegDouble.Predicates.LTE` pA2\n> pA1LTEpA2 = MkLTE Oh\n\n> -- The probability being able to implement low emission policies when\n> -- the current emissions are low and low emissions are selected\n> pLL : NonNegDouble\n> pLL = cast 0.9 -- cast 1.0 -- cast 0.9 -- cast 0.5\n\n> -- The probability being able to implement low emission policies when\n> -- the current emissions are high and low emissions are selected\n> pLH : NonNegDouble\n> pLH = cast 0.7 -- cast 1.0 -- cast 0.7 -- cast 0.5\n\n> -- Sanity check\n> pLHLTEpLL : pLH `NonNegDouble.Predicates.LTE` pLL\n> pLHLTEpLL = MkLTE Oh\n\n> -- The probability being able to implement high emission policies when\n> -- the current emissions are low and high emissions are selected\n> pHL : NonNegDouble\n> pHL = cast 0.7 -- cast 1.0 -- cast 0.7 -- cast 0.5\n\n> -- The probability being able to implement high emission policies when\n> -- the current emissions are high and high emissions are selected\n> pHH : NonNegDouble\n> pHH = cast 0.9 -- cast 1.0 -- cast 0.9 -- cast 0.5\n\n> -- Sanity check\n> pHLLTEpHH : pHL `NonNegDouble.Predicates.LTE` pHH\n> pHLLTEpHH = MkLTE Oh\n\nLow emissions leave the cumulated emissions unchanged, high emissions\nincrease the cumulated emissions by one:\n\n> -- The transition function:\n>\n> -- The transition function: high emissions\n>\n> -- The transition function: high emissions, unavailable GHG technologies\n>\n> -- The transition function: high emissions, unavailable GHG technologies, good world\n> \n> using implementation NumNonNegDouble\n> \n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Unavailable, Good) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLH * (one - pA1) * pS1), \n> (( FS e, High, Unavailable, Good), (one - pLH) * (one - pA1) * pS1),\n> ((weaken e, Low, Available, Good), pLH * pA1 * pS1), \n> (( FS e, High, Available, Good), (one - pLH) * pA1 * pS1),\n> ((weaken e, Low, Unavailable, Bad), pLH * (one - pA1) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA1) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), pLH * pA1 * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLH) * pA1 * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLH * (one - pA1) * pS2), \n> (( FS e, High, Unavailable, Good), (one - pLH) * (one - pA1) * pS2),\n> ((weaken e, Low, Available, Good), pLH * pA1 * pS2), \n> (( FS e, High, Available, Good), (one - pLH) * pA1 * pS2),\n> ((weaken e, Low, Unavailable, Bad), pLH * (one - pA1) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA1) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), pLH * pA1 * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLH) * pA1 * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLH * (one - pA2) * pS1), \n> (( FS e, High, Unavailable, Good), (one - pLH) * (one - pA2) * pS1),\n> ((weaken e, Low, Available, Good), pLH * pA2 * pS1), \n> (( FS e, High, Available, Good), (one - pLH) * pA2 * pS1),\n> ((weaken e, Low, Unavailable, Bad), pLH * (one - pA2) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA2) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), pLH * pA2 * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLH) * pA2 * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLH * (one - pA2) * pS2), \n> (( FS e, High, Unavailable, Good), (one - pLH) * (one - pA2) * pS2),\n> ((weaken e, Low, Available, Good), pLH * pA2 * pS2), \n> (( FS e, High, Available, Good), (one - pLH) * pA2 * pS2),\n> ((weaken e, Low, Unavailable, Bad), pLH * (one - pA2) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA2) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), pLH * pA2 * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLH) * pA2 * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Unavailable, Good) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHH) * (one - pA1) * pS1), \n> (( FS e, High, Unavailable, Good), pHH * (one - pA1) * pS1),\n> ((weaken e, Low, Available, Good), (one - pHH) * pA1 * pS1), \n> (( FS e, High, Available, Good), pHH * pA1 * pS1),\n> ((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA1) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA1) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA1 * (one - pS1)), \n> (( FS e, High, Available, Bad), pHH * pA1 * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHH) * (one - pA1) * pS2), \n> (( FS e, High, Unavailable, Good), pHH * (one - pA1) * pS2),\n> ((weaken e, Low, Available, Good), (one - pHH) * pA1 * pS2), \n> (( FS e, High, Available, Good), pHH * pA1 * pS2),\n> ((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA1) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA1) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA1 * (one - pS2)), \n> (( FS e, High, Available, Bad), pHH * pA1 * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHH) * (one - pA2) * pS1), \n> (( FS e, High, Unavailable, Good), pHH * (one - pA2) * pS1),\n> ((weaken e, Low, Available, Good), (one - pHH) * pA2 * pS1), \n> (( FS e, High, Available, Good), pHH * pA2 * pS1),\n> ((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA2) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA2) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA2 * (one - pS1)), \n> (( FS e, High, Available, Bad), pHH * pA2 * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHH) * (one - pA2) * pS2), \n> (( FS e, High, Unavailable, Good), pHH * (one - pA2) * pS2),\n> ((weaken e, Low, Available, Good), (one - pHH) * pA2 * pS2), \n> (( FS e, High, Available, Good), pHH * pA2 * pS2),\n> ((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA2) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA2) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA2 * (one - pS2)), \n> (( FS e, High, Available, Bad), pHH * pA2 * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n> -- The transition function: high emissions, unavailable GHG technologies, bad world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Unavailable, Bad) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLH * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA1)),\n> ((weaken e, Low, Available, Bad), pLH * pA1 ), \n> (( FS e, High, Available, Bad), (one - pLH) * pA1 )] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLH * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA1)),\n> ((weaken e, Low, Available, Bad), pLH * pA1 ), \n> (( FS e, High, Available, Bad), (one - pLH) * pA1 )] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLH * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA2)),\n> ((weaken e, Low, Available, Bad), pLH * pA2 ), \n> (( FS e, High, Available, Bad), (one - pLH) * pA2 )] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLH * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), (one - pLH) * (one - pA2)),\n> ((weaken e, Low, Available, Bad), pLH * pA2 ), \n> (( FS e, High, Available, Bad), (one - pLH) * pA2 )] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Unavailable, Bad) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA1)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA1 ), \n> (( FS e, High, Available, Bad), pHH * pA1 )] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA1)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA1 ), \n> (( FS e, High, Available, Bad), pHH * pA1 )] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA2)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA2 ), \n> (( FS e, High, Available, Bad), pHH * pA2 )] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHH) * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), pHH * (one - pA2)),\n> ((weaken e, Low, Available, Bad), (one - pHH) * pA2 ), \n> (( FS e, High, Available, Bad), pHH * pA2 )] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n>\n> -- The transition function: high emissions, available GHG technologies\n>\n> -- The transition function: high emissions, available GHG technologies, good world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Available, Good) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLH * pS1), \n> (( FS e, High, Available, Good), (one - pLH) * pS1),\n> ((weaken e, Low, Available, Bad), pLH * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLH) * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLH * pS2), \n> (( FS e, High, Available, Good), (one - pLH) * pS2),\n> ((weaken e, Low, Available, Bad), pLH * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLH) * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLH * pS1), \n> (( FS e, High, Available, Good), (one - pLH) * pS1),\n> ((weaken e, Low, Available, Bad), pLH * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLH) * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLH * pS2), \n> (( FS e, High, Available, Good), (one - pLH) * pS2),\n> ((weaken e, Low, Available, Bad), pLH * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLH) * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Available, Good) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHH) * pS1), \n> (( FS e, High, Available, Good), pHH * pS1),\n> ((weaken e, Low, Available, Bad), (one - pHH) * (one - pS1)), \n> (( FS e, High, Available, Bad), pHH * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHH) * pS2), \n> (( FS e, High, Available, Good), pHH * pS2),\n> ((weaken e, Low, Available, Bad), (one - pHH) * (one - pS2)), \n> (( FS e, High, Available, Bad), pHH * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHH) * pS1), \n> (( FS e, High, Available, Good), pHH * pS1),\n> ((weaken e, Low, Available, Bad), (one - pHH) * (one - pS1)), \n> (( FS e, High, Available, Bad), pHH * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHH) * pS2), \n> (( FS e, High, Available, Good), pHH * pS2),\n> ((weaken e, Low, Available, Bad), (one - pHH) * (one - pS2)), \n> (( FS e, High, Available, Bad), pHH * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n> -- The transition function: high emissions, available GHG technologies, bad world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Available, Bad) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLH ), \n> (( FS e, High, Available, Bad), (one - pLH))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLH ), \n> (( FS e, High, Available, Bad), (one - pLH))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLH ), \n> (( FS e, High, Available, Bad), (one - pLH))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLH ), \n> (( FS e, High, Available, Bad), (one - pLH))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, High, Available, Bad) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHH)), \n> (( FS e, High, Available, Bad), pHH )] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHH)), \n> (( FS e, High, Available, Bad), pHH )] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHH)), \n> (( FS e, High, Available, Bad), pHH )] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHH)), \n> (( FS e, High, Available, Bad), pHH )] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n>\n>\n>\n> -- The transition function: low emissions\n>\n> -- The transition function: low emissions, unavailable GHG technologies\n>\n> -- The transition function: low emissions, unavailable GHG technologies, good world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Unavailable, Good) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLL * (one - pA1) * pS1), \n> (( FS e, High, Unavailable, Good), (one - pLL) * (one - pA1) * pS1),\n> ((weaken e, Low, Available, Good), pLL * pA1 * pS1), \n> (( FS e, High, Available, Good), (one - pLL) * pA1 * pS1),\n> ((weaken e, Low, Unavailable, Bad), pLL * (one - pA1) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA1) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), pLL * pA1 * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLL) * pA1 * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLL * (one - pA1) * pS2), \n> (( FS e, High, Unavailable, Good), (one - pLL) * (one - pA1) * pS2),\n> ((weaken e, Low, Available, Good), pLL * pA1 * pS2), \n> (( FS e, High, Available, Good), (one - pLL) * pA1 * pS2),\n> ((weaken e, Low, Unavailable, Bad), pLL * (one - pA1) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA1) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), pLL * pA1 * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLL) * pA1 * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLL * (one - pA2) * pS1), \n> (( FS e, High, Unavailable, Good), (one - pLL) * (one - pA2) * pS1),\n> ((weaken e, Low, Available, Good), pLL * pA2 * pS1), \n> (( FS e, High, Available, Good), (one - pLL) * pA2 * pS1),\n> ((weaken e, Low, Unavailable, Bad), pLL * (one - pA2) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA2) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), pLL * pA2 * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLL) * pA2 * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), pLL * (one - pA2) * pS2), \n> (( FS e, High, Unavailable, Good), (one - pLL) * (one - pA2) * pS2),\n> ((weaken e, Low, Available, Good), pLL * pA2 * pS2), \n> (( FS e, High, Available, Good), (one - pLL) * pA2 * pS2),\n> ((weaken e, Low, Unavailable, Bad), pLL * (one - pA2) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA2) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), pLL * pA2 * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLL) * pA2 * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Unavailable, Good) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHL) * (one - pA1) * pS1), \n> (( FS e, High, Unavailable, Good), pHL * (one - pA1) * pS1),\n> ((weaken e, Low, Available, Good), (one - pHL) * pA1 * pS1), \n> (( FS e, High, Available, Good), pHL * pA1 * pS1),\n> ((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA1) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA1) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA1 * (one - pS1)), \n> (( FS e, High, Available, Bad), pHL * pA1 * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHL) * (one - pA1) * pS2), \n> (( FS e, High, Unavailable, Good), pHL * (one - pA1) * pS2),\n> ((weaken e, Low, Available, Good), (one - pHL) * pA1 * pS2), \n> (( FS e, High, Available, Good), pHL * pA1 * pS2),\n> ((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA1) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA1) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA1 * (one - pS2)), \n> (( FS e, High, Available, Bad), pHL * pA1 * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHL) * (one - pA2) * pS1), \n> (( FS e, High, Unavailable, Good), pHL * (one - pA2) * pS1),\n> ((weaken e, Low, Available, Good), (one - pHL) * pA2 * pS1), \n> (( FS e, High, Available, Good), pHL * pA2 * pS1),\n> ((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA2) * (one - pS1)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA2) * (one - pS1)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA2 * (one - pS1)), \n> (( FS e, High, Available, Bad), pHL * pA2 * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Good), (one - pHL) * (one - pA2) * pS2), \n> (( FS e, High, Unavailable, Good), pHL * (one - pA2) * pS2),\n> ((weaken e, Low, Available, Good), (one - pHL) * pA2 * pS2), \n> (( FS e, High, Available, Good), pHL * pA2 * pS2),\n> ((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA2) * (one - pS2)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA2) * (one - pS2)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA2 * (one - pS2)), \n> (( FS e, High, Available, Bad), pHL * pA2 * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n> -- The transition function: low emissions, unavailable GHG technologies, bad world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Unavailable, Bad) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLL * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA1)),\n> ((weaken e, Low, Available, Bad), pLL * pA1 ), \n> (( FS e, High, Available, Bad), (one - pLL) * pA1 )] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLL * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA1)),\n> ((weaken e, Low, Available, Bad), pLL * pA1 ), \n> (( FS e, High, Available, Bad), (one - pLL) * pA1 )] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLL * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA2)),\n> ((weaken e, Low, Available, Bad), pLL * pA2 ), \n> (( FS e, High, Available, Bad), (one - pLL) * pA2 )] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), pLL * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), (one - pLL) * (one - pA2)),\n> ((weaken e, Low, Available, Bad), pLL * pA2 ), \n> (( FS e, High, Available, Bad), (one - pLL) * pA2 )] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Unavailable, Bad) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA1)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA1 ), \n> (( FS e, High, Available, Bad), pHL * pA1 )] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA1)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA1)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA1 ), \n> (( FS e, High, Available, Bad), pHL * pA1 )] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA2)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA2 ), \n> (( FS e, High, Available, Bad), pHL * pA2 )] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Unavailable, Bad), (one - pHL) * (one - pA2)), \n> (( FS e, High, Unavailable, Bad), pHL * (one - pA2)),\n> ((weaken e, Low, Available, Bad), (one - pHL) * pA2 ), \n> (( FS e, High, Available, Bad), pHL * pA2 )] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n>\n> -- The transition function: low emissions, available GHG technologies\n>\n> -- The transition function: low emissions, available GHG technologies, good world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Available, Good) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLL * pS1), \n> (( FS e, High, Available, Good), (one - pLL) * pS1),\n> ((weaken e, Low, Available, Bad), pLL * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLL) * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLL * pS2), \n> (( FS e, High, Available, Good), (one - pLL) * pS2),\n> ((weaken e, Low, Available, Bad), pLL * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLL) * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLL * pS1), \n> (( FS e, High, Available, Good), (one - pLL) * pS1),\n> ((weaken e, Low, Available, Bad), pLL * (one - pS1)), \n> (( FS e, High, Available, Bad), (one - pLL) * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Good), pLL * pS2), \n> (( FS e, High, Available, Good), (one - pLL) * pS2),\n> ((weaken e, Low, Available, Bad), pLL * (one - pS2)), \n> (( FS e, High, Available, Bad), (one - pLL) * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Available, Good) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHL) * pS1), \n> (( FS e, High, Available, Good), pHL * pS1),\n> ((weaken e, Low, Available, Bad), (one - pHL) * (one - pS1)), \n> (( FS e, High, Available, Bad), pHL * (one - pS1))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHL) * pS2), \n> (( FS e, High, Available, Good), pHL * pS2),\n> ((weaken e, Low, Available, Bad), (one - pHL) * (one - pS2)), \n> (( FS e, High, Available, Bad), pHL * (one - pS2))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHL) * pS1), \n> (( FS e, High, Available, Good), pHL * pS1),\n> ((weaken e, Low, Available, Bad), (one - pHL) * (one - pS1)), \n> (( FS e, High, Available, Bad), pHL * (one - pS1))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Good), (one - pHL) * pS2), \n> (( FS e, High, Available, Good), pHL * pS2),\n> ((weaken e, Low, Available, Bad), (one - pHL) * (one - pS2)), \n> (( FS e, High, Available, Bad), pHL * (one - pS2))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n>\n> -- The transition function: low emissions, available GHG technologies, bad world\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Available, Bad) Low =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLL ), \n> (( FS e, High, Available, Bad), (one - pLL))] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLL ), \n> (( FS e, High, Available, Bad), (one - pLL))] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLL ), \n> (( FS e, High, Available, Bad), (one - pLL))] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), pLL ), \n> (( FS e, High, Available, Bad), (one - pLL))] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n> SequentialDecisionProblems.CoreTheory.nexts t (e, Low, Available, Bad) High =\n> let ttres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHL)), \n> (( FS e, High, Available, Bad), pHL )] in\n> let tfres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHL)), \n> (( FS e, High, Available, Bad), pHL )] in\n> let ftres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHL)), \n> (( FS e, High, Available, Bad), pHL )] in\n> let ffres = mkSimpleProb \n> [((weaken e, Low, Available, Bad), (one - pHL)), \n> (( FS e, High, Available, Bad), pHL )] in\n> case (t <= crN) of\n> True => case (fromFin e <= crE) of\n> True => trim ttres\n> False => trim tfres\n> False => case (fromFin e <= crE) of\n> True => trim ftres\n> False => trim ffres\n\n\n* |Val| and |LTE|:\n\n> SequentialDecisionProblems.CoreTheory.Val =\n> NonNegDouble.NonNegDouble\n \n> SequentialDecisionProblems.CoreTheory.plus =\n> NonNegDouble.Operations.plus\n\n> SequentialDecisionProblems.CoreTheory.zero =\n> fromInteger @{NumNonNegDouble} 0\n\n> SequentialDecisionProblems.CoreTheory.LTE =\n> NonNegDouble.Predicates.LTE\n\n> SequentialDecisionProblems.FullTheory.reflexiveLTE =\n> NonNegDouble.LTEProperties.reflexiveLTE\n\n> SequentialDecisionProblems.FullTheory.transitiveLTE =\n> NonNegDouble.LTEProperties.transitiveLTE\n \n> SequentialDecisionProblems.FullTheory.monotonePlusLTE =\n> NonNegDouble.LTEProperties.monotonePlusLTE\n\n> SequentialDecisionProblems.CoreTheoryOptDefaults.totalPreorderLTE =\n> NonNegDouble.LTEProperties.totalPreorderLTE\n\n\n* Reward function\n\nThe idea is that being in a good world yields one unit of benefits per\nstep and being in a bad world yield less benefits:\n\n> -- Ratio of the benefits in a bad world and the benefits in a good world\n> badOverGood : NonNegDouble\n> badOverGood = cast 0.89 -- cast 0.89 -- cast 0.5\n\n> -- Sanity check\n> badOverGoodLTEone : badOverGood `NonNegDouble.Predicates.LTE` one\n> badOverGoodLTEone = MkLTE Oh\n\nEmitting GHGs also brings benefits. These are a fraction of the step\nbenefits in a good world and low emissions bring less benefits than high\nemissions:\n\n> -- Ratio between low emissions and step benefits in good world, when\n> -- effective technologies for reducing GHG emissions are unavailable\n> lowOverGoodUnavailable : NonNegDouble\n> lowOverGoodUnavailable = cast 0.1 -- cast 0.0 -- cast 0.1\n\n> -- Ratio between low emissions and step benefits in good world, when\n> -- effective technologies for reducing GHG emissions are available\n> lowOverGoodAvailable : NonNegDouble\n> lowOverGoodAvailable = cast 0.2 -- cast 0.1 -- cast 0.2\n\n> -- Ratio between high emissions and step benefits in a good world\n> highOverGood : NonNegDouble\n> highOverGood = cast 0.3\n\n> -- Sanity check\n> lowOverGoodUnavailableLTEone : lowOverGoodUnavailable `NonNegDouble.Predicates.LTE` one\n> lowOverGoodUnavailableLTEone = MkLTE Oh\n\n> -- Sanity check\n> lowOverGoodAvailableLTEone : lowOverGoodAvailable `NonNegDouble.Predicates.LTE` one\n> lowOverGoodAvailableLTEone = MkLTE Oh\n\n> -- Sanity check\n> lowOverGoodUnavailableLTElowOverGoodAvailable : lowOverGoodUnavailable `NonNegDouble.Predicates.LTE` lowOverGoodAvailable\n> lowOverGoodUnavailableLTElowOverGoodAvailable = MkLTE Oh\n\n> -- Sanity check\n> highOverGoodLTEone : highOverGood `NonNegDouble.Predicates.LTE` one\n> highOverGoodLTEone = MkLTE Oh\n\n> -- Sanity check\n> lowLTEhigh : lowOverGoodAvailable `NonNegDouble.Predicates.LTE` highOverGood\n> lowLTEhigh = MkLTE Oh\n\nThe reward only depend on the next state, not on the current state or on\nthe selected control:\n\n> -- Reward function:\n> \n> using implementation NumNonNegDouble\n> \n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, High, Unavailable, Good) =\n> one + one * highOverGood\n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, High, Unavailable, Bad) =\n> one * badOverGood + one * highOverGood\n>\n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, High, Available, Good) =\n> one + one * highOverGood\n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, High, Available, Bad) =\n> one * badOverGood + one * highOverGood\n> \n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, Low, Unavailable, Good) =\n> one + one * lowOverGoodUnavailable\n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, Low, Unavailable, Bad) =\n> one * badOverGood + one * lowOverGoodUnavailable\n>\n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, Low, Available, Good) =\n> one + one * lowOverGoodAvailable\n> SequentialDecisionProblems.CoreTheory.reward _ _ _ (e, Low, Available, Bad) =\n> one * badOverGood + one * lowOverGoodAvailable\n\n \n* Completing the problem specification\n\nTo be able to apply the verified, generic backwards induction algorithm\nof |CoreTheory| to compute optimal policies for our problem, we have to\nexplain how the decision maker accounts for uncertainties on rewards\ninduced by uncertainties in the transition function. We first assume\nthat the decision maker measures uncertain rewards by their expected\nvalue:\n\n> SequentialDecisionProblems.CoreTheory.meas = expectedValue -- worst -- expectedValue\n> SequentialDecisionProblems.FullTheory.measMon = monotoneExpectedValue -- monotoneWorst -- monotoneExpectedValue\n\nFurther on, we have to implement the notions of viability and\nreachability. We start by positing that all states are viable for any\nnumber of steps:\n\n> -- Viable : (n : Nat) -> State t -> Type\n> SequentialDecisionProblems.CoreTheory.Viable n x = Unit\n\nFrom this definition, it trivially follows that all elements of an\narbitrary list of states are viable for an arbitrary number of steps:\n\n> viableLemma : {t, n : Nat} -> (xs : List (State t)) -> All (Viable n) xs\n> viableLemma Nil = Nil\n> viableLemma {t} {n} (x :: xs) = () :: (viableLemma {t} {n} xs)\n\nThis fact and the (less trivial) result that simple probability\ndistributions are never empty, see |nonEmptyLemma| in\n|MonadicProperties| in |SimpleProb|, allows us to show that the above\ndefinition of |Viable| fulfills |viableSpec1|:\n\n> -- viableSpec1 : (x : State t) -> Viable (S n) x -> GoodCtrl t x\n> SequentialDecisionProblems.CoreTheory.viableSpec1 {t} {n} s v =\n> MkSigma High (ne, av) where\n> ne : SequentialDecisionProblems.CoreTheory.NotEmpty (nexts t s High)\n> ne = nonEmptyLemma (nexts t s High)\n> av : SequentialDecisionProblems.CoreTheory.All (Viable {t = S t} n) (nexts t s High)\n> av = viableLemma {t = S t} (support (nexts t s High))\n\n> SequentialDecisionProblems.Utils.finiteViable n x = finiteUnit\n\n> SequentialDecisionProblems.Utils.decidableViable n x = decidableUnit\n\nFor reachability, we proceed in a similar way. We say that all states\nare reachable\n\n> -- Reachable : State t' -> Type\n> SequentialDecisionProblems.CoreTheory.Reachable x' = Unit\n\nwhich immediately implies |reachableSpec1|:\n\n> -- reachableSpec1 : (x : State t) -> Reachable {t' = t} x -> (y : Ctrl t x) -> All (Reachable {t' = S t}) (nexts t x y)\n> SequentialDecisionProblems.CoreTheory.reachableSpec1 {t} x r y = all (nexts t x y) where\n> all : (sp : SimpleProb (State (S t))) -> SequentialDecisionProblems.CoreTheory.All (Reachable {t' = S t}) sp\n> all sp = all' (support sp) where\n> all' : (xs : List (State (S t))) -> Data.List.Quantifiers.All (Reachable {t' = S t}) xs\n> all' Nil = Nil\n> all' (x :: xs) = () :: (all' xs)\n\nand decidability of |Reachable|:\n\n> SequentialDecisionProblems.TabBackwardsInduction1.decidableReachable x = decidableUnit\n\nFinally, we have to show that controls are finite\n\n> -- finiteCtrl : {t : Nat} -> (x : State t) -> Finite (Ctrl t x)\n> SequentialDecisionProblems.Utils.finiteCtrl _ = finiteLowHigh\n\nand, in order to use the fast, tail-recursive tabulated version of\nbackwards induction, that states are finite:\n\n> SequentialDecisionProblems.TabBackwardsInduction1.finiteState t =\n> finiteTuple4 finiteFin finiteLowHigh finiteAvailableUnavailable finiteGoodBad\n\n\n* Optimal policies, optimal decisions, ...\n\nWe can now apply the results of our |CoreTheory| and of the |FullTheory|\nto compute verified optimal policies, possible state-control sequences,\netc. To this end, we need to be able to show the outcome of the decision\nprocess. This means implemeting functions to print states and controls:\n\n> -- showState : {t : Nat} -> State t -> String\n> SequentialDecisionProblems.Utils.showState {t} (e, High, Unavailable, Good) =\n> \"(\" ++ show (finToNat e) ++ \",H,U,G)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, High, Unavailable, Bad) =\n> \"(\" ++ show (finToNat e) ++ \",H,U,B)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, High, Available, Good) =\n> \"(\" ++ show (finToNat e) ++ \",H,A,G)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, High, Available, Bad) =\n> \"(\" ++ show (finToNat e) ++ \",H,A,B)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, Low, Unavailable, Good) =\n> \"(\" ++ show (finToNat e) ++ \",L,U,G)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, Low, Unavailable, Bad) =\n> \"(\" ++ show (finToNat e) ++ \",L,U,B)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, Low, Available, Good) =\n> \"(\" ++ show (finToNat e) ++ \",L,A,G)\"\n> SequentialDecisionProblems.Utils.showState {t} (e, Low, Available, Bad) =\n> \"(\" ++ show (finToNat e) ++ \",L,A,B)\"\n\n> -- showControl : {t : Nat} -> {x : State t} -> Ctrl t x -> String\n> SequentialDecisionProblems.Utils.showCtrl {t} {x} Low = \"L\"\n> SequentialDecisionProblems.Utils.showCtrl {t} {x} High = \"H\"\n\n> -- ad-hoc trajectories computation\n> adHocPossibleStateCtrlSeqs : {t, n : Nat} -> \n> (ps : PolicySeq t n) ->\n> (x : State t) -> \n> SimpleProb (StateCtrlSeq t n)\n> adHocPossibleStateCtrlSeqs {t} {n = Z} Nil x = \n> FastSimpleProb.MonadicOperations.ret (Nil x)\n> adHocPossibleStateCtrlSeqs {t} {n = S m} (p :: ps') x =\n> {- \n> FastSimpleProb.MonadicOperations.fmap ((MkSigma x y) ::) (FastSimpleProb.MonadicOperations.naivebind mx' f) where\n> y : Ctrl t x\n> y = ctrl (p x () ())\n> mx' : SimpleProb (State (S t))\n> mx' = nexts t x y\n> f : State (S t) -> M (StateCtrlSeq (S t) m)\n> f = adHocPossibleStateCtrlSeqs {n = m} ps'\n> ---}\n> --{-\n> let y = ctrl (p x () ()) in\n> let mx' = nexts t x y in\n> let f = adHocPossibleStateCtrlSeqs {n = m} ps' in\n> FastSimpleProb.MonadicOperations.fmap ((MkSigma x y) ::) (FastSimpleProb.MonadicOperations.naivebind mx' f)\n> ---}\n\n> -- ad-hoc trajectories computation\n> %freeze cardReachableAndViableState\n> adHocPossibleStateCtrlSeqs1 : {t, n : Nat} -> \n> (pts : PolicyTableSeq t n) ->\n> (x : State t) -> \n> SimpleProb (StateCtrlSeq t n)\n> adHocPossibleStateCtrlSeqs1 {t} {n = Z} Nil x = \n> FastSimpleProb.MonadicOperations.ret (Nil x)\n> {-\n> adHocPossibleStateCtrlSeqs1 {t} {n = S m} (pt :: pts') x =\n> FastSimpleProb.MonadicOperations.fmap ((MkSigma x y) ::) (FastSimpleProb.MonadicOperations.naivebind mx' f) where\n> gy : GoodCtrl t x m\n> gy = goodCtrl x () () pt\n> y : Ctrl t x\n> y = ctrl gy\n> mx' : SimpleProb (State (S t))\n> mx' = nexts t x y\n> f : State (S t) -> M (StateCtrlSeq (S t) m)\n> f = adHocPossibleStateCtrlSeqs1 {n = m} pts'\n> -}\n> adHocPossibleStateCtrlSeqs1 {t} {n = S m} (pt :: pts') x =\n> let y = ctrl (goodCtrl x () () pt) in\n> let mx' = nexts t x y in\n> let f = adHocPossibleStateCtrlSeqs1 {n = m} pts' in\n> FastSimpleProb.MonadicOperations.fmap ((MkSigma x y) ::) (FastSimpleProb.MonadicOperations.naivebind mx' f)\n\n> constHigh : (t : Nat) -> (n : Nat) -> PolicySeq t n\n> constHigh t Z = Nil\n> constHigh t (S n) = p :: (constHigh (S t) n) where\n> p : Policy t (S n)\n> p x r v = MkSigma High (ne, av) where\n> ne : SequentialDecisionProblems.CoreTheory.NotEmpty (nexts t x High)\n> ne = nonEmptyLemma (nexts t x High)\n> av : SequentialDecisionProblems.CoreTheory.All (Viable {t = S t} n) (nexts t x High)\n> av = viableLemma {t = S t} (support (nexts t x High))\n\n\n> ||| Constant low policy sequences\n> constLow : (t : Nat) -> (n : Nat) -> PolicySeq t n\n> constLow t Z = Nil\n> constLow t (S n) = p :: (constLow (S t) n) where\n> p : Policy t (S n)\n> p x r v = MkSigma Low (ne, av) where\n> ne : SequentialDecisionProblems.CoreTheory.NotEmpty (nexts t x Low)\n> ne = nonEmptyLemma (nexts t x Low)\n> av : SequentialDecisionProblems.CoreTheory.All (Viable {t = S t} n) (nexts t x Low)\n> av = viableLemma {t = S t} (support (nexts t x Low))\n\n> \n> using implementation ShowNonNegDouble\n> \n> computation : { [STDIO] } Eff ()\n> computation =\n> do putStr (\"enter number of steps:\\n\")\n> nSteps <- getNat\n> putStrLn \"nSteps (number of decision steps):\"\n> putStrLn (\" \" ++ show nSteps)\n> \n> putStrLn \"crE (crit. cumulated emissions threshold):\"\n> putStrLn (\" \" ++ show crE)\n> putStrLn \"crN (crit. number of decision steps):\" \n> putStrLn (\" \" ++ show crN)\n> \n> putStrLn \"pS1 (prob. of staying in a good world, cumulated emissions below crE):\"\n> putStrLn (\" \" ++ show pS1)\n> putStrLn \"pS2 (prob. of staying in a good world, cumulated emissions above crE):\"\n> putStrLn (\" \" ++ show pS2)\n> \n> putStrLn \"pA1 (prob. of eff. tech. becoming available, number of steps below crN):\" \n> putStrLn (\" \" ++ show pA1)\n> putStrLn \"pA2 (prob. of eff. tech. becoming available, number of steps above crN):\"\n> putStrLn (\" \" ++ show pA2)\n> \n> putStrLn \"pLL (prob. of low emission policies, emissions low, low selected):\"\n> putStrLn (\" \" ++ show pLL)\n> putStrLn \"pLH (prob. of low emission policies, emissions high, low selected):\"\n> putStrLn (\" \" ++ show pLH)\n> putStrLn \"pHL (prob. of high emission policies, emissions low, high selected):\"\n> putStrLn (\" \" ++ show pHL)\n> putStrLn \"pHH (prob. of high emission policies, emissions high, high selected):\"\n> putStrLn (\" \" ++ show pHH) \n> \n> putStrLn \"badOverGood (step benefits ratio: bad over good world):\"\n> putStrLn (\" \" ++ show badOverGood)\n> putStrLn \"lowOverGoodUnavailable (benefits ratio: low emissions over step, good world, eff. tech. unavailable):\"\n> putStrLn (\" \" ++ show lowOverGoodUnavailable) \n> putStrLn \"lowOverGoodAvailable (benefits ratio: low emissions over step, good world, eff. tech. available):\"\n> putStrLn (\" \" ++ show lowOverGoodAvailable)\n> putStrLn \"highOverGood (benefits ratio: High emissions over step, good world):\"\n> putStrLn (\" \" ++ show highOverGood) \n> \n> putStrLn \"computing constHigh policies ...\"\n> constHigh_ps <- pure (constHigh Z nSteps)\n>\n> putStrLn \"computing constHigh state-control sequences ...\"\n> constHigh_mxys <- pure (adHocPossibleStateCtrlSeqs constHigh_ps (FZ, High, Unavailable, Good))\n> putStrLn \"pairing constHigh state-control sequences with their values ...\"\n> constHigh_mxysv <- pure (possibleStateCtrlSeqsRewards' constHigh_mxys)\n> -- putStrLn \"constHigh state-control sequences and their values:\"\n> -- putStrLn (showlong constHigh_mxysv) \n> \n> putStrLn \"computing (naively) the number of constHigh state-control sequences ...\"\n> constHigh_n <- pure (length (toList constHigh_mxysv))\n> putStrLn \"number of constHigh state-control sequences:\"\n> putStrLn (\" \" ++ show constHigh_n)\n> \n> putStrLn \"computing (naively) the most probable constHigh state-control sequence ...\"\n> constHigh_xysv <- pure (naiveMostProbableProb constHigh_mxysv)\n> putStrLn \"most probable constHigh state-control sequence and its probability:\"\n> putStrLn (\" \" ++ show constHigh_xysv) \n> \n> putStrLn \"sorting (naively) the constHigh state-control sequence ...\"\n> constHigh_xysvs <- pure (naiveSortToList constHigh_mxysv)\n> putStrLn \"most probable constHigh state-control sequences (first 3) and their probabilities:\"\n> putStrLn (showlong (take 3 constHigh_xysvs))\n> \n> putStrLn \"measure of constHigh rewards:\"\n> putStrLn (\" \" ++ show (meas (SequentialDecisionProblems.CoreTheory.fmap snd constHigh_mxysv))) \n>\n> putStrLn \"computing constLow policies ...\"\n> constLow_ps <- pure (constLow Z nSteps)\n>\n> putStrLn \"computing constLow state-control sequences ...\"\n> constLow_mxys <- pure (adHocPossibleStateCtrlSeqs constLow_ps (FZ, High, Unavailable, Good))\n> putStrLn \"pairing constLow state-control sequences with their values ...\"\n> constLow_mxysv <- pure (possibleStateCtrlSeqsRewards' constLow_mxys)\n> \n> putStrLn \"computing (naively) the number of constLow state-control sequences ...\"\n> constLow_n <- pure (length (toList constLow_mxysv))\n> putStrLn \"number of constLow state-control sequences:\"\n> putStrLn (\" \" ++ show constLow_n)\n> \n> putStrLn \"computing (naively) the most probable constLow state-control sequence ...\"\n> constLow_xysv <- pure (naiveMostProbableProb constLow_mxysv)\n> putStrLn \"most probable constLow state-control sequence and its probability:\"\n> putStrLn (\" \" ++ show constLow_xysv) \n> \n> putStrLn \"sorting (naively) the constLow state-control sequence ...\"\n> constLow_xysvs <- pure (naiveSortToList constLow_mxysv)\n> putStrLn \"most probable constLow state-control sequences (first 3) and their probabilities:\"\n> putStrLn (showlong (take 3 constLow_xysvs))\n> \n> putStrLn \"measure of constLow rewards:\"\n> putStrLn (\" \" ++ show (meas (SequentialDecisionProblems.CoreTheory.fmap snd constLow_mxysv))) \n> \n> putStrLn \"computing optimal policies ...\"\n> ps <- pure (tabTailRecursiveBackwardsInduction1 Z nSteps)\n> \n> putStrLn \"computing possible state-control sequences ...\"\n> mxys <- pure (adHocPossibleStateCtrlSeqs1 ps (FZ, High, Unavailable, Good))\n> putStrLn \"pairing possible state-control sequences with their values ...\"\n> mxysv <- pure (possibleStateCtrlSeqsRewards' mxys)\n> -- putStrLn \"possible state-control sequences and their values:\"\n> -- putStrLn (showlong mxysv) \n> \n> putStrLn \"computing (naively) the number of possible state-control sequences ...\"\n> n <- pure (length (toList mxysv))\n> putStrLn \"number of possible state-control sequences:\"\n> putStrLn (\" \" ++ show n)\n> \n> putStrLn \"computing (naively) the most probable state-control sequence ...\"\n> xysv <- pure (naiveMostProbableProb mxysv)\n> putStrLn \"most probable state-control sequence and its probability:\"\n> putStrLn (\" \" ++ show xysv)\n> \n> putStrLn \"sorting (naively) the possible state-control sequence ...\"\n> xysvs <- pure (naiveSortToList mxysv)\n> putStrLn \"most probable state-control sequences (first 3) and their probabilities:\"\n> putStrLn (showlong (take 3 xysvs))\n> \n> putStrLn \"measure of possible rewards:\"\n> putStrLn (\" \" ++ show (meas (SequentialDecisionProblems.CoreTheory.fmap snd mxysv)))\n \n> putStrLn \"done!\"\n\n\n> main : IO ()\n> main = run computation\n\n\n> {-\n\n> ---}\n\n\n-- Local Variables:\n-- idris-packages: (\"effects\")\n-- End:\n", "meta": {"hexsha": "1d54494ae090b650c2fed708487f80067c19a98e", "size": 61420, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/EmissionsGame2fast.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/EmissionsGame2fast.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/EmissionsGame2fast.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": 53.455178416, "max_line_length": 123, "alphanum_fraction": 0.5292738522, "num_tokens": 18426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.601049252160972}} {"text": "module xquant.Graph.Marked\n\n-- import Pruviloj\nimport xquant.Math.Set\n\n%default total\n\n||| Marks are used to signify sets of sites that are either\n||| occupied (X) or not (O)\ndata Mark = X | O\n\n||| Increment a Nat if X, do nothing if O.\n||| Used to count total number of marks that are X.\nmS : Mark -> Nat -> Nat\nmS X = S\nmS O = id\n\n||| Representation of a set of sites\n||| @ n total number of sites\n||| @ k numer that are occupied with X\ndata Marks : (n : Nat) -> (k : Nat) -> Type where\n Nil : Marks Z Z\n (::) : (m : Mark) -> Marks n k -> Marks (S n) (mS m k)\n\nempty_ : (n : Nat) -> Marks n Z\nempty_ Z = []\nempty_ (S k) = O :: empty_ k\n\nempty : {n : Nat} -> Marks n Z\nempty = empty_ _\n\ninsertMk : Fin n -> (y : Mark) -> Marks n j -> Marks (S n) (mS y j)\ninsertMk FZ y m = y :: m\ninsertMk (FS i) X (X :: m) = X :: insertMk i X m\ninsertMk (FS i) O (X :: m) = X :: insertMk i O m\ninsertMk (FS i) X (O :: m) = O :: insertMk i X m\ninsertMk (FS i) O (O :: m) = O :: insertMk i O m\n\n--countMZero : (n : Nat) -> Set [empty_ n]\n\n\ndata Compat : Marks n k -> Marks n j -> Type where\n ComZero : Compat [] []\n ComOO : Compat q w -> Compat (O :: q) (O :: w)\n ComXO : Compat q w -> Compat (X :: q) (O :: w)\n ComOX : Compat q w -> Compat (O :: q) (X :: w)\n\npL : {x : Marks n k} -> {y : Marks n j} -> Compat x y -> Marks n k\npL {x} c = x\n\npR : {x : Marks n k} -> {y : Marks n j} -> Compat x y -> Marks n j\npR {y} c = y\n\n\n\n||| Add two compatible marked sets together\nmarkAdd : {q : Marks n m} -> {w : Marks n j} -> Compat q w -> Marks n (m + j)\nmarkAdd ComZero = []\nmarkAdd (ComOO c) = O :: (markAdd c)\nmarkAdd (ComOX c) ?= X :: (markAdd c)\nmarkAdd (ComXO c) = X :: (markAdd c)\n\nmarkAdd_lemma_1 = proof\n intros\n rewrite plusSuccRightSucc m j\n trivial\n\n{-\nmarkLem : Elab ()\nmarkLem = do ns <- intros\n rewriteWith `(plusSuccRightSucc ~(Var m1) ~(Var j))\n hypothesis\n\nmlem = %runElab markLem\n-}\n\nMarks_ : Nat -> Type\nMarks_ n = (m ** Marks n m)\n\n\nshift : LTE n m -> LTE n (S m)\nshift LTEZero = LTEZero\nshift (LTESucc l) = LTESucc (shift l)\n\n\nmarkBound : Marks n m -> LTE m n\nmarkBound [] = LTEZero\nmarkBound (X :: q) with (markBound q)\n | w = LTESucc w\nmarkBound (O :: q) with (markBound q)\n | LTEZero = LTEZero\n | LTESucc x = LTESucc $ shift x\n\n\nXXnotCompat : Compat (X :: ys) (X :: zs) -> Void\nXXnotCompat ComZero impossible\n\nXOunfold : Compat (X :: ys) (O :: zs) -> Compat ys zs\nXOunfold (ComXO c) = c\n\nOXunfold : Compat (O :: ys) (X :: zs) -> Compat ys zs\nOXunfold (ComOX c) = c\n\nOOunfold : Compat (O :: ys) (O :: zs) -> Compat ys zs\nOOunfold (ComOO c) = c\n\n\nantiCom : Not (Compat xs ys) -> Not $ Compat (q::xs) (w::ys)\nantiCom contra ComZero impossible\n\n\ndecer : (m1 : Marks n i) -> (m2 : Marks n j) -> Dec (Compat m1 m2)\ndecer [] [] = Yes ComZero\ndecer (X :: ys) (X :: zs) = No XXnotCompat\ndecer (X :: ys) (O :: zs) with (decer ys zs)\n decer (X :: ys) (O :: zs) | Yes prf = Yes $ ComXO prf\n decer (X :: ys) (O :: zs) | No contra = No $ antiCom contra\ndecer (O :: ys) (X :: zs) with (decer ys zs)\n decer (O :: ys) (X :: zs) | Yes prf = Yes $ ComOX prf\n decer (O :: ys) (X :: zs) | No contra = No $ antiCom contra\ndecer (O :: ys) (O :: zs) with (decer ys zs)\n decer (O :: ys) (O :: zs) | Yes prf = Yes $ ComOO prf\n decer (O :: ys) (O :: zs) | No contra = No $ antiCom contra\n\npartial\nadd' : (m1 : Marks n i) -> (m2 : Marks n j) -> Compat m1 m2\nadd' m1 m2 with (decer m1 m2)\n | Yes c = c\n\n\ndata Compatible : List (Marks_ n) -> Marks_ n -> Type where\n OneCom : (m : Marks_ n) -> Compatible [m] m\n NextCom : (m : Marks_ n)\n -> Compatible l m0\n -> {c : Compat (getProof m) (getProof m0)}\n -> Compatible (m::l) (_ ** markAdd c)\n\ndata CompatSet : Nat -> Type where\n CompSet : {m : Marks_ n} -> (Compatible l m) -> CompatSet n\n\nmkComp : Marks n j -> CompatSet n\nmkComp m = CompSet $ OneCom (_ ** m)\n\npartial comp' : (x : Marks_ n) -> Compatible l m -> (j ** Compatible (x::l) j)\ncomp' {m} x allc with (decer (getProof x) (getProof m))\n | Yes c = (_ ** NextCom {c} x allc)\n\npartial comp : (x : Marks_ n) -> CompatSet n -> CompatSet n\ncomp x (CompSet c) = CompSet $ getProof $ comp' x c\n\n||| A partition of a set of sites into subsets\ndata Partition : (x : Marks n m) -> Type where\n POne : (y : Marks n m) -> Partition y\n PNext : (y : Marks n m) -> (c : Compat y z) -> Partition z -> Partition (markAdd c)\n\n\n||| A complete partition of a set of sites into subsets\ndata PartitionOfUnity : Nat -> Type where\n PUnity : {m : Marks n n} -> (p : Partition m) -> PartitionOfUnity n\n\n||| A partition of a set of sites into subsets of a particular size\n||| @ i the size of the subsets\n||| @ x which sites are included in the partition\ndata PartitionBy : (i : Nat) -> (x : Marks n m) -> Type where\n PBZero : PartitionBy i (empty_ n)\n PBNext : {y : Marks n i} -> (c : Compat y z) -> PartitionBy i z -> PartitionBy i (markAdd c)\n\n||| A complete partition of a set of sites into subsets of a fixed size\n||| @ i the size of the subsets\n||| @ n the size of the partitioned set\ndata PartitionOfUnityBy : (i : Nat) -> (n : Nat) -> Type where\n PUnityBy : {x : Marks n n} -> (p : PartitionBy i x) -> PartitionOfUnityBy i n\n\n\n||| The dual of a marked set, status of every site switched\ndual : Marks n m -> Marks n (n `minus` m)\ndual [] = []\ndual (X :: q) = O :: dual q\ndual (O :: q) ?= X :: dual q\n\n\ntest1 : Partition [X,O]\ntest1 = POne [X,O]\n\ntest2 : Partition [X,X]\ntest2 = PNext [O,X] (ComOX (ComXO ComZero)) test1\n\n\n---------- Proofs ----------\n\n\n\nminusSuccLeft : (n,m : Nat) -> LTE m n -> (S n) `minus` m = S (n `minus` m)\nminusSuccLeft n Z LTEZero = ?minusSuccLeft_rhs_1\nminusSuccLeft (S n) (S m) (LTESucc l) with (minusSuccLeft n m l)\n | eqn = ?minusSuccLeft_rhs_2\n\nminusSuccLeft_rhs_1 = proof\n intros\n rewrite sym $ minusZeroRight n\n trivial\n\nminusSuccLeft_rhs_2 = proof\n intros\n trivial\n\ndual_lemma_1 = proof\n intros\n let prf = markBound q\n let msl = minusSuccLeft n k prf\n rewrite sym msl\n trivial\n", "meta": {"hexsha": "79353e7b3f4f6a1c2cdc834d41b7cf391c9f62b4", "size": 6015, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/xquant/Graph/Marked.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/Graph/Marked.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/Graph/Marked.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": 28.2394366197, "max_line_length": 94, "alphanum_fraction": 0.5921862012, "num_tokens": 2175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6010492521609719}} {"text": "> module NonNegRational.MeasureProperties\n\n> import Syntax.PreorderReasoning\n\n> import NonNegRational.NonNegRational\n> import NonNegRational.Measures\n> import NonNegRational.BasicOperations\n> import NonNegRational.BasicProperties\n> import NonNegRational.Predicates\n> import NonNegRational.LTEProperties\n> import Fraction.Fraction\n> import Fraction.Normal\n> import Fraction.Predicates\n> import Fraction.BasicProperties\n> import List.Properties \n> import Nat.Positive\n> import PNat.PNat\n> import PNat.Operations\n> import PNat.Properties\n \n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Properties of |factor|:\n\n> %freeze fromFraction\n\n> |||\n> factorLemma : {A, B, C : Type} -> \n> (as : List A) -> (f : A -> B) -> (g : A -> C) ->\n> factor (map f as) = factor (map g as)\n> factorLemma Nil f g = Refl\n> factorLemma (a :: as) f g = \n> ( factor (map f (a :: as)) )\n> ={ Refl }=\n> ( factor (f a :: map f as) )\n> ={ Refl }=\n> ( fromFraction (1, Element (S (length (map f as))) MkPositive) )\n> ={ cong {f = \\ ZUZU => fromFraction (1, Element (S ZUZU) MkPositive)} (lengthLemma as f g) }=\n> ( fromFraction (1, Element (S (length (map g as))) MkPositive) ) \n> ={ Refl }=\n> ( factor (g a :: map g as) )\n> ={ Refl }=\n> ( factor (map g (a :: as)) )\n> QED\n> %freeze factorLemma\n\n\n* Properties of |sum|:\n\n> %thaw fromFraction\n\n> ||| |sum| is monotone\n> monotoneSum : {A : Type} ->\n> (f : A -> NonNegRational) -> (g : A -> NonNegRational) ->\n> (p : (a : A) -> f a `LTE` g a) ->\n> (as : List A) ->\n> sum (map f as) `LTE` sum (map g as) \n> monotoneSum f g p Nil = LTEZero\n> monotoneSum f g p (a :: as) = s5 where\n> s1 : sum (map f (a :: as)) = f a + sum (map f as)\n> s1 = Refl\n> s2 : sum (map g (a :: as)) = g a + sum (map g as)\n> s2 = Refl\n> s3 : f a `LTE` g a\n> s3 = p a\n> s4 : sum (map f as) `LTE` sum (map g as)\n> s4 = monotoneSum f g p as\n> s5 : sum (map f (a :: as)) `LTE` sum (map g (a :: as))\n> s5 = NonNegRational.LTEProperties.monotonePlusLTE s3 s4\n\n\n> %freeze fromFractionLinear\n> %freeze fromFraction\n\n> ||| The sum of n terms of the form 1/(S m) is n/(S m)\n> sumLemma0 : (n : Nat) -> (m : Nat ) -> \n> sum (replicate n (fromFraction (1, Element (S m) MkPositive))) \n> = \n> fromFraction (n, Element (S m) MkPositive)\n\n> sumLemma0 Z m =\n> let Sm' = Element (S m) MkPositive in\n> let SZ' = Element 1 MkPositive in\n> ( sum (replicate Z (fromFraction (1, Sm'))) )\n> ={ Refl }=\n> ( sum Nil )\n> ={ Refl }=\n> ( fromFraction (0, SZ') )\n> ={ fromFractionEqLemma (0, SZ') (0, Sm') Refl }=\n> ( fromFraction (0, Sm') )\n> QED\n\n> sumLemma0 (S n) m = \n> let Sm' : PNat = Element (S m) MkPositive in\n> let Sm : Nat = toNat Sm' in\n> let Sn : Nat = S n in \n> ( sum (replicate (S n) (fromFraction (1, Sm'))) )\n> ={ Refl }=\n> ( sum (fromFraction (1, Sm') :: replicate n (fromFraction (1, Sm'))) )\n> ={ Refl }=\n> ( fromFraction (1, Sm') + sum (replicate n (fromFraction (1, Sm'))) )\n> ={ cong {f = \\ X => fromFraction (1, Sm') + X} (sumLemma0 n m) }=\n> ( fromFraction (1, Sm') + fromFraction (n, Sm') )\n> ={ sym (fromFractionLinear (1, Sm') (n, Sm')) }=\n> ( fromFraction ((1, Sm') + (n, Sm')) )\n> ={ cong {f = fromFraction} Refl }=\n> ( fromFraction (1 * Sm + n * Sm, Sm' * Sm') )\n> ={ cong {f = \\ X => fromFraction (X, Sm' * Sm')} (sym (multDistributesOverPlusLeft 1 n Sm)) }=\n> ( fromFraction ((1 + n) * Sm, Sm' * Sm') )\n> ={ multElimRight (1 + n) Sm' Sm' }=\n> ( fromFraction (1 + n, Sm') ) \n> ={ cong {f = \\ X => fromFraction (X, Sm')} (plusOneSucc n) }=\n> ( fromFraction (Sn, Sm') )\n> QED\n\n\n* Properties of |average|:\n\n> %freeze monotoneSum\n\n> ||| |average| is monotone\n> monotoneAverage : {A : Type} ->\n> (f : A -> NonNegRational) -> (g : A -> NonNegRational) ->\n> (p : (a : A) -> f a `LTE` g a) ->\n> (as : List A) ->\n> average (map f as) `LTE` average (map g as) \n> monotoneAverage f g p as = monotoneMultLTE {a = sum (map f as)} \n> {b = sum (map g as)} \n> {c = factor (map f as)} \n> {d = factor (map g as)}\n> s1 s3 where\n> s1 : sum (map f as) `LTE` sum (map g as)\n> s1 = monotoneSum f g p as\n> s2 : factor (map f as) `LTE` factor (map f as)\n> s2 = reflexiveLTE (factor (map f as))\n> s3 : factor (map f as) `LTE` factor (map g as)\n> s3 = replace {P = \\ ZUZU => factor (map f as) `LTE` ZUZU} (factorLemma as f g) s2\n> %freeze monotoneAverage\n\n\n> {-\n\n> ---}\n \n", "meta": {"hexsha": "dd428194c1e907fbc99cf593badd43e466ce74d0", "size": 4784, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegRational/MeasureProperties.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/MeasureProperties.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/MeasureProperties.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": 32.3243243243, "max_line_length": 98, "alphanum_fraction": 0.5221571906, "num_tokens": 1633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6009552773476062}} {"text": "module ReflNotRefl1\n\nimport Data.Fin\nimport Data.Vect\n\nimport public Decidable.Decidable\nimport public Decidable.Equality\n\npublic export\ndata X : Nat -> Type where\n B : (0 n : Nat) -> X n\n W : X n -> (Fin n, Bool) -> X n\n\npublic export\nind : Fin n -> X n -> Bool\nind _ (B _) = False\nind i (W x (j, y)) = if isYes $ decEq i j then y else ind i x\n\nprop : ind 3 (B 4 `W` (3, True)) = True\nprop = Refl\n", "meta": {"hexsha": "7abb76c57114b631960750040d3e949b37d9e499", "size": 400, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ReflNotRefl1.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": "ReflNotRefl1.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": "ReflNotRefl1.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": 19.0476190476, "max_line_length": 61, "alphanum_fraction": 0.635, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.6723316860482763, "lm_q1q2_score": 0.6006002191353046}} {"text": "module Data.Profunctor\n\nimport public Control.Applicative.Const\nimport public Control.Monad.Identity\nimport public Data.Morphisms\n\n--------------------------------------------------------------------------------\n-- Forget\n--------------------------------------------------------------------------------\n\npublic export\nrecord Forget (r : Type) (a : Type) (b : Type) where\n constructor MkForget\n fun : a -> Maybe r\n\npublic export\nFunctor (Forget r a) where\n map _ (MkForget fun) = MkForget fun\n\n--------------------------------------------------------------------------------\n-- Profunctor\n--------------------------------------------------------------------------------\n\npublic export\ninterface (forall a . Functor (p a)) => Profunctor (0 p : Type -> Type -> Type) where\n dimap : (i2 -> i1) -> (o1 -> o2) -> p i1 o1 -> p i2 o2\n\n lmap : (i2 -> i1) -> p i1 o -> p i2 o\n lmap f = dimap f id\n\n rmap : (o1 -> o2) -> p i o1 -> p i o2\n rmap = dimap id\n\npublic export\nProfunctor Morphism where\n dimap f g (Mor fun) = Mor $ g . fun . f\n\npublic export\nProfunctor (Forget r) where\n dimap f _ (MkForget fun) = MkForget (fun . f)\n\npublic export\nFunctor m => Profunctor (Kleislimorphism m) where\n dimap f g (Kleisli fun) = Kleisli (map g . fun . f)\n\n--------------------------------------------------------------------------------\n-- Strong\n--------------------------------------------------------------------------------\n\npublic export\ninterface Profunctor p => Strong p where\n first : p a b -> p (a,c) (b,c)\n second : p a b -> p (c,a) (c,b)\n\npublic export\nStrong Morphism where\n first (Mor f) = Mor $ mapFst f\n second (Mor f) = Mor $ mapSnd f\n\npublic export\nFunctor m => Strong (Kleislimorphism m) where\n first (Kleisli f) = Kleisli $ \\(a,c) => (,c) <$> f a\n second (Kleisli f) = Kleisli $ \\(c,a) => (c,) <$> f a\n\npublic export\nStrong (Forget r) where\n first (MkForget f) = MkForget $ \\(a,_) => f a\n second (MkForget f) = MkForget $ \\(_,a) => f a\n\n--------------------------------------------------------------------------------\n-- Choice\n--------------------------------------------------------------------------------\n\npublic export\ninterface Profunctor p => Choice p where\n left : p a b -> p (Either a c) (Either b c)\n right : p a b -> p (Either c a) (Either c b)\n\npublic export\nChoice Morphism where\n left (Mor f) = Mor $ mapFst f\n right (Mor f) = Mor $ mapSnd f\n\npublic export\nApplicative m => Choice (Kleislimorphism m) where\n left (Kleisli f) = Kleisli $ bitraverse f pure\n right (Kleisli f) = Kleisli $ bitraverse pure f\n\npublic export\nChoice (Forget r) where\n left (MkForget f) = MkForget $ either f (const Nothing)\n right (MkForget f) = MkForget $ either (const Nothing) f\n", "meta": {"hexsha": "31071dd416817d4fc3c3c3c38bd6438b248ffa82", "size": 2741, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Profunctor.idr", "max_stars_repo_name": "stefan-hoeck/idris2-optics", "max_stars_repo_head_hexsha": "00638b43796e11fb6ecd954f5c0cc90da8dd18a9", "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/Data/Profunctor.idr", "max_issues_repo_name": "stefan-hoeck/idris2-optics", "max_issues_repo_head_hexsha": "00638b43796e11fb6ecd954f5c0cc90da8dd18a9", "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/Profunctor.idr", "max_forks_repo_name": "stefan-hoeck/idris2-optics", "max_forks_repo_head_hexsha": "00638b43796e11fb6ecd954f5c0cc90da8dd18a9", "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.4731182796, "max_line_length": 85, "alphanum_fraction": 0.4863188617, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6001075926285944}}