{"text": "module Vector\n\n%default total\n\n\ndata Vector = V Float Float Float\n\ndot : Vector -> Vector -> Float\ndot (V x y z) (V x' y' z') = x * x' + y * y' + z * z'\n\nmagnitude : Vector -> Float\nmagnitude v = v `dot` v\n\ncross : Vector -> Vector -> Vector\ncross (V x y z) (V x' y' z') = V (y * z' + z * y')\n (-(x * z' + z * x'))\n (x * y' + y * x')\n\nzero : Vector\nzero = V 0.0 0.0 0.0\n\nunit : Fin 3 -> Vector\nunit fZ = V 1 0 0\nunit (fS fZ) = V 0 1 0\nunit (fS (fS fZ)) = V 0 0 1\nunit (fS (fS (fS i))) = FalseElim (fin0empty i)\n where fin0empty : Fin 0 -> _|_\n fin0empty fZ impossible\n fin0empty (fS _) impossible\n\n(+) : Vector -> Vector -> Vector\n(V x y z) + (V x' y' z') = V (x + x') (y + y') (z + z')\n\n(*) : Vector -> Float -> Vector\n(V x y z) * i = V (i*x) (i*y) (i*z)\n\nneg : Vector -> Vector\nneg v = v * -1.0", "meta": {"hexsha": "d33877e912bc1cf9b800174efd9ced932ef73a7e", "size": 890, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Vector.idr", "max_stars_repo_name": "david-christiansen/idris-raytracer", "max_stars_repo_head_hexsha": "cdd7f4ca0a8f707e4d3ad14522cdc3a11f4e270c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-16T16:52:03.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-16T16:52:03.000Z", "max_issues_repo_path": "Vector.idr", "max_issues_repo_name": "david-christiansen/idris-raytracer", "max_issues_repo_head_hexsha": "cdd7f4ca0a8f707e4d3ad14522cdc3a11f4e270c", "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": "Vector.idr", "max_forks_repo_name": "david-christiansen/idris-raytracer", "max_forks_repo_head_hexsha": "cdd7f4ca0a8f707e4d3ad14522cdc3a11f4e270c", "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.4210526316, "max_line_length": 55, "alphanum_fraction": 0.4707865169, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778000158575, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6998261422244889}} {"text": "import Data.Vect\n\ntotal insert : Ord element => (x : element) -> (xsSorted : Vect k element) -> Vect (S k) element\ninsert x [] = [x]\ninsert x (y :: xs) = case x < y of\n False => y :: insert x xs\n True => x :: y :: xs\n\ntotal insSort : Ord element => Vect n element -> Vect n element\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insert x xsSorted\n", "meta": {"hexsha": "3d35c9ff51acad8a25ecbc488f08128ca0569447", "size": 439, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "VecSort.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": "VecSort.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": "VecSort.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": 33.7692307692, "max_line_length": 96, "alphanum_fraction": 0.5125284738, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6997914948579846}} {"text": "||| Binary representation of natural numbers\n||| See:\n||| * [Idris tutorial](https://github.com/idris-lang/idris-tutorial/blob/master/examples/binary.idr)\n||| * [Haskell](https://jaspervdj.be/posts/2018-09-04-binomial-heaps-101.html#binomial-forests) Binomial heap\n||| making use of binary numbers\nmodule Data.Binary\n\nimport public Data.Nat.Parity\n\n%access public export\n%default total\n\n||| Right to left binary representation of numbers.\n||| Working with a right-to-left representation makes addition much easier. We\n||| can always reconstruct the usual representation through a `Show` instance\n||| for example.\n|||\n||| ```\n||| > :x toBinary 12\n||| B0 (B0 (B1 (B1 BZero))) : Binary 12\n||| ```\ndata Binary : (value : Nat) -> Type where\n ||| Denote the single 0 number in binary representation\n ||| This is also used to _close_ a sequence of binary digits\n BZero : Binary Z\n\n ||| A `0` bit\n ||| Build a binary number equal to 2v. Note that because we don't want to have\n ||| multiple representations for the number 0, eg. `BZero` or an arbitrary\n ||| string of `B0` terminated by `BZero`, we require the next `bin`ary to be\n ||| strictly positive.\n ||| @bin the rest of this binary number\n ||| @n the value of the rest of this binary number.\n B0 : (bin : Binary (S n)) -> Binary ((S n) * 2)\n\n ||| A `1` bit\n ||| Build a binary number equal to 2v + 1\n ||| @bin the rest of this binary number\n ||| @n the value of the rest of this binary number\n B1 : (bin : Binary n) -> Binary (S (n * 2))\n\nimplementation Show (Binary k) where\n show BZero = \"0\"\n show (B0 bin) = show bin ++ \"0\"\n show (B1 BZero) = \"1\"\n show (B1 bin) = show bin ++ \"1\"\n\nshow_test_0 : show BZero = \"0\"\nshow_test_0 = Refl\n\nshow_test_10 : show (B0 (B1 BZero)) = \"10\"\nshow_test_10 = Refl\n\nshow_test_1 : show (B1 BZero) = \"1\"\nshow_test_1 = Refl\n\n-- there's probably a way to use lemmas from Prelude.Nat about distributivity\n-- of multiplication....\ndistributePlus2 : (k : Nat) -> (S (S (k * 2)) = (k + 1) * 2)\ndistributePlus2 Z = Refl\ndistributePlus2 (S k) =\n let hyp = distributePlus2 k\n in rewrite hyp in Refl\n\n\n||| Increment given `Binary`\ninc : Binary k -> Binary (S k)\ninc BZero = B1 BZero\ninc (B0 bin) = B1 bin\ninc (B1 bin) = B0 (inc bin)\n\n-- we would like to derive a `Num` instance for `Binary` but unfortunately\n-- we can't because `Binary` has a type-level argument hence it's not possible\n-- to provide meaning to `Num` operations\n--\n-- We therefore resort to work with specialized functions for casting and\n-- operating on binary numbers.\ntoBinary : (n : Nat) -> Binary n\ntoBinary Z = BZero\ntoBinary (S k) = inc (toBinary k)\n\nlemma1 : (n : Nat) -> toBinary (S n * 2) = B0 (toBinary (S n))\nlemma1 Z = Refl\nlemma1 (S k) = rewrite lemma1 k in Refl\n\nlemma2 : (n : Nat) -> (B1 (toBinary n) = inc (toBinary (mult n 2)))\nlemma2 Z = Refl\nlemma2 (S k) = rewrite sym (lemma2 k) in Refl\n\n||| A proof that we can convert a `Binary` from a `Nat` and get the\n||| same \"number\".\n||| @b a `Binary` number\n||| @n a `Nat` representing the same number than b\nnatIsBinary : (b : Binary n) -> (b = toBinary n)\nnatIsBinary BZero = Refl\nnatIsBinary (B0 bin {n}) = rewrite natIsBinary bin in\n rewrite lemma1 n in Refl\nnatIsBinary (B1 bin {n}) = rewrite natIsBinary bin in lemma2 n\n\nZero : Binary 0\nZero = BZero\n\nOne : Binary 1\nOne = toBinary 1\n\nTwo : Binary 2\nTwo = toBinary 2\n\ninfixl 6 +.\n\nlemmaB0plusB0 : (m, n : Nat) -> (S (plus n (S m)) * 2) =\n (S (S (plus (mult n 2) (S (S (mult m 2))))))\nlemmaB0plusB0 m n =\n rewrite plusCommutative n (S m) in\n rewrite plusCommutative (mult n 2) (S (S (mult m 2))) in\n rewrite multDistributesOverPlusLeft m n 2 in\n Refl\n\nlemmaB1plusB0 : (v, w : Nat) -> (mult (v + S w) 2 = (mult v 2) + (S (S (mult w 2))))\nlemmaB1plusB0 v w =\n rewrite multDistributesOverPlusLeft v (S w) 2 in\n Refl\n\nlemmaB0plusB1 : (v, w : Nat) -> (mult (S v + w) 2 = S (plus (mult v 2) (S (mult w 2))))\nlemmaB0plusB1 v w =\n rewrite multDistributesOverPlusLeft v w 2 in\n rewrite plusSuccRightSucc (mult v 2) (mult w 2) in\n Refl\n\nlemmaB1plusB1 : (v, w : Nat) -> (S (mult (v + w) 2) = plus (mult v 2) (S (mult w 2)))\nlemmaB1plusB1 v w =\n rewrite multDistributesOverPlusLeft v w 2 in\n rewrite plusSuccRightSucc (mult v 2) (mult w 2) in\n Refl\n\n||| Add two binary numbers\n|||\n||| Unsurprisingly, it returns the sum of the 2 numbers, in binary representation.\n||| **Implementation note**: We use `toBinary` to convert the sum of the 2 numbers\n||| which is probably very inefficient at runtime, probably in `O(n + m)` whereas\n||| standard addition has complexity `O(log(n + m))`. This is left to implement\n||| properly later on, using the first implementation provided in the comments\n||| below.\n|||\n||| @x left binary number to add\n||| @y right binary number to add\n||| @n `Nat` represented by `x`\n||| @m `Nat` represented by `y`\nadd : (x : Binary n) -> (y : Binary m) -> Binary (n + m)\nadd BZero y = y\nadd (B0 bin {n}) BZero = rewrite plusZeroRightNeutral (mult n 2) in B0 bin\nadd (B1 bin {n}) BZero = rewrite plusZeroRightNeutral (mult n 2) in B1 bin\nadd (B0 l {n=v}) (B0 r {n=w}) = rewrite sym (lemmaB0plusB0 w v) in B0 (add l r)\nadd (B1 l {n=v}) (B0 r {n=w}) = rewrite sym (lemmaB1plusB0 v w) in B1 (add l r)\nadd (B0 l {n=v}) (B1 r {n=w}) = rewrite sym (lemmaB0plusB1 v w) in B1 (add l r)\nadd (B1 l {n=v}) (B1 r {n=w}) = rewrite sym (lemmaB1plusB1 v w) in B0 (inc (add l r))\n\n(+.) : (x : Binary n) -> (y : Binary m) -> Binary (n + m)\n(+.) = add\n\n\n-- Properties\nbZeroRightNeutral : (b : Binary n) -> (add b BZero = b)\nbZeroRightNeutral BZero = Refl\nbZeroRightNeutral (B0 bin) = ?bZeroRightNeutral_rhs_2\nbZeroRightNeutral (B1 bin) = ?bZeroRightNeutral_rhs_3\n", "meta": {"hexsha": "26e2c9a50dcb9251ff930bf757efc5f1762c5efd", "size": 5746, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "bautzen1945/idris/Data/Binary.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/Binary.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/Binary.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": 34.4071856287, "max_line_length": 109, "alphanum_fraction": 0.6496693352, "num_tokens": 1980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.699770970250887}} {"text": "module NatGCD\n\nimport NatUtils\nimport NatOrder\nimport NatDivisors\n\n%default total\n%access public export\n\n----------------------------------------------------------------------------------------------\n\n-- Definitions\n\n|||Type of proof that d is the GCD of a and b, where atleast one of a and b are non-zero\nisGCD : (a : Nat) -> (b : Nat) -> (g : Nat) -> Type\nisGCD a b g = ((isCommonDivisor a b g), (isMaxDivisor a b g))\n\n|||Type that stores the GCD of two numbers\ngcd : (a : Nat) -> (b : Nat) -> Type\ngcd a b = (d : Nat ** (isGCD a b d))\n\n|||Type of proof that a and b are coprime\ncoprime : (a : Nat) -> (b : Nat) -> Type\ncoprime a b = ((n : Nat) -> (isCommonDivisor a b n) -> (n = 1))\n\n----------------------------------------------------------------------------------------------\n\n--Basic proofs involving GCDs and coprime numbers\n\n|||Proof that if a1 = a2, b1 = b2 then gcd (a1, b1) = gcd (a2, b2)\neqConservesGCD : {a1 : Nat} -> {b1 : Nat} -> {g1 : Nat} ->\n\t\t\t {a2 : Nat} -> {b2 : Nat} -> {g2 : Nat} ->\n\t\t\t (a1 = a2) -> (b1 = b2) -> (g1 = g2) ->\n\t\t\t (isGCD a1 b1 g1) -> (isGCD a2 b2 g2)\neqConservesGCD {a1} {b1} {g1} Refl Refl Refl proofGCD = proofGCD\n\n|||Proof that if a1 = a2, b1 = b2 and a1 and b1 are coprime, a2 and b2 are coprime\neqConservesCoprime : {a1 : Nat} -> {b1 : Nat} -> {a2 : Nat} -> {b2 : Nat} ->\n\t\t\t\t (a1 = a2) -> (b1 = b2) -> (coprime a1 b1) -> (coprime a2 b2)\neqConservesCoprime {a1} {b1} Refl Refl proofCoprime = proofCoprime\n\n|||Proof that the gcd is unique\ngcdUnique : {a : Nat} -> {b : Nat} ->\n\t\t (gcd1 : (gcd a b)) -> (gcd2 : (gcd a b)) -> ((fst gcd1) = (fst gcd2))\ngcdUnique {a} {b} (g1 ** (commDiv1, maxDiv1)) (g2 ** (commDiv2, maxDiv2)) = dividesAntiSymmetric (maxDiv1 g2 commDiv2) (maxDiv2 g1 commDiv1)\n\n|||Proof that gcd is symmetric\ngcdSymmetric : {a : Nat} -> {b : Nat} -> {g : Nat} -> (isGCD a b g) -> (isGCD b a g)\ngcdSymmetric {a} {b} {g} (commonDiv, maxDiv) = (commonDivisorSymmetric commonDiv, (\\n => (\\commDiv => (maxDiv n (commonDivisorSymmetric commDiv)))))\n\n|||Proof that coprimality is symmetric\ncoprimeSymmetric : {a : Nat} -> {b : Nat} -> (coprime a b) -> (coprime b a)\ncoprimeSymmetric {a} {b} proofCoprime =\n\t(\\n => (\\commDiv => (proofCoprime n (commonDivisorSymmetric commDiv))))\n\n|||Proof that gcd (a, b) = 1 implies a and b are coprime\ngcdOneImpliesCoprime : {a : Nat} -> {b : Nat} -> (isGCD a b 1) -> (coprime a b)\ngcdOneImpliesCoprime {a} {b} (commonDivisor, maxDivisor) =\n\t(\\n => (\\commonDiv => dividesAntiSymmetric oneDivides (maxDivisor n commonDiv)))\n\n|||Proof that gcd (a, b) exists implies that both a and b are not zero\ngcdImpliesNotBothZ : {a : Nat} -> {b : Nat} -> {g : Nat} ->\n\t\t\t\t (isGCD a b g) -> Either (Not (a = Z)) (Not (b = Z))\ngcdImpliesNotBothZ {a = Z} {b = Z} {g} (commonDiv, maxDiv) =\n\tvoid ((lneqImpliesNotLEQ (ltToLNEQ lteRefl)) (dividesImpliesGEQ (maxDiv (S g) (zeroDivisible SIsNotZ, zeroDivisible SIsNotZ)) (snd (snd (fst commonDiv)))))\ngcdImpliesNotBothZ {a = (S k)} {b} {g} _ = (Left SIsNotZ)\ngcdImpliesNotBothZ {a} {b = (S l)} {g} _ = (Right SIsNotZ)\n\n|||Proof that a and b are coprime implies gcd (a, b) = 1\ncoprimeImpliesGCDOne : {a : Nat} -> {b : Nat} -> (coprime a b) -> (isGCD a b 1)\ncoprimeImpliesGCDOne {a} {b} proofCoprime = (oneCommonDivisor, (\\n => (\\commonDiv => eqConservesDivisible oneDivides Refl (sym (proofCoprime n commonDiv)))))\n\n|||Proof that given g = gcd (a, b), 1 = gcd(a/g, b/g)\ndivImpliesGCDOne : {a : Nat} -> {b : Nat} -> {g : Nat} -> (proofGCD : isGCD a b g) ->\n\t\t\t (isGCD (fst (fst (fst proofGCD))) (fst (snd (fst proofGCD))) 1)\ndivImpliesGCDOne {a} {b} {g} ((divLeft1, divRight1), maxDiv) =\n\tcoprimeImpliesGCDOne proofCoprime where\n\t\tproofCoprime : (coprime (fst divLeft1) (fst divRight1))\n\t\tproofCoprime n (divLeft2, divRight2) = (multLeftIdIsOne (snd (snd divLeft1)) (dividesAntiSymmetric (dividesMultiple (divisionReflexive (snd (snd divLeft1))) n) (maxDiv (n * g) (multipleDivides divLeft1 divLeft2, multipleDivides divRight1 divRight2))))\n\n|||Generates gcd (a, Z) given a and a proof that a != 0\ngcdRightZero : (a : Nat) -> (Not (a = Z)) -> (gcd a Z)\ngcdRightZero a notZ = (a ** ((zeroCommonDivisorRight notZ, (\\n => (\\proofCommonDivisor => (fst proofCommonDivisor))))))\n\n|||Generates gcd (Z, b) given b and a proof that b != 0\ngcdLeftZero : (b : Nat) -> (Not (b = Z)) -> (gcd Z b)\ngcdLeftZero b notZ = (b ** (zeroCommonDivisorLeft notZ, (\\n => (\\proofCommonDivisor => (snd proofCommonDivisor)))))\n\n|||Proof that gcd (a, Z) = a\ngcdRightZeroRefl : (a : Nat) -> (proofGCD : (gcd a Z)) -> (a = (fst proofGCD))\ngcdRightZeroRefl a (g ** ((divA, divZ), maxDiv)) =\n\tcase (gcdImpliesNotBothZ ((divA, divZ), maxDiv)) of\n\t\t(Left notZ) => dividesAntiSymmetric divA (maxDiv a ((divisionReflexive notZ), (zeroDivisible notZ)))\n\t\t(Right notZ) => void (notZ Refl)\n\n|||Proof that gcd (Z, b) = b\ngcdLeftZeroRefl : (b : Nat) -> (proofGCD : (gcd Z b)) -> (b = (fst proofGCD))\ngcdLeftZeroRefl b (g ** ((divZ, divB), maxDiv)) =\n\tcase (gcdImpliesNotBothZ ((divZ, divB), maxDiv)) of\n\t\t(Left notZ) => void (notZ Refl)\n\t\t(Right notZ) => dividesAntiSymmetric divB (maxDiv b ((zeroDivisible notZ), (divisionReflexive notZ)))\n\n----------------------------------------------------------------------------------------------\n\n--Proofs used in Euclid's division algorithm for the GCD\n\n|||Proof that given gcd (b, r) = g, a = r + q * b, and b ! = 0, gcd (a, b) = g\nremainderExtendsGCD : {a : Nat} -> {b : Nat} -> {g : Nat} -> {r : Nat} -> {q : Nat} ->\n\t\t\t\t (isGCD b r g) -> (a = r + (q * b)) -> (isGCD a b g)\nremainderExtendsGCD {a} {b} {g} {r} {q} (commDiv, maxDiv) proofEq =\n\t(remExtendsCommDiv commDiv proofEq, remExtendsMaxDiv maxDiv proofEq)\n\n|||Proof that given gcd (a, b) = g, a = r + q * b, and b ! = 0, gcd (b, r) = g\nremainderConservesGCD : {a : Nat} -> {b : Nat} -> {g : Nat} -> {r : Nat} -> {q : Nat} ->\n\t\t\t\t (isGCD a b g) -> (a = r + (q * b)) -> (isGCD b r g)\nremainderConservesGCD {a} {b} {g} {r} {q} (commDiv, maxDiv) proofEq =\n\t(remConservesCommDiv commDiv proofEq, remConservesMaxDiv maxDiv proofEq)\n\n----------------------------------------------------------------------------------------------\n\n-- Euclid's algorithm for the GCD of two numbers\n\n|||Returns gcd (a, b) with proof that it is the gcd\neuclidGCD : (a : Nat) -> (b : Nat) -> (Either (Not (a = Z)) (Not (b = Z))) -> (gcd a b)\neuclidGCD a b notBothZ =\n\teuclidRecursion a b notBothZ (\\a => (\\b => (gcd a b))) gcdRightZero gcdLeftZero (\\proofGCD => (\\proofEq => ((fst proofGCD) ** remainderExtendsGCD (snd proofGCD) proofEq)))\n\n|||Returns gcd (a, b) with proof that it is the gcd and an auxilliary proof\neuclidGCDExtend : (a : Nat) -> (b : Nat) -> (Either (Not (a = Z)) (Not (b = Z))) ->\n(proofType : (Nat -> Nat -> Nat -> Type)) ->\n(baseLeft : (k : Nat) -> (Not (k = Z)) -> (proofType k Z k)) ->\n(baseRight : (k : Nat) -> (Not (k = Z)) -> (proofType Z k k)) ->\n(proofExtend : {a1 : Nat} -> {b1 : Nat} -> {g1 : Nat} -> {r1 : Nat} -> {q1 : Nat} -> (proofType b1 r1 g1) -> (a1 = r1 + (q1 * b1)) -> (isGCD b1 r1 g1) -> (proofType a1 b1 g1)) ->\n(g : Nat ** ((isGCD a b g), (proofType a b g)))\n\neuclidGCDExtend a b notBothZ proofType baseLeft baseRight proofExtend =\n\t(euclidRecursion a b notBothZ (\\a => (\\b => (typeNew a b))) baseLeftNew baseRightNew extendNew) where\n\n\ttypeNew : Nat -> Nat -> Type\n\ttypeNew a b = (g : Nat ** ((isGCD a b g), (proofType a b g)))\n\n\tbaseLeftNew : (k : Nat) -> (Not (k = Z)) -> (typeNew k Z)\n\tbaseLeftNew k notZ = (k ** ((snd (gcdRightZero k notZ)), (baseLeft k notZ)))\n\n\tbaseRightNew : (k : Nat) -> (Not (k = Z)) -> (typeNew Z k)\n\tbaseRightNew k notZ = (k ** ((snd (gcdLeftZero k notZ)), (baseRight k notZ)))\n\n\textendNew : {a1 : Nat} -> {b1 : Nat} -> {r1 : Nat} -> {q1 : Nat} -> (typeNew b1 r1) -> (a1 = r1 + (q1 * b1)) -> (typeNew a1 b1)\n\textendNew (g ** (proofGCD, proofAux)) proofEq = (g ** ((remainderExtendsGCD proofGCD proofEq), (proofExtend proofAux proofEq proofGCD)))\n\n----------------------------------------------------------------------------------------------\n\n--More proofs\n\n|||Proof that if g = gcd (a, b) and n != 0, n * g = gcd (n * a, n * b)\ngcdMult : {a : Nat} -> {b : Nat} -> {g : Nat} ->\n\t\t(isGCD a b g) -> (n : Nat) -> (Not (n = Z)) -> (isGCD (n * a) (n * b) (n * g))\n\ngcdMult {a} {b} {g} proofGCD n notZ = ((euclidRecursion a b (gcdImpliesNotBothZ proofGCD) (\\a => (\\b => proofType a b)) baseLeft baseRight proofExtend) g proofGCD n notZ) where\n\n\tproofType : Nat -> Nat -> Type\n\tproofType a1 b1 = (g1 : Nat) -> (isGCD a1 b1 g1) -> (n1 : Nat) -> (Not (n1 = Z)) -> (isGCD (n1 * a1) (n1 * b1) (n1 * g1))\n\n\tbaseLeft : (k : Nat) -> (Not (k = Z)) -> (proofType k Z)\n\tbaseLeft k kNotZ g1 prfGCD n1 nNotZ = (eqConservesGCD Refl (sym (multZeroRightZero n1)) proofEq (snd (gcdRightZero (n1 * k) (nonZeroMultNotZero nNotZ kNotZ)))) where\n\t\tproofEq = (cong {f = (\\l => n1 * l)} (gcdRightZeroRefl k (g1 ** prfGCD)))\n\n\tbaseRight : (k : Nat) -> (Not (k = Z)) -> (proofType Z k)\n\tbaseRight k kNotZ g1 prfGCD n1 nNotZ = (eqConservesGCD (sym (multZeroRightZero n1)) Refl proofEq (snd (gcdLeftZero (n1 * k) (nonZeroMultNotZero nNotZ kNotZ)))) where\n\t\tproofEq = (cong {f = (\\l => n1 * l)} (gcdLeftZeroRefl k (g1 ** prfGCD)))\n\n\tproofExtend : {a1 : Nat} -> {b1 : Nat} -> {r1 : Nat} -> {q1 : Nat} -> (proofType b1 r1) -> (a1 = r1 + (q1 * b1)) -> (proofType a1 b1)\n\tproofExtend {a1} {b1} {r1} {q1} remProof proofEq g1 prfGCD n1 nNotZ = (remainderExtendsGCD (remProof g1 (remainderConservesGCD prfGCD proofEq) n1 nNotZ) (extendEqualMult proofEq n1))\n\n\n\n|||Proof that d divides (a * b) and d and a are coprime implies d divides b\ncoprimeImpliesDiv : {d : Nat} -> {a : Nat} -> {b : Nat} ->\n\t\t\t\t(isDivisible (a * b) d) -> (coprime a d) -> (isDivisible b d)\ncoprimeImpliesDiv {d} {a} {b = Z} (k ** (proofDiv, notZ)) _ = zeroDivisible notZ\ncoprimeImpliesDiv {d} {a} {b = (S n)} (k ** (proofDiv, notZ)) proofCoprime = eqConservesDivisible ((snd (gcdMult (coprimeImpliesGCDOne proofCoprime) (S n) SIsNotZ)) d (eqConservesDivisible (k ** (proofDiv, notZ)) (multCommutative a (S n)) Refl, dividesMultiple (divisionReflexive notZ) (S n))) (multOneRightNeutral (S n)) Refl\n\n----------------------------------------------------------------------------------------------\n\n\n\n--deprecated functions\n\n{-\n\n|||Returns gcd (a, b) with proof that it is the gcd (helper function with bound to make euclidGCD total)\neuclidGCDBound : (bound : Nat) -> (a : Nat) -> (b : Nat) -> (LTE a bound) -> (LTE (S b) bound) -> (Either (Not (a = Z)) (Not (b = Z))) -> (d : Nat ** (isGCD a b d))\n\neuclidGCDBound bound a b leftLTE rightLTE notBothZ =\n\teuclidGCDBoundGen bound a b leftLTE rightLTE notBothZ isGCD baseLeft baseRight remainderExtendsGCD where\n\t\tbaseLeft = (\\a => (\\notZ => (a ** ((zeroCommonDivisorRight notZ, (\\n => (\\proofCommonDivisor => (fst proofCommonDivisor))))))))\n\t\tbaseRight = (\\b => (\\notZ => (b ** (zeroCommonDivisorLeft notZ, (\\n => (\\proofCommonDivisor => (snd proofCommonDivisor)))))))\n\n\n\neuclidGCDBound _ Z Z _ _ notBothZ =\n\tcase notBothZ of\n\t\tLeft notZ => void (notZ Refl)\n\t\tRight notZ => void (notZ Refl)\neuclidGCDBound _ (S a) Z _ _ _ = ((S a) ** ((zeroCommonDivisorRight SIsNotZ, (\\n => (\\proofCommonDivisor => (fst proofCommonDivisor))))))\neuclidGCDBound _ Z (S b) _ _ _ = ((S b) ** (zeroCommonDivisorLeft SIsNotZ, (\\n => (\\proofCommonDivisor => (snd proofCommonDivisor)))))\neuclidGCDBound Z (S a) (S b) lteLeft lteRight _ = void (succNotLTEzero lteLeft)\neuclidGCDBound (S bound) (S a) (S b) (LTESucc lteLeft) (LTESucc lteRight) notBothZ =\n\tcase (euclidDivide (S a) (S b) SIsNotZ) of\n\t(q ** (r ** (proofEq, proofLNEQ))) =>\n\t\tcase (euclidGCDBound bound (S b) r lteRight (lteTransitive (lneqToLT proofLNEQ) lteRight) (Left SIsNotZ)) of\n\t\t(d ** proofGCD) =>\n\t\t\t(d ** remainderExtendsGCD SIsNotZ proofEq proofGCD)\n-}\n\n\n\n{-\n\neuclidGCD a b notBothZ =\n\tcase (isLTE a b) of\n\t\t(Yes proofLTE) => euclidGCDBound (S b) a b (lteTransitive proofLTE (lteSuccRight lteRefl)) lteRefl notBothZ\n\t\t(No proofNotLTE) => euclidGCDBound (S a) a b (lteSuccRight lteRefl) (LTESucc (notLTEImpliesGTE proofNotLTE)) notBothZ\n\n-}\n", "meta": {"hexsha": "3dc832242495442e7e396acea036cae8d1d6bf2d", "size": 11990, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/NatGCD.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/NatGCD.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/NatGCD.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": 53.0530973451, "max_line_length": 326, "alphanum_fraction": 0.5976647206, "num_tokens": 4452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6997163120322075}} {"text": "module Control.Algebra.VectorSpace\n\nimport public Control.Algebra\n\ninfixl 5 <#>\ninfixr 2 <||>\n\n\n||| A module over a ring is an additive abelian group of 'vectors' endowed with a\n||| scale operation multiplying vectors by ring elements, and distributivity laws\n||| relating the scale operation to both ring addition and module addition.\n||| Must satisfy the following laws:\n|||\n||| + Compatibility of scalar multiplication with ring multiplication:\n||| forall a b v, a <#> (b <#> v) = (a <.> b) <#> v\n||| + Ring unity is the identity element of scalar multiplication:\n||| forall v, unity <#> v = v\n||| + Distributivity of `<#>` and `<+>`:\n||| forall a v w, a <#> (v <+> w) == (a <#> v) <+> (a <#> w)\n||| forall a b v, (a <+> b) <#> v == (a <#> v) <+> (b <#> v)\nclass (RingWithUnity a, AbelianGroup b) => Module a b where\n (<#>) : a -> b -> b\n\n||| A vector space is a module over a ring that is also a field\nclass (Field a, Module a b) => VectorSpace a b where {}\n\n||| An inner product space is a module – or vector space – over a ring, with a binary function\n||| associating a ring value to each pair of vectors.\nclass Module a b => InnerProductSpace a b where\n (<||>) : b -> b -> a\n", "meta": {"hexsha": "7c62d9ed446cf64ad499b1ae3870da488f96d976", "size": 1208, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Control/Algebra/VectorSpace.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/Control/Algebra/VectorSpace.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/VectorSpace.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": 38.9677419355, "max_line_length": 94, "alphanum_fraction": 0.6241721854, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6997163000479063}} {"text": "import Interfaces\n\ninfixr 7 :::\ninfixr 7 +++\n\ndata MyList : (a : Type) -> Type where\n MyNil : MyList a\n (:::) : a -> MyList a -> MyList a\n\ndata ListEq : list1 -> list2 -> Type where\n nilEq : ListEq MyNil MyNil\n consEq : (headEqPrf : x = y) -> (tailEqPrf : ListEq xs ys) -> ListEq (x ::: xs) (y ::: ys)\n\n(+++) : (xlist : MyList a) -> (ylist : MyList a) -> MyList a\n(+++) MyNil ylist = ylist\n(+++) xlist MyNil = xlist\n(+++) (x ::: xs) ylist = x ::: (xs +++ ylist)\n\nlistEqReflexive : {xlist : MyList a} -> xlist `ListEq` xlist\nlistEqReflexive {xlist = MyNil} = nilEq\nlistEqReflexive {xlist = (x ::: xs)} = consEq Refl listEqReflexive\n\nlistEqSymmetry : {xlist, ylist : MyList a} -> xlist `ListEq` ylist -> ylist `ListEq` xlist\nlistEqSymmetry {xlist = MyNil} {ylist = MyNil} nilEq = nilEq\nlistEqSymmetry {xlist = MyNil} {ylist = (x ::: y)} xlist_eq_ylist impossible\nlistEqSymmetry {xlist = (x ::: xs)} {ylist = MyNil} xlist_eq_ylist impossible\nlistEqSymmetry {xlist = (x ::: xs)} {ylist = (y ::: ys)} (consEq headEqPrf tailEqPrf) =\n consEq (sym headEqPrf) (listEqSymmetry tailEqPrf)\n\nlistEqTransitive : {xlist, ylist, zlist : MyList a} -> xlist `ListEq` ylist -> ylist `ListEq` zlist -> xlist `ListEq` zlist\nlistEqTransitive {xlist = MyNil} {ylist = MyNil} {zlist = MyNil} nilEq ylist_eq_zlist = ylist_eq_zlist\nlistEqTransitive {xlist = MyNil} {ylist = MyNil} {zlist = (x ::: y)} nilEq ylist_eq_zlist impossible\nlistEqTransitive {xlist = (x:::xs)} {ylist = (y:::ys)} {zlist = MyNil} (consEq headEqPrf tailEqPrf) ylist_eq_zlist impossible \nlistEqTransitive {xlist = (x:::xs)} {ylist = (y:::ys)} {zlist = (z:::zs)} (consEq x_eq_y xs_eq_ys) (consEq y_eq_z ys_eq_zs) =\n consEq (rewrite x_eq_y in y_eq_z) (listEqTransitive xs_eq_ys ys_eq_zs)\n\nmapList : (f : a -> b) -> (xs : MyList a) -> MyList b\nmapList f MyNil = MyNil\nmapList f (x ::: xs) = f x ::: mapList f xs\n\nlistFunctorLawIdentity : (xlist : MyList a) -> mapList Prelude.id xlist `ListEq` xlist\nlistFunctorLawIdentity MyNil = nilEq\nlistFunctorLawIdentity (x ::: xs) = consEq Refl (listFunctorLawIdentity xs)\n\nlistFunctorLawComposition : (v : b -> c) -> (u : a -> b) -> (xlist : MyList a) -> mapList (v . u) xlist `ListEq` mapList v (mapList u xlist)\nlistFunctorLawComposition v u MyNil = nilEq\nlistFunctorLawComposition v u (x ::: xs) = consEq Refl (listFunctorLawComposition v u xs)\n\nMyFunctor MyList where\n equalsTo = ListEq\n eqReflexive = listEqReflexive\n eqSymmetry = listEqSymmetry\n eqTransitive = listEqTransitive\n myMap = mapList\n functorLawIdentity = listFunctorLawIdentity\n functorLawComposition = listFunctorLawComposition\n\nreturnList : a -> MyList a\nreturnList x = x ::: MyNil\n\ninfixl 1 >>>==\n\n(>>>==) : (xlist : MyList a) -> (f : a -> MyList b) -> MyList b\nMyNil >>>== f = MyNil\n(x ::: xs) >>>== f = f x +++ (xs >>>== f)\n\nlistMonadLawIdentityLeftLemma : (z : MyList b) -> ListEq (z +++ MyNil) z\nlistMonadLawIdentityLeftLemma MyNil = nilEq\nlistMonadLawIdentityLeftLemma (z ::: zs) = consEq Refl listEqReflexive\n\nlistMonadLawIdentityLeft : (x : a) -> (f : a -> MyList b) -> (returnList x >>>== f) `ListEq` (f x)\nlistMonadLawIdentityLeft x f = listMonadLawIdentityLeftLemma (f x)\n\nlistTwoEqLemma : (z : a) -> (xlist : MyList a) -> (ylist : MyList a) -> (xlist_eq_ylist : ListEq xlist ylist) -> ListEq ((z ::: MyNil) +++ ylist) (z ::: xlist)\nlistTwoEqLemma z MyNil MyNil nilEq = consEq Refl nilEq\nlistTwoEqLemma _ MyNil (_ ::: _) nilEq impossible\nlistTwoEqLemma _ MyNil (_ ::: _) (consEq headEqPrf tailEqPrf) impossible\nlistTwoEqLemma _ (_ ::: _) MyNil nilEq impossible\nlistTwoEqLemma _ (_ ::: _) MyNil (consEq headEqPrf tailEqPrf) impossible\nlistTwoEqLemma z (x ::: xs) (y ::: ys) (consEq headEqPrf tailEqPrf) = consEq Refl (consEq (sym headEqPrf) (listEqSymmetry tailEqPrf))\n\nlistMonadLawIdentityRight : (n : MyList a) -> (n >>>== (::: MyNil)) `ListEq` n\nlistMonadLawIdentityRight MyNil = nilEq\nlistMonadLawIdentityRight (x ::: xs) = listTwoEqLemma x xs (xs >>>== (::: MyNil)) (listEqSymmetry $ listMonadLawIdentityRight xs)\n\nlistAppendNilLemma : (xlist : MyList a) -> xlist `ListEq` (xlist +++ MyNil)\nlistAppendNilLemma MyNil = nilEq\nlistAppendNilLemma (x ::: xs) = listEqReflexive\n\nreplaceLeft : (xlist : MyList a) -> (ylist : MyList a) -> (zlist : MyList a) -> (xlist_eq_ylist : ListEq xlist ylist) ->\n ListEq (xlist +++ zlist) (ylist +++ zlist)\nreplaceLeft MyNil MyNil MyNil nilEq = nilEq\nreplaceLeft MyNil MyNil (z ::: zs) nilEq = listEqReflexive\nreplaceLeft MyNil (_ ::: _) MyNil nilEq impossible\nreplaceLeft MyNil (_ ::: _) MyNil (consEq headEqPrf tailEqPrf) impossible\nreplaceLeft MyNil (_ ::: _) (_ ::: _) nilEq impossible\nreplaceLeft MyNil (_ ::: _) (_ ::: _) (consEq headEqPrf tailEqPrf) impossible\nreplaceLeft (_ ::: _) MyNil MyNil nilEq impossible\nreplaceLeft (_ ::: _) MyNil MyNil (consEq headEqPrf tailEqPrf) impossible\nreplaceLeft (_ ::: _) MyNil (_ ::: _) nilEq impossible\nreplaceLeft (_ ::: _) MyNil (_ ::: _) (consEq headEqPrf tailEqPrf) impossible\nreplaceLeft (x ::: xs) (y ::: ys) MyNil (consEq headEqPrf tailEqPrf) = consEq headEqPrf tailEqPrf\nreplaceLeft (x ::: xs) (y ::: ys) (z ::: zs) (consEq headEqPrf tailEqPrf) = consEq headEqPrf (replaceLeft xs ys (z ::: zs) tailEqPrf)\n\nreplaceRight : (xlist : MyList a) -> (ylist : MyList a) -> (zlist : MyList a) -> (xlist_eq_ylist : ListEq ylist zlist) ->\n ListEq (xlist +++ ylist) (xlist +++ zlist)\nreplaceRight MyNil MyNil MyNil nilEq = nilEq\nreplaceRight MyNil MyNil (_ ::: _) nilEq impossible\nreplaceRight MyNil MyNil (_ ::: _) (consEq headEqPrf tailEqPrf) impossible\nreplaceRight MyNil (_ ::: _) MyNil nilEq impossible\nreplaceRight MyNil (_ ::: _) MyNil (consEq headEqPrf tailEqPrf) impossible\nreplaceRight MyNil (y ::: ys) (z ::: zs) (consEq headEqPrf tailEqPrf) = consEq headEqPrf tailEqPrf\nreplaceRight (x ::: xs) MyNil MyNil nilEq = listEqReflexive\nreplaceRight (_ ::: _) MyNil (_ ::: _) nilEq impossible\nreplaceRight (_ ::: _) MyNil (_ ::: _) (consEq headEqPrf tailEqPrf) impossible\nreplaceRight (_ ::: _) (_ ::: _) MyNil nilEq impossible\nreplaceRight (_ ::: _) (_ ::: _) MyNil (consEq headEqPrf tailEqPrf) impossible\nreplaceRight (x ::: xs) (y ::: ys) (z ::: zs) (consEq headEqPrf tailEqPrf) = consEq Refl (replaceRight xs (y ::: ys) (z ::: zs) (consEq headEqPrf tailEqPrf))\n\nreplaceBoth : (xlist : MyList a) -> (ylist : MyList a) -> (zlist : MyList a) -> (wlist : MyList a) -> (xlist_eq_zlist : ListEq xlist zlist) -> (ylist_eq_wlist : ListEq ylist wlist) ->\n ListEq (xlist +++ ylist) (zlist +++ wlist)\nreplaceBoth xlist ylist zlist wlist xlist_eq_zlist ylist_eq_wlist =\n (listEqReflexive `listEqTransitive` replaceLeft xlist zlist ylist xlist_eq_zlist) `listEqTransitive` replaceRight zlist ylist wlist ylist_eq_wlist\n\nconcatAssociative : (xlist : MyList a) -> (ylist : MyList a) -> (zlist : MyList a) ->\n ListEq (xlist +++ ylist +++ zlist) ((xlist +++ ylist) +++ zlist)\nconcatAssociative MyNil MyNil MyNil = nilEq\nconcatAssociative MyNil MyNil (z ::: zs) = listEqReflexive\nconcatAssociative MyNil (y ::: ys) MyNil = listEqReflexive\nconcatAssociative MyNil (y ::: ys) (z ::: zs) = listEqReflexive\nconcatAssociative (x ::: xs) MyNil MyNil = listEqReflexive\nconcatAssociative (x ::: xs) MyNil (z ::: zs) = listEqReflexive\nconcatAssociative (x ::: xs) (y ::: ys) MyNil = listEqReflexive\nconcatAssociative (x ::: xs) (y ::: ys) (z ::: zs) = consEq Refl (concatAssociative xs (y ::: ys) (z ::: zs))\n\ndistributiveLaw : (z : a) -> (zs : MyList a) -> (x : a) -> (xs : MyList a) -> (g : a -> MyList b) ->\n (induction_assumption : ListEq ((zs +++ (x ::: xs)) >>>== g) ((zs >>>== g) +++ ((x ::: xs) >>>== g))) ->\n ListEq (g z +++ ((zs +++ (x ::: xs)) >>>== g)) (g z +++ (zs >>>== g) +++ ((x ::: xs) >>>== g))\ndistributiveLaw z zs x xs g induction_assumption =\n replaceRight (g z) ((zs +++ (x ::: xs)) >>>== g) ((zs >>>== g) +++ ((x ::: xs) >>>== g)) induction_assumption\n\n--(((z ::: zs) +++ (x ::: xs)) >>>== g) -- distribute1\n--(g z +++ ((zs +++ (x ::: xs)) >>>== g)) -- distributeIndctionLemma\n--(g z +++ (zs >>>== g) +++ ((x ::: xs) >>>== g)) -- distribute 2\n--(g z +++ (zs >>>== g) +++ g x +++ (xs >>>== g)) -- assosiativeLemma\n--((g z +++ (zs >>>== g)) +++ (g x +++ (xs >>>== g))) -- distribute 3\n--((z ::: zs) >>>== g) +++ ((x ::: xs) >>>== g)\n\nlistMonadLawCompositionLemma : (zlist : MyList a) -> (xlist : MyList a) -> (g : a -> MyList b) ->\n ListEq ((zlist +++ xlist) >>>== g) ((zlist >>>== g) +++ (xlist >>>== g))\nlistMonadLawCompositionLemma MyNil MyNil g = nilEq\nlistMonadLawCompositionLemma MyNil (x ::: xs) g = listEqReflexive\nlistMonadLawCompositionLemma (z ::: zs) MyNil g = listAppendNilLemma (g z +++ (zs >>>== g))\nlistMonadLawCompositionLemma (z ::: zs) (x ::: xs) g =\n distributiveLaw z zs x xs g (listMonadLawCompositionLemma zs (x ::: xs) g) `listEqTransitive`\n concatAssociative (g z) (zs >>>== g) (g x +++ (xs >>>== g))\n\n--((x ::: xs) >>>== f) >>>== g\n--(f x +++ (xs >>>== f)) >>>== g\n--((f x) >>>== g) +++ ((xs >>>== f) >>>== g)\n--((f x) >>>== g) +++ (xs >>>== \\z => f z >>>== g)\n--((x ::: MyNil) >>>== \\z -> f z >>>== g) +++ (xs >>>== \\z => f z >>>== g)\n--((x ::: MyNil) +++ xs) >>>== \\z => f z >>>= g\n--(x ::: xs) >>>== \\z => fz >>>= g\n\nlistMonadLawComposition : (xlist : MyList a) -> (f : a -> MyList b) -> (g : b -> MyList c) ->\n ((xlist >>>== f) >>>== g) `ListEq` (xlist >>>== \\z => f z >>>== g)\nlistMonadLawComposition MyNil f g = nilEq\nlistMonadLawComposition (x ::: xs) f g = \n (listMonadLawCompositionLemma (f x) (xs >>>== f) g `listEqTransitive`\n replaceRight (f x >>>== g) ((xs >>>== f) >>>== g) (xs >>>== (\\z => f z >>>== g)) (listMonadLawComposition xs f g)) `listEqTransitive`\n listEqReflexive\n\nMyMonad MyList where\n myReturn = returnList\n (>>>=) = (>>>==)\n monadLawIdentityLeft = listMonadLawIdentityLeft\n monadLawIdentityRight = listMonadLawIdentityRight\n monadLawComposition = listMonadLawComposition\n", "meta": {"hexsha": "abc9e19456a828419532caa96034763db2edb2c5", "size": 9960, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "MyList.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": "MyList.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": "MyList.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": 55.3333333333, "max_line_length": 183, "alphanum_fraction": 0.6286144578, "num_tokens": 3421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6995002403235043}} {"text": "myPlusCommutes: (left: Nat) -> (right: Nat) -> left + right = right + left\nmyPlusCommutes Z right = rewrite plusZeroRightNeutral right in Refl\nmyPlusCommutes (S left) right = \n rewrite myPlusCommutes left right in \n rewrite plusSuccRightSucc right left in Refl\n", "meta": {"hexsha": "443416c58e836946ac2405f58722801834ee27a4", "size": 263, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ProofExercise_8_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": "ProofExercise_8_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": "ProofExercise_8_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": 43.8333333333, "max_line_length": 74, "alphanum_fraction": 0.7604562738, "num_tokens": 77, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6992895068823487}} {"text": "module Isomorphism\n\nimport TypesAndFunctions\nimport public Category\n\n%default total\n\npublic export\nIsInverse : {cat : Category} -> {a, b: Object cat} ->\n Morphism cat a b -> Morphism cat b a -> Type\nIsInverse f g = (g .* f = catId a, f .* g = catId b)\n\npublic export\nIsIsomorphism : {cat : Category} -> {a, b: Object cat} ->\n Morphism cat a b -> Type\nIsIsomorphism f = DPair (Morphism cat b a) (Isomorphism.IsInverse f)\n\npublic export\nIsomorphic : {cat : Category} -> (a, b: Object cat) -> Type\nIsomorphic a b = DPair (Morphism cat a b) IsIsomorphism\n\npublic export\ninversePostComposeIsPostComposeInverse :\n {cat : Category} -> {a, b, c : Object cat} ->\n (f : Morphism cat b c) ->\n (isIsomorphism : IsIsomorphism {cat} {a=b} {b=c} f) ->\n IsBijection (postCompose {cat} {a} {b} {c} f)\ninversePostComposeIsPostComposeInverse f (fInv ** (isLeftInv, isRightInv)) =\n (postCompose fInv **\n (\\g =>\n let\n assoc = Associativity cat fInv f g\n cancelInverse =\n replace {p=(\\f' => After cat f' g = After cat fInv (After cat f g))}\n isLeftInv assoc\n cancelId =\n replace {p=(\\g' => g' = After cat fInv (After cat f g))}\n (LeftIdentity cat g) cancelInverse\n in\n sym cancelId,\n \\g =>\n let\n assoc = Associativity cat f fInv g\n cancelInverse =\n replace {p=(\\f' => After cat f' g = After cat f (After cat fInv g))}\n isRightInv assoc\n cancelId =\n replace {p=(\\g' => g' = After cat f (After cat fInv g))}\n (LeftIdentity cat g) cancelInverse\n in\n sym cancelId))\n\npublic export\ninversePreComposeIsPreComposeInverse :\n {cat : Category} -> {a, b, c : Object cat} ->\n (f : Morphism cat a b) ->\n (isIsomorphism : IsIsomorphism {cat} {a} {b} f) ->\n IsBijection (preCompose {cat} {a} {b} {c} f)\ninversePreComposeIsPreComposeInverse f (fInv ** (isLeftInv, isRightInv)) =\n (preCompose fInv **\n (\\g =>\n let\n assoc = Associativity cat g f fInv\n cancelInverse =\n replace {p=(\\f' => After cat (After cat g f) fInv = After cat g f')}\n isRightInv assoc\n cancelId =\n replace {p=(\\g' => After cat (After cat g f) fInv = g')}\n (RightIdentity cat g) cancelInverse\n in\n cancelId,\n \\g =>\n let\n assoc = Associativity cat g fInv f\n cancelInverse =\n replace {p=(\\f' => After cat (After cat g fInv) f = After cat g f')}\n isLeftInv assoc\n cancelId =\n replace {p=(\\g' => After cat (After cat g fInv) f = g')}\n (RightIdentity cat g) cancelInverse\n in\n cancelId))", "meta": {"hexsha": "234ca73452f2e7edcb47417330568eb868788db4", "size": 2600, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Isomorphism.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/Isomorphism.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/Isomorphism.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": 31.7073170732, "max_line_length": 77, "alphanum_fraction": 0.5953846154, "num_tokens": 789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6992805597109032}} {"text": "import Data.Vect\n\n%default total \n\n{- Types can be treat in same way as the values. -}\nreturnType : Nat -> Type\nreturnType Z = Int\nreturnType (S Z) = String\nreturnType (S (S n)) = Int -> Int -> Int\n\n\n{- We can return Int, String or function based on input value -}\nvalueType : (n : Nat) -> returnType n\nvalueType Z = 1\nvalueType (S Z) = \"Hello World\"\nvalueType (S (S n)) = \\x => \\y => x + y\n\n{- Let's extend this idea to variable length input -} \n\nvariableType : (n : Nat) -> Type -> Type\nvariableType Z type = type\nvariableType (S k) type = type -> variableType k type\n\n{- This function constructs a type level function\nλΠ> variableType 0 \nvariableType 0 : Type -> Type\nλΠ> variableType 0 Int\nInt : Type\nλΠ> variableType 1 INT\nWhen checking an application of function Main.variableType:\n No such variable INT\nλΠ> variableType 1 Int\nInt -> Int : Type\nλΠ> variableType 2 Int\nInt -> Int -> Int : Type\nλΠ> variableType 3 String\nString -> String -> String -> String : Type -}\n\n\nvariableValue : (n : Nat) -> (x : Type) -> (f : x -> x -> x) -> (y : x) -> variableType n x\nvariableValue Z x f y = y \nvariableValue (S k) x f y = \\inp => variableValue k x f (f inp y)\n\n{- \nλΠ> :t variableValue 0 Int (+) \nvariableValue 0 Int (+) : Int -> Int\n\nλΠ> variableValue 1 Int (+) 2 3\n5 : Int\nλΠ> variableValue 1 String (++) \"Hello\" \"World\"\n\"WorldHello\" : String \n-}\n\n{- \nprintf \"Hello!\" : String\nprintf \"Answer: %d\" : Int -> String\nprintf \"%s number %d\" : String -> Int -> String\n\n-}\n\n{- This function does not work because of reduction problem, \n so try parsing string into AST -}\nprintfType : List Char -> Type\nprintfType [] = String\nprintfType ('%' :: 'd' :: rest) = Int -> printfType rest\nprintfType ('%' :: 's' :: rest) = String -> printfType rest\nprintfType (c :: rest) = printfType rest \n\n\n{- construct value level function -}\nprintfValue : (xs : List Char) -> String -> printfType xs\nprintfValue [] acc = acc\nprintfValue ('%' :: 'd' :: rest) acc = \\x => printfValue rest (acc ++ show x)\nprintfValue ('%' :: 's' :: rest) acc = \\x => printfValue rest (acc ++ x)\nprintfValue (c :: rest) acc = ?acc -- printfValue rest (acc ++ singleton c)\n\n{- It works, but useless because last one is not reducing \nλΠ> printfValue (unpack \"%s%d%s\") \"\" \"hello\" 2 \"world\"\n\"hello2world\" : String\n-}\n\n\n\ndata Format = FInt Format\n | FString Format\n | FOther Char Format\n | FEnd\n\nformat : List Char -> Format\nformat [] = FEnd\nformat ('%' :: 'd' :: cs ) = FInt (format cs)\nformat ('%' :: 's' :: cs ) = FString (format cs)\nformat (c :: cs) = FOther c (format cs)\n\ninterpFormat : Format -> Type\ninterpFormat FEnd = String\ninterpFormat (FInt f) = Int -> interpFormat f\ninterpFormat (FString f) = String -> interpFormat f\ninterpFormat (FOther _ f) = interpFormat f\n\n\nformatString : String -> Format\nformatString s = format (unpack s)\n\n\ntoFunction : (fmt : Format) -> (acc : String) -> interpFormat fmt\ntoFunction FEnd acc = acc\ntoFunction (FInt f) acc = \\i => toFunction f (acc ++ show i)\ntoFunction (FString f) acc = \\s => toFunction f (acc ++ s)\ntoFunction (FOther c f) acc = toFunction f (acc ++ singleton c)\n\n\nprintf : (s : String) -> interpFormat (formatString s)\nprintf s = toFunction (formatString s) \"\" \n\n\n\n{- Matrix with n rows and m column -}\n\nMatrix : Nat -> Nat -> Type -> Type\nMatrix n m a = Vect n (Vect m a)\n\nrepeat : (n : Nat) -> a -> Vect n a\nrepeat Z _ = []\nrepeat (S n) a = a::repeat n a\n\ntransposeM : Matrix m n a -> Matrix n m a\ntransposeM [] = repeat _ []\ntransposeM (x::xs) = zipWith (::) x (transposeM xs)\n\n\ntwoByThree : Matrix 2 3 Int\ntwoByThree = [[1,2,3], \n [4,5,6]]\n\nthreeByTwo : Matrix 3 2 Int\nthreeByTwo = [[1, 4],\n [2, 5],\n [3, 6]]\n \ntProof : (xs : Matrix n m a) -> transposeM (transposeM xs) = xs\ntProof xs = ?proofisleftasanexercisetothereader\n\n\n{- This code is literally copied from memory when I was learning Haskell -}\nmatrixMultiplication : Num a => Matrix m r a -> Matrix r n a -> Matrix m n a \nmatrixMultiplication xs ys = [[sum $ zipWith (*) ar bc | bc <- (transposeM ys)] | ar <- xs]\n", "meta": {"hexsha": "148cbaaaf16f1eb4055fe2a4fe8a8a945bdc7235", "size": 4114, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Printf.idr", "max_stars_repo_name": "mukeshtiwari/CanberraFP", "max_stars_repo_head_hexsha": "89b6ab48fa3acd93c99d74e7c7586816efc1f7a6", "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": "Printf.idr", "max_issues_repo_name": "mukeshtiwari/CanberraFP", "max_issues_repo_head_hexsha": "89b6ab48fa3acd93c99d74e7c7586816efc1f7a6", "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": "Printf.idr", "max_forks_repo_name": "mukeshtiwari/CanberraFP", "max_forks_repo_head_hexsha": "89b6ab48fa3acd93c99d74e7c7586816efc1f7a6", "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.7972972973, "max_line_length": 92, "alphanum_fraction": 0.6273699562, "num_tokens": 1255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.6992804470755596}} {"text": "> module SequentialDecisionProblems.ReachabilityDefaults\n\n> import SequentialDecisionProblems.CoreTheory\n\n> import Sigma.Sigma\n\n> %default total\n> %auto_implicits off\n\n\nThis is the default implementation of |Reachable|: all states at the\nfirst decision step are reachable; a state at decision step |t' = t + 1|\nis reachable iff it has a reachable predecessor:\n\n> SequentialDecisionProblems.CoreTheory.Reachable {t' = Z} x' = Unit\n> SequentialDecisionProblems.CoreTheory.Reachable {t' = S t} x' = Sigma (State t) (\\ x => ReachablePred {t = t} x x')\n\nIf users can show that the monad |M| fulfills the specification\n\n> allElemSpec1 : {A : Type} -> {P : A -> Type} ->\n> (ma : M A) -> ((a : A) -> a `Elem` ma -> P a) -> All P ma\n\nwe can easily shoe that if |x| is reachable and admits a control |y|,\nthen all states that can be obtained by selecting |y| in |x| are also\nreachable, as required by the core theory:\n\n> SequentialDecisionProblems.CoreTheory.reachableSpec1 {t} x r y = s where\n> f : (x' : State (S t)) -> x' `Elem` (nexts t x y) -> Reachable {t' = S t} x'\n> f x' x'en = MkSigma x (r, MkSigma y x'en)\n> s : All Reachable (nexts t x y)\n> s = allElemSpec1 (nexts t x y) f\n\n\n> {-\n \n> ---}\n", "meta": {"hexsha": "eac8dc764b220e85fd2863a9b45508be3307508b", "size": 1217, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/ReachabilityDefaults.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/ReachabilityDefaults.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/ReachabilityDefaults.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.8918918919, "max_line_length": 117, "alphanum_fraction": 0.6663927691, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6991940313198615}} {"text": "> module Listable\n> import Functions\n> import Data.Fin\n> import Data.List\n> import Data.List.TypeEnumeration\n> import Data.Fin.Extensions\n\n\nNow we turn to propositions about finiteness. We start with the well-known\nKuratowski finiteness, which we will call `Listable`: a type $t$ is Kuratowski \nfinite if its elements can be put into a single list. That is, we can find a list\n$xs$ satisfying $\\texttt{All} \\{t\\} xs$.\n\n> ||| Proofs that a type `t` can be completely enumerated by a list `xs`.\n> ||| Alternatively, this is a definition of a finite type.\n> Listable : (t : Type) -> Type\n> Listable t = (xs ** (All {t} xs))\n\nAn alternative idea is to require a surjection $\\texttt{Fin} n \\rightarrow t$ \nfor some $n:\\texttt{Nat}$:\n\n> FinSurjective : (t: Type) -> Type\n> FinSurjective ty = (n:Nat ** (fromFin : (Fin n -> ty) ** (Surjective fromFin)))\n\nThese notions are equivalent. We need some helper lemmas... it is quite likely \nthat these can be cleaned up considerably...\n\n> ||| If we have a proof that `x` is contained in the list `xs`, then we can map\n> ||| that proof to a `Fin (length xs)` in the obvious way.\n> getIndexOfElem : {x:t} -> Elem x xs -> Fin (length xs)\n> getIndexOfElem Here = FZ\n> getIndexOfElem (There later) = FS (getIndexOfElem later)\n\n> ||| Given a proof that some `xs : List t` contains all instances of type `t`,\n> ||| get the `Fin (length xs)`-valued index of any `x : t`. \n> getIndexFromAll : All {t} xs -> t -> Fin (length xs)\n> getIndexFromAll {xs = []} pf x = absurd (pf x)\n> getIndexFromAll {xs = (y :: xs)} pf x = getIndexOfElem (pf x)\n\n> allFinBijection : {t:Type} -> All {t} xs -> (f:(t-> Fin (length xs)) ** Bijective f)\n> allFinBijection pf = ((getIndexFromAll pf) ** (?tvalHole1,?tvalHole2))\n\n\n\n> ||| Index into a list `l` with a `Fin (length l).`\n> finIndexList : (l:List t) -> Fin (length l) -> t\n> finIndexList [] _ impossible\n> finIndexList (x :: _) FZ = x\n> finIndexList (_ :: xs) (FS y) = finIndexList xs y\n\n> getIndexOfElemLemma : {x:t} -> (pf : Elem x xs) -> finIndexList xs (getIndexOfElem pf) = x\n> getIndexOfElemLemma {xs = (x :: ys)} Here = Refl\n> getIndexOfElemLemma {xs = (y :: ys)} (There later) = getIndexOfElemLemma later\n\n> getIndexOfAllLemma : (pf : All {t} xs) -> (x : t) -> finIndexList xs (getIndexFromAll pf x) = x\n> getIndexOfAllLemma {xs} pf x with (pf x)\n> getIndexOfAllLemma {xs= x :: ys} pf x | Here = getIndexOfElemLemma (pf x)\n> getIndexOfAllLemma {xs= y :: ys} pf x | (There later) = getIndexOfElemLemma (pf x)\n\n> finIndexListSurjectiveIfAll : All {t} xs -> Surjective (finIndexList xs)\n> finIndexListSurjectiveIfAll {xs} pf = \\y => ((getIndexFromAll pf y) ** (getIndexOfAllLemma pf y))\n\n> indexIntoAll : All {t} xs -> (f : (Fin (length xs) -> t) ** Surjective f)\n> indexIntoAll {xs} pf = ((finIndexList xs) ** (finIndexListSurjectiveIfAll pf))\n\n> listableIsFinSurjective : Listable t -> FinSurjective t\n> listableIsFinSurjective (xs ** pf) = ((length xs) ** (indexIntoAll pf))\n\n\n> elemToFinIndex : {t : Type} -> (x:t ** Elem x xs) -> Fin (length xs)\n> elemToFinIndex (_ ** Here) = FZ\n> elemToFinIndex ( x ** (There later)) = FS (elemToFinIndex (x ** later))\n\n> elemLemma : {y: t} -> (x ** Data.List.Elem x xs) -> (x ** Data.List.Elem x (y :: xs))\n> elemLemma (a ** pf) = (a ** (Data.List.There pf))\n\n> finIndexToElem : (xs : List t) -> (index : Fin (length xs)) -> (x : t ** (Elem x xs))\n> finIndexToElem [] _ impossible\n> finIndexToElem (x :: xs) FZ = (x ** Here)\n> finIndexToElem (b :: bs) (FS j) = elemLemma {y=b} (finIndexToElem bs j)\n\n> elemLemmaLemma : {y:t} -> {xs : List t} -> {e : (x ** Data.List.Elem x xs)} -> (elemToFinIndex e = m) -> (elemToFinIndex (elemLemma e) = FS m)\n> elemLemmaLemma {y = y} {e = (x ** pf)} Refl = Refl\n\n\n> elemToFinIndexLemma : (x : t) -> (xs : List t) -> (y : Fin (length xs)) -> \n> (subres2 : elemToFinIndex (finIndexToElem xs y) = y) -> \n> elemToFinIndex (elemLemma (finIndexToElem xs y)) = FS y\n> elemToFinIndexLemma x [] y _ impossible\n> elemToFinIndexLemma x (z :: xs) y subres2 = elemLemmaLemma {y=z} {xs=(z::xs)} {e=(finIndexToElem(z::xs) y)} subres2 \n\n> finIndexElemInverse1 : (xs : List t) -> (index : Fin (length xs)) -> (elemToFinIndex (finIndexToElem xs index) = index)\n> finIndexElemInverse1 [] _ impossible\n> finIndexElemInverse1 (x :: xs) FZ = Refl\n> finIndexElemInverse1 (x :: xs) (FS y) = let subres2 = (finIndexElemInverse1 xs y) in (elemToFinIndexLemma x xs y subres2)\n\n> finIndexElemInverse2 : {x:t} -> (xs : List t) -> (elem : Elem x xs) -> finIndexToElem xs (elemToFinIndex (x**elem)) = (x**elem)\n> finIndexElemInverse2 (x::ys) Here = Refl\n> finIndexElemInverse2 {x} (y::ys) (There later) = ?finIndexElemInverse2Hole2\n\n> finSurjectiveIsListable : FinSurjective t -> Listable t\n> finSurjectiveIsListable (bound ** (surj ** pf)) = ?finSurjectiveIsListable_rhs_2\n\nListability gives an upper bound on the cardinality of any given type considered \nas sets. We can strengthen this by forbidding duplicates:\n\n> ListableNoDuplicate : (t: Type) -> Type\n> ListableNoDuplicate t = (xs : List t ** (All {t} xs, NoDupes {t} xs))\n\nAlternatively, we can strengthen FinSurjectivity by requring a bijection:\n\n> FinBijective : (t: Type) -> Type\n> FinBijective t = (n:Nat ** (f : (t -> Fin n) ** Bijective f))\n\nThese two notions are equivalent:\n\n> finBijToListNoDupes : {t:Type} -> FinBijective t -> ListableNoDuplicate t\n\n> listNoDupesToFinBij : {t:Type} -> ListableNoDuplicate t -> FinBijective t\n\nActually, all four notions of finiteness are equivalent. The reason is that \nlistability implies decidable equality:\n\n> listableToDecEq : {t:Type} -> Listable t -> (x: t) -> (y : t) -> Dec (x = y)\n> listableToDecEq (xs **pf) x y = ?listableToDecEq_rhs\n\nWith this (along with the implication $\\texttt{DecEq} \\Rightarrow \\texttt{DecIn}$)\nwe can implement removal of duplicates.\n", "meta": {"hexsha": "fa389a15a521c210050550a1e761851513aeba5e", "size": 5836, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Finiteness.lidr", "max_stars_repo_name": "nicklecompte/idris-finite-sets", "max_stars_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Finiteness.lidr", "max_issues_repo_name": "nicklecompte/idris-finite-sets", "max_issues_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Finiteness.lidr", "max_forks_repo_name": "nicklecompte/idris-finite-sets", "max_forks_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.2403100775, "max_line_length": 144, "alphanum_fraction": 0.6632967786, "num_tokens": 1898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6990697084084753}} {"text": "module Baum\n\n-- ein Baum ist entweder ein leeres Blatt \n-- oder ein Ast mit einem Wert und zwei Unterbäumen\n-- überlege wie der entsprechende Datentyp aussehen könnte\n\ndata Baum : (a : Type) -> Type where\n Blatt : Baum a\n Ast : (wert : a) -> (links : Baum a) -> (rechts : Baum a) -> Baum a\n \n-- ähnlich `Elem` für den Vektor wollen wir eine Datenstruktur\n-- die \"beweist\", dass ein Wert in einem Baum ist, indem der Weg\n-- dorthin aufgezeigt wird\n-- Wie kann das ausehen?\n\ndata PfadZu : (wert : a) -> (baum : Baum a) -> Type where\n Hier : PfadZu wert (Ast wert l r)\n IstLinks : PfadZu wert links -> PfadZu wert (Ast y links r)\n IstRechts : PfadZu wert rechts -> PfadZu wert (Ast y l rechts)\n \n-- jetzt müssen wir noch entscheiden, ob wir einen Weg finden können\n\nnichtImBlatt : PfadZu zu Blatt -> Void\nnichtImBlatt Hier impossible\nnichtImBlatt (IstLinks _) impossible\n\n\nnowhere : (notRechts : PfadZu zu rechts -> Void) -> \n (notLinks : PfadZu zu links -> Void) -> \n (notHere : (zu = wert) -> Void) -> \n PfadZu zu (Ast wert links rechts) -> Void\nnowhere notRechts notLinks notHere Hier = notHere Refl\nnowhere notRechts notLinks notHere (IstLinks l) = notLinks l\nnowhere notRechts notLinks notHere (IstRechts r) = notRechts r\n\n\ngibtEsPfad : DecEq a => (zu : a) -> (baum : Baum a) -> Dec (PfadZu zu baum)\ngibtEsPfad zu Blatt = No nichtImBlatt\ngibtEsPfad zu (Ast wert links rechts) = \n case decEq zu wert of\n Yes Refl => Yes Hier\n No notHere =>\n case gibtEsPfad zu links of\n Yes links => Yes (IstLinks links)\n No notLinks => \n case gibtEsPfad zu rechts of\n Yes rechts => Yes (IstRechts rechts)\n No notRechts => No (nowhere notRechts notLinks notHere)\n \n\n----------------------------------------------------------------------\n-- Wenn alles passt sollte `zu0 = Yes (IstLinks (IstRechts Hier))` sein!\n \nbeispiel : Baum Int\nbeispiel = Ast 2 (Ast 1 Blatt (Ast 0 Blatt Blatt)) (Ast 3 Blatt Blatt)\n\nzu0 : Dec (PfadZu 0 Baum.beispiel)\nzu0 = gibtEsPfad _ _\n", "meta": {"hexsha": "0eba92dbc12422660fd2387eaebcb3d92f33de5a", "size": 2042, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Projekte/Loesungen/Baum.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": "Projekte/Loesungen/Baum.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": "Projekte/Loesungen/Baum.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": 34.6101694915, "max_line_length": 75, "alphanum_fraction": 0.6454456415, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6990561714666873}} {"text": "import Data.Vect\n\nword_lengths : Vect len String -> Vect len Nat\nword_lengths [] = []\nword_lengths (x :: xs) = length x :: word_lengths xs\n\ninsert : (Ord elem) => (x : elem) -> (xs_sorted : Vect k elem) -> Vect (S k) elem\ninsert x [] = [x]\ninsert x (y :: xs) = case x < y of\n False => y :: insert x xs\n True => x :: y :: 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", "meta": {"hexsha": "a4d00ab9559deb6715aaeab469a00764855318a5", "size": 540, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-03/wordlen_vec.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-03/wordlen_vec.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-03/wordlen_vec.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": 31.7647058824, "max_line_length": 81, "alphanum_fraction": 0.5259259259, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6988000848104589}} {"text": "> module Real.Sequence\n\n> import Real.Postulates\n> import Real.Properties\n\n> %default total\n> %access public export\n\n\n> ||| Sequences as functions \n> Sequence : Type\n> Sequence = Nat -> Real\n\n\n> using implementation NegReal\n> hasLimit : Sequence -> Real -> Type\n> hasLimit f x = (eps : Real) -> eps `GT` zero -> Exists (\\ N => P f x eps N) where\n> P : Sequence -> Real -> Real -> Nat -> Type\n> P f x eps N = (n : Nat) -> n `GT` N -> abs (f n - x) `LTE` eps \n\n> limit : (s : Sequence) -> Exists (hasLimit s) -> Real\n> limit s = getWitness\n\n\n\n> {-\n\n> ---}\n\n\n\n\n\n", "meta": {"hexsha": "0aa2d9075bd601185ecf022321f436c74d65c7d3", "size": 579, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Real/Sequence.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": "Real/Sequence.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": "Real/Sequence.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.0294117647, "max_line_length": 85, "alphanum_fraction": 0.5699481865, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073575, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6988000742920213}} {"text": "module SignedInt\n\n%default total\n%access public export\n\nrecord SignedInt where\n constructor SInt\n p : Nat\n n : Nat\n\nimplementation Num SignedInt where\n (SInt p1 n1) + (SInt p2 n2) = SInt (p1 + p2) (n1 + n2)\n (SInt p1 n1) * (SInt p2 n2) = SInt (p1 * p2 + n1 * n2) (p1 * n2 + p2 * n1)\n fromInteger i = if (i > 0)\n then SInt (fromIntegerNat i) 0\n else SInt 0 (fromIntegerNat (abs i))\n\nimplementation Neg SignedInt where\n negate (SInt p n) = SInt n p\n s1 - s2 = s1 + (negate s2)\n\ninfix 9 $*\n($*) : SignedInt -> Nat -> SignedInt\n(SInt p n) $* k = SInt (p * k) (n * k)\n\ndata SignedEq : SignedInt -> SignedInt -> Type where\n SignedRefl : (eq : (p1 + n2) = (p2 + n1)) -> SignedEq (SInt p1 n1) (SInt p2 n2)\n", "meta": {"hexsha": "7d1d8bd978b1f60e3484fc4f87bb5252df53cec8", "size": 735, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "hw6/SignedInt.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/SignedInt.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/SignedInt.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.25, "max_line_length": 83, "alphanum_fraction": 0.5959183673, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6985135242670453}} {"text": "import Data.Fin\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a\n\n%name Vect xs, ys, zs\n\nappend : Vect n elem -> Vect m elem -> Vect (n + m) elem\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n\nzip : Vect n a -> Vect n b -> Vect n (a, b)\nzip [] ys = []\nzip (x :: xs) (y :: ys) = (x, y) :: zip xs ys\n\nidx : Fin n -> Vect n a -> a\nidx FZ (x :: xs) = x\nidx (FS k) (x :: xs) = idx k xs\n\ntryIndex : Integer -> Vect n a -> Maybe a\ntryIndex {n} i xs = flip idx xs <$> integerToFin i n\n\ntake : (n : Nat) -> Vect (n + m) a -> Vect n a\ntake Z xs = []\ntake (S k) (x :: xs) = x :: take k xs\n\ndrop : (n : Nat) -> Vect (n + m) a -> Vect m a\ndrop Z xs = xs\ndrop (S k) (x :: xs) = drop k xs\n\nsum : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsum {n} pos xs ys = case integerToFin pos n of\n Nothing => Nothing\n (Just i) => Just (idx i xs + idx i ys)\n", "meta": {"hexsha": "9e12c07575d57032106c1a8509b8c69eb2058299", "size": 967, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-04/vect.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/vect.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/vect.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": 26.8611111111, "max_line_length": 65, "alphanum_fraction": 0.4984488108, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138559, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6982416911488145}} {"text": "module PermConsProperties\n\n\nimport Data.Vect\nimport congruence\nimport PermCons\n\n%access public export\n%default total\n\n||| a :: (perm xs) = (includePerm perm) (a :: xs)\n\nPermC_prp_1 : (n : Nat) -> (a : Nat) -> (xs : (Vect n Nat)) ->\n (perm : (PermC n)) -> \n ( (a :: (applyPerm n Nat perm xs)) = \n (applyPerm (S n) Nat (includePerm n perm) (a :: xs)))\n\nPermC_prp_1 Z a Nil perm = Refl\nPermC_prp_1 (S Z) a [x] perm = Refl\nPermC_prp_1 (S (S k)) a xs (Idt (S (S k))) = Refl\nPermC_prp_1 (S (S k)) a xs (Swap (S (S k)) FZ) = Refl\nPermC_prp_1 (S (S k)) a xs (Swap (S (S k)) (FS l)) = Refl\nPermC_prp_1 (S (S k)) a xs (CPerm (S (S k)) f g) = let\n \n f1 = applyPerm (S (S k)) Nat f \n f2 = applyPerm (S (S (S k))) Nat (includePerm (S (S k)) f)\n g1 = applyPerm (S (S k)) Nat g \n g2 = applyPerm (S (S (S k))) Nat (includePerm (S (S k)) g)\n \n pf1 = PermC_prp_1 (S (S k)) a xs g -- a :: (g1 xs) = (includePerm g1) (a :: xs)\n pf2 = congruence (Vect (S (S (S k))) Nat) (Vect (S (S (S k))) Nat)\n (a :: (g1 xs)) (g2 (a :: xs)) f2 pf1 -- f2 (a :: g1 xs) = f2 (g2 (a :: xs))\n \n v1 = g1 xs\n \n pf3 = PermC_prp_1 (S (S k)) a v1 f -- a :: (f1 v1) = f2 (a :: v1) \n in\n (trans pf3 pf2)\n \nPermC_prp_2 : (n : Nat) -> (u : (Vect n Nat)) -> ((applyPerm n Nat (Idt n) u) = u)\nPermC_prp_2 Z u = Refl\nPermC_prp_2 (S Z) u = Refl\nPermC_prp_2 (S (S k)) u = Refl\n\n\n\n\n\n\n\n\n\n\t \n", "meta": {"hexsha": "e759825d23dbed14d62a5303a4a747c1f5d35541", "size": 1448, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/PermConsProperties.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/PermConsProperties.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/PermConsProperties.idr", "max_forks_repo_name": "anotherArka/LTS2019", "max_forks_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2019-01-08T05:56:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-31T03:58:00.000Z", "avg_line_length": 26.8148148148, "max_line_length": 83, "alphanum_fraction": 0.5075966851, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6979870300570561}} {"text": "module Proofs.OrderTheory\n\nimport Common.Abbrev\nimport Common.Util\nimport Specifications.Order\n\n%default total\n%access export\n\nrewriteReflexive : isReflexive rel -> (a,b : s) -> a = b -> rel a b\nrewriteReflexive {rel} spec a b eq = rewriteRelation rel Refl eq (spec a)\n\norderContra : TotalOrderSpec leq -> (a,b : s) -> \n Not (leq a b) -> (leq b a, Not (a = b))\norderContra spec a b given = (o2, contraposition o3 given) where\n o1 : Either (leq a b) (leq b a)\n o1 = totalOrder spec a b\n o2 : leq b a\n o2 = o1 `butNotLeft` given\n o3 : a = b -> leq a b\n o3 = rewriteReflexive (reflexive (partialOrder spec)) a b\n", "meta": {"hexsha": "34c62e5cc00521da5e1ecff3982b4d16b38a1c8b", "size": 616, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Proofs/OrderTheory.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/OrderTheory.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/OrderTheory.idr", "max_forks_repo_name": "jeroennoels/verified-algebra", "max_forks_repo_head_hexsha": "85dfd88fecaf32bd20de72923d2d10de59d8b859", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0, "max_line_length": 73, "alphanum_fraction": 0.6769480519, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6978531941912774}} {"text": "import Data.Nat\n\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> {rest : _ } -> TakeN (n_xs ++ rest)\n\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN _ [] = Fewer\ntakeN 0 _ = Exact [] -- there's some left, and n == Z so it must mean we have an exact amount\ntakeN (S k) (x :: xs) = case takeN k xs of\n Fewer => Fewer\n Exact n_xs => Exact (x :: n_xs)\n\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest\n\nhalves : List a -> (List a, List a)\nhalves xs with (takeN (div (length xs) 2) xs)\n halves xs | Fewer = ([], xs)\n halves (n_xs ++ rest) | (Exact n_xs) = (n_xs, rest)\n\n", "meta": {"hexsha": "34ddb9ea2d63360bbf95829a132f9e7014795ec7", "size": 807, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch10/ex_10_1.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ch10/ex_10_1.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ch10/ex_10_1.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.625, "max_line_length": 93, "alphanum_fraction": 0.5439900867, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6977959156157009}} {"text": "> module Nat.GCD\n\n\n> import Nat.Divisor\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\n> |||\n> data GCD : (d : Nat) -> (m : Nat) -> (n : Nat) -> Type where\n> MkGCD : d `Divisor` m ->\n> d `Divisor` n ->\n> ((d' : Nat) -> d' `Divisor` m -> d' `Divisor` n -> d' `Divisor` d) ->\n> GCD d m n\n\n", "meta": {"hexsha": "4c7278a3a67579c74038515d1e740f61fb7ff991", "size": 338, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/GCD.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/GCD.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/GCD.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.7894736842, "max_line_length": 81, "alphanum_fraction": 0.4792899408, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966686936262, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6977914665106338}} {"text": "module ZZ_alt\n\nimport congruence\nimport Quotient_Type\n\n%access public export\n%default total\n\nZZ1 : Type\nZZ1 = (Nat, Nat)\t\n\t\nZZ_Rel : (Nat, Nat) -> (Nat, Nat) -> Type\nZZ_Rel (a, b) (c, d) = ( (plus a d) = (plus b c) )\n\nIsRefl_ZZ_Rel : (n : ZZ1) -> (ZZ_Rel n n)\nIsRefl_ZZ_Rel (a, b) = (plusCommutative a b)\n\nIsSym_ZZ_Rel : (n, m : ZZ1) -> (ZZ_Rel n m) -> (ZZ_Rel m n)\nIsSym_ZZ_Rel (a, b) (c, d) pf_rel = (rewrite (plusCommutative d a) in \n (rewrite (plusCommutative c b) in (sym pf_rel)))\n\ncongruence_1 : (ty1 : Type) -> (ty2 : Type) -> (a, b, c, d : ty1) -> \n (f : ty1 -> ty1 -> ty2) -> (a = b) -> (c = d) -> ( (f a c) = (f b d) )\n \ncongruence_1 ty1 ty2 a a c c f Refl Refl = Refl\n\nsuccCancellation : (a, b : Nat) -> ( (S a) = (S b) ) -> (a = b)\nsuccCancellation a a Refl = Refl\n\nplusCancellation_left : (a, b, c : Nat) -> ( (plus c a) = (plus c b) ) -> (a = b)\n\nplusCancellation_left a b Z pf = pf\n\nplusCancellation_left a b (S k) pf = let\n \n pf1 : (plus k a = plus k b)\n = succCancellation (plus k a) (plus k b) pf\n in\n\n (plusCancellation_left a b k pf1)\n\n\nplusCancellation_right : (a, b, c : Nat) -> ( (plus a c) = (plus b c) ) -> (a = b)\n\nplusCancellation_right a b Z pf = (rewrite (plusCommutative Z b) in \n (rewrite (plusCommutative Z a) in pf))\n \nplusCancellation_right a b (S k) pf = let\n \n pf1 : ( plus a (S k) = S (plus k a) ) \n = plusCommutative a (S k)\n \n pf2 : ( plus b (S k) = S (plus k b) )\n = ( plusCommutative b (S k))\n \n pf3 : ( S (plus k a) = S (plus k b) )\n = trans (sym pf1) (trans pf pf2) \n in\n (plusCancellation_left a b (S k) pf3)\t\n\nIsTrans_ZZ_Rel : (a, b, c : ZZ1) -> (ZZ_Rel a b) -> (ZZ_Rel b c) -> (ZZ_Rel a c)\nIsTrans_ZZ_Rel (a, b) (c, d) (k, l) pf1 pf2 = let\n \n pf3 : (plus (plus a d) (plus c l) = plus (plus b c) (plus d k)) \n = congruence_1 Nat Nat (plus a d) (plus b c) (plus c l) (plus d k) plus pf1 pf2\n \n pf4 : (plus a (plus d (plus c l)) = plus (plus a d) (plus c l)) \n = plusAssociative a d (plus c l)\n \n pf5 : (plus b (plus c (plus d k)) = plus (plus b c) (plus d k))\n = plusAssociative b c (plus d k) \n \n pf6 : (plus c l = plus l c)\n = plusCommutative c l\n \n pf7 : (plus d (plus c l) = plus d (plus l c))\n = congruence Nat Nat (plus c l) (plus l c) (\\x => (plus d x)) pf6\n \n pf8 : (plus d (plus l c) = plus (plus d l) c)\n = plusAssociative d l c \n \n pf9 : (plus d (plus c l) = plus (plus d l) c)\n = trans pf7 pf8\n \n pf10 : (plus d l = plus l d)\n = plusCommutative d l\n \n pf11 : (plus (plus d l) c = plus (plus l d) c)\n = congruence Nat Nat (plus d l) (plus l d) (\\x => (plus x c)) pf10 \n \n pf12 : ( plus d (plus l c) = plus (plus l d) c )\n = trans pf8 pf11\n \n pf13 : (plus d (plus c l) = plus (plus l d) c)\n = trans pf7 pf12\n \n pf14 : (plus l (plus d c) = plus (plus l d) c)\n = plusAssociative l d c \n \n pf15 : ( plus (plus d l) c = plus l (plus d c) )\n = trans pf11 (sym pf14)\n \n pf16 : (plus d (plus c l) = plus l (plus d c))\n = trans pf9 pf15\n \n pf17 : (plus a (plus d (plus c l)) = plus a (plus l (plus d c)))\n = congruence Nat Nat (plus d (plus c l)) (plus l (plus d c)) (\\x => (plus a x)) pf16 \n \n pf18 : (plus a (plus l (plus d c)) = plus (plus a l) (plus d c))\n = plusAssociative a l (plus d c)\n \n pf19 : (plus (plus a d) (plus c l) = plus (plus a l) (plus d c))\n = trans (trans (sym pf4) pf17) pf18\n \n pf20 : ( plus d k = plus k d )\n = plusCommutative d k\n \n pf21 : ( plus c (plus d k) = plus c (plus k d) )\n = congruence Nat Nat (plus d k) (plus k d) (\\x => (plus c x)) pf20 \n \n pf22 : ( plus c (plus k d) = plus (plus c k) d )\n = plusAssociative c k d\n\n pf23 : ( plus c k = plus k c )\n = plusCommutative c k\n \n pf24 : ( plus (plus c k) d = plus (plus k c) d )\n = congruence Nat Nat (plus c k) (plus k c) (\\x => (plus x d)) pf23 \n \n pf25 : ( plus (plus k c) d = plus k (plus c d) )\n = sym (plusAssociative k c d)\n \n pf26 : ( plus c (plus d k) = plus k (plus c d) ) \n = trans pf21 (trans pf22 (trans pf24 pf25))\n \n pf27 : ( plus b (plus c (plus d k)) = plus b (plus k (plus c d)) )\n = congruence Nat Nat (plus c (plus d k)) (plus k (plus c d)) (\\x => (plus b x)) pf26 \n \n pf28 : ( plus b (plus k (plus c d)) = plus (plus b k) (plus c d) )\n = plusAssociative b k (plus c d) \n \n pf29 : ( plus c d = plus d c )\n = plusCommutative c d\n \n pf30 : ( plus (plus b k) (plus c d) = plus (plus b k) (plus d c) )\n = congruence Nat Nat (plus c d) (plus d c) (\\x => (plus (plus b k) x)) pf29 \n \n pf31 : ( plus b (plus c (plus d k)) = plus (plus b k) (plus d c) )\n = (trans (trans pf27 pf28) pf30)\n \n pf32 : ( plus (plus b c) (plus d k) = plus (plus b k) (plus d c) )\n = trans (sym pf5) pf31\n \n pf33 : ( plus (plus a l) (plus d c) = plus (plus b k) (plus d c) )\n = trans (trans (sym pf19) pf3) pf32 \n \n in\n (plusCancellation_right (plus a l) (plus b k) (plus d c) pf33)\n \nZZ_Rel_is_EqRel : IsEqRel ZZ1 ZZ_Rel\nZZ_Rel_is_EqRel = (IsRefl_ZZ_Rel, (IsSym_ZZ_Rel, IsTrans_ZZ_Rel))\n\nZZ_Quotient : (Quotient_Type ZZ1 ZZ_Rel)\nZZ_Quotient = Cons_quotient_Type ZZ_Rel_is_EqRel \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "meta": {"hexsha": "ef9d8e88e581a117216a5dace69698195075feaa", "size": 5805, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/ZZ_alt.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/ZZ_alt.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/ZZ_alt.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": 32.0718232044, "max_line_length": 108, "alphanum_fraction": 0.4902670112, "num_tokens": 2012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966656805269, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6977914588234952}} {"text": "import Data.Vect\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties {n = Z} = []\ncreateEmpties {n = (S k)} = [] :: createEmpties\n\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n zipWith (::) x xsTrans\n\naddMatrix : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (+) x y :: addMatrix xs ys\n\nmultMatrixHelper : Num t => (xs : Vect n (Vect m t))\n -> (ysTrans : Vect p (Vect m t))\n -> Vect n (Vect p t)\nmultMatrixHelper [] ysTrans = []\nmultMatrixHelper (x :: xs) ysTrans = let topRow = multAll x ysTrans in\n topRow :: multMatrixHelper xs ysTrans\n where\n dotProd : Num t => Vect n t -> Vect n t -> t\n dotProd xs ys = sum (zipWith (*) xs ys)\n\n multAll : Num t => Vect n t -> Vect m (Vect n t) -> Vect m t\n multAll xs yss = map (dotProd xs) yss\n\nmultMatrix : Num t =>\n Vect n (Vect m t) -> Vect m (Vect p t) -> Vect n (Vect p t)\nmultMatrix xs ys = let ysTrans = transposeMat ys in\n multMatrixHelper xs ysTrans\n", "meta": {"hexsha": "e72727d1f1ae57f5daa3ceaba8f355e56b5566fe", "size": 1262, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter3/Matrix.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/Matrix.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/Matrix.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": 37.1176470588, "max_line_length": 80, "alphanum_fraction": 0.5491283677, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6977784326908261}} {"text": "module ex\n\n-- ex 9.1.6\n\n-- List version of Elem dependent type\ndata Elem : a -> List a -> Type where\n Here : Elem x (x::xs)\n There : (later : Elem x xs) -> Elem x (y::xs)\n\n\ndata Last : List a -> a -> Type where\n LastOne : Last [value] value\n LastCons : (prf : Last xs value) -> Last (x :: xs) value\n\n\nnotInNil : Last [] value -> Void\nnotInNil LastOne impossible\nnotInNil (LastCons _) impossible\n\n\nsingle : (contra : (x = value) -> Void) -> Last [x] value -> Void\nsingle contra LastOne = contra Refl\nsingle _ (LastCons LastOne) impossible\nsingle _ (LastCons (LastCons _)) impossible\n\n\nnoGood : (contra : Last (y :: ys) value -> Void) -> Last (x :: (y :: ys)) value -> Void\nnoGood contra (LastCons prf) = contra prf\n\n\nisLast : DecEq a => (xs : List a) -> (value : a) -> Dec (Last xs value)\nisLast [] value = No notInNil\nisLast (x :: []) value = case decEq x value of\n (Yes Refl) => Yes LastOne\n (No contra) => No (single contra)\nisLast (x :: (y :: ys)) value = case isLast (y :: ys) value of\n (Yes prf) => Yes (LastCons prf)\n (No contra) => No (noGood contra)\n", "meta": {"hexsha": "031f14a4e7eef4de124cb5d9faf7006eb7ca6cd9", "size": 1204, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "9-pred/ex.idr", "max_stars_repo_name": "prt2121/tdd-playground", "max_stars_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "9-pred/ex.idr", "max_issues_repo_name": "prt2121/tdd-playground", "max_issues_repo_head_hexsha": "6178c6ff150b11a462d40f0f3a0fd3ccc8d5ffb0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "9-pred/ex.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": 30.8717948718, "max_line_length": 87, "alphanum_fraction": 0.553986711, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6977692501801435}} {"text": "\nimport Data.Vect\n\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntransposeHelper : (x : Vect n elem) -> (xsTrans : Vect n (Vect len elem)) -> Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n zipWith (::) x xsTrans\naddMatrix : Num a => Vect m (Vect n a) -> Vect m (Vect n a) -> Vect m (Vect n a)\naddMatrix [] [] = []\naddMatrix xs ys = zipWith (zipWith (+)) xs ys\n\n\n\n\n-- dotProdHelper : Num a => (xs : Vect n (Vect m a)) -> (ys : Vect p (Vect m a)) -> Vect n (Vect p a)\n-- dotProdHelper [] [] = []\n-- dotProdHelper [] (x :: xs) = ?dotProdHelper_rhs_4\n-- -- dotProdHelper (x :: xs) ys = (foldl (\\acc, row => acc ++ (sum $ Data.Vect.zipWith (*) x row)) [[]] ys) -- ++ dotProdHelper xs ys\n\n-- dotProd : Num a => Vect n (Vect m a) -> Vect m (Vect p a) -> Vect n (Vect p a)\n-- dotProd [] [] = []\n-- dotProd [] (x :: xs) = []\n-- dotProd xs ys = dotProdHelper xs (transposeMat ys)\n", "meta": {"hexsha": "7bc71c65860afd7e609b5c55b1a803af5d72cadd", "size": 1153, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter3/matrices.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": "Chapter3/matrices.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": "Chapter3/matrices.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 36.03125, "max_line_length": 134, "alphanum_fraction": 0.5802254987, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6975354087221203}} {"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, Abs 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\nAbs ty => Abs (Expr ty) where\n abs = Abs\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(Eq ty, Abs ty, Integral ty, Neg ty)=> Eq (Expr ty) where\n (==) x y = eval x == eval y\n\nCast ty ty where\n cast orig = orig\n\n(Eq tx, Abs tx, Integral tx, Neg tx, Cast tx ty) => Cast (Expr tx) ty where\n cast orig = cast (eval orig)\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": "aeaa080c17a797daa16027709f39d9b523aff174", "size": 1532, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp7/Expr.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/chp7/Expr.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/chp7/Expr.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": 29.4615384615, "max_line_length": 75, "alphanum_fraction": 0.5150130548, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464114, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6971837649084204}} {"text": "import Data.Vect\n\nmy_plusCommutes : (n : Nat) -> (m : Nat) -> n + m = m + n\nmy_plusCommutes Z m = rewrite plusZeroRightNeutral m in Refl\nmy_plusCommutes (S k) m = rewrite my_plusCommutes k m in\n rewrite plusSuccRightSucc m k in\n Refl\n\nmy_reverse : Vect n elem -> Vect n elem\nmy_reverse [] = []\nmy_reverse (x :: xs) = reverseProof (my_reverse xs ++ [x])\n where\n reverseProof : Vect (plus k 1) elem -> Vect (S k) elem\n reverseProof {k} result = rewrite my_plusCommutes 1 k in result\n\nmy_reverse' : Vect n elem -> Vect n elem\nmy_reverse' xs = reverse' [] xs\n where\n reverseProof_nil : Vect n1 a -> Vect (plus n1 0) a\n reverseProof_nil {n1} acc = rewrite plusZeroRightNeutral n1 in acc\n\n reverseProof_xs : Vect ((S n) + k) a -> Vect (plus n (S k)) a\n reverseProof_xs {n} {k} xs = rewrite sym (plusSuccRightSucc n k) in xs\n\n reverse' : Vect n a -> Vect m a -> Vect (n + m) a\n reverse' acc [] = reverseProof_nil acc\n reverse' acc (x::xs) = reverseProof_xs (reverse' (x::acc) xs)\n\n", "meta": {"hexsha": "0330f05f81952082bd52d716f4157e98d4e13d90", "size": 1053, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-08/reverse_vec.idr", "max_stars_repo_name": "tekerson/type-driven-development", "max_stars_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-23T04:46:42.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-23T04:46:42.000Z", "max_issues_repo_path": "Chapter-08/reverse_vec.idr", "max_issues_repo_name": "tekerson/type-driven-development", "max_issues_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter-08/reverse_vec.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": 36.3103448276, "max_line_length": 74, "alphanum_fraction": 0.6296296296, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6971837435629132}} {"text": "> module Fraction.Predicates\n\n> import Fraction.Fraction\n> import PNat.PNat\n> import PNat.Operations\n> import Nat.Positive\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n> ||| Proofs that `x` is less than or equal to `y` \n> ||| @ x the smaller number \n> ||| @ y the larger number\n> LTE : (x, y : Fraction) -> Type\n> LTE (n1, d1') (n2, d2') = Prelude.Nat.LTE (n1 * (toNat d2')) (n2 * (toNat d1'))\n\n\n> ||| An equivalence relation (see below)\n> Eq : Fraction -> Fraction -> Type\n> Eq (m, d') (n, e') = let d = toNat d' in\n> let e = toNat e' in\n> m * e = n * d\n> -- %freeze Eq\n\nThe idea is to use |Eq| implement non-negative rational numbers as\nquotient of fractions by |Eq|. \n\nA naive approach toward implementing (non-negative) rational numbers\n(for which equality is well represented by syntactical equality) could\nbe to define rational numbers as normalized fractions, something like\n\n NonNegRational = Subset Fraction Normal\n\nwhere |Normal : Fraction -> Type| represents the property of being in\nnormal form, see \"FractionNormal\". It is easy to see that |normalize|\ndoes indeed return fractions in normal form, see |normalNormalize| in\n\"FractionProperties\". Thus, one could implement addition and\nmultiplication of rational numbers in terms of |normalize| and of\nfraction addition and multiplication. For instance:\n\n plus : NonNegRational -> NonNegRational -> NonNegRational\n plus x' y' = let x = getWitness x' in\n let y = getWitness y' in\n Element (normalize (x + y)) (normalNormalize (x + y))\n\nand similarly for multiplication. The problem with this approach is that\nimplementing proofs of\n\n 1. x + y = y + x\n 2. x + 0 = x\n 3. x + (y + z) = (x + y) + z\n 4. x * y = y * x\n 5. x * 1 = x\n\nfor fractions is tedious but trivial. Extending 1,2,4,5 to rational\nnumbers is pretty straightforward but extending 3 and deriving\n\n 6. x * (y + z) = (x * y) + (x * z)\n \n(which does not hold for fractions) turns out to be a nightmare. With\n|Eq| we can take advantage of Tim Richter's \"SplitQuotient\" and\n\"KernelQuotient\" modules (see ...) to define ...\n\n...\n\nTo this end, we only need to show that:\n\n a. Fraction addition and multiplication preserve Eq:\n\n a1. (x Eq x') -> (y Eq y') -> (x + y) Eq (x' + y') \n a2. (x Eq x') -> (y Eq y') -> (x * y) Eq (x' * y') \n\n b. Normalize fulfills: \n\n b1. (normalize x) Eq x\n b2. x Eq y -> normalize x = normalize y\n\nThese properties are implemented via\n\n< plusPreservesEq : (x, x', y, y' : Fraction) -> \n< (x `Eq` x') -> (y `Eq` y') -> (x + y) `Eq` (x' + y')\n\n< multPreservesEq : (x, x', y, y' : Fraction) -> \n< (x `Eq` x') -> (y `Eq` y') -> (x * y) `Eq` (x' * y')\n \nand\n \n< normalizeEqLemma1 : (x : Fraction) -> (normalize x) `Eq` x\n\n< normalizeEqLemma2 : (x : Fraction) -> (y : Fraction) -> \n< x `Eq` y -> normalize x = normalize y\n\nin \"FractionEqProperties\".\n\n\n\n\n\n", "meta": {"hexsha": "42256e5e770d8dbf8135aaff477ecd62ec3e8665", "size": 3166, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fraction/Predicates.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/Predicates.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/Predicates.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.3465346535, "max_line_length": 124, "alphanum_fraction": 0.5799115603, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.697080268007104}} {"text": "module Data.SnocList.Elem\n\nimport Data.SnocList\nimport Decidable.Equality\n\n||| A proof that some element is found in a list.\npublic export\ndata Elem : a -> SnocList a -> Type where\n ||| A proof that the element is at the head of the list\n Here : Elem x (sx :< x)\n ||| A proof that the element is in the tail of the list\n There : Elem x sx -> Elem x (sx :< y)\n\nexport\nUninhabited (Here = There e) where\n uninhabited Refl impossible\n\nexport\nUninhabited (There e = Here) where\n uninhabited Refl impossible\n\nexport\nUninhabited (Elem {a} x [<]) where\n uninhabited Here impossible\n uninhabited (There p) impossible\n\nexport\nthereInjective : {0 e1, e2 : Elem x sx} -> There e1 = There e2 -> e1 = e2\nthereInjective Refl = Refl\n\nexport\nDecEq (x `Elem` sx) where\n decEq Here Here = Yes Refl\n decEq Here (There _) = No absurd\n decEq (There _) Here = No absurd\n decEq (There y) (There z) with (decEq y z)\n decEq (There y) (There y) | Yes Refl = Yes Refl\n decEq (There y) (There z) | No neq = No $ neq . thereInjective\n\n||| Remove the element at the given position.\npublic export\ndropElem : (sx : SnocList a) -> (p : Elem x sx) -> SnocList a\ndropElem (sy :< _) Here = sy\ndropElem (sy :< y) (There p) = (dropElem sy p) :< y\n\n||| Erase the indices, returning the numeric position of the element\npublic export\nelemToNat : Elem x sx -> Nat\nelemToNat Here = Z\nelemToNat (There p) = S (elemToNat p)\n\n||| Find the element with a proof at a given position (in reverse), if it is valid\npublic export\nindexElem : Nat -> (sx : SnocList a) -> Maybe (x ** Elem x sx)\nindexElem _ [<] = Nothing\nindexElem Z (_ :< y) = Just (y ** Here)\nindexElem (S k) (sy :< _) = (\\(y ** p) => (y ** There p)) `map` (indexElem k sy)\n\n||| Lift the membership proof to a mapped list\nexport\nelemMap : (0 f : a -> b) -> Elem x sx -> Elem (f x) (map f sx)\nelemMap f Here = Here\nelemMap f (There el) = There $ elemMap f el\n\n||| An item not in the head and not in the tail is not in the list at all.\nexport\nneitherHereNorThere : Not (x = y) -> Not (Elem x sx) -> Not (Elem x (sx :< y))\nneitherHereNorThere xny _ Here = xny Refl\nneitherHereNorThere _ xnxs (There xxs) = xnxs xxs\n", "meta": {"hexsha": "1506270505dad8f5201c3eeb5fbce87df5d647e9", "size": 2143, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Data/SnocList/Elem.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "libs/base/Data/SnocList/Elem.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "libs/base/Data/SnocList/Elem.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": 30.6142857143, "max_line_length": 82, "alphanum_fraction": 0.6691553896, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6970802624143035}} {"text": "import Data.Vect\nimport Data.Nat\n\nexport\nlemmaPlusOneRight : (n : Nat) -> n + 1 = S n\nlemmaPlusOneRight n = rewrite plusCommutative n 1 in Refl\n\npublic export\nconsLin : (1 _ : Unit) -> (1 _ : Vect n Unit) -> Vect (S n) Unit\nconsLin () [] = [()]\nconsLin () (x :: xs) = () :: x :: xs\n\nconsNonLin : Unit -> Vect n Unit -> Vect (n+1) Unit\nconsNonLin u us = rewrite lemmaPlusOneRight n in u `consLin` us\n\nconsLin2 : (1 _ : Unit) -> (1 _ : Vect n Unit) -> Vect (n+1) Unit\nconsLin2 u us = rewrite lemmaPlusOneRight n in u `consLin` us\n\n\n", "meta": {"hexsha": "052d720753fdf1dbe607cf46c3d828f16b25b981", "size": 530, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/linear015/Issue1861.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/tests/idris2/linear015/Issue1861.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/tests/idris2/linear015/Issue1861.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 26.5, "max_line_length": 65, "alphanum_fraction": 0.6377358491, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6966301852577428}} {"text": "module BiNat.Properties.LT\n\nimport BiNat\nimport BiNat.Properties.Plus\nimport BiNat.Properties.Induction\n\n%access public export\n%default total\n\nnIsNotLessThanItself : (n : BiNat) -> Not (LT n n)\nnIsNotLessThanItself J lt = uninhabited {t = LT J J} lt\nnIsNotLessThanItself (ns -: n) (JLT ms m) impossible\nnIsNotLessThanItself (ns -: n) (LTLeading _ _ _) impossible\nnIsNotLessThanItself (ns -: n) (LTAppend ns ns lt n n) = nIsNotLessThanItself ns lt\n\nlessThanImpliesNotEqual : (m, n : BiNat) -> LT m n -> Not (m = n)\nlessThanImpliesNotEqual m n lt eq = nIsNotLessThanItself n $ replace {P = \\z => LT z n} eq lt\n\ngreaterThanImpliesNotEqual : (m, n : BiNat) -> GT m n -> Not (m = n)\ngreaterThanImpliesNotEqual m n gt = (lessThanImpliesNotEqual n m gt) . sym\n\nlessThanImpliesNotGreaterThan : (m, n : BiNat) -> LT m n -> Not (GT m n)\nlessThanImpliesNotGreaterThan J (ns -: n) (JLT ns n) lt = uninhabited lt\nlessThanImpliesNotGreaterThan (ms -: O) (ns -: I) (LTLeading ms ns eq) (LTAppend ns ms lt I O) =\n nIsNotLessThanItself ns (replace eq lt)\nlessThanImpliesNotGreaterThan (ms -: I) (ns -: O) (LTAppend ms ns lt I O) (LTLeading ns ms eq) =\n nIsNotLessThanItself ms (replace {P = \\z => LT ms z} eq lt)\nlessThanImpliesNotGreaterThan (ms -: m) (ns -: n) (LTAppend ms ns lt1 m n) (LTAppend ns ms lt2 n m) =\n lessThanImpliesNotGreaterThan ms ns lt1 lt2\n\nlessThanTransitive : BiNat.LT l m -> LT m n -> LT l n\nlessThanTransitive (JLT ms O) (LTLeading ms ns eq) = JLT ns I\nlessThanTransitive (JLT ms m) (LTAppend ms ns lt m n) = JLT ns n\nlessThanTransitive (LTLeading ls ms eq) (LTAppend ms ns lt I n) =\n LTAppend ls ns (replace {P = \\z => BiNat.LT z ns} (sym eq) lt) O n\nlessThanTransitive (LTAppend ls ms lt l O) (LTLeading ms ns eq) =\n LTAppend ls ns (replace {P = \\z => BiNat.LT ls z} eq lt) l I\nlessThanTransitive (LTAppend ls ms lt1 l m) (LTAppend ms ns lt2 m n) =\n LTAppend ls ns (lessThanTransitive lt1 lt2) l n\n\nlessThanEqualTransitive : BiNat.LTE l m -> LTE m n -> LTE l n\nlessThanEqualTransitive (LTEEqual l m eq1) (LTEEqual m n eq2) =\n LTEEqual l n (replace {P = \\z => z = n} (sym eq1) eq2)\nlessThanEqualTransitive (LTELessThan l m lt1) (LTEEqual m n eq2) =\n LTELessThan l n (replace {P = \\z => LT l z} eq2 lt1)\nlessThanEqualTransitive (LTEEqual l m eq1) (LTELessThan m n lt2) =\n LTELessThan l n (replace {P = \\z => LT z n} (sym eq1) lt2)\nlessThanEqualTransitive (LTELessThan l m lt1) (LTELessThan m n lt2) =\n LTELessThan l n (lessThanTransitive lt1 lt2)\n\nlessThanEqualAntiSymmetric : (m, n : BiNat) -> LTE m n -> GTE m n -> m = n\nlessThanEqualAntiSymmetric m n (LTEEqual m n eq1) (LTEEqual n m eq2) = eq1\nlessThanEqualAntiSymmetric m n (LTEEqual m n eq1) (LTELessThan n m lt2) =\n absurd $ nIsNotLessThanItself n (replace {P = \\z => LT n z} eq1 lt2)\nlessThanEqualAntiSymmetric m n (LTELessThan m n lt1) (LTEEqual n m eq2) =\n absurd $ nIsNotLessThanItself m (replace {P = \\z => LT m z} eq2 lt1)\nlessThanEqualAntiSymmetric m n (LTELessThan m n lt1) (LTELessThan n m lt2) =\n absurd $ lessThanImpliesNotGreaterThan m n lt1 lt2\n\ntransLTandLTE : BiNat.LT l m -> LTE m n -> LT l n\ntransLTandLTE lt1 (LTEEqual m n eq) = rewrite sym eq in lt1\ntransLTandLTE lt1 (LTELessThan m n lt2) = lessThanTransitive lt1 lt2\n\ntransLTEandLT : BiNat.LTE l m -> LT m n -> LT l n\ntransLTEandLT (LTEEqual l m eq) lt2 = rewrite eq in lt2\ntransLTEandLT (LTELessThan l m lt1) lt2 = lessThanTransitive lt1 lt2\n\nlessThanOrGTE : (m, n : BiNat) -> Either (LT m n) (GTE m n)\nlessThanOrGTE J J = Right $ LTEEqual J J Refl\nlessThanOrGTE J (ns -: n) = Left $ JLT ns n\nlessThanOrGTE (ms -: m) J = Right $ LTELessThan J (ms -: m) (JLT ms m)\nlessThanOrGTE (ms -: O) (ns -: O) =\n case lessThanOrGTE ms ns of\n Left lt => Left (LTAppend ms ns lt O O)\n Right (LTEEqual ns ms eq) => Right $ rewrite sym eq in LTEEqual (ns -: O) (ns -: O) Refl\n Right (LTELessThan ns ms gt) => Right $ LTELessThan (ns -: O) (ms -: O) (LTAppend ns ms gt O O)\nlessThanOrGTE (ms -: O) (ns -: I) =\n case lessThanOrGTE ms ns of\n Left lt => Left (LTAppend ms ns lt O I)\n Right (LTEEqual ns ms eq) => Left $ rewrite eq in LTLeading ms ms Refl\n Right (LTELessThan ns ms gt) => Right $ LTELessThan (ns -: I) (ms -: O) (LTAppend ns ms gt I O)\nlessThanOrGTE (ms -: I) (ns -: O) =\n case lessThanOrGTE ms ns of\n Left lt => Left (LTAppend ms ns lt I O)\n Right (LTEEqual ns ms eq) => Right $ LTELessThan (ns -: O) (ms -: I) (rewrite sym eq in LTLeading ns ns Refl)\n Right (LTELessThan ns ms gt) => Right $ LTELessThan (ns -: O) (ms -: I) (LTAppend ns ms gt O I)\nlessThanOrGTE (ms -: I) (ns -: I) =\n case lessThanOrGTE ms ns of\n Left lt => Left (LTAppend ms ns lt I I)\n Right (LTEEqual ns ms eq) => Right $ rewrite sym eq in LTEEqual (ns -: I) (ns -: I) Refl\n Right (LTELessThan ns ms gt) => Right $ LTELessThan (ns -: I) (ms -: I) (LTAppend ns ms gt I I)\n\nlessThanAppended : (n : BiNat) -> (b : Bit) -> LT n (n -: b)\nlessThanAppended J b = JLT J b\nlessThanAppended (ns -: n) b = LTAppend ns (ns -: n) (lessThanAppended ns n) n b\n\nsuccGreaterThanJ : (n : BiNat) -> GT (succ n) J\nsuccGreaterThanJ J = JLT J O\nsuccGreaterThanJ (ns -: O) = JLT ns I\nsuccGreaterThanJ (ns -: I) = rewrite succDashAppendsAcc ns [O] in JLT (succ ns) O\n\nlessThanSucc : (n : BiNat) -> LT n (succ n)\nlessThanSucc J = JLT J O\nlessThanSucc (ns -: O) = LTLeading ns ns Refl\nlessThanSucc (ns -: I) =\n replace {P = \\z => LT (ns -: I) z} (sym $ succDashAppendsAcc ns [O]) $\n LTAppend ns (succ ns) (lessThanSucc ns) I O\n\npredIsLessThan : (n : BiNat) -> LT J n -> LT (pred n) n\npredIsLessThan J _ impossible\npredIsLessThan (J -: O) _ = JLT J O\npredIsLessThan (ns -: O -: O) _ =\n replace {P = \\z => LT z (ns -: O -: O)} (sym $ predDashAppendsAcc (ns -: O) [I]) $\n LTAppend (pred (ns -: O)) (ns -: O) (predIsLessThan (ns -: O) (JLT ns O)) I O\npredIsLessThan (ns -: I -: O) _ = LTAppend (ns -: O) (ns -: I) (LTLeading ns ns Refl) I O\npredIsLessThan (ns -: I) _ = LTLeading ns ns Refl\n\npredLessThanEqual : (n : BiNat) -> LTE (pred n) n\npredLessThanEqual J = LTEEqual J J Refl\npredLessThanEqual (J -: O) = LTELessThan J (J -: O) (JLT J O)\npredLessThanEqual (ns -: n -: O) =\n rewrite predDashAppendsAcc (ns -: n) [I] in\n let lt = predIsLessThan (ns -: n) (JLT ns n) in\n LTELessThan (pred (ns -: n) -: I) (ns -: n -: O) (LTAppend (pred (ns -: n)) (ns -: n) lt I O)\npredLessThanEqual (ns -: I) = LTELessThan (ns -: O) (ns -: I) (LTLeading ns ns Refl)\n\nlessThanImpliesLTEPred : (m, n : BiNat) -> LT m n -> LTE m (pred n)\nlessThanImpliesLTEPred m J lt impossible\nlessThanImpliesLTEPred J (J -: O) _ = LTEEqual J J Refl\nlessThanImpliesLTEPred J (ns -: O -: O) _ =\n replace {P = \\z => LTE J z} (sym $ predDashAppendsAcc (ns -: O) [I]) $\n LTELessThan J (pred (ns -: O) -: I) (JLT (pred (ns -: O)) I)\nlessThanImpliesLTEPred J (ns -: I -: O) _ = LTELessThan J (ns -: O -: I) (JLT (ns -: O) I)\nlessThanImpliesLTEPred J (ns -: I) _ = LTELessThan J (ns -: O) (JLT ns O)\nlessThanImpliesLTEPred (ms -: O) (ns -: O) (LTAppend ms ns lt O O) =\n case ns of\n J => absurd (uninhabited lt)\n (ns2 -: n) =>\n replace {P = \\z => LTE (ms -: O) z} (sym $ predDashAppendsAcc (ns2 -: n) [I]) $\n case lessThanImpliesLTEPred ms (ns2 -: n) lt of\n LTEEqual _ _ eq =>\n replace {P = \\z => LTE (ms -: O) (z -: I)} eq (LTELessThan (ms -: O) (ms -: I) (LTLeading ms ms Refl))\n LTELessThan _ _ lt2 =>\n LTELessThan (ms -: O) (pred (ns2 -: n) -: I) (LTAppend ms (pred (ns2 -: n)) lt2 O I)\nlessThanImpliesLTEPred (ms -: O) (ns -: I) (LTLeading ms ns eq) =\n LTEEqual (ms -: O) (ns -: O) (rewrite eq in Refl)\nlessThanImpliesLTEPred (ms -: O) (ns -: I) (LTAppend ms ns lt O I) =\n LTELessThan (ms -: O) (ns -: O) (LTAppend ms ns lt O O)\nlessThanImpliesLTEPred (ms -: I) (J -: O) (LTAppend ms J lt I O) impossible\nlessThanImpliesLTEPred (ms -: I) (ns -: n -: O) (LTAppend ms (ns -: n) lt I O) =\n replace {P = \\z => LTE (ms -: I) z} (sym $ predDashAppendsAcc (ns -: n) [I]) $\n case lessThanImpliesLTEPred ms (ns -: n) lt of\n LTEEqual _ _ eq =>\n replace {P = \\z => LTE (ms -: I) (z -: I)} eq (LTEEqual (ms -: I) (ms -: I) Refl)\n LTELessThan _ _ lt2 =>\n LTELessThan (ms -: I) (pred (ns -: n) -: I) (LTAppend ms (pred (ns -: n)) lt2 I I)\nlessThanImpliesLTEPred (ms -: I) (ns -: I) (LTAppend ms ns lt I I) =\n LTELessThan (ms -: I) (ns -: O) (LTAppend ms ns lt I O)\n\nlessThanImpliesSuccLTE : (m, n : BiNat) -> LT m n -> LTE (succ m) n\nlessThanImpliesSuccLTE m J lt impossible\nlessThanImpliesSuccLTE J (J -: O) (JLT J O) = LTEEqual (J -: O) (J -: O) Refl\nlessThanImpliesSuccLTE J (J -: I) (JLT J I) =\n LTELessThan (J -: O) (J -: I) (LTLeading J J Refl)\nlessThanImpliesSuccLTE J (ns -: n -: O) lt =\n LTELessThan (J -: O) (ns -: n -: O) (LTAppend J (ns -: n) (JLT ns n) O O)\nlessThanImpliesSuccLTE J (ns -: n -: I) lt =\n LTELessThan (J -: O) (ns -: n -: I) (LTAppend J (ns -: n) (JLT ns n) O I)\nlessThanImpliesSuccLTE (ms -: O) (ns -: O) (LTAppend ms ns lt O O) =\n LTELessThan (ms -: I) (ns -: O) (LTAppend ms ns lt I O)\nlessThanImpliesSuccLTE (ms -: O) (ns -: I) (LTLeading ms ns eq) =\n LTEEqual (ms -: I) (ns -: I) (rewrite eq in Refl)\nlessThanImpliesSuccLTE (ms -: O) (ns -: I) (LTAppend ms ns lt O I) =\n LTELessThan (ms -: I) (ns -: I) (LTAppend ms ns lt I I)\nlessThanImpliesSuccLTE (ms -: I) (ns -: O) (LTAppend ms ns lt I O) =\n rewrite succDashAppendsAcc ms [O] in\n case lessThanImpliesSuccLTE ms ns lt of\n LTEEqual _ _ eq =>\n rewrite eq in LTEEqual (ns -: O) (ns -: O) Refl\n LTELessThan _ _ lt2 =>\n LTELessThan (succ ms -: O) (ns -: O) (LTAppend (succ ms) ns lt2 O O)\nlessThanImpliesSuccLTE (ms -: I) (ns -: I) (LTAppend ms ns lt I I) =\n rewrite succDashAppendsAcc ms [O] in\n case lessThanImpliesSuccLTE ms ns lt of\n LTEEqual _ _ eq =>\n rewrite eq in LTELessThan (ns -: O) (ns -: I) (LTLeading ns ns Refl)\n LTELessThan _ _ lt2 =>\n LTELessThan (succ ms -: O) (ns -: I) (LTAppend (succ ms) ns lt2 O I)\n\nsuccKeepsLessThan : (m, n : BiNat) -> LT m n -> LT (succ m) (succ n)\nsuccKeepsLessThan m J lt impossible\nsuccKeepsLessThan J (J -: O) lt = LTLeading J J Refl\nsuccKeepsLessThan J (ns -: n -: O) lt = LTAppend J (ns -: n) (JLT ns n) O I\nsuccKeepsLessThan J (J -: I) lt = LTAppend J (J -: O) (JLT J O) O O\nsuccKeepsLessThan J (ns -: n -: I) lt =\n rewrite succDashAppendsAcc (ns -: n) [O] in\n LTAppend J (succ (ns -: n)) (lessThanTransitive (JLT ns n) (lessThanSucc (ns -: n))) O O\nsuccKeepsLessThan (ms -: O) (ns -: O) (LTAppend ms ns lt O O) = LTAppend ms ns lt I I\nsuccKeepsLessThan (ms -: O) (ns -: I) (LTLeading ms ns eq) =\n rewrite sym eq in\n rewrite succDashAppendsAcc ms [O] in\n LTAppend ms (succ ms) (lessThanSucc ms) I O\nsuccKeepsLessThan (ms -: O) (ns -: I) (LTAppend ms ns lt O I) =\n rewrite succDashAppendsAcc ns [O] in\n LTAppend ms (succ ns) (lessThanTransitive lt (lessThanSucc ns)) I O\nsuccKeepsLessThan (ms -: I) (ns -: O) (LTAppend ms ns lt I O) =\n rewrite succDashAppendsAcc ms [O] in\n case lessThanImpliesSuccLTE ms ns lt of\n LTEEqual _ _ eq => rewrite eq in LTLeading ns ns Refl\n LTELessThan _ _ lt2 => LTAppend (succ ms) ns lt2 O I\nsuccKeepsLessThan (ms -: I) (ns -: I) (LTAppend ms ns lt I I) =\n rewrite succDashAppendsAcc ms [O] in\n rewrite succDashAppendsAcc ns [O] in\n LTAppend (succ ms) (succ ns) (succKeepsLessThan ms ns lt) O O\n\nplusNKeepsLessThan : (l, m : BiNat) -> LT l m -> (n : BiNat) -> LT (plus l n) (plus m n)\nplusNKeepsLessThan l m lt n =\n induction\n (\\k => LT (plus l k) (plus m k))\n (\\k, pk =>\n rewrite sym $ plusJIsSucc k in\n rewrite plusAssociative l k J in\n rewrite plusAssociative m k J in\n rewrite plusJIsSucc (plus l k) in\n rewrite plusJIsSucc (plus m k) in\n succKeepsLessThan (plus l k) (plus m k) pk\n )\n (rewrite plusJIsSucc l in rewrite plusJIsSucc m in succKeepsLessThan l m lt)\n n\n\nsuccsRecoversLessThan : (m, n : BiNat) -> LT (succ m) (succ n) -> LT m n\nsuccsRecoversLessThan m n lt =\n case\n replace {P = \\z => LTE (succ m) z} (predOfSucc n) $\n lessThanImpliesLTEPred (succ m) (succ n) lt\n of\n LTEEqual _ _ eq =>\n rewrite sym eq in lessThanSucc m\n LTELessThan _ _ lt2 =>\n lessThanTransitive (lessThanSucc m) lt2\n\nlessThanImpliesLTEOfPreds : (m, n : BiNat) -> LT m n -> LTE (pred m) (pred n)\nlessThanImpliesLTEOfPreds J (J -: O) lt = LTEEqual J J Refl\nlessThanImpliesLTEOfPreds J (ns -: n -: O) lt =\n rewrite predDashAppendsAcc (ns -: n) [I] in\n LTELessThan J (pred (ns -: n) -: I) (JLT (pred (ns -: n)) I)\nlessThanImpliesLTEOfPreds J (ns -: I) lt = LTELessThan J (ns -: O) (JLT ns O)\nlessThanImpliesLTEOfPreds (ms -: m) ns lt =\n lessThanEqualTransitive\n (LTELessThan (pred (ms -: m)) (ms -: m) (predIsLessThan (ms -: m) (JLT ms m)))\n (lessThanImpliesLTEPred (ms -: m) ns lt)\n\npredKeepsLessThan : (m, n : BiNat) -> LT J m -> LT m n -> LT (pred m) (pred n)\npredKeepsLessThan m n jltm lt =\n case lessThanImpliesLTEOfPreds m n lt of\n LTEEqual (pred m) (pred n) eq =>\n let nIsNotJ = greaterThanImpliesNotEqual n J (lessThanTransitive jltm lt) in\n let mIsNotJ = greaterThanImpliesNotEqual m J jltm in\n let mEQn = replace {P = \\z => m = z} (succOfPred n nIsNotJ) $\n replace {P = \\z => z = succ (pred n)} (succOfPred m mIsNotJ) $\n replace {P = \\z => succ (pred m) = succ z} eq Refl in\n absurd $ lessThanImpliesNotEqual m n lt mEQn\n LTELessThan (pred m) (pred n) lt =>\n lt\n\npredRecoversLT : (m, n : BiNat) -> LT (pred m) (pred n) -> LT m n\npredRecoversLT m J lt impossible\npredRecoversLT J (ns -: n) lt = JLT ns n\npredRecoversLT (ms -: m) (ns -: n) lt =\n rewrite sym $ succOfPred (ms -: m) uninhabited in\n rewrite sym $ succOfPred (ns -: n) uninhabited in\n succKeepsLessThan (pred (ms -: m)) (pred (ns -: n)) lt\n\nlessThanPlus : (m, n : BiNat) -> LT m (plus n m)\nlessThanPlus m n =\n induction\n (\\k => LT m (plus k m))\n (\\k, pk =>\n replace {P = \\z => LT m (plus z m)} (jPlusIsSucc k) $\n replace {P = \\z => LT m z} (plusAssociative J k m) $\n replace {P = \\z => LT m z} (sym $ jPlusIsSucc (plus k m)) $\n lessThanTransitive pk (lessThanSucc (plus k m))\n )\n (replace (sym $ jPlusIsSucc m) (lessThanSucc m))\n n\n\ncompleteInduction :\n (P : BiNat -> Type) ->\n ((k : BiNat) -> ((m : BiNat) -> LT m k -> P m) -> P k) ->\n (n : BiNat) -> P n\ncompleteInduction prop trans n =\n trans n $ induction\n (\\k => (m : BiNat) -> LT m k -> prop m)\n (\\k, pk, m, lt =>\n case lessThanImpliesLTEPred m (succ k) lt of\n LTEEqual _ _ eq =>\n rewrite eq in rewrite predOfSucc k in trans k pk\n LTELessThan _ _ lt2 =>\n pk m (replace (predOfSucc k) lt2)\n )\n (\\m, lt => absurd (uninhabited lt))\n n\n\ncompareSelf : (m, n : BiNat) -> m = n -> (last : Ordering) -> compare' m n last = last\ncompareSelf m J eq last = rewrite eq in Refl\ncompareSelf m (ns -: O) eq last = rewrite eq in compareSelf ns ns Refl last\ncompareSelf m (ns -: I) eq last = rewrite eq in compareSelf ns ns Refl last\n\ncompareLT : (m, n : BiNat) -> LT m n -> (last : Ordering) -> compare' m n last = LT\ncompareLT m J _ _ impossible\ncompareLT J (ns -: n) _ _ = Refl\ncompareLT (ms -: O) (ns -: O) (LTAppend ms ns lt O O) last = compareLT ms ns lt last\ncompareLT (ms -: O) (ns -: I) (LTAppend ms ns lt O I) last = compareLT ms ns lt LT\ncompareLT (ms -: O) (ns -: I) (LTLeading ms ns eq) last = rewrite eq in compareSelf ns ns Refl LT\ncompareLT (ms -: I) (ns -: O) (LTAppend ms ns lt I O) last = compareLT ms ns lt GT\ncompareLT (ms -: I) (ns -: I) (LTAppend ms ns lt I I) last = compareLT ms ns lt last\n\ncompareGT : (m, n : BiNat) -> GT m n -> (last : Ordering) -> compare' m n last = GT\ncompareGT J n _ _ impossible\ncompareGT (ms -: m) J _ _ = Refl\ncompareGT (ms -: O) (ns -: O) (LTAppend ns ms gt O O) last = compareGT ms ns gt last\ncompareGT (ms -: O) (ns -: I) (LTAppend ns ms gt I O) last = compareGT ms ns gt LT\ncompareGT (ms -: I) (ns -: O) (LTAppend ns ms gt O I) last = compareGT ms ns gt GT\ncompareGT (ms -: I) (ns -: O) (LTLeading ns ms eq) last = rewrite eq in compareSelf ms ms Refl GT\ncompareGT (ms -: I) (ns -: I) (LTAppend ns ms gt I I) last = compareGT ms ns gt last\n\n-- These should be in Prelude.Interfaces\nUninhabited (EQ = LT) where\n uninhabited Refl impossible\nUninhabited (EQ = GT) where\n uninhabited Refl impossible\nUninhabited (LT = EQ) where\n uninhabited Refl impossible\nUninhabited (Prelude.Interfaces.LT = GT) where\n uninhabited Refl impossible\nUninhabited (GT = EQ) where\n uninhabited Refl impossible\nUninhabited (Prelude.Interfaces.GT = LT) where\n uninhabited Refl impossible\n\ncompareRecoversEQ : (m, n : BiNat) -> compare m n = EQ -> m = n\ncompareRecoversEQ m n eq =\n case lessThanOrGTE m n of\n Left lt => absurd $ uninhabited $ trans (sym eq) (compareLT m n lt EQ)\n Right (LTEEqual n m eq2) => sym eq2\n Right (LTELessThan n m gt) => absurd $ uninhabited $ trans (sym eq) (compareGT m n gt EQ)\n\ncompareRecoversLT : (m, n : BiNat) -> compare m n = LT -> LT m n\ncompareRecoversLT m n eq =\n case lessThanOrGTE m n of\n Left lt => lt\n Right (LTEEqual n m eq2) => absurd $ uninhabited $ trans (sym eq) (compareSelf m n (sym eq2) EQ)\n Right (LTELessThan n m gt) => absurd $ uninhabited $ trans (sym eq) (compareGT m n gt EQ)\n\ncompareRecoversGT : (m, n : BiNat) -> compare m n = GT -> GT m n\ncompareRecoversGT m n eq =\n case lessThanOrGTE n m of\n Left gt => gt\n Right (LTEEqual m n eq2) => absurd $ uninhabited $ trans (sym eq) (compareSelf m n eq2 EQ)\n Right (LTELessThan m n lt) => absurd $ uninhabited $ trans (sym eq) (compareLT m n lt EQ)\n", "meta": {"hexsha": "30f4160836e2bb013d7c74282171facafd972d8d", "size": 18303, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "BiNat/Properties/LT.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/LT.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/LT.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": 50.7008310249, "max_line_length": 116, "alphanum_fraction": 0.6114844561, "num_tokens": 6438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6962967897899516}} {"text": "import Data.Vect\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n zipWith (\\el, vect => el :: vect) x xsTrans\n\naddMatrix : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (\\a, b => a + b) x y :: addMatrix xs ys\n\ncomputeRow : Num a => Vect m a -> Vect k (Vect m a) -> Vect k a\ncomputeRow xs [] = []\ncomputeRow xs (y :: ys) = sum (zipWith (*) xs y) :: computeRow xs ys\n\nmultMatrix: Num a => Vect n (Vect m a) -> Vect m (Vect k a) -> Vect n (Vect k a)\nmultMatrix [] ys = []\nmultMatrix (x :: xs) ys = let rightTrans = transposeMat ys in\n computeRow x rightTrans :: multMatrix xs ys\n", "meta": {"hexsha": "b503e9f1cbed9de52230c484b48b3653729b5577", "size": 881, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Excercises_ch3.idr", "max_stars_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_stars_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Excercises_ch3.idr", "max_issues_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_issues_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Excercises_ch3.idr", "max_forks_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_forks_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3043478261, "max_line_length": 80, "alphanum_fraction": 0.5925085131, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6962319159920306}} {"text": "module Rats\n\nimport ZZ\nimport ZZUtils\nimport Rationals\n\ndata Rats : Type where\n Rat : (p : ZZ) -> (q: ZZ) -> (pf: NotZero q) -> Rats\n\nnumerator: Rats-> ZZ\nnumerator (Rat p q pf) = p\n\ndenominator : Rats -> ZZ\ndenominator(Rat p q pf) = q\n\naddRats : Rats -> Rats -> Rats\naddRats (Rat p q x) (Rat y z w) =\n let\n num = (p * z) + (q * y)\n den = q * z\n pf : NotZero den = productNonZero x w\n in\n Rat num den pf\n\nmultRats : Rats -> Rats-> Rats\nmultRats (Rat p q x) (Rat y z w) =\n let\n num = p * y\n den = q * z\n pf : NotZero den = productNonZero x w\n in\n Rat num den pf\n\n\nZZtoRats : ZZ -> Rats\nZZtoRats x = Rat x (Pos(S Z)) PositiveZ\n\nInttoRats : Integer -> Rats\nInttoRats x = ZZtoRats (fromInt x)\n\nimplementation Num Rats where\n (+) = addRats\n (*) = multRats\n fromInteger = InttoRats\n\nEqualRats : Rats -> Rats-> Type\nEqualRats (Rat p q r) (Rat x y z) = (p*y = x*q)\n\nrewriteNonZero : (k : ZZ) -> NotZero k -> NotZero (k*1) = NotZero k\nrewriteNonZero k pf = rewrite ( multOneRightNeutralZ k) in Refl\n{-\nNonZeroIdentity: {a:ZZ}->{x: NotZero (Pos(S Z))}-> (r: NotZero a)-> ((productNonZero r x) = r)\nNonZeroIdentity {a=Pos (S q)} {x=(PositiveZ{k=Z})} (PositiveZ{k=q}) =\n rewrite blah Pos(S q) in Refl\nNonZeroIdentity {a= NegS q} {x=(PositiveZ{k=Z})} (NegativeZ{k=q}) = rewrite multOneRightNeutralZ (NegS q) in Refl\n\nZIsIdentity:(a: Rats) -> ((a + (Rat 0 1 x)) = a )\nZIsIdentity (Rat p (Pos(S k)) PositiveZ) =\n rewrite multOneRightNeutralZ p in\n rewrite multZeroRightZeroZ (Pos(S k)) in\n rewrite plusZeroRightNeutralZ p in\n rewrite multOneRightNeutralZ (Pos(S k)) in\n Refl\nZIsIdentity (Rat p (NegS k) NegativeZ) =\n rewrite multOneRightNeutralZ p in\n rewrite multZeroRightZeroZ (NegS k) in\n rewrite plusZeroRightNeutralZ p in\n rewrite multOneRightNeutralZ (NegS k) in\n Refl\n\n--PostulateEquality : EqualRats x y -> (x=y)\n -}\n", "meta": {"hexsha": "01354c15e9b3286d25ba0c214bc09fd10d76f854", "size": 1855, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Rats.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/Rats.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/Rats.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": 25.4109589041, "max_line_length": 113, "alphanum_fraction": 0.651212938, "num_tokens": 697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.695519737014385}} {"text": "||| This module implements a relation between a natural number and a list.\n||| The relation witnesses the fact the number is the length of the list.\n|||\n||| It is meant to be used in a runtime-irrelevant fashion in computations\n||| manipulating data indexed over lists where the computation actually only\n||| depends on the length of said lists.\n|||\n||| Instead of writing:\n||| ```idris example\n||| f0 : (xs : List a) -> P xs\n||| ```\n|||\n||| We would write either of:\n||| ```idris example\n||| f1 : (n : Nat) -> (0 _ : HasLength xs n) -> P xs\n||| f2 : (n : Subset n (HasLength xs)) -> P xs\n||| ```\n|||\n||| See `sucR` for an example where the update to the runtime-relevant Nat is O(1)\n||| but the udpate to the list (were we to keep it around) an O(n) traversal.\n\nmodule Data.List.HasLength\n\nimport Data.DPair\nimport Data.List\n\n%default total\n\n------------------------------------------------------------------------\n-- Type\n\n||| Ensure that the list's length is the provided natural number\npublic export\ndata HasLength : List a -> Nat -> Type where\n Z : HasLength [] Z\n S : HasLength xs n -> HasLength (x :: xs) (S n)\n\n------------------------------------------------------------------------\n-- Properties\n\n||| The length is unique\nexport\nhasLengthUnique : HasLength xs m -> HasLength xs n -> m === n\nhasLengthUnique Z Z = Refl\nhasLengthUnique (S p) (S q) = cong S (hasLengthUnique p q)\n\n||| This specification corresponds to the length function\nexport\nhasLength : (xs : List a) -> HasLength xs (length xs)\nhasLength [] = Z\nhasLength (_ :: xs) = S (hasLength xs)\n\nexport\nmap : (f : a -> b) -> HasLength xs n -> HasLength (map f xs) n\nmap f Z = Z\nmap f (S n) = S (map f n)\n\n||| @sucR demonstrates that snoc only increases the lenght by one\n||| So performing this operation while carrying the list around would cost O(n)\n||| but relying on n together with an erased HasLength proof instead is O(1)\nexport\nsucR : HasLength xs n -> HasLength (snoc xs x) (S n)\nsucR Z = S Z\nsucR (S n) = S (sucR n)\n\n------------------------------------------------------------------------\n-- Views\n\nnamespace SubsetView\n\n ||| We provide this view as a convenient way to perform nested pattern-matching\n ||| on values of type `Subset Nat (HasLength xs)`. Functions using this view will\n ||| be seen as terminating as long as the index list `xs` is left untouched.\n ||| See e.g. listTerminating below for such a function.\n public export\n data View : (xs : List a) -> Subset Nat (HasLength xs) -> Type where\n Z : View [] (Element Z Z)\n S : (p : Subset Nat (HasLength xs)) -> View (x :: xs) (Element (S (fst p)) (S (snd p)))\n\n ||| This auxiliary function gets around the limitation of the check ensuring that\n ||| we do not match on runtime-irrelevant data to produce runtime-relevant data.\n viewZ : (0 p : HasLength xs Z) -> View xs (Element Z p)\n viewZ Z = Z\n\n ||| This auxiliary function gets around the limitation of the check ensuring that\n ||| we do not match on runtime-irrelevant data to produce runtime-relevant data.\n viewS : (n : Nat) -> (0 p : HasLength xs (S n)) -> View xs (Element (S n) p)\n viewS n (S p) = S (Element n p)\n\n ||| Proof that the view covers all possible cases.\n export\n view : (p : Subset Nat (HasLength xs)) -> View xs p\n view (Element Z p) = viewZ p\n view (Element (S n) p) = viewS n p\n\nnamespace CurriedView\n\n ||| We provide this view as a convenient way to perform nested pattern-matching\n ||| on pairs of values of type `n : Nat` and `HasLength xs n`. If transformations\n ||| to the list between recursive calls (e.g. mapping over the list) that prevent\n ||| it from being a valid termination metric, it is best to take the Nat argument\n ||| separately from the HasLength proof and the Subset view is not as useful anymore.\n ||| See e.g. natTerminating below for (a contrived example of) such a function.\n public export\n data View : (xs : List a) -> (n : Nat) -> HasLength xs n -> Type where\n Z : View [] Z Z\n S : (n : Nat) -> (0 p : HasLength xs n) -> View (x :: xs) (S n) (S p)\n\n ||| Proof that the view covers all possible cases.\n export\n view : (n : Nat) -> (0 p : HasLength xs n) -> View xs n p\n view Z Z = Z\n view (S n) (S p) = S n p\n\n------------------------------------------------------------------------\n-- Examples\n\n-- /!\\ Do NOT re-export these examples\n\nlistTerminating : (p : Subset Nat (HasLength xs)) -> HasLength (xs ++ [x]) (S (fst p))\nlistTerminating p = case view p of\n Z => S Z\n S p => S (listTerminating p)\n\ndata P : List Nat -> Type where\n PNil : P []\n PCon : P (map f xs) -> P (x :: xs)\n\ncovering\nnotListTerminating : (p : Subset Nat (HasLength xs)) -> P xs\nnotListTerminating p = case view p of\n Z => PNil\n S p => PCon (notListTerminating {xs = map id (tail xs)} ({ snd $= map id } p))\n\nnatTerminating : (n : Nat) -> (0 p : HasLength xs n) -> P xs\nnatTerminating n p = case view n p of\n Z => PNil\n S n p => PCon (natTerminating n (map id p))\n", "meta": {"hexsha": "1ef804efd761e53c8b0ae1f6d238e31fc5b4a5ee", "size": 4930, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/List/HasLength.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/libs/contrib/Data/List/HasLength.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/libs/contrib/Data/List/HasLength.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 35.4676258993, "max_line_length": 91, "alphanum_fraction": 0.6182555781, "num_tokens": 1405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.69546663110667}} {"text": "\nmodule Typing\n\n-- Typing judgement for the simply-typed lambda\n-- calculus with \n-- (1) natural numbers as the only base type, and\n-- (2) general recursion.\n\n\nimport Term\n\n\n%default total\n%access public export\n\n\n\n---------------------------------------------------\n-- Begin: TYPES IN THE SIMPLY-TYPED LAMBDA CALCULUS\n\n-- Data type 'Ty' represents the types in the\n-- simply-typed lambda calculus:\n-- (1) Base type 'TyNat' of natural numbers.\n-- (2) Type constructor 'TyFun' for forming\n-- function types.\ndata Ty = TyNat | TyFun Ty Ty\n\n\n-- Simplified syntax for function types:\ninfixr 10 :->:\n(:->:) : Ty -> Ty -> Ty\n(:->:) t1 t2 = TyFun t1 t2\n\n-- End: TYPES IN THE SIMPLY-TYPED LAMBDA CALCULUS\n-------------------------------------------------\n\n\n\n\n---------------------------------------------------------\n-- Begin: CONTEXT FOR TYPING TERMS IN THE LAMBDA CALCULUS\n\nContext : Type\nContext = List Ty\n\n-- End: CONTEXT FOR TYPING TERMS IN THE LAMBDA CALCULUS\n-------------------------------------------------------\n\n\n\n\n--------------------------\n-- Begin: TYPING JUDGEMENT\n\ndata Typing : Context -> Term -> Ty -> Type where\n TyVar : (prf : index' i ctx = Just t) -> \n Typing ctx (TVar i) t\n --\n TyAbs : (s : Ty) ->\n Typing (s::ctx) e t ->\n Typing ctx (TAbs e) (s :->: t)\n --\n TyApp : Typing ctx e1 (s :->: t) -> Typing ctx e2 s ->\n Typing ctx (TApp e1 e2) t\n --\n TyRec : Typing ctx e1 TyNat -> Typing ctx e2 t -> \n Typing ctx e3 (TyNat :->: t :->: t) ->\n Typing ctx (TRec e1 e2 e3) t\n --\n TyZero : Typing ctx TZero TyNat\n --\n TySucc : Typing ctx e TyNat ->\n Typing ctx (TSucc e) TyNat\n --\n TyPred : Typing ctx e TyNat ->\n Typing ctx (TPred e) TyNat\n --\n TyIfz : Typing ctx e1 TyNat -> Typing ctx e2 t -> Typing ctx e3 t ->\n Typing ctx (TIfz e1 e2 e3) t\n\n\ntype : Typing ctx e t -> Ty\ntype {t} _ = t\n\n-- End: TYPING JUDGEMENT\n------------------------\n\n\n\n\n-------------------------\n-- Begin: CANONICAL FORMS\n\ncanonicalNat : (e : Term) ->\n Typing ctx e TyNat ->\n Value e ->\n Either (e = TZero) (e' : Term ** (Value e', e = TSucc e'))\ncanonicalNat (TVar i) (TyVar prf) v impossible\ncanonicalNat (TApp e1 e2) (TyApp ty1 ty2) v impossible\ncanonicalNat (TRec e1 e2 e3) (TyRec ty1 ty2 ty3) v impossible\ncanonicalNat TZero TyZero v = Left Refl\ncanonicalNat (TSucc e) (TySucc ty) (VSucc v) = \n let ih = canonicalNat e ty v\n in case ih of\n (Left eq) => let eq' = cong {f = TSucc} eq\n in Right (TZero ** (VZero, eq'))\n (Right (e1 ** (v1, eq))) => let e' = TSucc e1\n v' = VSucc v1\n eq' = cong {f = TSucc} eq\n in Right (e' ** (v', eq'))\ncanonicalNat (TPred e) (TyPred ty) v impossible\ncanonicalNat (TIfz e1 e2 e3) (TyIfz ty1 ty2 ty3) v impossible\n\n\ncanonicalFun : (e : Term) ->\n Typing ctx e (s :->: t) ->\n Value e ->\n (e' : Term ** (e = TAbs e'))\ncanonicalFun (TVar i) (TyVar prf) v impossible\ncanonicalFun (TAbs e) (TyAbs s ty) v = (e ** Refl)\ncanonicalFun (TApp e1 e2) (TyApp ty1 ty2) v impossible\ncanonicalFun (TRec e1 e2 e3) (TyRec ty1 ty2 ty3) v impossible\ncanonicalFun (TIfz e1 e2 e3) (TyIfz ty1 ty2 ty3) v impossible\n\n-- End: CANONICAL FORMS\n-----------------------\n", "meta": {"hexsha": "efb602d8fa9297ec99a5a7a3996465e4f249b497", "size": 3392, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "totality/src/Typing.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "totality/src/Typing.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "totality/src/Typing.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7086614173, "max_line_length": 73, "alphanum_fraction": 0.5209316038, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6952675865214045}} {"text": "> module Num.Properties\n\n> import Data.Fin\n> import Data.Vect\n> import Syntax.PreorderReasoning\n\n> import Matrix.Matrix\n> import Matrix.Operations\n> import Num.Refinements\n> import Num.Operations\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\nThe following\n\n> foldrVectLemma : {A, B : Type} -> {n : Nat} ->\n> (f : A -> B -> B) -> (e : B) ->\n> (a : A) -> (as : Vect n A) ->\n> foldr f e (a :: as) = f a (foldr f e as)\n\nshould hold by definition and \n\n< foldrVectLemma f e a as = Refl\n\nshould, in principle, type check. In fact, however, |foldr| is\nimplemented in terms of an accumulator and a proof of |foldrVectLemma|\nis not that simple. We start from the \"classical\" (traditional)\ndefinition of |foldr| for vectors:\n\n> total foldrClassic : (t -> acc -> acc) -> acc -> Vect n t -> acc\n> foldrClassic f e [] = e\n> foldrClassic f e (x::xs) = f x (foldrClassic f e xs)\n\nIn the Idris libraries |foldrImpl| is used instead, but we can prove\nthe following specification:\n\n> foldrImplLemma : {A, B : Type} -> {n : Nat} ->\n> (f : A -> B -> B) -> (e : B) -> (go : B -> B) ->\n> (as : Vect n A) ->\n> foldrImpl f e go as = go (foldrClassic f e as)\n> foldrImplLemma f e go [] = Refl\n> foldrImplLemma f e go (a :: as) =\n> ( foldrImpl f e go (a :: as) )\n> ={ Refl }=\n> ( foldrImpl f e (go . (f a)) as )\n> ={ foldrImplLemma f e (go . (f a)) as }=\n> ( (go . (f a)) (foldrClassic f e as) )\n> ={ Refl }=\n> ( go (f a (foldrClassic f e as)) )\n> ={ Refl }=\n> ( go (foldrClassic f e (a :: as) ) )\n> QED\n> %freeze foldrImplLemma\n\nThen we can specialise to when |go| is |id| as in the definition of\n|foldr|:\n\n> foldrImplCorr : {A, B : Type} -> {n : Nat} ->\n> (f : A -> B -> B) -> (e : B) ->\n> (as : Vect n A) ->\n> foldrImpl f e Prelude.Basics.id as = foldrClassic f e as\n> foldrImplCorr f e as = foldrImplLemma f e Prelude.Basics.id as\n> %freeze foldrImplCorr\n\nNow we can continue with the proof:\n\n> foldrVectLemma g e a as =\n> ( foldr g e (a :: as) )\n> ={ Refl }=\n> ( foldrImpl g e id (a :: as) )\n> ={ foldrImplCorr g e (a :: as) }=\n> ( foldrClassic g e (a :: as) )\n> ={ Refl }=\n> ( g a (foldrClassic g e as) )\n> ={ cong {f = g a} (sym (foldrImplCorr g e as)) }=\n> ( g a (foldrImpl g e id as) )\n> ={ Refl }=\n> ( g a (foldr g e as) )\n> QED\n> %freeze foldrVectLemma\n\nFinally we get to the one-step unfolding of |sum|:\n\n> sumLemma : (Num t) => (x : t) -> (xs : Vect m t) -> sum (x :: xs) = x + sum xs\n> sumLemma x xs = ( sum (x :: xs) )\n> ={ Refl }=\n> ( foldr (+) (fromInteger 0) (x :: xs) )\n> ={ foldrVectLemma (+) (fromInteger 0) x xs }=\n> ( x + foldr (+) (fromInteger 0) xs )\n> ={ Refl }=\n> ( x + sum xs )\n> QED\n> %freeze sumLemma\n\nThe corresponding lemma for append (|++|) follows from the definition\nof append (because it is not defined in terms of |foldrImpl|)\n\n> appendLemma : (x : t) -> (xs : Vect m t) -> (ys : Vect n t) ->\n> ((x :: xs) ++ ys) = (x :: (xs ++ ys))\n> appendLemma x xs ys =\n> ( (x :: xs) ++ ys )\n> ={ Refl }=\n> ( x :: (xs ++ ys) )\n> QED\n> %freeze appendLemma\n\n> |||\n> multSumLemma : (NumMultDistributesOverPlus t) =>\n> (x : t) -> (xs : Vect m t) ->\n> x * sum xs = sum (multSV x xs)\n> multSumLemma x Nil = ( x * (fromInteger 0) )\n> ={ multZeroRightZero x }=\n> ( fromInteger 0 )\n> ={ Refl }=\n> ( sum Data.Vect.Nil )\n> QED\n> multSumLemma x (y :: ys) = ( x * (sum (y :: ys)) )\n> ={ cong (sumLemma y ys) }=\n> ( x * (y + sum ys) )\n> ={ Num.Refinements.multDistributesOverPlusRight x y (sum ys) }=\n> ( (x * y) + (x * sum ys) )\n> ={ cong (multSumLemma x ys) }=\n> ( x * y + sum (multSV x ys) )\n> ={ sym (sumLemma (x * y) (multSV x ys)) }=\n> ( sum (x * y :: multSV x ys) )\n> ={ Refl }=\n> ( sum (multSV x (y :: ys)) )\n> QED\n> %freeze multSumLemma\n\n> sumsTo : Num t => (s : t) -> (xs : Vect m t) -> Type\n> sumsTo s xs = (sum xs = s)\n\n> sumOne : Num t => (xs : Vect m t) -> Type\n> sumOne = sumsTo (fromInteger 1)\n\n\n> lemma0 : (NumPlusZeroNeutral t) => (x : t) -> sum (Data.Vect.(::) x Nil) = x\n> lemma0 x = ( x + 0 )\n> ={ plusZeroRightNeutral x }=\n> ( x )\n> QED\n\n\n> lemma1 : (NumMultDistributesOverPlus t) =>\n> (x : t) -> (xs : Vect n t) ->\n> sumOne xs -> sumsTo x (multSV x xs)\n> lemma1 x xs pxs =\n> ( sum (multSV x xs) )\n> ={ sym (multSumLemma x xs) }=\n> ( x * sum xs )\n> ={ cong pxs }=\n> ( x * fromInteger 1 )\n> ={ multOneRightNeutral x }=\n> x\n> QED\n\n> sumPlusAppendLemma : NumPlusAssociative t =>\n> (xs : Vect n t) -> (ys : Vect m t) ->\n> (sum xs + sum ys) = sum (xs ++ ys)\n> sumPlusAppendLemma Nil ys = plusZeroLeftNeutral (sum ys)\n> sumPlusAppendLemma (x :: xs) ys =\n> ( sum (x :: xs) + sum ys )\n> ={ cong {f = (+ sum ys)} (sumLemma x xs) }=\n> ( (x + sum xs) + sum ys )\n> ={ sym (plusAssociative x (sum xs) (sum ys)) }=\n> ( x + (sum xs + sum ys) )\n> ={ cong (sumPlusAppendLemma xs ys) }=\n> ( x + sum (xs ++ ys) )\n> ={ sym (sumLemma x (xs ++ ys)) }=\n> ( sum (x :: (xs ++ ys)) )\n> ={ Refl }=\n> ( sum ((x :: xs) ++ ys) )\n> QED\n>\n> sumMapConcat : (NumPlusAssociative t) => (xss : Matrix m n t) ->\n> sum (map sum xss) = sum (Vect.concat xss)\n> sumMapConcat Nil = Refl\n> sumMapConcat (row :: rows) =\n> ( sum (map sum (row :: rows)) )\n> ={ Refl }=\n> ( sum (sum row :: map sum rows) )\n> ={ sumLemma (sum row) (map sum rows) }=\n> ( sum row + sum (map sum rows) )\n> ={ cong (sumMapConcat rows) }=\n> ( sum row + sum (Vect.concat rows) )\n> ={ sumPlusAppendLemma row (Vect.concat rows) }=\n> ( sum (row ++ Vect.concat rows) )\n> ={ Refl }=\n> ( sum (Vect.concat (row :: rows)) )\n> QED\n\n\nThe |multVMLemma| requires both NumAssocPlus and\nNumMultDistributesOverPlus and currently there is some problem with\n\"multiple constraints\" so we changed the NumRefinements classes to a\nchain instead of a tree.\n\n> ||| 'Tail' of a finite dependently typed function\n> depTail : {n : Nat} -> {P : Fin (S n) -> Type} ->\n> ((k : Fin (S n)) -> P k) -> ((j : Fin n) -> P (FS j))\n> depTail f k = f (FS k)\n\n> |||\n> multVMLemma0 : (NumMultDistributesOverPlus t) =>\n> (xs : Vect m t) -> (xss : Matrix m n t) ->\n> ((k : Fin m) -> sumOne (row k xss)) ->\n> sum (Vect.concat (multVM xs xss)) = sum xs\n> multVMLemma0 {m = Z} {n} Nil Nil _ = Refl\n> multVMLemma0 {m = S m'} {n} (x :: xs) (ys :: yss) ps =\n> ( sum (Vect.concat (multVM (x :: xs) (ys :: yss))) )\n> ={ Refl }=\n> ( sum (Vect.concat ((multSV x ys) :: (multVM xs yss))) )\n> ={ sym (sumMapConcat ((multSV x ys) :: (multVM xs yss))) }=\n> ( sum (map sum ((multSV x ys) :: (multVM xs yss))) )\n> ={ Refl }=\n> ( sum (sum (multSV x ys) :: (map sum (multVM xs yss))) )\n> ={ cong {f = \\ X => sum (X :: (map sum (multVM xs yss)))}\n> (lemma1 x ys (ps FZ)) }=\n> ( sum (x :: (map sum (multVM xs yss))) )\n> ={ sumLemma x (map sum (multVM xs yss)) }=\n> ( x + sum (map sum (multVM xs yss)) )\n> ={ cong (sumMapConcat (multVM xs yss)) }=\n> ( x + sum (Vect.concat (multVM xs yss)) )\n> ={ cong (multVMLemma0 xs yss (depTail {P = \\ k => sumOne (row k (ys :: yss))} ps)) }=\n> ( x + sum xs )\n> ={ sym (sumLemma x xs) }=\n> ( sum (x :: xs) )\n> QED\n\n \n> multVMLemma : (NumMultDistributesOverPlus t) =>\n> (m : Nat) ->\n> (xs : Vect m t) -> sumOne xs ->\n> (n : Nat) ->\n> (xss : Matrix m n t) ->\n> ((k : Fin m) -> sumOne (row k xss)) ->\n> sumOne (Vect.concat (multVM xs xss))\n> multVMLemma m xs pxs n xss pxss =\n> ( sum (Vect.concat (multVM xs xss)) )\n> ={ multVMLemma0 xs xss pxss }=\n> ( sum xs )\n> ={ pxs }=\n> ( fromInteger 1 )\n> QED\n\n\n> {-\n> ||| Alternative - no case analysis, but would need a few lemmas.\n> multVMLemma m xs pxs n xss pxss =\n> ( sum (Vect.concat (multVM xs xss)) )\n> ={ sym (sumMapConcat (multVM xs xss)) }=\n> ( sum (map sum (multVM xs xss)) )\n> ={ Refl }=\n> ( sum (map sum (map (uncurry multSV) (zip xs xss))) )\n> ={ ?mapFunctorLemma }=\n> ( sum (map (sum . uncurry multSV ) (zip xs xss)) )\n> ={ ?mapZipLemma }=\n> ( sum (zipWith (\\x, xs => sum (multSV x xs)) xs xss) )\n> ={ ?roughlyLemma1UnderLambdas }=\n> ( sum (zipWith (\\x, xs => x ) xs xss) )\n> ={ ?lala4 }=\n> ( sum xs )\n> ={ pxs }=\n> ( fromInteger 1 )\n> QED\n> -}\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "cf54daae3c45851a9d9b187a977c942b95f1b96d", "size": 9179, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Num/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": "Num/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": "Num/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.2572463768, "max_line_length": 90, "alphanum_fraction": 0.4787013836, "num_tokens": 3084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768094082276, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6952029527106489}} {"text": "module Sigma\n\nimport Basic\nimport Unit\nimport Void\n\ninfixr 0 #\npublic export\ndata Sigma : (a : Type) -> (p : a -> Type) -> Type where\n (#) : (x : a) -> p x -> Sigma a p\n\npublic export\nPair : Type -> Type -> Type\nPair a b = Sigma a (const b)\n\npublic export\npr1 : Sigma a p -> a\npr1 (x # _) = x\n\npublic export\npr2 : (s : Sigma a p) -> p (pr1 s)\npr2 (_ # y) = y\n\npublic export\nSigmaInduction : (q : Sigma a p -> Type)\n -> ((x : a) -> (y : p x) -> q (x # y))\n -> (s : Sigma a p) -> q s\nSigmaInduction _ f (x # y) = f x y\n\npublic export\nuncurry : (q : Sigma a p -> Type)\n -> ((x : a) -> (y : p x) -> q (x # y))\n -> (s : Sigma a p) -> q s\nuncurry = SigmaInduction\n\npublic export\ncurry : (q : Sigma a p -> Type)\n -> ((s : Sigma a p) -> q s)\n -> ((x : a) -> (y : p x) -> q (x # y))\ncurry _ f x y = f (x # y)\n\n", "meta": {"hexsha": "35658103fb6fc1cc9b10c77263e1a99d1b4dd712", "size": 848, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Sigma.idr", "max_stars_repo_name": "Russoul/Idris2-HoTT", "max_stars_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-17T05:44:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T09:36:13.000Z", "max_issues_repo_path": "src/Sigma.idr", "max_issues_repo_name": "Russoul/Idris2-HoTT", "max_issues_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Sigma.idr", "max_forks_repo_name": "Russoul/Idris2-HoTT", "max_forks_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1904761905, "max_line_length": 56, "alphanum_fraction": 0.4905660377, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6951179175695894}} {"text": "-- vim: set ft=idris sw=2 ts=2:\n--\n-- fibonacci.idr\n-- Calculate Fibonacci numbers in the Idris programming language\n--\n\nmodule Fibonacci\n\n\n-- Naive implementation\nexport\nfib_naive : Int -> Int\nfib_naive 0 = 0\nfib_naive 1 = 1\nfib_naive n = fib_naive (n - 1) + fib_naive (n - 2)\n\n-- Tail-call friendly version\nexport\nfib : Nat -> Nat\nfib n = fib_aux Z (S Z) n where\n fib_aux : Nat -> Nat -> Nat -> Nat\n fib_aux a b Z = a\n fib_aux a b (S n) = fib_aux b (plus a b) n\n\n\n", "meta": {"hexsha": "671071425291188b4441240f745562a8bd6556f4", "size": 469, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/Benchmark/src/Fibonacci.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/Benchmark/src/Fibonacci.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/Benchmark/src/Fibonacci.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": 18.0384615385, "max_line_length": 64, "alphanum_fraction": 0.6567164179, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6949253227998646}} {"text": "module CH07\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\ndata 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\narea : Shape -> Double\narea (Triangle x y) = x * y / 2\narea (Rectangle x y) = x * y\narea (Circle x) = pi * x * x\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\nEq Shape where\n (Triangle x0 y0) == (Triangle x1 y1) = x0 == x1 && y0 == y1\n (Rectangle x0 y0) == (Rectangle x1 y1) = x0 == x1 && y0 == y1\n (Circle x0) == (Circle x1) = x0 == x1\n _ == _ = False\n\nOrd Shape where\n compare shape0 shape1 = compare (area shape0) (area shape1)\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\nShow ty => Show (Expr ty) where\n show (Val n) = show n\n show (Add l r) = \"(\" ++ show l ++ \" + \" ++ show r ++ \")\"\n show (Sub l r) = \"(\" ++ show l ++ \" - \" ++ show r ++ \")\"\n show (Mul l r) = \"(\" ++ show l ++ \" * \" ++ show r ++ \")\"\n show (Div l r) = \"(\" ++ show l ++ \" / \" ++ show r ++ \")\"\n show (Abs e) = \"(abs \" ++ show e ++ \")\"\n\n(Neg ty, Integral ty, Eq ty) => Eq (Expr ty) where\n l == r = (eval l) == (eval r)\n\n(Neg from_ty, Integral from_ty) => Cast (Expr from_ty) from_ty where\n cast expr = eval expr\n\nFunctor Expr where\n map f (Val n) = Val $ f n\n map f (Add l r) = Add (map f l) (map f r)\n map f (Sub l r) = Sub (map f l) (map f r)\n map f (Mul l r) = Mul (map f l) (map f r)\n map f (Div l r) = Div (map f l) (map f r)\n map f (Abs e) = Abs $ map f e\n\nFunctor (Vect n) where\n map f Nil = Nil\n map f (x :: xs) = f x :: map f xs\n\nFoldable (Vect n) where\n foldr f acc Nil = acc\n foldr f acc (x :: xs) = f x (foldr f acc xs)\n\n foldl f acc Nil = acc\n foldl f acc (x :: xs) = foldl f (f acc x) xs\n\nEq e => Eq (Vect n e) where\n Nil == Nil = True\n (x :: xs) == (y :: ys) = x == y && xs == ys\n", "meta": {"hexsha": "031a8eb3448c57074ea08fec046c4b3727df9f14", "size": 2418, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch07/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/ch07/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/ch07/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": 28.1162790698, "max_line_length": 68, "alphanum_fraction": 0.5016542597, "num_tokens": 857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936262, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6949150930802473}} {"text": "module Data.Bool.Algebra\n\nimport Control.Algebra\nimport Data.Bool.Xor\n\n%default total\n\n-- && is Bool -> Lazy Bool -> Bool,\n-- but Bool -> Bool -> Bool is required\nand : Bool -> Bool -> Bool\nand True True = True\nand _ _ = False\n\nSemigroup Bool where\n (<+>) = xor\n\nSemigroupV Bool where\n semigroupOpIsAssociative = xorAssociative\n\nMonoid Bool where\n neutral = False\n\nMonoidV Bool where\n monoidNeutralIsNeutralL True = Refl\n monoidNeutralIsNeutralL False = Refl\n\n monoidNeutralIsNeutralR True = Refl\n monoidNeutralIsNeutralR False = Refl\n\nGroup Bool where\n -- Each Bool is its own additive inverse.\n inverse = id\n\n groupInverseIsInverseR True = Refl\n groupInverseIsInverseR False = Refl\n\nAbelianGroup Bool where\n groupOpIsCommutative = xorCommutative\n\nRing Bool where\n (<.>) = and\n\n ringOpIsAssociative True True True = Refl\n ringOpIsAssociative True True False = Refl\n ringOpIsAssociative True False True = Refl\n ringOpIsAssociative True False False = Refl\n ringOpIsAssociative False True True = Refl\n ringOpIsAssociative False False True = Refl\n ringOpIsAssociative False True False = Refl\n ringOpIsAssociative False False False = Refl\n\n ringOpIsDistributiveL True True True = Refl\n ringOpIsDistributiveL True True False = Refl\n ringOpIsDistributiveL True False True = Refl\n ringOpIsDistributiveL True False False = Refl\n ringOpIsDistributiveL False True True = Refl\n ringOpIsDistributiveL False False True = Refl\n ringOpIsDistributiveL False True False = Refl\n ringOpIsDistributiveL False False False = Refl\n\n ringOpIsDistributiveR True True True = Refl\n ringOpIsDistributiveR True True False = Refl\n ringOpIsDistributiveR True False True = Refl\n ringOpIsDistributiveR True False False = Refl\n ringOpIsDistributiveR False True True = Refl\n ringOpIsDistributiveR False False True = Refl\n ringOpIsDistributiveR False True False = Refl\n ringOpIsDistributiveR False False False = Refl\n\nRingWithUnity Bool where\n unity = True\n\n unityIsRingIdL True = Refl\n unityIsRingIdL False = Refl\n\n unityIsRingIdR True = Refl\n unityIsRingIdR False = Refl\n", "meta": {"hexsha": "4321d347c972377b847f3e1fc1e66b3c71209b94", "size": 2079, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Bool/Algebra.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/contrib/Data/Bool/Algebra.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/contrib/Data/Bool/Algebra.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 26.6538461538, "max_line_length": 48, "alphanum_fraction": 0.7768157768, "num_tokens": 625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846919, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6947765216742392}} {"text": "module NewEden.NaturalAxioms\n\nimport Prelude.Either\n\nimport NewEden.Algebra\n\n{- NaturalProperties -\n \n An incomplete (http://www.dicosmo.org/Articles/zeroisnfa.pdf), non-recursive,\n axiomatic description of the natural numbers defined in terms of functions on a\n given type t.\n \n Despite the fact that this is *not* a full description of the behavior of the \n Peano naturals, it is probably good enough to do anything of practical interest\n to most people (even mathematicians, in most cases).\n-}\n\ndata NaturalProperties : (t:Type) -> Type where\n ProofNaturalProperties :\n (Zero:t)\n -> (One:t)\n -> (lemmaDistinction: (Zero = One -> Void))\n -> (plus: (t -> t -> t))\n -> (lemmaPlusCommut: CommutativeFunction t plus)\n -> (lemmaPlusMonoid: Monoid t plus Zero)\n -> (lemmaPlusNoInverses: StrictMonoid lemmaPlusMonoid)\n -> (lemmaPlusMonomorphic: ((a:t) -> MonomorphicFunction $ plus a))\n -> (multiply: (t -> t -> t))\n -> (lemmaMultCommut: CommutativeFunction t multiply)\n -> (lemmaMultMonoid: Monoid t multiply One)\n -> (lemmaMultNoInverses: StrictMonoid lemmaMultMonoid)\n -> (lemmaMultiplyMonomorphic: ((a:t) -> MonomorphicFunction $ multiply a))\n -> (lemmaMultByZeroIsZero: ((a:t) -> multiply a Zero = Zero))\n -> (lemmaDistributive: ((a:t) -> (b:t) -> (c:t) -> multiply a (plus b c) = plus (multiply a b) (multiply a c)))\n -> (lemmaSequence: ((a:t) -> (b:t) -> (p1: (a = Zero -> Void)) -> (p2: plus a b = One) -> a = One))\n -> (compare:((a:t) -> (b:t) -> Either (a = b) (Either ((c ** ((plus a c = b, (c = Zero -> Void))))) (c ** ((plus b c = a, (c = Zero -> Void)))))))\n -> NaturalProperties t\n\n", "meta": {"hexsha": "32d734d6d1d60be3ad50e8e34c0875f06d6aa7de", "size": 1648, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/NewEden/NaturalAxioms.idr", "max_stars_repo_name": "identicalsnowflake/neweden", "max_stars_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-07T15:26:51.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-07T15:26:51.000Z", "max_issues_repo_path": "src/NewEden/NaturalAxioms.idr", "max_issues_repo_name": "identicalsnowflake/neweden", "max_issues_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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/NewEden/NaturalAxioms.idr", "max_forks_repo_name": "identicalsnowflake/neweden", "max_forks_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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.2564102564, "max_line_length": 149, "alphanum_fraction": 0.6419902913, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6946759970701609}} {"text": "\ndata SplitList : List a -> Type where\n SplitNil : SplitList []\n SplitOne : SplitList [x]\n SplitPair : (lefts : List a) -> (rights : List a) -> SplitList (lefts ++ rights)\n\nsplitList : (xs : List a) -> SplitList xs\nsplitList xs = splitList' xs xs\n where\n splitList' : (counter : List a) -> (input : List a) -> SplitList input\n splitList' _ [] = SplitNil\n splitList' _ [x] = SplitOne\n splitList' (_ :: _ :: counter) (item :: items)\n = case splitList' counter items of\n SplitNil => SplitOne\n SplitOne {x} => SplitPair [item] [x]\n (SplitPair lefts rights) => SplitPair (item :: lefts) rights\n splitList' _ items = SplitPair [] items\n\nmerge_sort : Ord a => List a -> List a\nmerge_sort xs with (splitList xs)\n merge_sort [] | SplitNil = []\n merge_sort [x] | SplitOne = [x]\n merge_sort (lefts ++ rights) | (SplitPair lefts rights)\n = merge (merge_sort lefts) (merge_sort rights)\n", "meta": {"hexsha": "97bc31b05f7f1f8fb618a6775567ef73ecfe1da0", "size": 939, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/merge_sort.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/merge_sort.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/merge_sort.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": 36.1153846154, "max_line_length": 82, "alphanum_fraction": 0.6198083067, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6946759769748665}} {"text": "module TypeTrans.Array \n\n-- Module to represent Vector types, we use\n-- Array as it's not already a taken construct\n-- in the Idris prelude\n\nimport Data.Vect\nimport Data.List\n\n%default total\n\n-- A Shape is a Vector which represents the structure\n-- of an Array e.g. the shape of [[1,2,3],[1,2,3]] would be [2,3]\nShape : Type\nShape = List Nat\n\n-- Rank represents the number of dimensions in an\n-- Array, e.g. the rank of [[]] would be 2\nRank : Type\nRank = Nat\n\n\nArray : Shape -> Type -> Type\nArray [] t = t\nArray (v::vs) t = Vect v (Array vs t)\n\n\n-- Give number of dimensions in the given Array\ndim : Array xs t -> Nat\ndim arr {xs} = length xs\n\n-- Given a Vector returns the number of items\n-- in the vector\nlength' : Vect n t -> Nat\nlength' v {n} = n \n\n-- Give the shape of a given array\nshape : Array xs t -> Shape \nshape arr {xs} = xs\n\n\n-- Gives a count of the total amount of elements in \n-- a vector based on its dimensions\nsize : Array xs t -> Nat\nsize arr {xs} = foldr (*) 1 xs\n\n\n-- Proof that a zero dimensional array cannot\n-- contain more than zero dimensions\narrayCannotBeEmpty : Array (0::xs) t -> Void\narrayCannotBeEmpty (v::vs) impossible\n\n\n-- | Lift a 0 dimensional Vector into a 1 dimensional \n-- Vector \nsingleton : Array (xs) t -> Array (1::xs) t\nsingleton t = [t]\n\n-- | Inverse operation from singletonV, reduce dimension\n-- of a 1 dimensional Vector with a single value into\n-- a 0 dimensional Vector\ninvSingleton : Array (1::xs) t -> Array (xs) t\ninvSingleton [t] = t\n\n\n-- | Map operation on an Array, maps\n-- all base elements\nmapA : (a -> b) -> Array xs a -> Array xs b\nmapA f v {xs=[]} = f v\nmapA f v {xs = (y::ys)} = map (mapA f) v\n\n\nmapM : Monad m => (a -> m b) -> Vect n a -> m (Vect n b)\nmapM _ Nil = return Vect.Nil\nmapM f (x::xs) = do\n x' <- f x\n xs' <- mapM f xs\n return (Vect.(::) x' xs')\n\nmapM_ : Monad m => (a -> m b) -> Vect n a -> m ()\nmapM_ _ Nil = return ()\nmapM_ f (x::xs) = do\n f x\n mapM_ f xs\n\nmapMA : Monad m => (a -> m b) -> Array xs a -> m (Array xs b)\nmapMA f v {xs=[]} = f v\nmapMA f v {xs = (y::ys)} = mapM (mapMA f) v\n\nmapMA_ : Monad m => (a -> m b) -> Array xs a -> m ()\nmapMA_ f v = do\n mapMA f v\n return ()\n\nmapML : Monad m => (a -> m b) -> List a -> m (List b)\nmapML _ [] = return []\nmapML f (x::xs) = do\n x' <- f x\n xs' <- mapML f xs\n return (x'::xs')\n\nmapML_ : Monad m => (a -> m b) -> List a -> m ()\nmapML_ f v = do \n mapML f v\n return ()\n\n-- | Reduce the dimensions of a 2+ dimensional vector\nredDim : Array (x1::x2::xs) t -> Array (x1*x2::xs) t\nredDim [] = []\nredDim (v::vs) = v ++ redDim vs \n\n\n\n-- | Flaten an Array down to 1 dimension\nflattenA : Array (x::xs) t -> (n ** Array [S n] t) \nflattenA v {x = Z} = void (arrayCannotBeEmpty v)\nflattenA v {x=S m} {xs=[]} = (_ ** v)\nflattenA v {xs = (y::ys)} = (flattenA (redDim v))\n\n\n\n-- | FoldL operation on Array\nfoldlA : (a -> b -> a) -> a -> Array (x::xs) b -> a\nfoldlA f e v with (flattenA v)\n | (_ ** v') = foldlA' f e v'\n where foldlA' : (a -> b -> a) -> a -> Array [(S ys)] b -> a\n foldlA' f e v = foldl f e v\n\n\n\n-- | Foldl1 operation on an Array\nfoldlA1 : (a -> a -> a) -> Array (x::xs) a -> a\nfoldlA1 f v with (flattenA v)\n | (_ ** v') = foldlA1' f v'\n where foldlA1' : (a -> a -> a) -> Array [(S ys)] a -> a \n foldlA1' f v = foldl1 f v\n\n\n\n-- | Transpose a 2+ dimensional Vector, switches first and second dimensions\ntransposeA : Array (x1::x2::xs) t -> Array (x2::x1::xs) t\ntransposeA = transpose\n\n\n\n-- Given a 1+ dimensional Vector in which the size of the highest dimension\n-- sz_d0 = m * n, increases the Vector by 1 dimension by taking m lots\n-- of n values\nincDim : Array (m * n::xs) t -> Array (m::n::xs) t\nincDim v {m = Z} = []\nincDim v {m = S r} {n} = \n let (fstN, rest) = (take n v, drop n v) in \n fstN :: (incDim rest)\n\n\nreshape' : Array (x1::(m * x2)::xs) t -> Array((x1 * m)::x2::xs) t\nreshape' [] = []\nreshape' (v::vs) = incDim v ++ reshape' vs\n\nreshape : Array (x1::(m * x2)::xs) t -> Array ((m * x1)::x2::xs) t\nreshape v {m} {x1} = rewrite (multCommutative m x1) in reshape' v\n\n\ninvReshape' : Array ((x1 * m)::x2::xs) t -> Array (x1::(m * x2)::xs) t\ninvReshape' v {x1 = Z} = [] \ninvReshape' v {x1 =S r} = map redDim $ incDim v\n\n\ninvReshape : Array ((m * x1)::x2::xs) t -> Array (x1::(m * x2)::xs) t\ninvReshape v = invReshape' $ flip v\n where flip : Array ((m * x1)::x2::xs) t -> Array ((x1 * m)::x2::xs) t\n flip v {m} {x1} = rewrite multCommutative x1 m in v\n\n\n-- Section for reshaping a vector keeping the dimensionality\n-- the same except showing that the most outer dimension\n-- is comprised of 2 factors multiplied together\n\n-- Proof dividing 0 by a non zero number gives 0\ndivZProof : (m : Nat) -> (nz : Not (m = Z)) -> divNatNZ 0 m nz = 0\ndivZProof Z nz = void (nz Refl)\ndivZProof (S Z) _ = Refl\ndivZProof (S (S n)) _ = Refl \n\n\n-- Proof modulo 0 by a non zero number gives 0\nmodZProof : (m : Nat) -> (nz : Not (m = Z)) -> modNatNZ 0 m nz = 0\nmodZProof Z nz = void (nz Refl)\nmodZProof (S Z) _ = Refl\nmodZProof (S (S n)) _ = Refl \n\n\n-- Proof modNatNZ (m * n) n = 0\nmodMProof : (m : Nat) -> (n: Nat) -> {default SIsNotZ nz : Not (m = Z)} -> modNatNZ (mult m n) m nz = 0\nmodMProof Z _ {nz} = void (nz Refl)\nmodMProof _ Z ?= Z\nmodMProof m n ?= Z\n\n\n\n-- TODO fill these out latee\nTypeTrans.Array.modMProof_lemma_1 = proof\n intro\n intro\n exact believe_me Z\n\nTypeTrans.Array.modMProof_lemma_2 = proof\n intro\n intro\n exact believe_me Z\n\n\n-- Proof of the Quotient Remainder theorem for the specific\n-- case of remainder = mod n m, and quotient = div n m\ndivModProof : (m : Nat) -> (n : Nat) -> \n (nz : Not (m = Z)) ->\n (n = m * (divNatNZ n m nz) + (modNatNZ n m nz)) \ndivModProof Z _ nz = void (nz Refl) -- Contraction m /= Z by supplied nz proof\ndivModProof m Z nz ?= Z -- Proof when n = 0 for all m\ndivModProof m n nz ?= n \n\n\nTypeTrans.Array.divModProof_lemma_1 = proof\n intros\n rewrite sym (divZProof m nz)\n rewrite sym (modZProof m nz)\n rewrite sym (plusZeroRightNeutral (mult m 0))\n rewrite sym (multZeroRightZero m)\n trivial\n\n\n-- TODO Temporary \"believe_me\" proof, should be replaced\n-- with the proof that n = m * (n `div` m) + (n `mod` m) if/when possible\nTypeTrans.Array.divModProof_lemma_2 = proof \n intro\n intro\n exact believe_me n\n\n\n-- Proof that when m divides n that n = m * (n / m) in the case of\n-- integer division\nfactorDivProof : (m : Nat) -> (n : Nat) -> \n (nz : Not (m = Z)) -> \n (mz : modNatNZ n m nz = Z) -> n = m * (divNatNZ n m nz)\n \nfactorDivProof Z _ nz _ = void (nz Refl) -- Contradiction, m /= Z by supplied nz proof\nfactorDivProof m Z nz _ ?= Z \nfactorDivProof m n nz mz ?= n \n\nTypeTrans.Array.factorDivProof_lemma_1 = proof\n intros\n rewrite sym (divZProof m nz)\n rewrite sym (multZeroRightZero m)\n trivial\n\n-- Considering this is a special case of the Quotient Remainder theorem\n-- (remainder = 0) we show that this is contained within it, and use that \n-- proof to prove this proof\nTypeTrans.Array.factorDivProof_lemma_2 = proof\n intros\n rewrite (plusZeroRightNeutral (m * divNatNZ n m nz))\n rewrite mz\n rewrite (divModProof m n nz)\n trivial\n\n\n-- Given a Vector of size n and a natural number m, and the conditions that m | n and m != 0\n-- transforms the Vector of size n into a Vector of size (m * (n `div` m)) which is equivalent\nreshapeByFactor : (m : Nat) -> Array (n::ns) t -> \n {default SIsNotZ nz : Not (m = Z)} -> \n {auto mz : modNatNZ n m nz = Z} ->\n Array ((m * (divNatNZ n m nz))::ns) t\n\nreshapeByFactor Z _ {nz} = void (nz Refl)\nreshapeByFactor m xs {n} {nz} {mz} = rewrite sym (factorDivProof m n nz mz) in xs\n\n\n-- Split in one step\nsplitA : (m : Nat) -> Array (n::ns) t -> \n {default SIsNotZ nz : Not (m = Z)} -> \n {auto mz : modNatNZ n m nz = Z} ->\n Array (m ::(divNatNZ n m nz)::ns) t\nsplitA m a {mz} {nz} = incDim $ reshapeByFactor m a {mz = mz} {nz = nz}\n\n\n\n-- Helper functions for reshaping Vectors instead of Arrays,\n-- as Unification behaviour is being a bit strange atm,\n\n\n-- Flatten a 2d vector into a 1d vector\nmerge : Vect x1 (Vect x2 t) -> Vect (x1 * x2) t\nmerge [] = []\nmerge (v::vs) = v ++ merge vs\n\n \nincDimV : Vect (m * n) t -> Vect m (Vect n t)\nincDimV v {m = Z} = []\nincDimV v {m = S r} {n} = \n let (fstN, rest) = (take n v, drop n v) in \n fstN :: (incDimV rest)\n\n\nreshapeByFV : (m : Nat) -> Vect n t -> \n {default SIsNotZ nz : Not (m = Z)} -> \n {auto mz : modNatNZ n m nz = Z} ->\n Vect (m * divNatNZ n m nz) t\n\nreshapeByFV Z _ {nz} = void (nz Refl)\nreshapeByFV m xs {n} {nz} {mz} = rewrite sym (factorDivProof m n nz mz) in xs\n\n\nsplitV : (m : Nat) -> Vect n t -> \n {default SIsNotZ nz : Not (m = Z)} -> \n {auto mz : modNatNZ n m nz = Z} ->\n Vect m (Vect (divNatNZ n m nz) t)\nsplitV m a {mz} {nz} = incDimV $ reshapeByFV m a {mz = mz} {nz = nz}\n\n\n\ndoubleToNat : Double -> Nat\ndoubleToNat d = fromIntegerNat $ cast d\n\n-- Generate all factors for a given number\nfactors : Nat -> List Nat\nfactors (S Z) = [(S Z)]\nfactors n = assert_total $ lows ++ (reverse $ map (div n) lows)\n where lows = filter ((== 0) . modNat n) [1..doubleToNat .floor . sqrt $ cast n]\n\n\n-- Get all factors of the largest dimension in\n-- the given Vector\nfactorsV : Array (x::xs) t -> List Nat\nfactorsV {x} _ = factors x\n\n-- Generate all factor pairs of a given natural number\nfactorPairs : Nat -> List (Nat, Nat)\nfactorPairs n = assert_total $ map (\\f => (f, div n f)) fs \n where fs = factors n\n\n\n-- Sacrificing totality for functionality, split an Array into a higher\n-- dimension\npartial\nsplitA2 : (n : Nat) -> Array (x::xs) t -> Array (n :: div x n :: xs) t\nsplitA2 n xs {x} = split' n (div x n) (toList xs)\n where \n partial\n getN : (n : Nat) -> List t -> Vect n t\n getN Z l = []\n getN (S n) (x::xs) = x::(getN n xs)\n \n partial \n split' : (m : Nat) -> (n : Nat) -> List t -> Vect m (Vect n t)\n split' Z _ _ = []\n split' (S m) n xs = (getN n xs)::(split' m n (drop n xs))\n\ninfixr 5 !!;\npartial\n(!!) : {a : Type} -> List a -> Nat -> a\n(x::xs) !! Z = x\n(x::xs) !! (S n) = xs !! n\n\n-- Split an array by the nth factor of its highest dimension, \n-- returns a Sigma Type containing the given factor with the split array\npartial\nsplitNFactor: (n : Nat) -> Array (x::xs) t -> (f : Nat ** Array (f :: div x f :: xs) t)\nsplitNFactor n xs {x} = (f ** (splitA2 f xs))\n where f = factors x !! n\n\n-- Generate all possible vector combinations using the factors of the highest\n-- dimension of the given vector, returns a list of sigma values containing the\n-- largest dimension of each split array along with the split array itself\npartial\nsplitFactors : Array (x::xs) t -> List (f : Nat ** Array (f :: div x f :: xs) t)\nsplitFactors xs {x} = map (\\f => (f ** splitA2 f xs)) (factors x)\n\npartial\nconvertFactors : (f ** Array (f :: div x f :: xs) t) -> (ys ** Array ys t) \nconvertFactors (f ** ys) {x} {xs} = assert_total $ ((f :: div x f :: xs) ** ys)\n\npartial\nsplitFactorsGeneric : Array (x::xs) t -> List (ys ** Array ys t)\nsplitFactorsGeneric xs = map convertFactors $ splitFactors xs\n\n\n\ntoVect : Array (x::xs) t -> Vect x (Array xs t)\ntoVect = id\n\nfromVect : Vect n t -> Array [n] t\nfromVect = id\n\npartial\nprintVect : (Show t) => Vect xs t -> IO()\nprintVect xs = do \n print \"[ \" \n mapM_ (\\x => print x >>= \\_ => print \" \") xs\n print \"]\"\n\n\npartial\nprintArr : (Show t) => Array xs t -> IO ()\nprintArr vs {t} = printArr' vs >>= \\_ => putStrLn \"\"\n where \n printArr' : (Show t) => Array xs t -> IO ()\n printArr' v {xs=[]} = print v >>= \\_ => putStr \"\"\n printArr' v {xs = (y::ys)} = do\n putStr \"[\"\n case v of\n [] => putStr \"\"\n (a::as) => do\n mapM_ (\\x => printArr' x >>= \\_ => putStr \",\") $ init (a::as)\n printArr' (last (a::as)) \n \n putStr \"]\"\n\npartial\nprintSigmaArr : (Show t) => (xs ** Array xs t) -> IO ()\nprintSigmaArr v {t} with (v) \n | (xs ** vs) = printArr vs {t}\n\n\npartial\nprintArrs : (Show t) => List (xs ** Array xs t) -> IO ()\nprintArrs vs {t} = mapML_ (\\v => printSigmaArr v {t}) vs\n\n", "meta": {"hexsha": "fac9dcc19aa103c31cff6c417019befcf0ad4583", "size": 12428, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/TypeTrans/Array.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/Array.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/Array.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": 29.0373831776, "max_line_length": 103, "alphanum_fraction": 0.5814290312, "num_tokens": 4156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.6946660855065865}} {"text": "module SC\n\n-- import Data.Stream\n\n{-\ninterface Comonad (w : Type -> Type) where\n extract : w a -> a\n duplicate : w a -> w (w a)\n\nComonad Stream where\n extract (x :: _) = x\n duplicate (x :: xs) = (x :: xs) :: duplicate xs\n-}\n\ndata Cofree : (Type -> Type) -> Type -> Type where\n (::) : a -> Inf (f (Cofree f a)) -> Cofree f a\n\nFunctor f => Functor (Cofree f) where\n map f (x :: xs) = f x :: map (map f) xs\n\nduplicate : (Functor f) => Cofree f a -> Cofree f (Cofree f a)\nduplicate (x :: xs) = (x :: xs) :: map duplicate xs\n\npure : Cofree f a -> a\npure (x :: _) = x\n\n(>>=) : (Functor f) => Cofree f a -> (Cofree f a -> b) -> Cofree f b\nw >>= g = map g (duplicate w)\n\nextend : (Functor f) => (Cofree f a -> b) -> (Cofree f a) -> Cofree f b\nextend g w = map g (duplicate w)\n\ndata Id a = MkId a\n\nFunctor Id where\n map f (MkId x) = MkId (f x)\n\nStrm : Type -> Type\nStrm = Cofree Id\n\niterate : (f : a -> a) -> (x : a) -> Strm a\niterate f x = x :: MkId (iterate f (f x))\n\nzeros : Strm Int\nzeros = 0 :: MkId zeros\n\ntest : Strm Int\ntest = do\n x <- zeros\n pure x\n\ndata Cofree : (Type -> Type) -> Type -> Type where\n (::) : a -> Inf (f (Cofree f a)) -> Cofree f a\n\ndata ZP a = MkZP a a\ndata MV = L | R\n\nFunctor ZP where\n map f (MkZP x y) = MkZP (f x) (f y)\n\nbrowsing : (forall b . f b -> i -> b) -> Cofree f a -> List i -> a\nbrowsing idx (a :: as) [] = a\nbrowsing idx (a :: as) (k :: ks) = browsing idx (idx as k) ks\n\nZipper : Type -> Type\nZipper = Cofree ZP\n\nmove : ZP a -> MV -> a\nmove (MkZP l r) L = l\nmove (MkZP l r) R = r\n\nmoves : List MV -> Zipper a -> Zipper a\nmoves m = extend (\\x => browsing move x m)\n\n\n-- https://chrispenner.ca/posts/representable-cofree-zippers\n-- moveLeft : Zipper a -> Zipper a\n\n", "meta": {"hexsha": "994a659a082bd3d45586fd121489a5f2e112293a", "size": 1718, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/pearls/SC.idr", "max_stars_repo_name": "andorp/IdrisExtSTGCodegen", "max_stars_repo_head_hexsha": "3565a6fdd5f58fc6556214685d6da4dd5db25865", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2020-10-30T22:06:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T07:14:52.000Z", "max_issues_repo_path": "src/pearls/SC.idr", "max_issues_repo_name": "andorp/IdrisExtSTGCodegen", "max_issues_repo_head_hexsha": "3565a6fdd5f58fc6556214685d6da4dd5db25865", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/pearls/SC.idr", "max_forks_repo_name": "andorp/IdrisExtSTGCodegen", "max_forks_repo_head_hexsha": "3565a6fdd5f58fc6556214685d6da4dd5db25865", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-11T10:59:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:20:02.000Z", "avg_line_length": 21.746835443, "max_line_length": 71, "alphanum_fraction": 0.5605355064, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6942436358397556}} {"text": "-- Minimal implicational logic, PHOAS approach, initial encoding\n\nmodule Pi.ArrMp\n\n%default total\n\n\n-- Types\n\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n\n\n-- Context and truth judgement\n\nCx : Type\nCx = Ty -> Type\n\nisTrue : Ty -> Cx -> Type\nisTrue a tc = tc a\n\n\n-- Terms\n\ninfixl 1 :$\ndata Tm : Cx -> Ty -> Type where\n var : isTrue a tc -> Tm tc a\n lam' : (isTrue a tc -> Tm tc b) -> Tm tc (a :=> b)\n (:$) : Tm tc (a :=> b) -> Tm tc a -> Tm tc b\n\nlam'' : (Tm tc a -> Tm tc b) -> Tm tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\n\nThm : Ty -> Type\nThm a = {tc : Cx} -> Tm tc a\n\n\n-- Example theorems\n\naI : Thm (a :=> a)\naI =\n lam x :=> x\n\naK : Thm (a :=> b :=> a)\naK =\n lam x :=>\n lam y :=> x\n\naS : Thm ((a :=> b :=> c) :=> (a :=> b) :=> a :=> c)\naS =\n lam f :=>\n lam g :=>\n lam x :=> f :$ x :$ (g :$ x)\n\ntSKK : Thm (a :=> a)\ntSKK {a} =\n aS {b = a :=> a} :$ aK :$ aK\n", "meta": {"hexsha": "414bfde8be1a1be6f14d183df757ee55329dec4b", "size": 985, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pi/ArrMp.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/ArrMp.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/ArrMp.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": 15.8870967742, "max_line_length": 64, "alphanum_fraction": 0.4456852792, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109622750986, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6942227055690293}} {"text": "import Data.Nat\nimport Data.Vect\n\nmyReverse1 : Vect n a -> Vect n a\nmyReverse1 [] = []\nmyReverse1 {n = S k} (x :: xs)\n = let result = myReverse1 xs ++ [x] in\n rewrite plusCommutative 1 k in result\n\nmyReverse : Vect n a -> Vect n a\nmyReverse [] = []\nmyReverse (x :: xs) = reverseProof (myReverse xs ++ [x])\n where\n reverseProof : Vect (k + 1) a -> Vect (S k) a\n reverseProof {k} result = rewrite plusCommutative 1 k in result\n", "meta": {"hexsha": "e561bb032758835a3b46a9b0a69a99a12b9d50e0", "size": 452, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter08/ReverseVec.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "idris2/tests/typedd-book/chapter08/ReverseVec.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "idris2/tests/typedd-book/chapter08/ReverseVec.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.25, "max_line_length": 67, "alphanum_fraction": 0.6172566372, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6941370410008196}} {"text": "import Data.Vect\n\n{-\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n-}\n\n\nfourInts : Vect 4 Int\nfourInts = [0, 1, 2, 3]\n\nsixInts : Vect 6 Int\nsixInts = [4, 5, 6, 7, 8, 9]\n\ntenInts : Vect 10 Int\ntenInts = fourInts ++ sixInts\n\n--reverse fourInts\n\n--map (\\x => x+1) fourInts\n", "meta": {"hexsha": "8b1f46d6f9da5fa8f2b93555cc1f657a39e45a57", "size": 321, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZPF/Slajdy19/PlikiIdrisa/Vectors.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/Vectors.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/Vectors.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": 14.5909090909, "max_line_length": 39, "alphanum_fraction": 0.5732087227, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.6940829178510983}} {"text": "-- ----------------------------------------------------------- [ DataTypes.idr ]\n-- Module : Chapter.DataTypes\n-- Description : Definitions from Chapter 4 of Edwin Brady's book,\n-- \"Type-Driven Development with Idris.\"\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Chapter.DataTypes\n\n%access export\n\n-- ------------------------------------------------------- [ 4.1.2 Union Types ]\n\npublic export\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\n%name Shape shape, shape1, shape2\n\nnamespace Shape\n\n ||| Calculate the area of a shape.\n area : Shape -> Double\n area (Triangle base height) = 0.5 * base * height\n area (Rectangle width height) = width * height\n area (Circle radius) = pi * radius * radius\n\n-- --------------------------------------------------- [ 4.1.3 Recursive Types ]\n\npublic export\ndata Picture = ||| A primitive shape.\n Primitive Shape\n | ||| A combination of two other pictures.\n Combine Picture Picture\n | ||| A picture rotated through an angle.\n Rotate Double Picture\n | ||| A picture translated to a different location.\n Translate Double Double Picture\n\n%name Picture pic, pic1, pic2\n\nnamespace Picture\n\n area : Picture -> Double\n area (Primitive shape) = area shape\n area (Combine pic pic1) = area pic + area pic1\n area (Rotate _ pic) = area pic\n area (Translate _ _ pic) = area pic\n\n-- ------------------------------------------------ [ 4.1.4 Generic Data Types ]\n\n||| A binary search tree.\npublic export\ndata Tree elem = ||| A tree with no data.\n Empty\n | ||| A node with a left subtree, a value, and a right subtree.\n Node (Tree elem) elem (Tree elem)\n \n%name Tree tree, tree1\n\n||| Insert a value into a binary search tree.\n||| @ x a value to insert\n||| @ tree a binary search tree to insert into\ninsert : Ord elem => (x : elem) -> (tree : Tree elem) -> Tree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left val right)\n = case compare x val of\n LT => Node (insert x left) val right\n EQ => orig\n GT => Node left val (insert x right)\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "df9e754e931824ef750f57a8cbf5780ef8bd0dd7", "size": 2391, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Chapter/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/Chapter/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/Chapter/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": 33.2083333333, "max_line_length": 80, "alphanum_fraction": 0.5123379339, "num_tokens": 510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6940451646155129}} {"text": "module Grover\n\nimport Data.Nat\nimport Data.Vect\nimport Decidable.Equality\nimport Unitary\nimport Injection\nimport LinearTypes\nimport Lemmas\nimport Control.Linear.LIO\nimport QStateT\nimport AlterningBitsOracle\nimport QuantumOp\n\n%default total\n\n|||GROVER'S ALGORITHM\n|||1. Start with |0> ¤ n\n|||2. Apply H ¤ n\n|||3. Grover iteration\n||| 3.1 : Apply oracle\n||| 3.2 : Apply H ¤ n\n||| 3.3 : Amplification\n||| 3.4 : Apply H ¤ n\n\n\n------------- AMPLIFICATION-------------\n\npublic export total\namplification : (n : Nat) -> Unitary n\namplification 0 = IdGate\namplification 1 = IdGate\namplification (S k) = \n let x = tensorn (S k) (X 0 IdGate)\n h1 = H k {prf = lemmaLTSucc k} x\n c = multipleQubitControlledNOT (S k) . h1\n h2 = H k {prf = lemmaLTSucc k} c\n in x . h2 \n\n---------------GROVER ITERATION--------------\n\npublic export total\ngroverIteration : (n : Nat) -> {p : Nat} -> (oracle : Unitary (n + p)) -> Unitary (n + p)\ngroverIteration n oracle = \n let h = tensorn n (H 0 IdGate) \n in (h # IdGate) . (amplification n # IdGate) . (h # IdGate) . oracle\n\npublic export total\nrepeatGroverIteration : (k : Nat) -> (n : Nat) -> {p : Nat} -> (oracle : Unitary (n + p)) -> Unitary (n + p)\nrepeatGroverIteration 0 n _ = IdGate\nrepeatGroverIteration (S k) n oracle = (groverIteration n oracle) . (repeatGroverIteration k n oracle)\n\n----------------GROVER'S ALGORITHM------------------\n\nxhAncilla : (p : Nat) -> Unitary p\nxhAncilla 0 = IdGate\nxhAncilla (S p) = let xh = (H 0 IdGate) . (X 0 IdGate) in rewrite sym $ lemmaplusOneRight p in IdGate # xh\n\nhxAncilla : (p : Nat) -> Unitary p\nhxAncilla 0 = IdGate \nhxAncilla (S p) = let xh = (X 0 IdGate) . (H 0 IdGate) in rewrite sym $ lemmaplusOneRight p in IdGate # xh\n\npublic export total\ngrover' : (n : Nat) -> {p : Nat} -> (oracle : Unitary (n + p)) -> (nbIter : Nat) -> Unitary (n + p)\ngrover' n oracle nbIter = \n let h = (tensorn n (H 0 IdGate)) # xhAncilla p\n in (IdGate # hxAncilla p) . (repeatGroverIteration nbIter n oracle) . h\n \n\npublic export total\ngrover : QuantumOp t =>\n (n : Nat) -> {p : Nat} -> (oracle : Unitary (n + p)) -> (nbIter : Nat) -> IO (Vect n Bool)\ngrover n oracle nbIter = do\n let circuit = grover' n oracle nbIter\n w <- run (do\n q <- newQubits {t=t} (n + p)\n q <- applyUnitary q circuit\n v <- measureAll q\n pure v\n )\n pure (take n w)\n\n\n--------------------------SMALL TEST---------------------------\n\n--Example with the alternating bits oracle\n\npublic export\ntestGrover : IO (Vect 4 Bool)\ntestGrover = \n grover {t = SimulatedOp} 4 {p = 1} (solve 2) 1\n\npublic export\ntestG : (nbIter : Nat) -> IO (Vect 3 Nat)\ntestG 0 = pure [0,0,0]\ntestG (S k) = do\n [a,b,c] <- testG k\n v <- testGrover\n case v of\n [True,False,True,False] => pure [S a,b,c]\n [False,True,False,True] => pure [a,S b,c]\n _ => pure [a,b,S c]\n\n\n\n", "meta": {"hexsha": "52a49ee3c691d4e1bfaca506bd137a7722629c4a", "size": 2913, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Grover.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": "Grover.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": "Grover.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": 27.4811320755, "max_line_length": 108, "alphanum_fraction": 0.5883968417, "num_tokens": 997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6940451547140333}} {"text": "module Quantities.FreeAbelianGroup\n\nimport Quantities.Power\n\n%default total\n%access public export\n\nmergeWithBy : (k -> k -> Ordering) -> (v -> v -> v) ->\n List (k, v) -> List (k, v) -> List (k, v)\nmergeWithBy _ _ [] ys = ys\nmergeWithBy _ _ xs [] = xs\nmergeWithBy order combine ((k1, v1) :: xs) ((k2, v2) :: ys) = let o = order k1 k2 in\n if o == LT then (k1, v1) :: mergeWithBy order combine xs ((k2, v2) :: ys)\n else if o == GT then (k2, v2) :: mergeWithBy order combine ((k1, v1) :: xs) ys\n else (k1, combine v1 v2) :: mergeWithBy order combine xs ys\n\nmergeWith : Ord k => (v -> v -> v) ->\n List (k, v) -> List (k, v) -> List (k, v)\nmergeWith = mergeWithBy compare\n\nfilterValues : (v -> Bool) -> List (k, v) -> List (k, v)\nfilterValues p = filter (p . snd)\n\nmapValue : (v -> w) -> List (k, v) -> List (k, w)\nmapValue f = map (\\(k, v) => (k, f v))\n\ndata FreeAbGrp : Type -> Type where\n MkFreeAbGrp : {a : Type} -> (List (a, Integer)) -> FreeAbGrp a\n\nmkFreeAbGrp : Ord a => List (a, Integer) -> FreeAbGrp a\nmkFreeAbGrp = MkFreeAbGrp . filterValues (\\x => x /= 0)\n . foldr (\\x => mergeWith (+) [x]) []\n\nunit : FreeAbGrp a\nunit = MkFreeAbGrp []\n\nimplicit\ninject : a -> FreeAbGrp a\ninject x = MkFreeAbGrp [(x, 1)]\n\nfreeAbGrpPower : FreeAbGrp a -> Integer -> FreeAbGrp a\nfreeAbGrpPower _ 0 = unit\nfreeAbGrpPower (MkFreeAbGrp xs) i = MkFreeAbGrp $ mapValue (i*) xs\n\nfreeAbGrpInverse : FreeAbGrp a -> FreeAbGrp a\nfreeAbGrpInverse x = freeAbGrpPower x (-1)\n\ninfixl 6 <<+>>\n(<<+>>) : Ord a => FreeAbGrp a -> FreeAbGrp a -> FreeAbGrp a\n(MkFreeAbGrp xs) <<+>> (MkFreeAbGrp ys) = MkFreeAbGrp $ filterValues (\\x => x /= 0) $ mergeWithBy compare (+) xs ys\n\nimplementation Eq a => Eq (FreeAbGrp a) where\n (MkFreeAbGrp xs) == (MkFreeAbGrp ys) = xs == ys\n\nimplementation Ord a => Ord (FreeAbGrp a) where\n compare (MkFreeAbGrp xs) (MkFreeAbGrp ys) = compare xs ys\n\nimplementation [freeabgrppower] Power (FreeAbGrp a) where\n (^) = freeAbGrpPower\n\nimplementation Ord a => Semigroup (FreeAbGrp a) where\n (<+>) = (<<+>>)\n\nimplementation Ord a => Monoid (FreeAbGrp a) where\n neutral = unit\n\nimplementation Ord a => Group (FreeAbGrp a) where\n inverse = freeAbGrpInverse\n\nimplementation Ord a => AbelianGroup (FreeAbGrp a) where\n\n-- Lift a function A -> G to a group homomorphism between the freely generated\n-- abelian group of A to the group G.\nlift : (Group g, Power g) => (a -> g) -> FreeAbGrp a -> g\nlift f (MkFreeAbGrp xs) = concatMap (\\(x, i) => ((f x) ^ i)) xs\n\ninject_lift_lem : (Group g, Power g) => (f : a -> g) -> (x : a) -> lift f (inject x) = f x\ninject_lift_lem f x = really_believe_me (Refl {x=(lift f (inject x))})\n\nlift_power_lem : (Group g, Power g, Ord a) => (f : a -> g) -> (x : FreeAbGrp a) ->\n (i : Integer) -> lift f (x ^ i) = lift f x ^ i\nlift_power_lem f x i = really_believe_me (Refl {x=(lift f (x ^ i))})\n\nlift_mult_lem : (Ord a, Group g, Power g) => (f : a -> g) -> (x : FreeAbGrp a) ->\n (y : FreeAbGrp a) -> lift f (x <+> y) = lift f x <+> lift f y\nlift_mult_lem f x y = really_believe_me (Refl {x=(lift f (x <+> y))})\n\nfreeabgrppower_correct : (Ord a) => (x : FreeAbGrp a) -> (i : Integer) -> freeAbGrpPower x i = (^) x i\nfreeabgrppower_correct x i = really_believe_me (Refl {x=(freeAbGrpPower x i)})\n", "meta": {"hexsha": "928c24b48c248489cc306d79778a509690c1d408", "size": 3297, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Quantities/FreeAbelianGroup.idr", "max_stars_repo_name": "timjb/quantities", "max_stars_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 112, "max_stars_repo_stars_event_min_datetime": "2015-01-18T13:52:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T14:15:46.000Z", "max_issues_repo_path": "Quantities/FreeAbelianGroup.idr", "max_issues_repo_name": "timjb/quantities", "max_issues_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-04T08:51:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-17T09:52:29.000Z", "max_forks_repo_path": "Quantities/FreeAbelianGroup.idr", "max_forks_repo_name": "timjb/quantities", "max_forks_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-04-28T23:49:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T17:28:34.000Z", "avg_line_length": 36.6333333333, "max_line_length": 115, "alphanum_fraction": 0.6141947225, "num_tokens": 1204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.693453507866312}} {"text": "import Data.List.Views\n\nlist1: List Int\nlist1 = [1,2,3]\n\ndata ListLast: List a -> Type where\n Empty: ListLast []\n NonEmpty: (xs: List a) -> (x: a) -> ListLast (xs ++ [x])\n\ntotal listLast: (xs: List a) -> ListLast xs\nlistLast [] = Empty\nlistLast (x :: xs) = case listLast xs of\n Empty => NonEmpty [] x\n (NonEmpty ys y) => NonEmpty (x :: ys) y\n\ntotal describeHelper: (input: List Int) -> (form: ListLast input) -> String\ndescribeHelper [] Empty = \"Empty\"\ndescribeHelper (xs ++ [x]) (NonEmpty xs x) = \"NonEmpty - All but one: \" ++ show xs\n\ntotal describeListEnd: List Int -> String\ndescribeListEnd xs with (listLast xs)\n describeListEnd [] | Empty = \"Empty!\"\n describeListEnd (ys ++ [x]) | (NonEmpty ys x) = \"Non-empty :) All but last: \" ++ show ys\n\nmyReverse: List a -> List a\nmyReverse input with (listLast input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (NonEmpty xs x) = x :: myReverse xs\n\ndata SplitList: List a -> Type where\n SplitNil: SplitList []\n SplitOne: SplitList [x]\n SplitPair: (lefts: List a) -> (rights: List a) -> SplitList (lefts ++ rights)\n\ntotal splitList: (input: List a) -> SplitList input\nsplitList input = splitListHelp input input\n where\n splitListHelp: List a -> (input: List a) -> SplitList input\n splitListHelp _ [] = SplitNil\n splitListHelp _ [x] = SplitOne\n splitListHelp (_ :: _ :: counter) (item :: items) =\n case splitListHelp counter items of\n SplitNil => SplitOne\n SplitOne {x} => SplitPair [item] [x]\n SplitPair lefts rights => SplitPair (item :: lefts) rights\n splitListHelp _ items = SplitPair [] items\n\nmergeSort: Ord a => List a -> List a\nmergeSort input with (splitList input)\n mergeSort [] | SplitNil = []\n mergeSort [x] | SplitOne = [x]\n mergeSort (lefts ++ rights) | (SplitPair lefts rights) =\n merge (mergeSort lefts) (mergeSort rights)\n\ntotal mergeSort2: Ord a => List a -> List a\nmergeSort2 input with (splitRec input)\n mergeSort2 [] | SplitRecNil = []\n mergeSort2 [x] | SplitRecOne = [x]\n mergeSort2 (lefts ++ rights) | (SplitRecPair lrec rrec) =\n merge (mergeSort2 lefts | lrec)\n (mergeSort2 rights | rrec)\n\n\nexample: List Int\nexample = [6,5,4,3,3,1,3,7,3,4,5,1,2,1,2,4,6,9,6]\n", "meta": {"hexsha": "5be9c9a08f17bd7b3b31691182f911eb7036afa4", "size": 2279, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "DescribeList.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": "DescribeList.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": "DescribeList.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": 34.5303030303, "max_line_length": 90, "alphanum_fraction": 0.6296621325, "num_tokens": 715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6927780042726027}} {"text": "data Tree elem = Empty | Node (Tree elem) elem (Tree elem)\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 left value right) = case compare x value of\n LT => Node (insert x left) value right\n EQ => orig \n GT => Node left value (insert x right)\n\ninsert_helper : Ord a => (x : a) -> Tree a -> Tree a\ninsert_helper x t = insert x t\n\nlistToTree : Ord a => List a -> Tree a\nlistToTree [] = Empty\nlistToTree (x :: xs) = let inserted = listToTree xs in\n insert_helper x inserted\n \ntreeToList : Tree a -> List a\ntreeToList Empty = []\ntreeToList (Node left x right) = let leftList = (treeToList left) \n rightList = x :: treeToList right \n in leftList ++ rightList\n\nFoldable Tree where\n foldr func acc Empty = acc\n foldr func acc (Node left value right) = let leftFold = foldr func acc left \n rightFold = foldr func leftFold right in\n func value rightFold\n", "meta": {"hexsha": "5e1cd552e47c96358800438c8d8fa413da977073", "size": 1239, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tree.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": "tree.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": "tree.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": 41.3, "max_line_length": 87, "alphanum_fraction": 0.5246166263, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6927181581930058}} {"text": "{-\ndata Nat = Z | S Nat\n\nplus : Nat -> Nat -> Nat\nplus Z y = y\nplus (S x) y = S (plus x y)\n-}\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n%name Vect xs, ys, zs\n\nappend : Vect n a -> Vect m a -> Vect (n + m) a\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n\n\nzipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\nzipWith f [] ys = []\nzipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys\n\ncreate_empties : Vect m (Vect 0 elem)\ncreate_empties {m = Z} = []\ncreate_empties {m = (S k)} = [] :: create_empties\n\ntranspose_helper : (row : Vect m elem) -> (rest_trans : Vect m (Vect k elem)) ->\n Vect m (Vect (S k) elem)\ntranspose_helper [] [] = []\ntranspose_helper (rowval :: xs) (restrow :: ys) = (rowval :: restrow) :: transpose_helper xs ys\n\ntranspose_vec : Vect n (Vect m elem) -> Vect m (Vect n elem)\ntranspose_vec [] = create_empties\ntranspose_vec (row :: rest) = let rest_trans = transpose_vec rest in\n transpose_helper row rest_trans\n\n\n\n\n\n\n\n\n------- A main program to read dimensions, generate and tranpose a vector\n\nimplementation Functor (Vect m) where\n map m [] = []\n map m (x :: xs) = m x :: map m xs\n\nimplementation Show a => Show (Vect m a) where\n show x = show (toList x)\n where\n toList : Vect m a -> List a\n toList [] = []\n toList (y :: xs) = y :: toList xs\n\ncountTo : (m : Nat) -> Vect m Int\ncountTo Z = []\ncountTo (S k) = 0 :: map (+1) (countTo k)\n\nmkVect : (n, m : Nat) -> Vect n (Vect m Int)\nmkVect Z m = []\nmkVect (S k) m = countTo m :: map (map (+ cast m)) (mkVect k m)\n\nmain : IO ()\nmain = do putStr \"Rows: \"\n let r : Nat = 5 \n putStr \"Columns: \"\n let c : Nat = 6 \n printLn (mkVect r c)\n putStrLn \"Transposed:\"\n printLn (transpose_vec (mkVect r c))\n", "meta": {"hexsha": "ec0c329554b2cd5fc9495c537a1a712ae5d379a8", "size": 1883, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/idris-dev/basic015/basic015.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/basic015/basic015.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/basic015/basic015.idr", "max_forks_repo_name": "grin-compiler/idris-grin", "max_forks_repo_head_hexsha": "0514e4d41933143223cb685e23f450dcbf3d5593", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-14T13:14:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-07T06:20:45.000Z", "avg_line_length": 25.4459459459, "max_line_length": 95, "alphanum_fraction": 0.5485926713, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6927071642812175}} {"text": "> module BoundedNat.BoundedNat\n\n> import Sigma.Sigma\n\n> %default total\n\n> %access public export\n\n\n> ||| Natural numbers bounded by LT\n> LTB : Nat -> Type\n> LTB b = Sigma Nat (\\ n => LT n b)\n\n> ||| Natural numbers bounded by LTE\n> LTEB : Nat -> Type\n> LTEB b = Sigma Nat (\\ n => LTE n b)\n", "meta": {"hexsha": "a7186cd7146165b7354b677c5470472309fce26c", "size": 289, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "BoundedNat/BoundedNat.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "BoundedNat/BoundedNat.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BoundedNat/BoundedNat.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.0, "max_line_length": 38, "alphanum_fraction": 0.6228373702, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6920132771934294}} {"text": "\n||| The cardinal directions\ndata Direction = North\n | East\n | South\n | West\n\ntotal turn : Direction -> Direction\nturn North = East\nturn East = South\nturn South = West\nturn West = North\n\n||| A Shape\ndata Shape = ||| A triangle\n Triangle Double Double\n | ||| A rectangle\n Rectangle Double Double\n | ||| A circle\n Circle Double\n\ntotal area : Shape -> Double\narea (Triangle x y) = 0.5 * x * y\narea (Rectangle x y) = x * y\narea (Circle x) = pi * x * x\n\n||| A shape defined as a type function\ndata Shape' : Type where\n Triangle' : Double -> Double -> Shape'\n Rectangle' : Double -> Double -> Shape'\n Circle' : Double -> Shape'\n\ndata Nat = Z | S Nat\n\ndata Picture = Primitive Shape\n | Combine Picture Picture\n | Rotate Double Picture\n | Translate Double Double Picture\n\n", "meta": {"hexsha": "45a55a4b3c8d2ffdf9f6ab261df7fd4045fbd1b5", "size": 901, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/4-UserDefinedDataTypes.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/4-UserDefinedDataTypes.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/4-UserDefinedDataTypes.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": 22.525, "max_line_length": 46, "alphanum_fraction": 0.5704772475, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.691438981143721}} {"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\nelem : Eq a => (value : a) -> (xs : Vect n a) -> Bool\nelem value [] = False\nelem value (x :: xs) = case value == x of\n False => elem value xs\n True => True\n", "meta": {"hexsha": "81a3192a5621624d645b67d1fa64345500101542", "size": 335, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter09/ElemBool.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": "Chapter9/ElemBool.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": "Chapter9/ElemBool.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.9166666667, "max_line_length": 53, "alphanum_fraction": 0.4417910448, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6914368371828508}} {"text": "\n\ncheckEqNat : (num1 : Nat) -> (num2 : Nat) -> Maybe (num1 = num2)\ncheckEqNat 0 0 = Just Refl\ncheckEqNat 0 (S k) = Nothing\ncheckEqNat (S k) 0 = Nothing\ncheckEqNat (S k) (S j) = case checkEqNat k j of\n Nothing => Nothing\n Just prf => Just (cong S prf)\n\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nexactLength : {m : _} -> (len : Nat) -> (input : Vect m a) -> Maybe (Vect len a)\nexactLength len input = case checkEqNat m len of\n Nothing => Nothing\n Just prf => Just ?something\n", "meta": {"hexsha": "f57d4513e2fdac50da3045e5c4e702c4246dc729", "size": 648, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch8/ExactLength.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/ExactLength.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/ExactLength.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.4, "max_line_length": 80, "alphanum_fraction": 0.5015432099, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391558356, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6914368288406603}} {"text": "module xquant.Core.Spectrum\n\nimport public xquant.Core.Types\nimport public xquant.Core.NonZero\nimport Data.Matrix.Algebraic\n\n\n%default total\n\n\ndata SysType = Finite Nat | Infinite\n\n||| Spectrum – list of energies – for\n||| a finite-dimensional system\ndata FSpectrum : Nat -> Type where\n FSpect : Vect n Fl -> FSpectrum n\n\n||| Finite system degeneracy, i.e.,\n||| state multiplicity by energy level\ndata FDegen : Nat -> Type where\n FDeg : {v : Vect n Nat} -> NVect v -> FDegen n\n\nsize : FDegen n -> Nat\nsize (FDeg {v} _) = sum v\n\nrep : FDegen n -> Type\nrep fd = StateSpace (size fd) Amp\n\ndata FSystem : Nat -> Type where\n FSys : (fd : FDegen n) ->\n FSpectrum n ->\n rep fd ->\n FSystem n\n\n||| Infinite system spectrum\ndata ISpectrum = ISpect (Nat -> Fl)\n\n||| Infinite system degeneracy\n||| (state multiplicity by energy level)\ndata IDegen : Type where\n IDeg : (Nat -> NonZ) -> IDegen\n", "meta": {"hexsha": "d6d701175a14f0d5374a2728300bd7657a322c7f", "size": 908, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/xquant/Core/Spectrum.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/Core/Spectrum.idr", "max_issues_repo_name": "fieldstrength/xquant", "max_issues_repo_head_hexsha": "b94d87609aa63af2d88b6cca50f85b58a00fc92f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/xquant/Core/Spectrum.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": 21.619047619, "max_line_length": 48, "alphanum_fraction": 0.6662995595, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6911513325621574}} {"text": "module VecSort\n\nimport Data.Vect\n\ninsertElement : Ord elem => (x : elem) -> (xsSorted : Vect len elem) -> Vect (S len) elem\ninsertElement x [] = [x]\ninsertElement x (y :: ys) = case x < y of\n False => y :: insertElement x ys \n True => x :: y :: ys\n\ninsSort : Ord elem => Vect n elem -> Vect n elem\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insertElement x xsSorted\n\n\n-- Exercises\nmy_length : List a -> Nat\nmy_length [] = 0\nmy_length (x :: xs) = S (my_length xs)\n\nmy_reverse : List a -> List a\nmy_reverse [] = []\nmy_reverse (x :: xs) = my_reverse xs ++ [x]\n\nmy_map : (a -> b) -> List a -> List b\nmy_map f [] = []\nmy_map f (x :: xs) = f x :: my_map f xs\n\nmy_map2 : (a -> b) -> Vect n a -> Vect n b -- why doesn't this overload?\nmy_map2 f [] = []\n--my_map2 f (x :: xs) = ?my_map2_rhs_2 -- o to search and...\nmy_map2 f (x :: xs) = f x :: my_map2 f xs -- BOOM!\n", "meta": {"hexsha": "e8104aae2ff92d773bacdb74b6ecee719250e663", "size": 978, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "VecSort.idr", "max_stars_repo_name": "neduard/type-driven-development", "max_stars_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "VecSort.idr", "max_issues_repo_name": "neduard/type-driven-development", "max_issues_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "VecSort.idr", "max_forks_repo_name": "neduard/type-driven-development", "max_forks_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7647058824, "max_line_length": 89, "alphanum_fraction": 0.5388548057, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6908320730488363}} {"text": "module xquant.Spinor.Gamma\n\nimport xquant.Core.Types\nimport public Data.Matrix.Algebraic\nimport public Control.Algebra.NumericInstances\nimport public Data.Complex\n\n%default total\n\n-- Begin with two primative Gamma matrices, Γ0 and Γ1, generating Spin(2)\n\n||| Γ0 = iσy\ng0 : Matrix 2 2 (Complex Integer)\ng0 = [[c0, c1], [m1, c0]]\n\n||| Γ1 = σx\ng1 : Matrix 2 2 (Complex Integer)\ng1 = [[c0, c1], [c1, c0]]\n\n{- Construct gammas for even-dimensional spinor representations (D = 2k + 2)\n First tensor as follows:\n\n G^μ = Γ^mu <&> diag(-1,1), (where mu <- [0..D-2]) or equivalently,\n G^μ = Γ^mu <&> (g1 <> g0)\n\n Then adding two new gammas:\n\n G^{D-1} = Id <&> Γ1 = Id ⊗ σx\n G^D = Id <&> -iΓ0 = Id ⊗ σy -}\n\n||| Gamma matrices for even dimensions D = 2k + 2, with size 2^(k+1)\ngammaEven : (k : Nat) -> Vect (k*2 + 2) $ Matrix (power 2 (S k)) (power 2 (S k)) (Complex Integer)\ngammaEven Z = [g0, g1]\ngammaEven (S k) ?= {Lemma_1} map (\\g => g <&> (g1 <> g0)) (gammaEven k) ++ [Id <&> g1, mi <#> Id <&> g0]\n\n{- Matrices defined in this way satisy the gamma matrix algebra:\n\n {Γμ,Γν} = 2 η{μν} Id (upstairs indices)\n\n They also furnish Poincaré generators Σ^{μν} = −i[Γ^μ,Γ^ν]\n satisfying, by definition: i[Σμν,Σσρ] = ηνσΣμρ + ημρΣνσ − ηνρΣμσ − ημσΣνρ\n\n This holds in any dimensionality and in both Minkowski and Euclidean signatures.\n\n Now define the \"fifth Gamma Matrix\", denoted Γ -}\n\n||| The \"fifth gamma matrix\" given by\n|||\n||| Γ = i^{–k} (Γ^0 ... Γ^{D-1})\n|||\n||| forms an odd-dimensional (irriducible) spinor representation by adding to the appropriate (gammaEven k)\ngamma : Vect (k*2+2) $ Matrix (power 2 $ S k) (power 2 $ S k) (Complex Integer) ->\n Matrix (power 2 $ S k) (power 2 $ S k) (Complex Integer)\ngamma {k} gs = (pow' mi k) <#> (product' gs)\n\n{- Γ has eigenvalues of ±1 and satisfies:\n\n Γ^2 = 1\n {Γ,Γ^μ} = 0\n [Γ,Σ^{μν}] = 0 -}\n\ng3 : Matrix 2 2 (Complex Integer)\ng3 = product' $ with List [g0,g1]\n\n{-\n||| Anticommutation relation, {Γμ,Γν} = 2 η{μν} Id, for D = 2\nD2_anticommRelation_00 : (g0 >><< g0) = ((-2 :+ 0) <#> Id)\nD2_anticommRelation_00 = Refl\n\n||| Anticommutation relation, {Γμ,Γν} = 2 η{μν} Id, for D = 2\nD2_anticommRelation_01 : g0 >><< g1 = [neutral, neutral]\nD2_anticommRelation_01 = Refl\n\n||| Anticommutation relation, {Γμ,Γν} = 2 η{μν} Id, for D = 2\nD2_anticommRelation_10 : g1 >><< g0 = [neutral, neutral]\nD2_anticommRelation_10 = Refl\n\n||| Anticommutation relation, {Γμ,Γν} = 2 η{μν} Id, for D = 2\nD2_anticommRelation_11 : g1 >><< g1 = (2 :+ 0) <#> Id\nD2_anticommRelation_11 = Refl\n-}\n\n---------- Proofs ----------\n\nmultTwoRightPlusTimesOne : (n : Nat) -> mult n 2 = n + (mult n 1)\nmultTwoRightPlusTimesOne = proof\n intros\n rewrite (multRightSuccPlus n (S Z))\n trivial\n\nmultTwoRightPlus : (n : Nat) -> n * 2 = plus n n\nmultTwoRightPlus = proof\n intros\n rewrite (sym $ multTwoRightPlusTimesOne n)\n rewrite (sym $ multOneRightNeutral n)\n trivial\n\nplusPlusZero : (x,y : Nat) -> x + y = x + (y + 0)\nplusPlusZero = proof\n intros\n rewrite (sym $ plusZeroRightNeutral y)\n trivial\n\nLemma_1 = proof\n intros\n rewrite (plusZeroRightNeutral (plus (mult k 2) 2))\n rewrite (sym $ plusSuccRightSucc (plus (mult k 2) 2) 0)\n rewrite (sym $ plusSuccRightSucc (plus (mult k 2) 2) 1)\n rewrite (sym $ plusZeroRightNeutral (power 2 k))\n rewrite (sym $ plusZeroRightNeutral (power 2 k + (power 2 k)))\n rewrite (multTwoRightPlus (plus (power 2 k) (power 2 k)))\n rewrite (sym $ plusPlusZero (power 2 k) (power 2 k))\n trivial\n", "meta": {"hexsha": "b09f5df329c6e37801a0f5b06283134184f4213d", "size": 3526, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/xquant/Spinor/Gamma.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/Gamma.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/Gamma.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": 30.9298245614, "max_line_length": 107, "alphanum_fraction": 0.6301758366, "num_tokens": 1387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6907086821180407}} {"text": "module Data.InSet\n\nimport Data.Bool\nimport Data.Bool.Xor\n\nimport public Data.InSet.Equality\n\nimport Decidable.Equality\n\n%default total\n\n---------------------\n---------------------\n--- ---\n--- DEFINITIONS ---\n--- ---\n---------------------\n---------------------\n\ninfix 6 ==\ninfix 7 `isin`, `notin`\ninfixl 8 +, -, ^\ninfixl 9 *, #\n\n-------------------\n--- Type itself ---\n-------------------\n\npublic export\nInSet : Type -> Type\nInSet a = a -> Bool\n\n-- TODO To think, maybe equality relation should be shown in the `InSet` type as a parameter?\n-- However, if this is only in the append operation, this gives an ability to union sets with different equalities.\n\n------------------------------------\n--- Intesional test of existence ---\n------------------------------------\n\nexport\nisin : a -> InSet a -> Bool\nisin = flip apply\n\npublic export %inline\nnotin : a -> InSet a -> Bool\nnotin x y = not $ isin x y\n\n----------------\n--- Creation ---\n----------------\n\n--- Syntax for list-like literals ---\n\npublic export\nNil : InSet a\nNil _ = False\n\npublic export\n(::) : Equality a => a -> InSet a -> InSet a\n(::) added parent x = if x =?= added then True else x `isin` parent\n\n--- Constants\n\npublic export %inline\nEmpty : InSet a\nEmpty = []\n\npublic export\nUniverse : InSet a\nUniverse _ = True\n\n---------------------------\n--- Basic set relations ---\n---------------------------\n\npublic export\n(==) : InSet a -> InSet a -> Type\nsa == sb = (x : a) -> x `isin` sa = x `isin` sb\n\npublic export\n(<=) : InSet a -> InSet a -> Type\nsa <= sb = (x : a) -> x `isin` sa = True -> x `isin` sb = True\n\npublic export\nNotEmpty : {a : Type} -> InSet a -> Type\nNotEmpty s = (x ** x `isin` s = True)\n\n----------------------------\n--- Basic set operations ---\n----------------------------\n\nexport\n(+) : InSet a -> InSet a -> InSet a -- union\n(+) sa sb x = x `isin` sa || x `isin` sb\n\nexport\n(#) : InSet a -> InSet a -> InSet a -- intersection\n(#) sa sb x = x `isin` sa && x `isin` sb\n\nexport\n(-) : InSet a -> InSet a -> InSet a -- set difference\n(-) sa sb x = x `isin` sa && x `notin` sb\n\nexport\n(^) : InSet a -> InSet a -> InSet a -- symmetrical difference\n(^) sa sb x = (x `isin` sa) `xor` (x `isin` sb)\n\nexport %inline\ncomplement : InSet a -> InSet a\ncomplement s x = x `notin` s\n\n------------------------------------\n--- Non-algebraic set operations ---\n------------------------------------\n\nexport\n(*) : InSet a -> InSet b -> InSet (a, b)\n(*) sx sy (x, y) = x `isin` sx && y `isin` sy\n\n--------------\n--------------\n--- ---\n--- LAWS ---\n--- ---\n--------------\n--------------\n\n------------------------\n--- Laws of equality ---\n------------------------\n\nexport\neq_reflexivity : (0 s : InSet a) -> s == s\neq_reflexivity _ _ = Refl\n\nexport\neq_symmerty : {0 sa, sb : InSet a} -> (0 _ : sa == sb) -> sb == sa\neq_symmerty f x = rewrite f x in Refl\n\nexport\neq_transitivity : {0 sa, sb, sc : InSet a} -> (0 _ : sa == sb) -> (0 _ : sb == sc) -> sa == sc\neq_transitivity f g x = rewrite f x in\n rewrite g x in\n Refl\n\n-- Definition above can be written as\n-- sa <= sb = (x : a) -> So (x `isin` sa) -> So (x `isin` sb)\n-- but this leads to constant using `soToEq` and `eqToSo` in proofs.\n\n--- Negative equality-related laws ---\n\ntrueNotFalse : Not (True = False)\ntrueNotFalse Refl impossible\n\nexport\nnon_empty_is_not_empty : NotEmpty s -> Not (s = Empty)\nnon_empty_is_not_empty (x ** prf_t) prf_f = trueNotFalse $ rewrite sym prf_t in rewrite prf_f in Refl\n\nexport\nnon_empty_not_eq_empty : NotEmpty s -> Not (s == Empty)\nnon_empty_not_eq_empty (x ** prf_t) prf_f = trueNotFalse $ rewrite sym prf_t in rewrite prf_f x in Refl\n\nexport\ncant_in_and_not_in : (s : InSet a) -> (x : a) -> Not (x `isin` s = x `notin` s)\ncant_in_and_not_in s x prf with (s x)\n cant_in_and_not_in _ _ Refl | True impossible\n\n-------------------------------\n--- Laws of subset relation ---\n-------------------------------\n\n--- Order laws of subset relation ---\n\nexport\nsubset_equal : {0 sa, sb : InSet a} -> (0 _ : sa == sb) -> sa <= sb\nsubset_equal f x prf = rewrite sym $ f x in\n rewrite prf in\n Refl\n\nexport\nsubset_reflexivity : (0 s : InSet a) -> s <= s\nsubset_reflexivity _ _ = id\n\nexport\nsubset_antisymmetry : {sa, sb : InSet a} -> sa <= sb -> sb <= sa -> sa == sb\nsubset_antisymmetry f g x with (decEq (sa x) True)\n subset_antisymmetry f _ x | Yes pa with (decEq (sb x) True)\n subset_antisymmetry _ _ _ | Yes pa | Yes pb = rewrite pa in\n rewrite pb in\n Refl\n subset_antisymmetry f _ x | Yes pa | No nb = absurd . nb $ f x pa\n subset_antisymmetry _ g x | No pa with (decEq (sb x) True)\n subset_antisymmetry _ _ _ | No na | No nb = rewrite notTrueIsFalse na in\n rewrite notTrueIsFalse nb in\n Refl\n subset_antisymmetry _ g x | No na | Yes pb = absurd . na $ g x pb\n\nexport\nsubset_transitivity : {0 sa, sb, sc : InSet a} -> (0 _ : sa <= sb) -> (0 _ : sb <= sc) -> sa <= sc\nsubset_transitivity f g x y = rewrite g x (f x y) in Refl\n\n-- Subset relation's totality seems to be unprovable for intensional sets neither in\n-- `Either (sa <= sb) (sb <= sa)`, nor in `Not $ sa <= sb => sb <= sa` variant.\n\n--- Alternative subset representations with unions and intersections ---\n\nexport\nsubset_thru_union : {sa, sb : InSet a} -> (0 _ : sa <= sb) -> sa + sb == sb\nsubset_thru_union f x with (decEq (sa x) True)\n subset_thru_union f x | Yes pa = rewrite pa in\n rewrite f x pa in\n Refl\n subset_thru_union _ _ | No na = rewrite notTrueIsFalse na in Refl\n\nexport\nunion_thru_subset : {0 sa, sb : InSet a} -> (0 _ : sa + sb == sb) -> sa <= sb\nunion_thru_subset f x y = rewrite sym $ f x in\n rewrite y in\n Refl\n\nexport\nsubset_thru_intersection : {sa, sb : InSet a} -> (0 _ : sa <= sb) -> sa # sb == sa\nsubset_thru_intersection f x with (decEq (sa x) True)\n subset_thru_intersection f x | Yes pa = rewrite pa in\n rewrite f x pa in\n Refl\n subset_thru_intersection _ _ | No na = rewrite notTrueIsFalse na in Refl\n\nexport\nintersection_thru_subset : {0 sa, sb : InSet a} -> (0 _ : sa # sb == sa) -> sa <= sb\nintersection_thru_subset f x pa = rewrite sym pa in\n rewrite sym $ f x in\n rewrite pa in\n Refl\n\n--- Subset with binary set operations ---\n\nexport\nsubset_for_unioned_right : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa <= sb) -> sa <= sb + sc\nsubset_for_unioned_right sc f x prf = rewrite f x prf in Refl\n\nand_true_left_true : (a, b : Bool) -> a && b = True -> a = True\nand_true_left_true True _ _ = Refl\n\nexport\nsubset_for_intersected_left : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa <= sb) -> (sa # sc) <= sb\nsubset_for_intersected_left sc f x prf = rewrite f x $ and_true_left_true (sa x) (sc x) prf in Refl\n\nexport\nsubset_for_diffed_left : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa <= sb) -> (sa - sc) <= sb\nsubset_for_diffed_left sc f x prf = rewrite f x $ and_true_left_true (sa x) (x `notin` sc) prf in Refl\n\n-- Particular cases for the properties from above, where `sb = sa`\n\nexport\nsubset_refl_unioned_right : (0 sa, sc : InSet a) -> sa <= sa + sc\nsubset_refl_unioned_right sa sc = subset_for_unioned_right sc $ subset_reflexivity sa\n\nexport\nsubset_refl_intersected_left : (0 sa, sc : InSet a) -> (sa # sc) <= sa\nsubset_refl_intersected_left sa sc = subset_for_intersected_left sc $ subset_reflexivity sa\n\nexport\nsubset_refl_diffed_left : (0 sa, sc : InSet a) -> (sa - sc) <= sa\nsubset_refl_diffed_left sa sc = subset_for_diffed_left sc $ subset_reflexivity sa\n\n--- Subset with complement ---\n\nexport\nsubset_of_complements : {0 sa, sb : InSet a} -> (0 _ : sa <= sb) -> complement sb <= complement sa\nsubset_of_complements f x prf = rewrite sym $ subset_thru_intersection f x in\n rewrite the (sb x = False) $ rewrite sym $ notInvolutive $ sb x in cong not prf in\n rewrite andFalseFalse $ sa x in\n Refl\n\nexport\nsubset_of_complements_back : {0 sa, sb : InSet a} -> (0 _ : complement sb <= complement sa) -> sa <= sb\nsubset_of_complements_back f x prf = rewrite sym $ subset_of_complements f x (rewrite notInvolutive $ sa x in prf) in\n rewrite notInvolutive $ sb x in\n Refl\n\n--------------------------------------------------\n--- Congruence of relations in specializations ---\n--------------------------------------------------\n\n--- Append ---\n\nexport\nappend_eq_cong_l : Equality a => (0 s : InSet a) -> {0 n, m : a} -> (0 _ : n = m) -> n::s == m::s\nappend_eq_cong_l _ prf _ = rewrite prf in Refl\n\nexport\nappend_eq_cong_r : Equality a => {0 sa, sb : InSet a} -> (n : a) -> (0 _ : sa == sb) -> n::sa == n::sb\nappend_eq_cong_r n f x with (x =?= n)\n append_eq_cong_r _ _ _ | True = Refl\n append_eq_cong_r _ f x | False = rewrite f x in Refl\n\n--- Union ---\n\nexport\nunion_eq_cong_l : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa == sb) -> sa + sc == sb + sc\nunion_eq_cong_l _ f x = rewrite f x in Refl\n\nexport\nunion_eq_cong_r : {0 sa, sb : InSet a} -> (0 sc : InSet a) -> (0 _ : sa == sb) -> sc + sa == sc + sb\nunion_eq_cong_r _ f x = rewrite f x in Refl\n\n-- particular case for `append_eq_cong_l`\nexport\nunion_singleton_eq_cong_l : Equality a => (0 s : InSet a) -> {0 n, m : a} -> (0 _ : n = m) -> [n] + s == [m] + s\nunion_singleton_eq_cong_l _ prf x = rewrite append_eq_cong_l [] prf x in Refl\n\n-- TODO to add for subset\n\n--- Intersection ---\n\n-- TODO to add for equality\n\n-- TODO to add for subset\n\n--- Difference ---\n\n-- TODO to add for equality\n\n-- TODO to add for subset\n\n--- Symmetrical difference ---\n\n-- TODO to add for equality\n\n-- TODO to add for subset\n\n--- Complement ---\n\n-- TODO to add for equality\n\n-- TODO to add for subset\n\n--- Cartesian product ---\n\nexport\ncart_eq_cong_l : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa == sb) -> sc * sa == sc * sb\ncart_eq_cong_l _ f (_, y) = rewrite f y in Refl\n\nexport\ncart_eq_cong_r : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa == sb) -> sa * sc == sb * sc\ncart_eq_cong_r _ f (x, _) = rewrite f x in Refl\n\nand_true_then_left_true : (a : Bool) -> {b : Bool} -> a && b = True -> a = True\nand_true_then_left_true True {b=True} Refl = Refl\n\nand_true_then_right_true : {a : Bool} -> (b : Bool) -> a && b = True -> b = True\nand_true_then_right_true {a=True} True Refl = Refl\n\nexport\ncart_subset_cong_l : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa <= sb) -> sc * sa <= sc * sb\ncart_subset_cong_l sc f (y, x) prf = rewrite f x $ and_true_then_right_true _ prf in\n rewrite and_true_then_left_true (sc y) prf in\n Refl\n\nexport\ncart_subset_cong_r : {0 sa, sb : InSet a} -> (0 sc : InSet c) -> (0 _ : sa <= sb) -> sa * sc <= sb * sc\ncart_subset_cong_r sc f (x, y) prf = rewrite f x $ and_true_then_left_true _ prf in\n rewrite and_true_then_right_true (sc y) prf in\n Refl\n\n----------------------\n--- Laws of `isin` ---\n----------------------\n\nexport\nnot_in_empty : Equality a => (0 x : a) -> x `isin` [] = False\nnot_in_empty _ = Refl\n\nexport\nx_in_x_etc : Equality a => (0 x : a) -> (0 s : InSet a) -> x `isin` (x::s) = True\nx_in_x_etc x s = rewrite equ_reflexive x in Refl\n\nexport\nx_in_same_etc : Equality a => (0 x, y : a) -> (0 s : InSet a) -> (0 _ : x =?= y = True) -> x `isin` (y::s) = True\nx_in_same_etc _ _ _ prf = rewrite prf in Refl\n\nexport\nnot_x_not_in_x_etc : Equality a => (x, y : a) -> NeqPrf x y -> x `isin` [y] = False\nnot_x_not_in_x_etc x y neq = case @@(x =?= y) of\n (False ** prf) => rewrite prf in Refl\n (True ** prf) => absurd $ cant_eq_neq (eq_val_to_prf prf) neq\n\nexport\nnot_in_both : Equality a => (0 x, y : a) -> (0 ys : InSet a) -> (0 _ : x =?= y = False) -> (0 _ : x `isin` ys = False) -> x `isin` (y::ys) = False\nnot_in_both x y ys xy xys = rewrite xy in\n rewrite xys in\n Refl\n\nexport\nis_in_tail : Equality a => (0 x, y : a) -> (0 ys : InSet a) -> (0 _ : x =?= y = False) -> (0 _ : x `isin` (y::ys) = True) -> x `isin` ys = True\nis_in_tail _ _ _ xy xyys = rewrite sym xyys in\n rewrite xy in\n Refl\n\n----------------------\n--- Laws of append ---\n----------------------\n\nexport\nappend_is_union : Equality a => (n : a) -> (0 s : InSet a) -> n::s == [n] + s\nappend_is_union n _ x with (x =?= n)\n append_is_union _ _ _ | True = Refl\n append_is_union _ _ _ | False = Refl\n\n---------------------\n--- Laws of union ---\n---------------------\n\nexport\nunion_of_self : (0 s : InSet a) -> s + s == s\nunion_of_self s x = rewrite orSameNeutral $ s x in Refl\n\nexport\nunion_commutative : (0 sa, sb : InSet a) -> sa + sb == sb + sa\nunion_commutative sa sb x = rewrite orCommutative (sa x) (sb x) in Refl\n\nexport\nunion_associative : (0 sa, sb, sc : InSet a) -> sa + (sb + sc) == (sa + sb) + sc\nunion_associative sa sb sc x = rewrite orAssociative (sa x) (sb x) (sc x) in Refl\n\nexport\nunion_empty_neutral : (0 s : InSet a) -> s + [] == s\nunion_empty_neutral s x = rewrite orFalseNeutral $ s x in Refl\n\nexport\nunion_preserves_universe : (0 s : InSet a) -> s + Universe == Universe\nunion_preserves_universe s x = rewrite orTrueTrue $ s x in Refl\n\n-- ... with intersection\n\nexport\nunion_distributes_over_intersection : (0 sa, sb, sc : InSet a) -> sa + (sb # sc) == (sa + sb) # (sa + sc)\nunion_distributes_over_intersection sa sb sc x = rewrite orDistribAndR (sa x) (sb x) (sc x) in Refl\n\n-- ... with diff\n\nexport\nunion_with_diff : (0 sa, sb, sc : InSet a) -> sa + (sb - sc) == (sa + sb) - (sc - sa)\nunion_with_diff sa sb sc x = rewrite orDistribAndR (sa x) (sb x) (not $ sc x) in\n rewrite notAndIsOr (sc x) (not $ sa x) in\n rewrite notInvolutive $ sa x in\n rewrite orCommutative (sa x) (not $ sc x) in\n Refl\n\n-- ... with symdiff\n\n-- TODO To make this functon to have `(0 sa, sb : InSet a)` in the signature.\nexport\nunion_thru_symdiff_and_intersection : (sa, sb : InSet a) -> sa + sb == (sa ^ sb) ^ (sa # sb)\nunion_thru_symdiff_and_intersection sa sb x = case (decEq (sa x) True, decEq (sb x) True) of\n (Yes pa, Yes pb) => rewrite pa in rewrite pb in Refl\n (Yes pa, No nb) => rewrite pa in rewrite notTrueIsFalse nb in Refl\n (No na, Yes pb) => rewrite notTrueIsFalse na in rewrite pb in Refl\n (No na, No nb) => rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl\n\n-- ... with complement\n\nexport\nunion_with_its_complement : (0 s : InSet a) -> s + complement s == Universe\nunion_with_its_complement s x = rewrite orNotTrue $ s x in Refl\n\n----------------------------\n--- Laws of intersection ---\n----------------------------\n\nexport\nintersection_of_self : (0 s : InSet a) -> s # s == s\nintersection_of_self s x = rewrite andSameNeutral $ s x in Refl\n\nexport\nintersection_commutative : (0 sa, sb : InSet a) -> sa # sb == sb # sa\nintersection_commutative sa sb x = rewrite andCommutative (sa x) (sb x) in Refl\n\nexport\nintersection_associative : (0 sa, sb, sc : InSet a) -> sa # (sb # sc) == (sa # sb) # sc\nintersection_associative sa sb sc x = rewrite andAssociative (sa x) (sb x) (sc x) in Refl\n\nexport\nintersection_universe_neutral : (0 s : InSet a) -> s # Universe == s\nintersection_universe_neutral s x = rewrite andTrueNeutral $ s x in Refl\n\nexport\nintersection_preserves_empty : (0 s : InSet a) -> s # [] == []\nintersection_preserves_empty s x = rewrite andFalseFalse $ s x in Refl\n\n-- ... with union\n\nexport\nintersection_distributes_over_union : (0 sa, sb, sc : InSet a) -> sa # (sb + sc) == (sa # sb) + (sa # sc)\nintersection_distributes_over_union sa sb sc x = rewrite andDistribOrR (sa x) (sb x) (sc x) in Refl\n\n-- ... with set diff\n\nexport\nintersection_diff_swap : (0 sa, sb, sc : InSet a) -> sa # (sb - sc) == sb # (sa - sc)\nintersection_diff_swap sa sb sc x = rewrite andAssociative (sa x) (sb x) (not $ sc x) in\n rewrite andAssociative (sb x) (sa x) (not $ sc x) in\n rewrite andCommutative (sa x) (sb x) in\n Refl\n\nexport\nintersection_diff_assoc : (0 sa, sb, sc : InSet a) -> sa # (sb - sc) == (sa # sb) - sc\nintersection_diff_assoc sa sb sc x = rewrite sym $ andAssociative (sa x) (sb x) (not $ sc x) in Refl\n\n-- ... with symmetrical diff\n\n-- TODO To make this functon to have `(0 sa, sb, sc : InSet a)` in the signature.\nexport\nintersection_distributes_over_symdiff : (sa, sb, sc : InSet a) -> sa # (sb ^ sc) == (sa # sb) ^ (sa # sc)\nintersection_distributes_over_symdiff sa sb sc x = case decEq (sa x) True of\n Yes pa => rewrite pa in Refl\n No na => rewrite notTrueIsFalse na in Refl\n\n-- ... with complement\n\nexport\nintersection_with_complement : (0 sa, sb : InSet a) -> sa # complement sb == sa - sb\nintersection_with_complement _ _ _ = Refl\n\nexport\nintersection_with_its_complement : (0 s : InSet a) -> s # complement s == []\nintersection_with_its_complement s x = rewrite andNotFalse $ s x in Refl\n\n------------------------------\n--- Laws of set difference ---\n------------------------------\n\nexport\ndiff_of_intersection : (0 sa, sb, sc : InSet a) -> sc - (sa # sb) == (sc - sa) + (sc - sb)\ndiff_of_intersection sa sb sc x = rewrite notAndIsOr (sa x) (sb x) in\n rewrite andDistribOrR (sc x) (not $ sa x) (not $ sb x) in\n Refl\n\nexport\ndiff_of_union : (0 sa, sb, sc : InSet a) -> sc - (sa + sb) == (sc - sa) # (sc - sb)\ndiff_of_union sa sb sc x = rewrite notOrIsAnd (sa x) (sb x) in\n rewrite andAssociative (sc x && not (sa x)) (sc x) (not $ sb x) in\n rewrite sym $ andAssociative (sc x) (not $ sa x) (sc x) in\n rewrite andCommutative (not $ sa x) (sc x) in\n rewrite andAssociative (sc x) (sc x) (not $ sa x) in\n rewrite andSameNeutral $ sc x in\n rewrite andAssociative (sc x) (not $ sa x) (not $ sb x) in\n Refl\n\nexport\ndiff_of_diff : (0 sa, sb, sc : InSet a) -> sc - (sb - sa) == (sc # sa) + (sc - sb)\ndiff_of_diff sa sb sc x = rewrite notAndIsOr (sb x) (not $ sa x) in\n rewrite notInvolutive $ sa x in\n rewrite orCommutative (not $ sb x) (sa x) in\n rewrite andDistribOrR (sc x) (sa x) (not $ sb x) in\n Refl\n\nexport\ndiff_of_self : (0 s : InSet a) -> s - s == []\ndiff_of_self s x = rewrite andNotFalse $ s x in Refl\n\nexport\ndiff_of_empty_left : (0 s : InSet a) -> [] - s == []\ndiff_of_empty_left _ _ = Refl\n\nexport\ndiff_of_empty_right : (0 s : InSet a) -> s - [] == s\ndiff_of_empty_right s x = rewrite andTrueNeutral $ s x in Refl\n\nexport\ndiff_of_universe : (0 s : InSet a) -> s - Universe == []\ndiff_of_universe s x = rewrite andFalseFalse $ s x in Refl\n\nexport\ndiff_of_complements : (0 sa, sb : InSet a) -> complement sa - complement sb == sb - sa\ndiff_of_complements sa sb x = rewrite andCommutative (sb x) (not $ sa x) in\n rewrite notInvolutive $ sb x in\n Refl\n\n--------------------------------------\n--- Laws of symmetrical difference ---\n--------------------------------------\n\n-- TODO To make this functon to have `(0 sa, sb : InSet a)` in the signature.\nexport\nsymdiff_as_union_of_diffs : (sa, sb : InSet a) -> sa ^ sb == (sa - sb) + (sb - sa)\nsymdiff_as_union_of_diffs sa sb x = case (decEq (sa x) True, decEq (sb x) True) of\n (Yes pa, Yes pb) => rewrite pa in rewrite pb in Refl\n (Yes pa, No nb) => rewrite pa in rewrite notTrueIsFalse nb in Refl\n (No na, Yes pb) => rewrite notTrueIsFalse na in rewrite pb in Refl\n (No na, No nb) => rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl\n\n-- TODO To make this functon to have `(0 sa, sb : InSet a)` in the signature.\nexport\nsymdiff_as_diff_of_ui : (sa, sb : InSet a) -> sa ^ sb == (sa + sb) - (sa # sb)\nsymdiff_as_diff_of_ui sa sb x = case (decEq (sa x) True, decEq (sb x) True) of\n (Yes pa, Yes pb) => rewrite pa in rewrite pb in Refl\n (Yes pa, No nb) => rewrite pa in rewrite notTrueIsFalse nb in Refl\n (No na, Yes pb) => rewrite notTrueIsFalse na in rewrite pb in Refl\n (No na, No nb) => rewrite notTrueIsFalse na in rewrite notTrueIsFalse nb in Refl\n\nexport\nsymdiff_commutative : (0 sa, sb : InSet a) -> sa ^ sb == sb ^ sa\nsymdiff_commutative sa sb x = rewrite xorCommutative (sa x) (sb x) in Refl\n\nexport\nsymdiff_associative : (0 sa, sb, sc : InSet a) -> sa ^ (sb ^ sc) == (sa ^ sb) ^ sc\nsymdiff_associative sa sb sc x = rewrite xorAssociative (sa x) (sb x) (sc x) in Refl\n\nexport\nsymdiff_with_empty : (0 s : InSet a) -> s ^ [] == s\nsymdiff_with_empty s x = rewrite xorCommutative (s x) False in\n rewrite xorFalseNeutral $ s x in\n Refl\n\nexport\nsymdiff_with_self : (0 s : InSet a) -> s ^ s == []\nsymdiff_with_self s x = rewrite xorSameFalse $ s x in Refl\n\n-- TODO To make this functon to have `(0 sa, sb, sc : InSet a)` in the signature.\nexport\nsymdiff_twice_negates : (sa, sb, sc : InSet a) -> (sa ^ sb) ^ (sb ^ sc) == sa ^ sc\nsymdiff_twice_negates sa sb sc x = rewrite xorCommutative (sa x) (sb x) in\n case decEq (sb x) True of\n Yes pb => rewrite pb in\n rewrite xorTrueNot $ sa x in\n rewrite xorTrueNot $ sc x in\n rewrite notXorCancel (sa x) (sc x) in\n Refl\n No nb => rewrite notTrueIsFalse nb in\n rewrite xorFalseNeutral $ sa x in\n rewrite xorFalseNeutral $ sc x in\n Refl\n\nexport\nsymdiff_of_complements : (0 sa, sb : InSet a) -> sa ^ sb == complement sa ^ complement sb\nsymdiff_of_complements sa sb x = rewrite notXorCancel (sa x) (sb x) in Refl\n\n--------------------------\n--- Laws of complement ---\n--------------------------\n\nexport\ncomp_of_union : (0 sa, sb : InSet a) -> complement (sa + sb) == complement sa # complement sb\ncomp_of_union sa sb x = rewrite notOrIsAnd (sa x) (sb x) in Refl\n\nexport\ncomp_of_intersection : (0 sa, sb : InSet a) -> complement (sa # sb) == complement sa + complement sb\ncomp_of_intersection sa sb x = rewrite notAndIsOr (sa x) (sb x) in Refl\n\nexport\ncomp_of_empty : complement [] == Universe\ncomp_of_empty _ = Refl\n\nexport\ncomp_of_universe : complement Universe == []\ncomp_of_universe _ = Refl\n\nexport\ncomp_involutive : (0 s : InSet a) -> complement (complement s) == s\ncomp_involutive s x = rewrite notInvolutive $ s x in Refl\n\nexport\ncomp_of_diff : (0 sa, sb : InSet a) -> complement (sa - sb) == complement sa + sb\ncomp_of_diff sa sb x = rewrite notAndIsOr (sa x) (not $ sb x) in\n rewrite notInvolutive $ sb x in\n Refl\n\n---------------------------------\n--- Laws of cartesian product ---\n---------------------------------\n\n--- Operations over cartesian products at both sides:\n\nexport\nintersection_of_carts : (0 sa, sb : InSet a) -> (0 sc, sd : InSet c) -> (sa * sc) # (sb * sd) == (sa # sb) * (sc # sd)\nintersection_of_carts sa sb sc sd (x, y) = rewrite sym $ andAssociative (sa x) (sc y) (sb x && sd y) in\n rewrite sym $ andAssociative (sa x) (sb x) (sc y && sd y) in\n rewrite andAssociative (sc y) (sb x) (sd y) in\n rewrite andAssociative (sb x) (sc y) (sd y) in\n rewrite andCommutative (sb x) (sc y) in\n Refl\n\nexport\ndiff_of_carts : (0 sa, sb : InSet a) -> (0 sc, sd : InSet c) -> (sa * sc) - (sb * sd) == sa * (sc - sd) + (sa - sb) * sc\n\nexport\nunion_of_carts : (0 sa, sb : InSet a) -> (0 sc, sd : InSet c) -> (sa * sc) + (sb * sd) == ((sa - sb) * sc) # ((sa # sb) * (sc + sd)) # ((sb - sa) * sd)\n\n--- Distributivity:\n\nexport\ncart_distributes_over_intersection : (0 sa : InSet a) -> (0 sb, sc : InSet b) -> sa * (sb # sc) == (sa * sb) # (sa * sc)\ncart_distributes_over_intersection sa sb sc (x, y) = rewrite sym $ andAssociative (sa x) (sb y) (sa x && sc y) in\n rewrite andAssociative (sb y) (sa x) (sc y) in\n rewrite andCommutative (sb y) (sa x) in\n rewrite sym $ andAssociative (sa x) (sb y) (sc y) in\n rewrite andAssociative (sa x) (sa x) (sb y && sc y) in\n rewrite andSameNeutral (sa x) in\n Refl\n\nexport\ncart_distributes_over_union : (0 sa : InSet a) -> (0 sb, sc : InSet b) -> sa * (sb + sc) == (sa * sb) + (sa * sc)\n\nexport\ncart_distributes_over_diff : (0 sa : InSet a) -> (0 sb, sc : InSet b) -> sa * (sb - sc) == (sa * sb) - (sa * sc)\n\nexport\ncomplement_of_cart : (0 sa : InSet a) -> (0 sb : InSet b) -> complement (sa * sb) = (complement sa * complement sb) + (complement sa * sb) + (sa * complement sb)\n\n--- Cartesian products with relations\n\nexport\nsubset_of_carts_drops_l : {0 sa, sb : InSet a} -> {0 sc, sd : InSet c} -> (0 _ : NotEmpty sa) -> (0 _ : NotEmpty sc) ->\n (0 _ : (sa * sc) <= (sb * sd)) -> sa <= sb\n\nexport\nsubset_of_carts_drops_r : {0 sa, sb : InSet a} -> {0 sc, sd : InSet c} -> (0 _ : NotEmpty sa) -> (0 _ : NotEmpty sc) ->\n (0 _ : (sa * sc) <= (sb * sd)) -> sc <= sd\n\nexport\ncart_of_subsets : {0 sa, sb : InSet a} -> {0 sc, sd : InSet c} -> (0 _ : sa <= sb) -> (0 _ : sc <= sd) -> (sa * sc) <= (sb * sd)\n", "meta": {"hexsha": "063e142b8442b439b10e9cf9a88806f720ec7d4e", "size": 26730, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/InSet.idr", "max_stars_repo_name": "buzden/prog-prove-exercises", "max_stars_repo_head_hexsha": "053fb3d07e09c4b2e70a66ca33aa61ec46ff1254", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data/InSet.idr", "max_issues_repo_name": "buzden/prog-prove-exercises", "max_issues_repo_head_hexsha": "053fb3d07e09c4b2e70a66ca33aa61ec46ff1254", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Data/InSet.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": 36.9198895028, "max_line_length": 161, "alphanum_fraction": 0.5471380471, "num_tokens": 7817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401363, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.6907041025221152}} {"text": "import Data.Vect\n\n-- Exercise 1\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\n{-\ntransposeHelper : (x : Vect n elem)\n -> (xTrans : Vect n (Vect k elem))\n -> Vect n (Vect (S k) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n-}\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xTrans = transposeMat xs in\n zipWith (::) x xTrans\n\n-- Exercise 2\naddMatrix : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (+) x y :: addMatrix xs ys\n\naddMatrix' : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\naddMatrix' mat1 mat2 = zipWith (zipWith (+)) mat1 mat2\n\n(+) : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\n(+) = addMatrix\n\n-- Exercise 3\nmultVecs : Num a => (xs : Vect n a) -> (ys : Vect n a) -> a\nmultVecs xs ys = sum (zipWith (*) xs ys)\n\nmakeRow : Num a => (x : Vect n a)\n -> (ysTrans : Vect p (Vect n a))\n -> Vect p a\nmakeRow x [] = []\nmakeRow x (y :: xs) = multVecs x y :: makeRow x xs\n\nmultMatrixHelper : Num a => (xs : Vect m (Vect n a))\n -> (ysTrans : Vect p (Vect n a))\n -> Vect m (Vect p a)\nmultMatrixHelper [] ysTrans = []\nmultMatrixHelper (x :: xs) ysTrans\n = makeRow x ysTrans :: multMatrixHelper xs ysTrans\n\nmultMatrix : Num a => Vect m (Vect n a)\n -> Vect n (Vect p a)\n -> Vect m (Vect p a)\nmultMatrix xs ys = let ysTrans = transposeMat ys\n in multMatrixHelper xs ysTrans\n", "meta": {"hexsha": "244749c6ecc5bfd5dc77f7ced00d53eaab85eef9", "size": 1750, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter03/Exercises/ex_3_3.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 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_3.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_3.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": 33.0188679245, "max_line_length": 81, "alphanum_fraction": 0.5422857143, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6906104349703587}} {"text": "import Data.Vect\n\n-- Defining functions by pattern matching\ninvert : Bool -> Bool\ninvert True = False\ninvert False = True\n\ndescribeList : List Int -> String\ndescribeList [] = \"Empty\"\ndescribeList (x :: xs) = \"Non-empty, tail = \" ++ show xs\n\n-- Given just the type declaration below, can use Ctrl-Alt-A in Atom to add a\n-- definition.\nallLengths_list : List String -> List Nat\n-- allLengths_list list = ?rhs -- put the cursor on list and do ctrl-alt-c in\n-- Atom to expand the cases as below:\n-- allLengths_list [] = ?rhs_1\n-- allLengths_list (x :: xs) = ?rhs_2\nallLengths_list [] = []\nallLengths_list (x :: xs) = length x :: allLengths_list xs\n-- Check if allLengths_list is total\n-- :total allLengths_list -> Main.allLengths_list is Total\n\nallLengths : Vect len String -> Vect len Nat\nallLengths [] = []\nallLengths (word :: words) = 0 :: allLengths words\n\n-- :doc List pulls up the documentation for List.\n-- In Atom, ctrl-alt-D\n\n-- Data types are defined in terms of their constructors, a bit like Java enum\n-- members but often with parameters.\n\n-- mutual lets you define functions that call each other, otherwise Idris\n-- requires everything to be top-down.\n\nmutual\n isEven : Nat -> Bool\n isEven Z = True\n isEven (S k) = not $ isOdd k\n\n isOdd : Nat -> Bool\n isOdd Z = False\n isOdd (S k) = not $ isEven k\n\nfourInts : Vect 4 Int\nfourInts = [0, 1, 2, 3]\n\nsixInts : Vect 6 Int\nsixInts = [4, 5, 6, 7, 8, 9]\n\ntenInts : Vect 10 Int\ntenInts = fourInts ++ sixInts\n\ninsert : Ord elem => (x : elem) -> (xs : Vect len elem) -> Vect (S len) elem\ninsert x [] = [x]\ninsert x (y :: ys) = if (x < y) then (x :: y :: ys) else (y :: insert x ys)\n\ninsertSort : (Ord elem) => Vect n elem -> Vect n elem\ninsertSort [] = []\ninsertSort (x :: xs) = insert x (insertSort xs)\n\nmy_length : List a -> Nat\nmy_length [] = Z\nmy_length (x :: xs) = S (my_length xs)\n\nmy_reverse : List a -> List a\nmy_reverse [] = []\nmy_reverse (x :: xs) = my_reverse xs ++ [x]\n\nmy_map : (a -> b) -> List a -> List b\nmy_map f [] = []\nmy_map f (x :: xs) = f x :: my_map f xs\n\nmy_vect_map : (a -> b) -> Vect n a -> Vect n b\nmy_vect_map f [] = []\nmy_vect_map f (x :: xs) = f x :: my_vect_map f xs\n\n-- total makes sure it won't compile if it's not total, total meaning every\n-- scenario is accounted for.\n\n-- I struggled with this, something about two-dimensional arrays seems to cause\n-- me problems. Transposing means taking the top row, transposing the rest\n-- recursively, then prefixing each transposed row with the values from the top\n-- row to form a new column.\n\n-- Ctrl-Alt-T in Atom to find types, only works on the right hand side.\n-- Ctrl-Alt-A to add missing cases\n-- Ctrl-Alt-C to split out a case by destructuring a particular variable\n-- Ctrl-Alt-S to do an expression search, if the type is specific enough it\n-- can fill in a right hand side.\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\nprefixEach : (x : Vect n elem) -> Vect n (Vect k elem) -> Vect n (Vect (S k) elem)\nprefixEach [] [] = []\nprefixEach (x :: xs) (y :: ys) = (x :: y) :: prefixEach xs ys\n\ntotal transposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = prefixEach x (transposeMat xs)\n\n-- Exercise 1 - reimplement using zipWith\n\ntotal transposeMat_zipWith : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat_zipWith [] = replicate _ []\ntransposeMat_zipWith (x :: xs) = zipWith (::) x (transposeMat_zipWith xs)\n\n-- Exercise 2\n\naddMatrix : Num a => Vect n (Vect m a) -> Vect n (Vect m a) -> Vect n (Vect m a)\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = zipWith (+) x y :: addMatrix xs ys\n\n-- Exercise 3\n\n-- [1 2] [ 7 8 9 10] [1*7 + 2*11 = 29] -- sum(row 1 * column 1)\n-- [3 4] x [11 12 13 14] =\n-- [5 6]\n\n-- Transposing:\n-- [1 2] [ 7 11] [1*7 + 2*11, 1*8 + 2*12, 1*9 + 2*13, 1*10 + 2*14]\n-- [3 4] x [ 8 12] = [3*7 + 4*11, 3*8 + 4*12, 3*9 + 4*13, 3*10 + 4*14]\n-- [5 6] [ 9 13] [5*7 + 6*11, 5*8 + 6*12, 5*9 + 6*13, 5*10 + 6*14]\n-- [10 14]\n\nmultMatrix : Num a => Vect n (Vect m a) -> Vect m (Vect p a) -> Vect n (Vect p a)\nmultMatrix xs ys = multHelper xs (transposeMat_zipWith ys)\n where\n sumOneRow : Num a => Vect m a -> Vect m a -> a\n sumOneRow xs ys = sum (zipWith (*) xs ys)\n\n multHelper : Num a => Vect n (Vect m a) -> Vect p (Vect m a) -> Vect n (Vect p a)\n multHelper [] _ = []\n multHelper (x :: xs) ys = map (sumOneRow x) ys :: multHelper xs ys\n\n-- Implicit values: _ means infer the value.\n-- Implicit parameters: {param: Type} means infer the parameter.\n\nvect_length : Vect n elem -> Nat\nvect_length {n} xs = n -- {n} brings the argument into scope\n\ncreateEmpties_inferred : Vect n (Vect 0 a)\ncreateEmpties_inferred {n = Z} = []\ncreateEmpties_inferred {n = (S k)} = [] :: createEmpties\n", "meta": {"hexsha": "d39e7e7954a9f12b4a2eb54eb5bb53a01945abf8", "size": 4781, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tdd/Chapter3.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/Chapter3.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/Chapter3.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.5238095238, "max_line_length": 85, "alphanum_fraction": 0.639405982, "num_tokens": 1582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8791467564270272, "lm_q1q2_score": 0.6904014916817842}} {"text": "module NewEden.Natural\n\nimport Prelude.Either\nimport public Prelude.Uninhabited\n\nimport public NewEden.Algebra\nimport public NewEden.NaturalAxioms\nimport public NewEden.NaturalPropertiesHelpers -- compiler bug #144; can't use private in types\n\n{- Natural\n \n Natural p is a natural number expressed in terms of operations on a given\n set of NaturalProperties p.\n \n Everything else in this module is expressing the axioms given in \n NaturalProperties in terms of operations on Natural p, so now\n we can use Natural p much the same as we would the 'normal' numeric types.\n-}\n\ndata Natural : NaturalProperties t -> Type where\n MkNatural : (n:NaturalProperties t) -> (a:t) -> Natural n\n\nvalue : {p:NaturalProperties t} -> Natural p -> t\nvalue {p} (MkNatural p x) = x\n\nproperties : {p:NaturalProperties t} -> Natural p -> NaturalProperties t\nproperties (MkNatural p _) = p\n\n(+) : {p:NaturalProperties t} -> Natural p -> Natural p -> Natural p\n(+) {p} (MkNatural p x) (MkNatural p y) =\n MkNatural p $ privatePlus p x y\n\n(*) : {p:NaturalProperties t} -> Natural p -> Natural p -> Natural p\n(*) {p} (MkNatural p x) (MkNatural p y) =\n MkNatural p $ privateMultiply p x y\n\n{- fromInteger\n \n This is the first place we see the real power of an axiomatic implementation.\n Here we are able to construct arbitrary natural numbers and put them in the \n compiler's head in *logarithmic* space (rather than linear space, like the Peano Nat).\n-}\n\nfromInteger : Integer -> Natural p\nfromInteger rem =\n let z = MkNatural p (zero p) in\n let o = MkNatural p (one p) in\n case rem of\n 0 => z\n 1 => o\n _ =>\n case (assert_total $ prim__sremBigInt rem 2) of\n 0 => (o + o) * (assert_total $ fromInteger (prim__sdivBigInt rem 2))\n 1 => o + (assert_total $ fromInteger (prim__subBigInt rem 1))\n _ => o -- impossible\n\n-- force resolution of 0 to Natural p, since occasionally 0 is\n-- ambiguous (e.g., right below in zeroIsNotOne)\nZ : (p:NaturalProperties t) -> Natural p\nZ p = 0\n\nzeroIsNotOne : (p:NaturalProperties t) -> (Z p = 1 -> Void)\nzeroIsNotOne p =\n let prf = NewEden.NaturalPropertiesHelpers.privateZeroIsNotOne p in\n (\\given => prf $ equalityMap value given)\n\nplusCommutative : (p:NaturalProperties t) -> CommutativeFunction (Natural p) (+)\nplusCommutative p =\n let (MkCommutativeFunction _ prf) = NewEden.NaturalPropertiesHelpers.privatePlusCommutative p in\n MkCommutativeFunction\n (+)\n (\\(MkNatural p x),(MkNatural p y) => equalityMap (MkNatural p) $ prf x y)\n\nplusAssociative : (p:NaturalProperties t) -> AssociativeFunction (Natural p) (+)\nplusAssociative p =\n let (MkMonoid af _ _ _) = NewEden.NaturalPropertiesHelpers.privatePlusMonoid p in\n let (MkAssociativeFunction _ prf) = af in\n MkAssociativeFunction\n (+)\n (\\(MkNatural p x),(MkNatural p y),(MkNatural p z) => equalityMap (MkNatural p) $ prf x y z)\n\nplusMonoid : (p:NaturalProperties t) -> NewEden.Algebra.Monoid (Natural p) (+) 0\nplusMonoid P =\n let (MkMonoid _ _ p1 p2) = NewEden.NaturalPropertiesHelpers.privatePlusMonoid P in\n MkMonoid\n (plusAssociative P)\n (Z P)\n (\\(MkNatural P x) => equalityMap (MkNatural P) $ p1 x)\n (\\(MkNatural P x) => equalityMap (MkNatural P) $ p2 x)\n\nplusLacksInverses : (p:NaturalProperties t) -> StrictMonoid $ NewEden.Natural.plusMonoid p\nplusLacksInverses P =\n let (MkStrictMonoid _ prf) = NewEden.NaturalPropertiesHelpers.privatePlusLacksInverses P in\n MkStrictMonoid\n (plusMonoid P)\n (\\(MkNatural P x),(MkNatural P y),given =>\n let given' = equalityMap value $ given in\n equalityMap (MkNatural P) $ prf x y given'\n )\n\nplusMonomorphic : (p:NaturalProperties t) -> ((n:Natural p) -> MonomorphicFunction $ (+) n)\nplusMonomorphic p =\n let g = NewEden.NaturalPropertiesHelpers.privatePlusMonomorphic p in\n (\\(MkNatural p x) =>\n let (MkMonomorphicFunction _ prf) = g x in\n MkMonomorphicFunction\n ((+) (MkNatural p x))\n (\\(MkNatural p y),(MkNatural p z),given =>\n equalityMap (MkNatural p) $ prf y z (equalityMap value given)\n )\n )\n\nmultiplyCommutative : (p:NaturalProperties t) -> CommutativeFunction (Natural p) (*)\nmultiplyCommutative p =\n let (MkCommutativeFunction _ prf) = NewEden.NaturalPropertiesHelpers.privateMultiplyCommutative p in\n MkCommutativeFunction\n (*)\n (\\(MkNatural p x),(MkNatural p y) => equalityMap (MkNatural p) $ prf x y)\n\nmultiplyAssociative : (p:NaturalProperties t) -> AssociativeFunction (Natural p) (*)\nmultiplyAssociative p =\n let (MkMonoid af _ _ _) = NewEden.NaturalPropertiesHelpers.privateMultiplyMonoid p in\n let (MkAssociativeFunction _ prf) = af in\n MkAssociativeFunction\n (*)\n (\\(MkNatural p x),(MkNatural p y),(MkNatural p z) => equalityMap (MkNatural p) $ prf x y z)\n\nmultiplyMonoid : (p:NaturalProperties t) -> NewEden.Algebra.Monoid (Natural p) (*) 1\nmultiplyMonoid P =\n let (MkMonoid _ _ p1 p2) = NewEden.NaturalPropertiesHelpers.privateMultiplyMonoid P in\n MkMonoid\n (multiplyAssociative P)\n 1\n (\\(MkNatural P x) => equalityMap (MkNatural P) $ p1 x)\n (\\(MkNatural P x) => equalityMap (MkNatural P) $ p2 x)\n\nmultiplyLacksInverses : (p:NaturalProperties t) -> StrictMonoid $ NewEden.Natural.multiplyMonoid p\nmultiplyLacksInverses P =\n let (MkStrictMonoid _ prf) = NewEden.NaturalPropertiesHelpers.privateMultiplyLacksInverses P in\n MkStrictMonoid\n (multiplyMonoid P)\n (\\(MkNatural P x),(MkNatural P y),given =>\n let given' = equalityMap value $ given in\n equalityMap (MkNatural P) $ prf x y given'\n )\n\nmultiplyMonomorphic : (p:NaturalProperties t) -> ((n:Natural p) -> MonomorphicFunction $ (*) n)\nmultiplyMonomorphic p =\n let g = NewEden.NaturalPropertiesHelpers.privateMultiplyMonomorphic p in\n (\\(MkNatural p x) =>\n let (MkMonomorphicFunction _ prf) = g x in\n MkMonomorphicFunction\n ((*) (MkNatural p x))\n (\\(MkNatural p y),(MkNatural p z),given =>\n equalityMap (MkNatural p) $ prf y z (equalityMap value given)\n )\n )\n\nmultiplyByZeroIsZero : (p:NaturalProperties t) -> ((a:(Natural p)) -> a * 0 = 0)\nmultiplyByZeroIsZero P =\n let prf = NewEden.NaturalPropertiesHelpers.privateMultiplyByZero P in\n (\\(MkNatural P x) => equalityMap (MkNatural P) $ prf x)\n\nmultiplyDistributive : (p:NaturalProperties t) -> ((a:Natural p) -> (b:Natural p) -> (c:Natural p) -> a * (b + c) = (a * b) + (a * c))\nmultiplyDistributive p =\n let prf = NewEden.NaturalPropertiesHelpers.privateDistributiveProperty p in\n (\\(MkNatural p x),(MkNatural p y),(MkNatural p z) =>\n equalityMap (MkNatural p) $ prf x y z\n )\n\nnaturalNoNumbersBetweenZeroAndOne : (p:NaturalProperties t) -> ((a:Natural p) -> (b:Natural p) -> (p1:(a = 0 -> Void)) -> (p2: a + b = 1) -> a = 1)\nnaturalNoNumbersBetweenZeroAndOne P =\n let lemmaSequence = NewEden.NaturalPropertiesHelpers.privateSequenceProperty P in\n (\\(MkNatural P x),(MkNatural P y),given1,given2 =>\n let given1' = (\\lemma => given1 $ equalityMap (MkNatural P) lemma) in\n let given2' = equalityMap value given2 in\n equalityMap (MkNatural P) $ lemmaSequence x y given1' given2'\n )\n\ndata LessThan : (a:Natural p) -> (b:Natural p) -> Type where\n MkLessThan : (a:Natural p) -> (b:Natural p) -> (c ** ((a + c = b), (c = 0 -> Void))) -> LessThan a b\n\ndata Trichotomy : (a:Type) -> (b:Type) -> (c:Type) -> Type where\n Left : {a:Type} -> {b:Type} -> {c:Type} -> (x:a) -> Trichotomy a b c\n Middle : {a:Type} -> {b:Type} -> {c:Type} -> (x:b) -> Trichotomy a b c\n Right : {a:Type} -> {b:Type} -> {c:Type} -> (x:c) -> Trichotomy a b c\n\ncompare : ((a:Natural p) -> (b:Natural p) -> Trichotomy (LessThan a b) (a = b) (LessThan b a))\ncompare (MkNatural p x) (MkNatural p y) =\n let prf = NewEden.NaturalPropertiesHelpers.privateCompare p in\n case prf x y of\n Left h => Middle $ equalityMap (MkNatural p) h\n Right r => case r of\n Left (c**(h,prf')) =>\n let lt = MkLessThan (MkNatural p x) (MkNatural p y) in\n Left $ lt ((MkNatural p c) ** ((equalityMap (MkNatural p) h),\n (\\prf'' => prf' $ equalityMap value prf'')))\n Right (c**(r,prf')) =>\n let lt = MkLessThan (MkNatural p y) (MkNatural p x) in\n Right $ lt ((MkNatural p c) ** ((equalityMap (MkNatural p) r),(\\prf'' => prf' $ equalityMap value prf'')))\n\n(-) : (a:Natural p) -> (b:Natural p) -> {auto prf:((LessThan a b) -> Void)} -> Natural p\n(-) {prf} a b = case compare a b of\n Left x => absurd (prf x)\n Middle _ => 0\n Right (MkLessThan _ _ (c ** _)) => c\n\n", "meta": {"hexsha": "dc2f6ad26440e16421c7e0a0fdc0d40f3e7db848", "size": 8451, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/NewEden/Natural.idr", "max_stars_repo_name": "identicalsnowflake/neweden", "max_stars_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-07T15:26:51.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-07T15:26:51.000Z", "max_issues_repo_path": "src/NewEden/Natural.idr", "max_issues_repo_name": "identicalsnowflake/neweden", "max_issues_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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/NewEden/Natural.idr", "max_forks_repo_name": "identicalsnowflake/neweden", "max_forks_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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.6298076923, "max_line_length": 147, "alphanum_fraction": 0.6743580641, "num_tokens": 2702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6903997086125436}} {"text": "-- Example of a union type.\n||| Represents shapes.\ndata Shape = ||| A triangle, with its base length and height\n Triangle Double Double\n | ||| A rectangle, with its lengths and height\n Rectangle Double Double\n | ||| A circle, with its radius\n Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n", "meta": {"hexsha": "72abe167a75934564c5d53704525ca58eb3bc8f4", "size": 474, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter04/Shape.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TypeDrivenDevelopment/Chapter04/Shape.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypeDrivenDevelopment/Chapter04/Shape.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": 33.8571428571, "max_line_length": 60, "alphanum_fraction": 0.6308016878, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6901901289633615}} {"text": "module NewEden.Algebra\n\n%default total\n\ndata AssociativeFunction : (t:Type) -> (f:(t -> t -> t)) -> Type where\n MkAssociativeFunction :\n (f:(t -> t -> t))\n -> (prf:((a:t) -> (b:t) -> (c:t) -> f a (f b c) = f (f a b) c))\n -> AssociativeFunction t f\n\ndata CommutativeFunction : (t:Type) -> (f:(t -> t -> t)) -> Type where\n MkCommutativeFunction :\n (f:(t -> t -> t))\n -> (prf:((a:t) -> (b:t) -> f a b = f b a))\n -> CommutativeFunction t f\n\ndata MonomorphicFunction : (t1 -> t2) -> Type where\n MkMonomorphicFunction :\n (f:(t1 -> t2))\n -> ((a:t1) -> (b:t1) -> f a = f b -> a = b)\n -> MonomorphicFunction f\n\ndata Monoid : (t:Type) -> (f:(t -> t -> t)) -> (zero:t) -> Type where\n MkMonoid :\n (lemma:AssociativeFunction t f)\n -> (zero:t)\n -> (prf1:((a:t) -> f a zero = a))\n -> (prf2:((a:t) -> f zero a = a))\n -> Monoid t f zero\n\n-- monoid which is strictly not strong enough to be a group (proven lack of inverses)\ndata StrictMonoid : (m:Monoid t f z) -> Type where\n MkStrictMonoid :\n (m:Monoid t f z)\n -> (prfNoInverses:((a:t) -> (b:t) -> (p:(f a b = z)) -> (a = z)))\n -> StrictMonoid m\n\ndata Group : Monoid t f z -> Type where\n MkGroup :\n (m:Monoid t f z)\n -> (prfInverse:((a:t) -> (b : t ** (f a b = z))))\n -> Group m\n\ndata Coproduct : (C : Type) -> Type where\n MkCoproduct :\n {C : Type}\n -> (coproduct : C -> C -> C)\n -> ((x1 : C) -> (x2 : C) ->\n (\n i1 : C -> C **\n (\n i2 : C -> C **\n (\n i1 x1 = coproduct x1 x2\n , i2 x2 = coproduct x1 x2\n , (x : C) ->\n (\n f1 : C -> C **\n (\n f2 : C -> C **\n (\n f1 x1 = x\n , f2 x2 = x\n , (f : C -> C **\n (\n f $ coproduct x1 x2 = x\n , ((c : C) -> f1 c = f (i1 c))\n , ((c : C) -> f2 c = f (i2 c))\n , ((f' : C -> C)\n -> f' $ coproduct x1 x2 = x\n -> ((c : C) -> f1 c = f' (i1 c))\n -> ((c : C) -> f2 c = f' (i2 c))\n -> ((n : C) -> f' c = f c)\n )\n ))\n )\n )\n )\n )\n )\n )\n )\n -> Coproduct C\n\ndata Product : (C : Type) -> Type where\n MkProduct :\n {C : Type}\n -> (product : C -> C -> C)\n -> ((x1 : C) -> (x2 : C) ->\n (\n p1 : C -> C **\n (\n p2 : C -> C **\n ((y : C) ->\n (f1 : C -> C) ->\n f1 y = x1 ->\n (f2 : C -> C) ->\n f2 y = x2 ->\n (\n f : C -> C **\n (\n f y = product x1 x2\n , ((c : C) -> p1 (f c) = f1 c)\n , ((c : C) -> p2 (f c) = f2 c)\n , ((f' : C -> C) ->\n f' y = product x1 x2 ->\n ((c : C) -> p1 (f' c) = f1 c) ->\n ((c : C) -> p2 (f' c) = f2 c) ->\n ((c : C) -> f' c = f c)\n )\n )\n )\n )\n )\n )\n )\n -> Product C\n\ndata InitialObject : (C : Type) -> Type where\n MkInitialObject :\n {C : Type}\n -> (initialObject : C)\n -> ((x : C) ->\n (f : C -> C **\n ( (f initialObject = x)\n , ((f' : C -> C) ->\n f' initialObject = x ->\n ((c : C) -> f' c = f c)\n )\n )\n )\n )\n -> InitialObject C\n\ndata TerminalObject : (C : Type) -> Type where\n MkTerminalObject :\n {C : Type}\n -> (terminalObject : C)\n -> ((x : C) ->\n (f : C -> C **\n ((f x = terminalObject)\n , ((f' : C -> C) ->\n f' x = terminalObject ->\n ((c : C) -> f' c = f c)\n )\n )\n )\n )\n -> TerminalObject C\n\ndata Isomorphism : (t:Type) -> (u:Type) -> (f:(t -> u)) -> (g:(u -> t)) -> Type where\n MkIsomorphism : (t:Type) -> (u:Type) -> (f:(t -> u)) -> (g:(u -> t)) -> ((a:t) -> g (f a) = a) -> ((a:u) -> f (g a) = a) -> Isomorphism t u f g\n\nequalityMap : (f:(t -> u)) -> a = b -> f a = f b\nequalityMap f Refl = Refl\n\ntransitivity : a = b -> b = c -> a = c\ntransitivity Refl Refl = Refl\n\nsymmetric : a = b -> b = a\nsymmetric Refl = Refl\n\nsubstitution : {t1:Type} -> {t2:Type} -> {a:t1} -> {b:t1} -> {c:t2} -> (f:t1 -> t2) -> a = b -> f a = c -> f b = c\nsubstitution _ Refl Refl = Refl\n\n", "meta": {"hexsha": "720aa1ef86717da97548caddc3f05337f7861c0f", "size": 4540, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/NewEden/Algebra.idr", "max_stars_repo_name": "identicalsnowflake/neweden", "max_stars_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-07T15:26:51.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-07T15:26:51.000Z", "max_issues_repo_path": "src/NewEden/Algebra.idr", "max_issues_repo_name": "identicalsnowflake/neweden", "max_issues_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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/NewEden/Algebra.idr", "max_forks_repo_name": "identicalsnowflake/neweden", "max_forks_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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.3493975904, "max_line_length": 145, "alphanum_fraction": 0.3477973568, "num_tokens": 1518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6901780437055541}} {"text": "import Data.Vect\n\n\nappend_nil : Vect m elem -> Vect (plus m 0) elem\nappend_nil {m} xs = rewrite plusZeroRightNeutral m in xs\n\nappend_xs : Vect (S (m + k)) elem -> Vect (plus m (S k)) elem\nappend_xs {m} {k} xs = rewrite sym\n (plusSuccRightSucc m k) in xs\n\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)\n", "meta": {"hexsha": "3865e4dfc92cefbf9a64d2f9d3bc008414580502", "size": 415, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter08/AppendVec.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/AppendVec.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/AppendVec.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": 29.6428571429, "max_line_length": 61, "alphanum_fraction": 0.621686747, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6901476382829768}} {"text": "module Control.Algebra.ZZVerifiedInstances\n-- We will forego treating this as Control.Algebra.NumericVerifiedInstances\n\nimport Data.ZZ\nimport Control.Algebra\nimport Classes.Verified\nimport Control.Algebra.NumericInstances\n\n%default total\n\n-- These can be proven through an isomorphism with the free ring on the empty type.\n\nmonoidNeutralIsNeutralL_ZZ : (l : ZZ) -> l <+> Algebra.neutral = l\nmonoidNeutralIsNeutralL_ZZ (Pos n) = cong {f=Pos} $ plusZeroRightNeutral n\nmonoidNeutralIsNeutralL_ZZ (NegS n) = Refl\n\nmonoidNeutralIsNeutralR_ZZ : (r : ZZ) -> Algebra.neutral <+> r = r\nmonoidNeutralIsNeutralR_ZZ (Pos n) = cong {f=Pos} $ plusZeroLeftNeutral n\nmonoidNeutralIsNeutralR_ZZ (NegS n) = Refl\n\nnegPlusNegnatToNegnatPlus : (l, r : Nat) -> (NegS l) <+> negNat r = negNat $ S $ l `plus` r\nnegPlusNegnatToNegnatPlus l Z = rewrite plusZeroRightNeutral l in Refl\nnegPlusNegnatToNegnatPlus l (S predr) = cong {f=NegS} $ plusSuccRightSucc l predr\n\nonePlusMinusNatReduction : (a, b : Nat) -> Pos 1 <+> minusNatZ a (S b) = minusNatZ a b\nonePlusMinusNatReduction Z b = Refl\nonePlusMinusNatReduction (S preda) Z = Refl\nonePlusMinusNatReduction (S preda) (S predb) = onePlusMinusNatReduction preda predb\n\nplusNegOneMinusNatProduction : (a, b : Nat) -> minusNatZ a b <+> NegS 0 = minusNatZ a (S b)\nplusNegOneMinusNatProduction Z Z = Refl\nplusNegOneMinusNatProduction Z (S predb) = rewrite plusZeroRightNeutral predb in Refl\nplusNegOneMinusNatProduction (S preda) Z = Refl\nplusNegOneMinusNatProduction (S preda) (S predb) = plusNegOneMinusNatProduction preda predb\n\nabelianGroupOpIsCommutative_ZZ : (l, r : ZZ) -> l <+> r = r <+> l\nabelianGroupOpIsCommutative_ZZ (Pos n) (Pos m) = cong $ plusCommutative _ _\nabelianGroupOpIsCommutative_ZZ (NegS n) (NegS m) = cong {f=NegS . S} $ plusCommutative _ _\nabelianGroupOpIsCommutative_ZZ (Pos n) (NegS m) = Refl\nabelianGroupOpIsCommutative_ZZ (NegS n) (Pos m) = Refl\n\ntotal\nsemigroupOpIsAssociative_ZZ : (l, c, r : ZZ) -> l <+> (c <+> r) = l <+> c <+> r\nsemigroupOpIsAssociative_ZZ (Pos l) (Pos c) (Pos r) = cong $ plusAssociative _ _ _\nsemigroupOpIsAssociative_ZZ (Pos l) (Pos Z) (NegS r) = rewrite plusZeroRightNeutral l in Refl\nsemigroupOpIsAssociative_ZZ (Pos l) (Pos (S predc)) (NegS Z) = rewrite sym $ plusSuccRightSucc l predc in Refl\nsemigroupOpIsAssociative_ZZ (Pos l) (Pos (S predc)) (NegS (S predr)) = rewrite sym $ plusSuccRightSucc l predc in assert_total $ semigroupOpIsAssociative_ZZ (Pos l) (Pos predc) (NegS predr)\nsemigroupOpIsAssociative_ZZ (Pos l) (NegS Z) (Pos Z) = sym $ monoidNeutralIsNeutralL_ZZ _\nsemigroupOpIsAssociative_ZZ (Pos Z) (NegS Z) (Pos (S predr)) = Refl\nsemigroupOpIsAssociative_ZZ (Pos (S predl)) (NegS Z) (Pos (S predr)) = rewrite plusSuccRightSucc predl predr in Refl\nsemigroupOpIsAssociative_ZZ (Pos Z) (NegS (S predc)) (Pos r) = monoidNeutralIsNeutralR_ZZ _\nsemigroupOpIsAssociative_ZZ (Pos (S predl)) (NegS (S predc)) (Pos Z) = sym $ monoidNeutralIsNeutralL_ZZ _\nsemigroupOpIsAssociative_ZZ (Pos l) (NegS (S predc)) (Pos (S predr)) = trans (assert_total $ semigroupOpIsAssociative_ZZ (Pos l) (NegS predc) (Pos predr))\n\t$ trans (cong {f=(<+> Pos predr)}\n\t\t$ trans (sym $ onePlusMinusNatReduction l (S predc))\n\t\t$ abelianGroupOpIsCommutative_ZZ (Pos 1) (minusNatZ l $ S $ S predc))\n\t$ sym $ assert_total $ semigroupOpIsAssociative_ZZ _ (Pos 1) (Pos predr)\nsemigroupOpIsAssociative_ZZ (Pos Z) (NegS c) (NegS r) = Refl\nsemigroupOpIsAssociative_ZZ (Pos (S predl)) (NegS Z) (NegS r) = Refl\nsemigroupOpIsAssociative_ZZ (Pos (S predl)) (NegS (S predc)) (NegS r) = assert_total $ semigroupOpIsAssociative_ZZ (Pos predl) (NegS predc) (NegS r)\nsemigroupOpIsAssociative_ZZ (NegS l) (Pos Z) (Pos r) = Refl\nsemigroupOpIsAssociative_ZZ (NegS Z) (Pos (S predc)) (Pos r) = Refl\nsemigroupOpIsAssociative_ZZ (NegS (S predl)) (Pos (S predc)) (Pos r) = assert_total $ semigroupOpIsAssociative_ZZ (NegS predl) (Pos predc) (Pos r)\nsemigroupOpIsAssociative_ZZ (NegS l) (Pos Z) (NegS Z) = Refl\nsemigroupOpIsAssociative_ZZ (NegS l) (Pos Z) (NegS (S predr)) = Refl\nsemigroupOpIsAssociative_ZZ (NegS l) (Pos (S predc)) (NegS Z) = sym $ plusNegOneMinusNatProduction predc l\n{- \n* Recurses to case [ (NegS l) (Pos predc) (NegS predr) ]\n* Depends on cases for [ x (NegS 0) (NegS predr) ]\n-}\nsemigroupOpIsAssociative_ZZ (NegS l) (Pos (S predc)) (NegS (S predr)) = trans (assert_total $ semigroupOpIsAssociative_ZZ (NegS l) (Pos predc) (NegS predr))\n\t$ trans (cong {f=flip plusZ $ NegS predr} $ sym $ plusNegOneMinusNatProduction predc l)\n\t$ sym $ assert_total $ semigroupOpIsAssociative_ZZ ((NegS l)<+>(Pos (S predc))) (NegS 0) (NegS predr)\nsemigroupOpIsAssociative_ZZ (NegS l) (NegS Z) (Pos Z) = Refl\nsemigroupOpIsAssociative_ZZ (NegS l) (NegS Z) (Pos (S predr)) = rewrite plusZeroRightNeutral l in Refl\nsemigroupOpIsAssociative_ZZ (NegS l) (NegS c) (Pos Z) = Refl\nsemigroupOpIsAssociative_ZZ (NegS l) (NegS (S predc)) (Pos (S predr)) = rewrite sym $ plusSuccRightSucc l predc in assert_total $ semigroupOpIsAssociative_ZZ (NegS l) (NegS predc) (Pos predr)\nsemigroupOpIsAssociative_ZZ (NegS l) (NegS c) (NegS r) = rewrite sym $ plusSuccRightSucc l (c+r) in cong {f=NegS . S . S} $ plusAssociative l c r\n\nminusNatZSelfZ : (n : Nat) -> minusNatZ n n = Pos 0\nminusNatZSelfZ Z = Refl\nminusNatZSelfZ (S predn) = minusNatZSelfZ predn\n\ngroupInverseIsInverseL_ZZ : (l : ZZ) -> l <+> inverse l = Algebra.neutral\ngroupInverseIsInverseL_ZZ (Pos Z) = Refl\ngroupInverseIsInverseL_ZZ (Pos (S predn)) = trans (cong {f=minusNatZ predn} $ multOneRightNeutral predn) $ minusNatZSelfZ predn\ngroupInverseIsInverseL_ZZ (NegS n) = trans (cong {f=flip minusNatZ n} $ multOneRightNeutral n) $ minusNatZSelfZ n\n\ngroupInverseIsInverseR_ZZ : (r : ZZ) -> inverse r <+> r = Algebra.neutral\ngroupInverseIsInverseR_ZZ (Pos Z) = Refl\ngroupInverseIsInverseR_ZZ (Pos (S predn)) = trans (cong {f=minusNatZ predn} $ multOneRightNeutral predn) $ minusNatZSelfZ predn\ngroupInverseIsInverseR_ZZ (NegS n) = trans (cong {f=flip minusNatZ n} $ multOneRightNeutral n) $ minusNatZSelfZ n\n\nmultZPosZRightZero : (left : ZZ) -> multZ left (Pos 0) = Pos 0\nmultZPosZRightZero (Pos n) = cong {f=Pos} $ multZeroRightZero _\nmultZPosZRightZero (NegS n) = cong {f=negNat} $ multZeroRightZero _\n\nmultZPosZLeftZero : (right : ZZ) -> multZ (Pos 0) right = Pos 0\nmultZPosZLeftZero (Pos n) = Refl\nmultZPosZLeftZero (NegS n) = Refl\n\nringOpIsAssociative_ZZ : (l, c, r : ZZ) -> l <.> (c <.> r) = l <.> c <.> r\nringOpIsAssociative_ZZ (Pos l) (Pos c) (Pos r) = cong $ multAssociative _ _ _\nringOpIsAssociative_ZZ (NegS l) (Pos Z) (Pos r) = rewrite cong {f=negNat} $ multZeroRightZero l in Refl\nringOpIsAssociative_ZZ (NegS l) (Pos c) (Pos Z) = trans (rewrite multZeroRightZero c in rewrite multZeroRightZero l in Refl) $ sym $ multZPosZRightZero _\nringOpIsAssociative_ZZ (NegS l) (Pos (S predc)) (Pos (S predr)) = cong {f=negNat} $ multAssociative (S l) (S predc) (S predr)\nringOpIsAssociative_ZZ (NegS l) (NegS c) (Pos Z) = rewrite multZeroRightZero c in trans (cong {f=negNat} $ multZeroRightZero l) $ cong {f=Pos} $ sym $ multZeroRightZero $ _\nringOpIsAssociative_ZZ (NegS l) (NegS c) (Pos (S predr)) = cong {f=Pos} $ multAssociative (S l) (S c) (S predr)\nringOpIsAssociative_ZZ (NegS l) (Pos Z) (NegS r) = rewrite multZeroRightZero l in Refl\nringOpIsAssociative_ZZ (NegS l) (Pos (S predc)) (NegS r) = cong {f=Pos} $ multAssociative (S l) (S predc) (S r)\nringOpIsAssociative_ZZ (NegS l) (NegS c) (NegS r) = cong {f=negNat} $ multAssociative (S l) (S c) (S r)\nringOpIsAssociative_ZZ (Pos Z) (NegS c) (Pos r) = multZPosZLeftZero _\nringOpIsAssociative_ZZ (Pos l) (NegS c) (Pos Z) = rewrite multZeroRightZero c in trans (multZPosZRightZero (Pos l)) $ sym $ multZPosZRightZero _\nringOpIsAssociative_ZZ (Pos (S predl)) (NegS c) (Pos (S predr)) = cong {f=negNat} $ multAssociative (S predl) (S c) (S predr)\nringOpIsAssociative_ZZ (Pos Z) (Pos c) (NegS r) = multZPosZLeftZero _\nringOpIsAssociative_ZZ (Pos l) (Pos Z) (NegS r) = rewrite (multZeroRightZero l) in Refl\nringOpIsAssociative_ZZ (Pos (S predl)) (Pos (S predc)) (NegS r) = cong {f=negNat} $ multAssociative (S predl) (S predc) (S r)\nringOpIsAssociative_ZZ (Pos Z) (NegS c) (NegS r) = Refl\nringOpIsAssociative_ZZ (Pos (S predl)) (NegS c) (NegS r) = cong {f=Pos} $ multAssociative (S predl) (S c) (S r)\n\nnegativeIsNegOneTimesRight : (right : ZZ) -> inverse right = (inverse Algebra.unity) <.> right\nnegativeIsNegOneTimesRight (Pos r) = cong {f=negNat} $ trans (multOneRightNeutral r) $ sym $ plusZeroRightNeutral r\nnegativeIsNegOneTimesRight (NegS r) = cong {f=Pos . S} $ trans (multOneRightNeutral r) $ sym $ plusZeroRightNeutral r\n\nminusNatZNegOneTimesFlip : multZ (NegS 0) $ minusNatZ a b = minusNatZ b a\nminusNatZNegOneTimesFlip {a=Z} {b=Z} = Refl\nminusNatZNegOneTimesFlip {a=Z} {b=S predb} = cong {f=Pos . S} $ plusZeroRightNeutral predb\nminusNatZNegOneTimesFlip {a=S preda} {b=Z} = cong {f=NegS} $ plusZeroRightNeutral preda\nminusNatZNegOneTimesFlip {a=S preda} {b=S predb} = minusNatZNegOneTimesFlip {a=preda} {b=predb}\n\nnegOneDistributesL_ZZ : (c, r : ZZ) -> (inverse Algebra.unity) <.> (c <+> r) = (inverse Algebra.unity)<.>c <+> (inverse Algebra.unity)<.>r\nnegOneDistributesL_ZZ (Pos Z) r = rewrite monoidNeutralIsNeutralR_ZZ (NegS 0 <.> r) in rewrite monoidNeutralIsNeutralR_ZZ r in Refl\nnegOneDistributesL_ZZ (Pos (S predc)) (Pos Z) = rewrite plusZeroRightNeutral predc in rewrite plusZeroRightNeutral predc in Refl\nnegOneDistributesL_ZZ (Pos (S predc)) (Pos (S predr)) = rewrite plusZeroRightNeutral predr in rewrite plusZeroRightNeutral predc in rewrite plusZeroRightNeutral (predc+(S predr)) in cong {f=NegS} $ sym $ plusSuccRightSucc predc predr\nnegOneDistributesL_ZZ (Pos (S Z)) (NegS Z) = Refl\nnegOneDistributesL_ZZ (Pos (S $ S predc)) (NegS Z) = Refl\nnegOneDistributesL_ZZ (Pos (S predc)) (NegS (S predr)) = trans minusNatZNegOneTimesFlip $ rewrite plusZeroRightNeutral predc in rewrite plusZeroRightNeutral predr in Refl\nnegOneDistributesL_ZZ (NegS c) (Pos Z) = rewrite plusZeroRightNeutral c in rewrite plusZeroRightNeutral c in Refl\nnegOneDistributesL_ZZ (NegS c) (Pos (S predr)) = rewrite plusZeroRightNeutral c in rewrite plusZeroRightNeutral predr in minusNatZNegOneTimesFlip\nnegOneDistributesL_ZZ (NegS c) (NegS r) = cong {f=Pos . S} $ rewrite plusZeroRightNeutral (c+r) in rewrite plusZeroRightNeutral c in rewrite plusZeroRightNeutral r in plusSuccRightSucc c r\n\ntotal\nringOpIsDistributiveL_ZZ : ( l, c, r : ZZ ) -> l <.> (c <+> r) = l <.> c <+> l <.> r\nringOpIsDistributiveL_ZZ (Pos l) (Pos c) (Pos r) = cong {f=Pos} $ multDistributesOverPlusRight _ _ _\nringOpIsDistributiveL_ZZ (NegS l) (Pos Z) (Pos r) = rewrite (multZeroRightZero l) in sym $ plusZeroLeftNeutralZ _\nringOpIsDistributiveL_ZZ (NegS l) (Pos (S predc)) (Pos r) = trans (cong {f=negNat} $ multDistributesOverPlusRight (S l) (S predc) r) $ sym $ negPlusNegnatToNegnatPlus _ _\nringOpIsDistributiveL_ZZ (Pos l) (NegS c) (Pos Z) = rewrite multZeroRightZero l in sym $ plusZeroRightNeutralZ _\n-- if (r) is a successor, induce from the theorem on its predecessor.\nringOpIsDistributiveL_ZZ (Pos l) (NegS c) (Pos (S predr)) = trans (trans (cong $ sym $ onePlusMinusNatReduction predr c) $\n\ttrans (assert_total $ ringOpIsDistributiveL_ZZ (Pos l) (Pos 1) (minusNatZ predr (S c))) $ rewrite multOneRightNeutral l in Refl)\n\t$ trans (cong {f=((Pos l)<+>)} $ assert_total $ ringOpIsDistributiveL_ZZ (Pos l) (NegS c) (Pos predr))\n\t$ trans (semigroupOpIsAssociative_ZZ (Pos l) (negNat $ mult l $ S c) $ Pos $ mult l predr)\n\t$ trans ( trans (cong {f=flip plusZ $ Pos $ mult l predr} $ abelianGroupOpIsCommutative_ZZ (Pos l) (negNat $ mult l $ S c))\n\t\t$ sym $ semigroupOpIsAssociative_ZZ (negNat $ mult l $ S c) (Pos l) (Pos $ mult l predr))\n\t$ cong {f=(plusZ $ negNat $ mult l $ S c) . Pos}\n\t\t$ trans (cong {f=flip plus $ mult l predr} $ sym $ multOneRightNeutral l)\n\t\t$ sym $ multDistributesOverPlusRight l 1 predr\n-- reduces to 3 and the special case (negOneDistributesL_ZZ)\nringOpIsDistributiveL_ZZ (NegS l) (NegS c) (Pos r) = trans (cong {f=(flip multZ $ minusNatZ r $ S c) . NegS} $ sym $ plusZeroRightNeutral l)\n\t$ trans (sym $ ringOpIsAssociative_ZZ (inverse Algebra.unity) (Pos (S l)) $ minusNatZ r (S c))\n\t$ trans (cong {f=multZ $ inverse unity} $ assert_total $ ringOpIsDistributiveL_ZZ (Pos (S l)) (NegS c) (Pos r))\n\t$ trans (negOneDistributesL_ZZ (Pos (S l) <.> NegS c) (Pos (S l) <.> Pos r))\n\t$ trans (cong $ sym $ negativeIsNegOneTimesRight (Pos (S l) <.> Pos r))\n\t$ trans (cong {f=(flip plusZ $ negNat (mult (plus r (mult l r)) 1)) . Pos . S} $ plusZeroRightNeutral _)\n\t$ cong {f=plusZ $ Pos $ S $ plus c $ mult l $ S c} $ cong {f=negNat} $ multOneRightNeutral _\n-- reduces to 3\nringOpIsDistributiveL_ZZ (Pos l) (Pos c) (NegS r) = trans (cong {f=((Pos l) <.>)} $ abelianGroupOpIsCommutative_ZZ (Pos c) (NegS r))\n\t$ trans (assert_total $ ringOpIsDistributiveL_ZZ (Pos l) (NegS r) (Pos c))\n\t$ abelianGroupOpIsCommutative_ZZ ((Pos l)<.>(NegS r)) ((Pos l)<.>(Pos c))\n-- reduces to 4\nringOpIsDistributiveL_ZZ (NegS l) (Pos c) (NegS r) = trans (cong {f=((NegS l) <.>)} $ abelianGroupOpIsCommutative_ZZ (Pos c) (NegS r))\n\t$ trans (assert_total $ ringOpIsDistributiveL_ZZ (NegS l) (NegS r) (Pos c))\n\t$ abelianGroupOpIsCommutative_ZZ ((NegS l)<.>(NegS r)) ((NegS l)<.>(Pos c))\nringOpIsDistributiveL_ZZ (Pos Z) (NegS c) (NegS r) = Refl\nringOpIsDistributiveL_ZZ (Pos (S predl)) (NegS c) (NegS r) = cong {f=NegS . S}\n\t$ trans (cong\n\t\t$ trans (cong $ plusSuccRightSucc (S c) r)\n\t\t$ multDistributesOverPlusRight predl (S c) (S r))\n\t$ trans (sym $ plusAssociative c r _)\n\t$ trans (cong {f=plus c}\n\t\t$ trans (plusCommutative r _)\n\t\t$ trans (sym $ plusAssociative (mult predl $ S c) (mult predl $ S r) r)\n\t\t$ cong $ plusCommutative _ r)\n\t$ plusAssociative c (mult predl $ S c) $ plus r $ mult predl $ S r\n-- Reduces to 7 and the special case (negOneDistributesL_ZZ)\n-- mirrors the proof of case [(NegS l) (NegS c) (Pos r)].\nringOpIsDistributiveL_ZZ (NegS l) (NegS c) (NegS r) = trans (rewrite sym $ plusZeroRightNeutral l in Refl)\n\t-- THIS LINE HERE IS CLEARER THAN IN case [(NegS l) (NegS c) (Pos r)]'s proof! Change (NegS r) to (Pos r).\n\t$ trans (sym $ ringOpIsAssociative_ZZ (inverse Algebra.unity) (Pos (S l)) $ NegS c <+> NegS r)\n\t$ trans (cong {f=multZ $ inverse unity} $ assert_total $ ringOpIsDistributiveL_ZZ (Pos (S l)) (NegS c) (NegS r))\n\t$ trans (negOneDistributesL_ZZ (Pos (S l) <.> NegS c) (Pos (S l) <.> NegS r))\n\t$ trans ( cong {f=plusZ (multZ (NegS 0) (Pos (S l) <.> NegS c))} $ sym $ negativeIsNegOneTimesRight (Pos (S l) <.> NegS r) )\n\t{-\n\tHERE THE PROOF IS DIFFERENT BECAUSE THE CONGs ON THE (multOneRightNeutral)\n\tWOULD HAVE TO BE DIFFERENT.\n\t-}\n\t$ trans (rewrite plusZeroRightNeutral $ c+l*(S c) in Refl)\n\t$ rewrite multOneRightNeutral (r+l*(S r)) in Refl\n\nringOpIsCommutative_ZZ : ( l, r : ZZ ) -> l <.> r = r <.> l\nringOpIsCommutative_ZZ (Pos l) (Pos r) = cong $ multCommutative l r\nringOpIsCommutative_ZZ (NegS l) (Pos r) = cong {f=negNat} $ multCommutative (S l) r\nringOpIsCommutative_ZZ (Pos l) (NegS r) = cong {f=negNat} $ multCommutative l (S r)\nringOpIsCommutative_ZZ (NegS l) (NegS r) = cong {f=Pos} $ multCommutative (S l) (S r)\n\nringOpIsDistributiveR_ZZ : ( l, c, r : ZZ ) -> (l <+> c) <.> r = l <.> r <+> c <.> r\nringOpIsDistributiveR_ZZ l c r = trans (ringOpIsCommutative_ZZ (l<+>c) r)\n\t$ trans (ringOpIsDistributiveL_ZZ r l c)\n\t$ trans (cong {f=((r<.>l) <+>)} $ ringOpIsCommutative_ZZ r c)\n\t$ cong {f=(<+> (c<.>r))} $ ringOpIsCommutative_ZZ r l\n\nringWithUnityIsUnityL_ZZ : ( l : ZZ ) -> l <.> Algebra.unity = l\nringWithUnityIsUnityL_ZZ (Pos l) = cong $ multOneRightNeutral l\nringWithUnityIsUnityL_ZZ (NegS l) = cong $ multOneRightNeutral l\n\nringWithUnityIsUnityR_ZZ : ( r : ZZ ) -> Algebra.unity <.> r = r\nringWithUnityIsUnityR_ZZ (Pos r) = cong $ multOneLeftNeutral r\nringWithUnityIsUnityR_ZZ (NegS r) = cong $ multOneLeftNeutral r\n\ninstance VerifiedSemigroup ZZ where\n\tsemigroupOpIsAssociative = semigroupOpIsAssociative_ZZ\n\ninstance VerifiedMonoid ZZ where {\n\tmonoidNeutralIsNeutralL = monoidNeutralIsNeutralL_ZZ\n\tmonoidNeutralIsNeutralR = monoidNeutralIsNeutralR_ZZ\n}\n\ninstance VerifiedGroup ZZ where {\n\tgroupInverseIsInverseL = groupInverseIsInverseL_ZZ\n\tgroupInverseIsInverseR = groupInverseIsInverseR_ZZ\n}\n\ninstance VerifiedAbelianGroup ZZ where {\n\tabelianGroupOpIsCommutative = abelianGroupOpIsCommutative_ZZ\n}\n\ninstance VerifiedRing ZZ where {\n\tringOpIsAssociative = ringOpIsAssociative_ZZ\n\tringOpIsDistributiveL = ringOpIsDistributiveL_ZZ\n\tringOpIsDistributiveR = ringOpIsDistributiveR_ZZ\n}\n\ninstance VerifiedRingWithUnity ZZ where {\n\tringWithUnityIsUnityL = ringWithUnityIsUnityL_ZZ\n\tringWithUnityIsUnityR = ringWithUnityIsUnityR_ZZ\n}\n", "meta": {"hexsha": "b84b6aecaeddfd339785dc9b607f21bd1eb63e9a", "size": 16583, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Control/Algebra/ZZVerifiedInstances.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": "Control/Algebra/ZZVerifiedInstances.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": "Control/Algebra/ZZVerifiedInstances.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": 67.1376518219, "max_line_length": 233, "alphanum_fraction": 0.7273714045, "num_tokens": 6154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6901476325637692}} {"text": "module Marginalization\n\nimport Semiring\nimport HetVect\nimport Data.Morphisms\n\n%default total\n%access public export\n\nprodFuncsV\n : Semiring n\n => {xs, ys: List Type}\n -> (Vect xs -> n)\n -> (Vect ys -> n)\n -> Vect (xs++ys)\n -> n\nprodFuncsV {xs=[]} f g vs = f Nil * g vs\nprodFuncsV {xs=x::xs} f g (y :: z) = prodFuncsV (f . (y::)) g z\n\n||| A proof that every type in a given list belongs to a finite, bounded,\n||| enumerable domain. Possibly better modelled in a more generic way (ie for\n||| arbitrary constraints).\ndata AllFinite : List Type -> Type where\n Empty : AllFinite []\n Extra\n : (rest : AllFinite xs)\n -> (MinBound x, MaxBound x, Enum x)\n => AllFinite (x::xs)\n\n||| Maybe reformulate this in a tail-recursive way.\nmarg : (Semiring n, MinBound a, MaxBound a, Enum a) => (a -> n) -> n\nmarg f = sum (map f [minBound .. maxBound])\n\nmargOnce\n : (Semiring n, MinBound t, MaxBound t, Enum t)\n => (Vect (t::ts) -> n) -> (Vect ts -> n)\nmargOnce f = (applyMor . marg) (\\x => Mor (f . (x::)))\n\nmargVec\n : Semiring n\n => {xs : List Type}\n -> {auto prf : AllFinite xs}\n -> (Vect xs -> n) -> n\nmargVec {xs=[]} f = f []\nmargVec {xs=x::xs} {prf=Extra rest} f = margVec (margOnce f)\n\nmargVecL\n : Semiring n\n => {xs, ys: List Type}\n -> {auto prf : AllFinite ys}\n -> (Vect (xs++ys) -> n)\n -> Vect xs -> n\nmargVecL f [] = margVec f\nmargVecL f (x :: xs) = margVecL (\\ys => f (x::ys)) xs\n\nmargVecR\n : Semiring n\n => {xs, ys: List Type}\n -> (Vect (xs++ys) -> n)\n -> {auto prf : AllFinite xs}\n -> Vect ys\n -> n\nmargVecR f = applyMor (margVec (\\xs => Mor (\\ys => f (xs++ys))))\n\nfiniteDistL\n : {xs, ys : List Type}\n -> (prf : AllFinite (xs++ys))\n -> AllFinite xs\nfiniteDistL {xs=[]} prf = Empty\nfiniteDistL {xs=x::xs} (Extra rest) = Extra (finiteDistL rest)\n\nfiniteDistR\n : {xs,ys : List Type}\n -> (prf : AllFinite (xs++ys))\n -> AllFinite ys\nfiniteDistR {xs=[]} prf = prf\nfiniteDistR {xs=x::xs} (Extra rest) = finiteDistR {xs} rest\n\n-- elemConforms : {x : Type} -> {xs : List Type} -> (conform : AllFinite xs) -> (el : Elem x xs) -> Enum x\n-- elemConforms (Extra rest) Here = Enum x\n-- elemConforms conform (There x) = ?elemConforms_rhs_2\n\nmargVecAny\n : Semiring n\n => {x : Type}\n -> {xs : List Type}\n -> (fin : AllFinite xs)\n -> (elem : Elem x xs)\n -> (Vect xs -> n)\n -> x -> n\nmargVecAny (Extra rest) Here f x = margVec {prf = rest} (f . (x::))\nmargVecAny (Extra rest) (There z) f x = margVecAny rest z (margOnce f) x\n\n-- Can almost certainly be written quicker.\nmargAll\n : Semiring s\n => {xs : List Type}\n -> {auto finite : AllFinite xs}\n -> curried xs s\n -> s\nmargAll = go where\n go\n : Semiring s\n => {xs : List Type}\n -> {auto finite : AllFinite xs}\n -> curried xs s\n -> s\n go {finite = Empty} m = m\n go {finite = (Extra rest)} m =\n sum (map (go . m) [minBound .. maxBound])\n\nprodFuncs\n : Semiring n\n => {xs: List Type}\n -> curried xs n\n -> curried xs n\n -> curried xs n\nprodFuncs {xs=[]} x y = x * y\nprodFuncs {n} {xs=x::xs} f g\n = \\y => prodFuncs {n} {xs} (f y) (g y)\n", "meta": {"hexsha": "e09ccae3a6206b038e69899ad11cdcef0f507e50", "size": 3039, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Marginalization.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": "Marginalization.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": "Marginalization.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": 25.1157024793, "max_line_length": 106, "alphanum_fraction": 0.5867061533, "num_tokens": 1121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.6898640253310084}} {"text": "data Natural = Zero | S Natural\n\neval : Natural -> Int\neval Zero = 0\neval (S n) = succ (eval n)\n\nfromInt : Int -> Natural\nfromInt n = case n <= 0 of\n True => Zero\n otherwise => S (fromInt (pred n))\n", "meta": {"hexsha": "bc35b4e3a2414ea7d340d9b19906f818038d1469", "size": 205, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "natural.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": "natural.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": "natural.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": 18.6363636364, "max_line_length": 35, "alphanum_fraction": 0.6048780488, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026663679977, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6898231339539148}} {"text": "\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n%name Tree left, val, right\n\nEq elem => Eq (Tree elem) where\n (==) Empty Empty = ?Eq_rhs1_2\n (==) (Node left e right) (Node left' e' right') = left == left' && e == e' && right == right'\n (==) _ _ = False\n\ninsert : Ord elem => elem -> Tree elem -> Tree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left val right) = case compare x val of\n LT => Node (insert x left) val right\n EQ => orig\n GT => Node left val (insert x right)\n\nlistToTree : Ord a => List a -> Tree a\nlistToTree [] = Empty\nlistToTree (x :: xs) = let tree = listToTree xs in insert x tree\n\ntreeToList : Tree a -> List a\ntreeToList Empty = []\ntreeToList (Node left val right) = treeToList left ++ [val] ++ treeToList right\n", "meta": {"hexsha": "53dc23e180c6ff1e50f6d57d11f42f3f7de3927d", "size": 897, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch4/Tree.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/ch4/Tree.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/ch4/Tree.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": 35.88, "max_line_length": 97, "alphanum_fraction": 0.5496098105, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6898231288514065}} {"text": "\\iffalse\nSPDX-License-Identifier: AGPL-3.0-only\n\nThis file is part of `idris-ct` Category Theory in Idris library.\n\nCopyright (C) 2019 Stichting Statebox \n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU Affero General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU Affero General Public License for more details.\n\nYou should have received a copy of the GNU Affero General Public License\nalong with this program. If not, see .\n\\fi\n\n> module Monoid.MonoidMorphismAsFunctor\n>\n> import Basic.Category\n> import Basic.Functor\n> import Monoid.Monoid\n> import Monoid.MonoidAsCategory\n> import Monoid.MonoidMorphism\n>\n> -- contrib\n> import Interfaces.Verified\n>\n> %access public export\n> %default total\n>\n> monoidMorphismToFunctor :\n> (monoid1, monoid2 : Monoid)\n> -> MonoidMorphism monoid1 monoid2\n> -> CFunctor (monoidAsCategory monoid1) (monoidAsCategory monoid2)\n> monoidMorphismToFunctor monoid1 monoid2 (MkMonoidMorphism fun frOp frId) =\n> MkCFunctor\n> id\n> (\\_, _ => fun)\n> (\\_ => frId)\n> (\\_, _, _, f, g => frOp f g)\n", "meta": {"hexsha": "4404616aefbf5d87857a04f2453f3bd48ef48b8e", "size": 1428, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "data/github.com/statebox/idris-ct/9eb218b365eebedab1227823b8e0cd304462a610/src/Monoid/MonoidMorphismAsFunctor.lidr", "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z", "max_issues_repo_path": "data/github.com/statebox/idris-ct/9eb218b365eebedab1227823b8e0cd304462a610/src/Monoid/MonoidMorphismAsFunctor.lidr", "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 91, "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_forks_repo_path": "data/github.com/statebox/idris-ct/9eb218b365eebedab1227823b8e0cd304462a610/src/Monoid/MonoidMorphismAsFunctor.lidr", "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z", "avg_line_length": 31.0434782609, "max_line_length": 76, "alphanum_fraction": 0.7485994398, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6897517618623548}} {"text": "> module Main\n\n> import Data.List\n\n> import EscardoOliva.SelectionFunction\n> import EscardoOliva.Quantifier\n> import EscardoOliva.Operations\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n> data Player = X | O\n\n> Outcome : Type\n> Outcome = Int\n\n> Move : Type\n> Move = Int\n\n> Board : Type\n> Board = (List Move, List Move)\n\n> contained : {X : Type} -> Ord X => List X -> List X -> Bool\n> contained [] ys = True\n> contained xs [] = False\n> contained (x :: xs) (y :: ys) = if x == y \n> then contained xs ys\n> else if x >= y\n> then contained (x :: xs) ys\n> else False\n\n> someContained : {X : Type} -> Ord X => \n> List (List X) -> List X -> Bool\n> someContained [] ys = False\n> someContained xss [] = False\n> someContained (xs :: xss) ys = contained xs ys || someContained xss ys\n\n> wins : List Move -> Bool\n> wins = someContained [[0,1,2],[3,4,5],[6,7,8],\n> [0,3,6],[1,4,7],[2,5,8],\n> [0,4,8],[2,4,6]]\n\n> value : Board -> Outcome\n> value (xs, os) = if wins xs \n> then 1\n> else if wins os \n> then -1\n> else 0\n\n> insert : {X : Type} -> Ord X => X -> List X -> List X\n> insert x [] = [x]\n> insert x (y :: ys) = if x == y \n> then (y :: ys)\n> else if x < y\n> then x :: (y :: ys)\n> else y :: (insert x ys) \n\n> outcome : Player -> List Move -> Board -> Board\n> outcome _ Nil board = board\n> outcome X (m :: ms) (xs, os) = if wins os \n> then (xs, os)\n> else outcome O ms (insert m xs, os)\n> outcome O (m :: ms) (xs, os) = if wins xs \n> then (xs, os)\n> else outcome X ms (xs, insert m os)\n\n> delete : {X : Type} -> Ord X => X -> List X -> List X\n> delete x [] = []\n> delete x (y :: ys) = if x == y\n> then ys\n> else if x < y\n> then y :: ys\n> else y :: Main.delete x ys\n\n> setMinus : {X : Type} -> Ord X => \n> List X -> List X -> List X\n> setMinus xs [] = xs\n> setMinus xs (y :: ys) = setMinus (Main.delete y xs) ys\n\n> partial \n> epsilons : List (List Move -> J Outcome Move)\n> epsilons = take 3 all where\n> partial\n> eX : List Move -> J Outcome Move\n> eX = \\ h => argsup (setMinus [0..8] h)\n> partial\n> eO : List Move -> J Outcome Move\n> eO = \\ h => arginf (setMinus [0..8] h)\n> partial\n> all : List (List Move -> J Outcome Move)\n> all = [eX, eO, eX, eO, eX, eO, eX, eO, eX, eO]\n\n> p : List Move -> Outcome\n> p ms = value (outcome X ms (Nil, Nil))\n\n> partial\n> optimalPlay : List Move\n> optimalPlay = bigotimes epsilons p\n\n> partial\n> optimalOutcome : Outcome\n> optimalOutcome = p optimalPlay\n\n> partial\n> main : IO ()\n> main = \n> do putStr (\"An optimal play for Tic-Tac-Toe is \"\n> ++\n> show optimalPlay ++ \"\\n\"\n> ++\n> \"and the optimal outcome is \"\n> ++\n> show optimalOutcome ++ \"\\n\"\n> )\n\n\n> {-\n\n\n> ---}\n\n\n \n \n", "meta": {"hexsha": "b993f5213b1959691c93313fa94041fda43fb9db", "size": 3398, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "EscardoOliva/TicTacToe.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": "EscardoOliva/TicTacToe.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": "EscardoOliva/TicTacToe.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.7559055118, "max_line_length": 72, "alphanum_fraction": 0.444967628, "num_tokens": 973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6897480974106187}} {"text": "module Data.List.Equalities\n\nimport Data.List\n\n%default total\n\n||| A list constructued using snoc cannot be empty.\nexport\nsnocNonEmpty : {x : a} -> {xs : List a} -> Not (xs ++ [x] = [])\nsnocNonEmpty {xs = []} prf = uninhabited prf\nsnocNonEmpty {xs = y :: ys} prf = uninhabited prf\n\n||| Proof that snoc'ed list is not empty in terms of `NonEmpty`.\nexport %hint\nSnocNonEmpty : (xs : List a) -> (x : a) -> NonEmpty (xs `snoc` x)\nSnocNonEmpty [] _ = IsNonEmpty\nSnocNonEmpty (_::_) _ = IsNonEmpty\n\n||| Two lists are equal, if their heads are equal and their tails are equal.\nexport\nconsCong2 : {x : a} -> {xs : List a} -> {y : b} -> {ys : List b} ->\n x = y -> xs = ys -> x :: xs = y :: ys\nconsCong2 Refl Refl = Refl\n\n||| Equal non-empty lists should result in equal components after destructuring 'snoc'.\nexport\nsnocInjective : {x : a} -> {xs : List a} -> {y : a} -> {ys : List a} ->\n (xs `snoc` x) = (ys `snoc` y) -> (xs = ys, x = y)\nsnocInjective {xs = []} {ys = []} Refl = (Refl, Refl)\nsnocInjective {xs = []} {ys = z :: zs} prf =\n let nilIsSnoc = snd $ consInjective {xs = []} {ys = zs ++ [y]} prf\n in void $ snocNonEmpty (sym nilIsSnoc)\nsnocInjective {xs = z :: xs} {ys = []} prf =\n let snocIsNil = snd $ consInjective {x = z} {xs = xs ++ [x]} {ys = []} prf\n in void $ snocNonEmpty snocIsNil\nsnocInjective {xs = w :: xs} {ys = z :: ys} prf =\n let (wEqualsZ, xsSnocXEqualsYsSnocY) = consInjective prf\n (xsEqualsYS, xEqualsY) = snocInjective xsSnocXEqualsYsSnocY\n in (consCong2 wEqualsZ xsEqualsYS, xEqualsY)\n\n||| Appending pairwise equal lists gives equal lists\nexport\nappendCong2 : {x1 : List a} -> {x2 : List a} ->\n {y1 : List b} -> {y2 : List b} ->\n x1 = y1 -> x2 = y2 -> x1 ++ x2 = y1 ++ y2\nappendCong2 {x1=[]} {y1=(_ :: _)} Refl _ impossible\nappendCong2 {x1=(_ :: _)} {y1=[]} Refl _ impossible\nappendCong2 {x1=[]} {y1=[]} _ eq2 = eq2\nappendCong2 {x1=(_ :: _)} {y1=(_ :: _)} eq1 eq2 =\n let (hdEqual, tlEqual) = consInjective eq1\n in consCong2 hdEqual (appendCong2 tlEqual eq2)\n\n||| List.map is distributive over appending.\nexport\nmapDistributesOverAppend\n : (f : a -> b)\n -> (xs : List a)\n -> (ys : List a)\n -> map f (xs ++ ys) = map f xs ++ map f ys\nmapDistributesOverAppend _ [] _ = Refl\nmapDistributesOverAppend f (x :: xs) ys =\n cong (f x ::) $ mapDistributesOverAppend f xs ys\n\n||| List.length is distributive over appending.\nexport\nlengthDistributesOverAppend\n : (xs, ys : List a)\n -> length (xs ++ ys) = length xs + length ys\nlengthDistributesOverAppend [] ys = Refl\nlengthDistributesOverAppend (x :: xs) ys =\n cong S $ lengthDistributesOverAppend xs ys\n\n||| Length of a snoc'd list is the same as Succ of length list.\nexport\nlengthSnoc : (x : _) -> (xs : List a) -> length (snoc xs x) = S (length xs)\nlengthSnoc x [] = Refl\nlengthSnoc x (_ :: xs) = cong S (lengthSnoc x xs)\n\n||| Appending the same list at left is injective.\nexport\nappendSameLeftInjective : (xs, ys, zs : List a) -> zs ++ xs = zs ++ ys -> xs = ys\nappendSameLeftInjective xs ys [] = id\nappendSameLeftInjective xs ys (_::zs) = appendSameLeftInjective xs ys zs . snd . consInjective\n\n||| Appending the same list at right is injective.\nexport\nappendSameRightInjective : (xs, ys, zs : List a) -> xs ++ zs = ys ++ zs -> xs = ys\nappendSameRightInjective xs ys [] = rewrite appendNilRightNeutral xs in\n rewrite appendNilRightNeutral ys in\n id\nappendSameRightInjective xs ys (z::zs) = rewrite appendAssociative xs [z] zs in\n rewrite appendAssociative ys [z] zs in\n fst . snocInjective . appendSameRightInjective (xs ++ [z]) (ys ++ [z]) zs\n\n||| List cannot be equal to itself prepended with some non-empty list.\nexport\nappendNonEmptyLeftNotEq : (zs, xs : List a) -> NonEmpty xs => Not (zs = xs ++ zs)\nappendNonEmptyLeftNotEq [] (_::_) Refl impossible\nappendNonEmptyLeftNotEq (z::zs) (_::xs) prf\n = appendNonEmptyLeftNotEq zs (xs ++ [z]) @{SnocNonEmpty xs z}\n $ rewrite sym $ appendAssociative xs [z] zs in snd $ consInjective prf\n\n||| List cannot be equal to itself appended with some non-empty list.\nexport\nappendNonEmptyRightNotEq : (zs, xs : List a) -> NonEmpty xs => Not (zs = zs ++ xs)\nappendNonEmptyRightNotEq [] (_::_) Refl impossible\nappendNonEmptyRightNotEq (_::zs) (x::xs) prf = appendNonEmptyRightNotEq zs (x::xs) $ snd $ consInjective prf\n", "meta": {"hexsha": "8e09ecdc05d2f4a1ea70c3912f76e51b6e8a79ce", "size": 4465, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/List/Equalities.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/contrib/Data/List/Equalities.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/contrib/Data/List/Equalities.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 41.3425925926, "max_line_length": 114, "alphanum_fraction": 0.6277715566, "num_tokens": 1469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6896397609142695}} {"text": "-- Local Variables:\n-- idris-load-packages: (\"prelude\" \"effects\" \"contrib\" \"base\")\n-- End:\n\nimport Data.Vect\nimport Effects\nimport Effect.State\n\n\n-- Here we're going to include some algorithms related to Huth and Ryan's book, for practice\n\ndata Formula = Atom String | Disj Formula Formula | Conj Formula Formula\n | Imp Formula Formula | Neg Formula\n \n-- we could do a CNF conversion to a different type but I'd also like to try seeing if\n-- I can do a thing of converting to the same type and actually proving that it won't\n-- produce terms outside the subset\n\nnoImp : Formula -> Formula\nnoImp (Atom x) = (Atom x)\nnoImp (Disj x y) = Disj (noImp x) (noImp y)\nnoImp (Conj x y) = Conj (noImp x) (noImp y)\nnoImp (Imp x y) = Disj (Neg x) y\nnoImp (Neg x) = Neg (noImp x)\n\n-- now how do we state our property? Maybe something like\n\nnoImpCorrect : (f : Formula) -> (g : Formula) -> (h : Formula) -> (Imp g h) = (noImp f) -> Void\nnoImpCorrect (Atom _) _ _ Refl impossible\nnoImpCorrect (Disj _ _) _ _ Refl impossible\nnoImpCorrect (Conj _ _) _ _ Refl impossible\nnoImpCorrect (Imp _ _) _ _ Refl impossible\nnoImpCorrect (Neg _) _ _ Refl impossible\n\ndata Lit = PosAtom String | NegAtom String -- yes this is really just an either type\n\nnegLit : Lit -> Lit\nnegLit (PosAtom x) = NegAtom x\nnegLit (NegAtom x) = PosAtom x\n\ninstance Eq Lit where\n (PosAtom x) == (PosAtom y) = x == y\n (NegAtom x) == (NegAtom y) = x == y\n x == y = False\n\nCNF : Type\nCNF = List (List Lit) -- the outer ones are conjunctions the inner lists are disjunctions\n\naux : List Lit -> Bool\naux [] = True\naux (x :: xs) = (elem (negLit x) xs) || (aux xs)\n\n-- Okay I'm really confused why it can't figure out the type instance if I put cnf instead of List (List Lit).\ncnfValid : CNF -> Bool\ncnfValid c = all aux c\n\ndata ImpFree = IConj ImpFree ImpFree | IDisj ImpFree ImpFree | INeg ImpFree\n | IAtom String\n \nimpFree : Formula -> ImpFree\nimpFree (Atom x) = (IAtom x)\nimpFree (Disj x y) = IDisj (impFree x) (impFree y)\nimpFree (Conj x y) = IConj (impFree x) (impFree y)\nimpFree (Imp x y) = IDisj (INeg (impFree x)) (impFree y)\nimpFree (Neg x) = INeg (impFree x)\n\ndata NNF = NConj NNF NNF | NDisj NNF NNF | NLit Lit\n\ntoNNF : ImpFree -> NNF\ntoNNF (IConj x y) = NConj (toNNF x) (toNNF y)\ntoNNF (IDisj x y) = NDisj (toNNF x) (toNNF y)\ntoNNF (INeg (IConj x y)) = NDisj (toNNF arg1)\n (toNNF arg2)\n where arg1 = assert_smaller (INeg (IConj x y)) (INeg x)\n arg2 = assert_smaller (INeg (IConj x y)) (INeg y)\n\ntoNNF (INeg (IDisj x y)) = NConj (toNNF (assert_smaller (INeg (IDisj x y)) (INeg x)))\n (toNNF (assert_smaller (INeg (IDisj x y)) (INeg y)))\ntoNNF (INeg (INeg x)) = toNNF x\ntoNNF (INeg (IAtom x)) = NLit (NegAtom x)\ntoNNF (IAtom x) = NLit (PosAtom x)\n\naccumLits : NNF -> List Lit\naccumLits (NConj x y) = accumLits x ++ accumLits y -- this case won't happen in disjLift\naccumLits (NDisj x y) = accumLits x ++ accumLits y\naccumLits (NLit x) = [x]\n\ndisjLift : (x : NNF) -> (y : NNF) -> List (List Lit) \ndisjLift (NConj x1 x2) y = (disjLift x1 y) ++ (disjLift x2 y)\ndisjLift x (NConj y1 y2) = (disjLift x y1) ++ (disjLift x y2)\ndisjLift x y = [(accumLits x) ++ (accumLits y)]\n\nnnfTocnf : NNF -> CNF\nnnfTocnf (NConj x y) = nnfTocnf x ++ nnfTocnf y\nnnfTocnf (NDisj x y) = disjLift x y\nnnfTocnf (NLit x) = [[x]]\n\nisValid : Formula -> Bool\nisValid = cnfValid . nnfTocnf . toNNF . impFree\n\n-- okay then!\n\n{- \n Now let's get to horn clauses. These are going to be built up inductively as\n-}\n\ndata P = PBot | PTop | PLit Lit\n\ndata Clause p = CImp (List p) p\n\nHorn : Type -> Type\nHorn p = List (Clause p)\n\nblah : Clause P -> List P\nblah (CImp xs x) = xs ++ [x]\n\ncollectPs : Horn P -> List P\ncollectPs = concat . map blah\n\ndata IsMarked = Marked P | Unmarked P\n\nsatHorn : Horn (Fin n) -> Vect n IsMarked -> Bool\nsatHorn h v = ?rhs\n\n{- \n Now the problem here is that the Huth and Ryan algorithm for this is a while loop that translates rather uglily from an imperative language to a functional one.\n \n Now, we could do a translation of the loop with just recursion, yes\n-}\n\nmarkTop : IsMarked -> IsMarked\nmarkTop (Marked x) = (Marked x)\nmarkTop a@(Unmarked PBot) = a\nmarkTop (Unmarked PTop) = Marked PTop\nmarkTop a@(Unmarked (PLit x)) = a\n\nisDone : Horn (Fin n) -> Bool\nisDone h = ?fdas\n\nnotBot : IsMarked -> Bool\nnotBot m = ?asdf\n\nuglySatAux : (h : List (Clause (Fin n))) -> Vect n IsMarked -> Bool\nuglySatAux h vs = if (isDone h) then (and (map notBot vs)) else ?blee\n\nuglySat : Horn (Fin n) -> Vect n IsMarked -> Bool\nuglySat h v = uglySatAux h (map markTop v)\n", "meta": {"hexsha": "afe568abc4d771934605ab54fb2eaaec6d0ec10c", "size": 4631, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "huth.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": "huth.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": "huth.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.2905405405, "max_line_length": 162, "alphanum_fraction": 0.656229756, "num_tokens": 1625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.6896397514205145}} {"text": "import Data.Vect\n\nfourInts: Vect 4 Int\nfourInts = [0, 1, 2, 3]\n\nsixInts : Vect 6 Int\nsixInts = [4, 5, 6, 7, 8, 9]\n\ntenInts : Vect 10 Int\ntenInts = fourInts ++ sixInts\n\nallLengths : Vect len String -> Vect len Nat\nallLengths [] = []\nallLengths (word :: words) = length word :: allLengths words\n\ninsert : Ord elem => (x : elem) -> (xsSorted : Vect len elem) -> Vect (S len) elem\ninsert x [] = [x]\ninsert x (y :: xs) = case x < y of\n False => y :: insert x xs\n True => x :: y :: xs\n\ninsSort : Ord elem => Vect n elem -> Vect n elem\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insert x xsSorted\n", "meta": {"hexsha": "ac41289ff74dac14e6b6f7e4fa19aa53e309f5bc", "size": 688, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp3/Vectors.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "type_driven_book/chp3/Vectors.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "type_driven_book/chp3/Vectors.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": 26.4615384615, "max_line_length": 82, "alphanum_fraction": 0.550872093, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6896240028340126}} {"text": "module Data.List.NotElem\n\n%default total\n%access public export\n\ndata NotElem : (prfEq : a -> a -> Type) -> a -> List a -> Type where\n IsEmpty : NotElem prfEq x Nil\n NotFirst : (prf : Not (prfEq x y)) -> NotElem prfEq x Nil -> NotElem prfEq x [y]\n NotThere : (prf : Not (prfEq x y))\n -> (notLater : NotElem prfEq x there)\n -> NotElem prfEq x (y::there)\n\nisFirstElem : (decEq : (x : a) -> (y : a) -> Dec (prfSame x y))\n -> (prf : prfSame n x)\n -> NotElem prfSame n (x :: xs)\n -> Void\nisFirstElem decEq prf (NotFirst f x) = f prf\nisFirstElem decEq prf (NotThere f notLater) = f prf\n\nisFoundLater : (decEq : (x : a) -> (y : a) -> Dec (prfSame x y))\n -> (contra : prfSame n x -> Void)\n -> (f : NotElem prfSame n xs -> Void)\n -> NotElem prfSame n (x :: xs)\n -> Void\nisFoundLater decEq contra f (NotFirst prf x) = f x\nisFoundLater decEq contra f (NotThere prf notLater) = f notLater\n\nnotElem : (decEq : (x,y : a) -> Dec (prfSame x y))\n -> (n : a)\n -> (ns : List a)\n -> Dec (NotElem prfSame n ns)\nnotElem decEq n [] = Yes IsEmpty\nnotElem decEq n (x :: xs) with (decEq n x)\n notElem decEq n (x :: xs) | (Yes prf) = No (isFirstElem decEq prf)\n notElem decEq n (x :: xs) | (No contra) with (notElem decEq n xs)\n notElem decEq n (x :: xs) | (No contra) | (Yes prf) = Yes (NotThere contra prf)\n notElem decEq n (x :: xs) | (No contra) | (No f) = No (isFoundLater decEq contra f)\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "1a158a544019d153ef0c5f81c8b819447d2852dc", "size": 1569, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/List/NotElem.idr", "max_stars_repo_name": "witt3rd/idris-containers", "max_stars_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 99, "max_stars_repo_stars_event_min_datetime": "2015-03-01T20:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:17:39.000Z", "max_issues_repo_path": "Data/List/NotElem.idr", "max_issues_repo_name": "witt3rd/idris-containers", "max_issues_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2015-03-23T19:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T13:05:44.000Z", "max_forks_repo_path": "Data/List/NotElem.idr", "max_forks_repo_name": "witt3rd/idris-containers", "max_forks_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-06-02T17:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T14:51:07.000Z", "avg_line_length": 39.225, "max_line_length": 87, "alphanum_fraction": 0.5423836839, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7772998560157663, "lm_q1q2_score": 0.6896239936799693}} {"text": "module Addition.Digit\n\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.TranslationInvariance\nimport Proofs.Interval\n\n%default total\n%access public export\n\ndata Digit : (leq : Binrel s) -> (neg : s -> s) -> s -> Type where\n MkDigit : (x : s) -> .InSymRange leq neg u x -> Digit leq neg u\n\nval : Digit {s} _ _ _ -> s\nval (MkDigit x _) = x\n\nimplementation Show s => Show (Digit {s} leq neg u) where\n show (MkDigit x _) = show x\n\n||| adding two digits makes the range twice as big\naddDigits : Ringops s => PartiallyOrderedGroupSpec {s} (+) Zero Ng leq ->\n OuterBinop (Digit leq Ng) u u (u + u)\naddDigits spec (MkDigit x p) (MkDigit y q) =\n MkDigit (x + y) (addInSymRange spec p q)\n\n\n||| To produce test input, full decidability is overkill\nmaybeDigit : Decidable [s,s] leq => (neg : s -> s) -> (u : s) ->\n s -> Maybe (Digit leq neg u)\nmaybeDigit {leq} neg u x =\n case decideBetween {leq} (neg u) u x of\n Yes prf => Just (MkDigit x prf)\n No _ => Nothing\n\n||| To produce test input, full decidability is overkill\nmaybeDigits : (Traversable trav, Decidable [s,s] leq) =>\n (neg : s -> s) -> (u : s) -> trav s -> Maybe (trav (Digit leq neg u))\nmaybeDigits {leq} neg u = sequence . map (maybeDigit {leq} neg u)\n", "meta": {"hexsha": "7d674420d2195da0e7ad127ff2e19c06cfc3e378", "size": 1232, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Addition/Digit.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/Digit.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/Digit.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": 31.5897435897, "max_line_length": 73, "alphanum_fraction": 0.6590909091, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652496, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6896071328562144}} {"text": "import Data.Vect\nimport Data.Vect.Views\n\ntotal\nmerge_sort : Ord a => Vect n a -> Vect n a\nmerge_sort xs with (splitRec xs)\n merge_sort [] | SplitRecNil = []\n merge_sort [x] | SplitRecOne = [x]\n merge_sort (lefts ++ rights) | (SplitRecPair lrec rrec)\n = merge (merge_sort lefts | lrec) (merge_sort rights | rrec)\n", "meta": {"hexsha": "6ff1cece10b7185911b0c907c33bd084a2256b0a", "size": 319, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/merge_sort_vect.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/merge_sort_vect.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/merge_sort_vect.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.0, "max_line_length": 65, "alphanum_fraction": 0.6865203762, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.68960711006277}} {"text": "> module Nat.OperationsProperties\n\n> import Syntax.PreorderReasoning\n\n> -- import NatPredicates\n> import Nat.Operations\n> import Nat.BasicProperties\n> import Nat.LTEProperties\n> import Nat.LTProperties\n> import Basic.Operations\n> import Functor.Predicates\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\nProperties of |pred|:\n\n> |||\n> predLemma : (n : Nat) -> (prf : Z `LT` n) -> S (pred n prf) = n\n> predLemma Z prf = absurd prf\n> predLemma (S m) _ = Refl\n> %freeze predLemma\n\n\nProperties of |=|:\n\n> ||| EQ is contained in LTE\n> eqInLTE : (m : Nat) -> (n : Nat) -> m = n -> m `LTE` n\n> eqInLTE Z n prf = LTEZero\n> eqInLTE (S m) Z prf = absurd prf\n> eqInLTE (S m) (S n) prf = LTESucc (eqInLTE m n (succInjective m n prf))\n> %freeze eqInLTE\n\n\nProperties of |plus|:\n\n> |||\n> plusPlusElimLeft : {m1, n1, m2, n2 : Nat} -> m1 + n1 = m2 + n2 -> m1 = m2 -> n1 = n2\n> plusPlusElimLeft {m1 = Z} {n1} {m2 = Z} {n2} p1 Refl = s2 where\n> s1 : n1 = Z + n2\n> s1 = replace {x = Z + n1}\n> {y = n1}\n> {P = \\ ZUZU => ZUZU = Z + n2}\n> (plusZeroLeftNeutral n1)\n> p1\n> s2 : n1 = n2\n> s2 = replace {x = Z + n2}\n> {y = n2}\n> {P = \\ ZUZU => n1 = ZUZU}\n> (plusZeroLeftNeutral n2)\n> s1\n> plusPlusElimLeft {m1 = Z} {n1} {m2 = S m2} {n2} p1 Refl impossible\n> plusPlusElimLeft {m1 = S m1} {n1} {m2 = Z} {n2} p1 Refl impossible\n> plusPlusElimLeft {m1 = S m1} {n1} {m2 = S m2} {n2} p1 p2 = plusPlusElimLeft p1' p2' where\n> p1' : m1 + n1 = m2 + n2\n> p1' = succInjective (m1 + n1) (m2 + n2) p1\n> p2' : m1 = m2\n> p2' = succInjective m1 m2 p2\n> %freeze plusPlusElimLeft\n\n> |||\n> plusElimLeft : (m1 : Nat) -> (n : Nat) -> (m2 : Nat) -> m1 + n = m2 -> m1 = m2 -> n = Z\n> plusElimLeft m n m p Refl = plusLeftLeftRightZero m n p\n> %freeze plusElimLeft\n\n> {-\n\n> |||\n> idPlusAnyPreservesLT : (m : Nat) -> (n : Nat) -> m `LT` n -> (p : Nat) -> m `LT` (n + p)\n\n> |||\n> idAnyPlusPreservesLT : (m : Nat) -> (n : Nat) -> m `LT` n -> (p : Nat) -> m `LT` (p + n)\n\n> |||\n> plusPreservesLT : (m : Nat) -> (n : Nat) -> m `LT` n ->\n> (p : Nat) -> (q : Nat) -> p `LT` q ->\n> (m + p) `LT` (n + q)\n> plusPreservesLT Z Z zLTz _ _ _ = absurd zLTz \n> plusPreservesLT Z (S n) zLTsn p q pLTq = idAnyPlusPreservesLT p q pLTq (S n)\n> plusPreservesLT (S m) Z smLTz _ _ _ = absurd smLTz \n> plusPreservesLT (S m) (S n) smLTsn p q pLTq = LTESucc (plusPreservesLT m n (fromLteSucc smLTsn) p q pLTq)\n\n> -}\n\n\nProperties of |minus|:\n\n> ||| The difference of equal numbers is zero\n> minusLemma0 : m = n -> m - n = Z\n> minusLemma0 {m = Z} {n = Z} Refl = Refl\n> minusLemma0 {m = Z} {n = S n'} prf = absurd prf\n> minusLemma0 {m = S m'} {n = Z} prf = absurd prf\n> minusLemma0 {m = S m'} {n = S n'} prf = trans s1 s2 where\n> s1 : S m' - S n' = m' - n'\n> s1 = Refl\n> s2 : m' - n' = Z\n> s2 = minusLemma0 (succInjective m' n' prf)\n> %freeze minusLemma0\n\n> |||\n> minusLemma1 : n - m = S l -> l = n - (S m)\n> minusLemma1 {l} {m = Z} {n = Z} p = absurd p\n> minusLemma1 {l} {m = Z} {n = S n'} p = s5 where\n> s1 : S n' = S l\n> s1 = p\n> s2 : l = n'\n> s2 = sym (succInjective n' l s1)\n> s3 : n' = n' - Z\n> s3 = sym (minusZeroRight n')\n> s4 : n' - Z = S n' - S Z\n> s4 = Refl\n> s5 : l = S n' - S Z\n> s5 = trans s2 (trans s3 s4)\n> minusLemma1 {l} {m = S m'} {n = Z} p = absurd p\n> minusLemma1 {l} {m = S m'} {n = S n'} p = s3 where\n> s1 : n' - m' = S l\n> s1 = p\n> s2 : l = n' - (S m')\n> s2 = minusLemma1 s1\n> s3 : l = S n' - S (S m')\n> s3 = trans s2 Refl\n> %freeze minusLemma1\n\n> |||\n> minusLemma2 : LTE m n -> n - m = S l -> LTE (S m) n\n> minusLemma2 {m = Z} {n = Z} p q = absurd q\n> minusLemma2 {m = Z} {n = S n'} p q = LTESucc LTEZero\n> minusLemma2 {m = S m'} {n = Z} p q = absurd p\n> minusLemma2 {m = S m'} {n = S n'} (LTESucc p') q = LTESucc (minusLemma2 p' q)\n> %freeze minusLemma2\n\n> |||\n> minusLemma3 : LTE m n -> Z = n - m -> m = n\n> minusLemma3 {m = Z} {n = Z} p q = Refl\n> minusLemma3 {m = Z} {n = S n'} p q = absurd q\n> minusLemma3 {m = S m'} {n = Z} p q = absurd p\n> minusLemma3 {m = S m'} {n = S n'} (LTESucc p') q =\n> eqSucc m' n' (minusLemma3 {m = m'} {n = n'} p' q') where\n> q' : Z = n' - m'\n> q' = trans q Refl\n> %freeze minusLemma3\n\n> |||\n> minusLemma4 : LTE (S m) n -> S (n - S m) = n - m\n> minusLemma4 {m = Z} {n = Z} p = absurd p\n> minusLemma4 {m = Z} {n = S n'} (LTESucc p') =\n> ( S (S n' - S Z) )\n> ={ Refl }=\n> ( S (n' - Z) )\n> ={ cong (minusZeroRight n') }=\n> ( S n' )\n> ={ Refl }=\n> ( S n' - Z )\n> QED\n> minusLemma4 {m = S m'} {n = Z} p = absurd p\n> minusLemma4 {m = S m'} {n = S n'} (LTESucc p') =\n> ( S (S n' - S (S m')) )\n> ={ Refl }=\n> ( S (n' - S m') )\n> ={ minusLemma4 p' }=\n> ( n' - m' )\n> ={ Refl }=\n> ( S n' - S m' )\n> QED\n> %freeze minusLemma4\n\n\nProperties of |plus| and |minus|:\n\n> |||\n> plusZeroLeftZero : (m : Nat) -> (n : Nat) -> m + n = Z -> m = Z\n> plusZeroLeftZero Z Z _ = Refl\n> plusZeroLeftZero Z (S n) prf = absurd prf\n> plusZeroLeftZero (S m) Z prf = absurd prf\n> plusZeroLeftZero (S m) (S n) prf = absurd prf\n> %freeze plusZeroLeftZero\n\n> |||\n> plusZeroRightZero : (m : Nat) -> (n : Nat) -> m + n = Z -> n = Z\n> plusZeroRightZero Z Z _ = Refl\n> plusZeroRightZero Z (S n) prf = absurd prf\n> plusZeroRightZero (S m) Z prf = absurd prf\n> plusZeroRightZero (S m) (S n) prf = absurd prf\n> %freeze plusZeroRightZero\n\n> -- plusOneEither : (m : Nat) -> (n : Nat) -> m + n = S Z -> Either (m = Z) (n = Z)\n\n> plusRightInverseMinus : (m : Nat) -> (n : Nat) -> m `LTE` n -> (n - m) + m = n\n> plusRightInverseMinus Z n _ =\n> ( (n - Z) + Z )\n> ={ plusZeroRightNeutral (n - Z) }=\n> ( n - Z )\n> ={ minusZeroRight n }=\n> ( n )\n> QED\n> plusRightInverseMinus (S m) n p =\n> ( (n - S m) + S m )\n> ={ plusCommutative (n - S m) (S m) }=\n> ( S m + (n - S m) )\n> ={ plusSuccRightSucc m (n - S m) }=\n> ( m + S (n - S m) )\n> ={ replace {x = S (n - S m)}\n> {y = n - m}\n> {P = \\ ZUZU => m + S (n - S m) = m + ZUZU }\n> (minusLemma4 p) Refl}=\n> ( m + (n - m) )\n> ={ plusCommutative m (n - m) }=\n> ( (n - m) + m )\n> ={ plusRightInverseMinus m n (lteLemma1 m n p) }=\n> ( n )\n> QED\n> %freeze plusRightInverseMinus\n\n\nProperties of |mult|:\n\n> ||| Multiplication of successors is not zero\n> multSuccNotZero : (m : Nat) -> (n : Nat) -> Not ((S m) * (S n) = Z)\n> multSuccNotZero m n p = absurd p\n> %freeze multSuccNotZero\n\n> ||| Multiplication of non-zeros is not zero\n> multNotZeroNotZero : (m : Nat) -> (n : Nat) -> Not (m = Z) -> Not (n = Z) -> Not (m * n = Z)\n> multNotZeroNotZero Z n p q = void (p Refl)\n> multNotZeroNotZero (S m) Z p q = void (q Refl)\n> multNotZeroNotZero (S m) (S n) p q = multSuccNotZero m n\n> %freeze multNotZeroNotZero\n\n> ||| Multiplication not zero implies non-zero left\n> multNotZeroNotZeroLeft : (m : Nat) -> (n : Nat) -> Not (m * n = Z) -> Not (m = Z)\n> multNotZeroNotZeroLeft Z n p = void (p (multZeroLeftZero n))\n> multNotZeroNotZeroLeft (S m) _ _ = SIsNotZ\n> %freeze multNotZeroNotZeroLeft\n\n> ||| Multiplication not zero implies non-zero right\n> multNotZeroNotZeroRight : (m : Nat) -> (n : Nat) -> Not (m * n = Z) -> Not (n = Z)\n> multNotZeroNotZeroRight m Z p = void (p (multZeroRightZero m))\n> multNotZeroNotZeroRight _ (S n) _ = SIsNotZ\n> %freeze multNotZeroNotZeroRight\n\n> ||| Multiplication of greater-than-zeros is greater than zero\n> multZeroLTZeroLT : (m : Nat) -> (n : Nat) -> Z `LT` m -> Z `LT` n -> Z `LT` (m * n)\n> multZeroLTZeroLT Z n p _ = absurd p\n> multZeroLTZeroLT (S m) Z _ q = absurd q\n> multZeroLTZeroLT (S m) (S n) _ _ = ltZS (n + m * (S n))\n> %freeze multZeroLTZeroLT\n\n> ||| Multiplication greater than zero implies greater than zero left\n> multLTZeroLeftLTZero : (m : Nat) -> (n : Nat) -> Z `LT` (m * n) -> Z `LT` m\n> multLTZeroLeftLTZero Z n p = absurd p' where\n> p' : Z `LT` Z\n> p' = replace {x = Z * n}\n> {y = Z}\n> {P = \\ ZUZU => Z `LT` ZUZU}\n> (multZeroLeftZero n) p\n> multLTZeroLeftLTZero (S m) n _ = ltZS m\n> %freeze multLTZeroLeftLTZero\n\n> ||| Multiplication greater than zero implies greater than zero right\n> multLTZeroRightLTZero : (m : Nat) -> (n : Nat) -> Z `LT` (m * n) -> Z `LT` n\n> multLTZeroRightLTZero m Z p = absurd p' where\n> p' : Z `LT` Z\n> p' = replace {x = m * Z}\n> {y = Z}\n> {P = \\ ZUZU => Z `LT` ZUZU}\n> (multZeroRightZero m) p\n> multLTZeroRightLTZero m (S n) _ = ltZS n\n> %freeze multLTZeroRightLTZero\n\n> ||| \n> multZeroRightOneLeftZero : (m : Nat) -> (n : Nat) -> m * (S n) = Z -> m = Z\n> multZeroRightOneLeftZero m n prf = plusZeroLeftZero m (n * m) prf' where\n> prf' : (S n) * m = Z\n> prf' = replace {x = m * (S n)} {y = (S n) * m} {P = \\ ZUZU => ZUZU = Z} (multCommutative m (S n)) prf\n> %freeze multZeroRightOneLeftZero\n\n> |||\n> multZeroLeftOneRightZero : (m : Nat) -> (n : Nat) -> (S m) * n = Z -> n = Z\n> multZeroLeftOneRightZero m n prf = plusZeroLeftZero n (m * n) prf\n> %freeze multZeroLeftOneRightZero\n\n> |||\n> multOneLeftOne : (m : Nat) -> (n : Nat) -> m * n = S Z -> m = S Z\n> multOneLeftOne Z n prf = absurd prf\n> multOneLeftOne (S m) Z prf = absurd prf' where\n> prf' : Z = S Z\n> prf' = replace {x = (S m) * Z}\n> {y = Z}\n> {P = \\ ZUZU => ZUZU = S Z}\n> (multZeroRightZero (S m)) prf\n> multOneLeftOne (S m) (S n) prf = eqSucc m Z s5 where\n> s1 : S (n + m * (S n)) = S Z\n> s1 = prf\n> s2 : n + m * (S n) = Z\n> s2 = succInjective (n + m * (S n)) Z s1\n> s3 : n = Z\n> s3 = plusZeroLeftZero n (m * (S n)) s2\n> s4 : m * (S n) = Z\n> s4 = plusZeroRightZero n (m * (S n)) s2\n> s5 : m = Z\n> s5 = multZeroRightOneLeftZero m n s4\n> %freeze multOneLeftOne\n\n> |||\n> multOneRightOne : (m : Nat) -> (n : Nat) -> m * n = S Z -> n = S Z\n> multOneRightOne m n prf = multOneLeftOne n m prf' where\n> prf' : n * m = S Z\n> prf' = replace {x = m * n} {y = n * m} {P = \\ ZUZU => ZUZU = S Z} (multCommutative m n) prf\n> %freeze multOneRightOne\n\n> |||\n> multPreservesEq : (m1 : Nat) -> (m2 : Nat) -> (n1 : Nat) -> (n2 : Nat) ->\n> m1 = m2 -> n1 = n2 -> m1 * n1 = m2 * n2\n> multPreservesEq m m n n Refl Refl = Refl\n> %freeze multPreservesEq\n\n> |||\n> multMultElimLeft : (m1 : Nat) -> (m2 : Nat) -> (n1 : Nat) -> (n2 : Nat) ->\n> m1 = m2 -> Not (m1 = Z) -> m1 * n1 = m2 * n2 -> \n> n1 = n2\n> multMultElimLeft _ _ Z Z _ _ _ = Refl\n> multMultElimLeft m1 m2 Z (S n2) m1EQm2 nm1EQZ m1ZEQm2sn2 = \n> void (nm1EQZ s4) where\n> s0 : m1 * Z = m2 * (S n2)\n> s0 = m1ZEQm2sn2\n> s1 : Z = m2 * (S n2)\n> s1 = replace {x = m1 * Z} {y = Z} {P = \\ ZUZU => ZUZU = m2 * (S n2)} (multZeroRightZero m1) s0\n> s2 : Z = m2\n> s2 = sym (multZeroRightOneLeftZero m2 n2 (sym s1))\n> s3 : m2 = Z\n> s3 = sym s2\n> s4 : m1 = Z\n> s4 = replace (sym m1EQm2) s3\n> multMultElimLeft m1 m2 (S n1) Z m1EQm2 nm1EQZ m1sn1EQm2Z = \n> void (nm1EQZ s2) where\n> s0 : m1 * (S n1) = m2 * Z\n> s0 = m1sn1EQm2Z\n> s1 : m1 * (S n1) = Z\n> s1 = replace {x = m2 * Z} {y = Z} {P = \\ ZUZU => m1 * (S n1) = ZUZU} (multZeroRightZero m2) s0\n> s2 : m1 = Z\n> s2 = multZeroRightOneLeftZero m1 n1 s1\n> multMultElimLeft m1 m2 (S n1) (S n2) m1EQm2 nm1EQZ m1sn1EQm2sn2 = \n> eqSucc n1 n2 s5 where\n> s0 : m1 * (S n1) = m2 * (S n2)\n> s0 = m1sn1EQm2sn2\n> s1 : (S n1) * m1 = (S n2) * m2\n> s1 = replace2 {a = Nat} {a1 = m1 * (S n1)} {a2 = (S n1) * m1} \n> {b = Nat} {b1 = m2 * (S n2)} {b2 = (S n2) * m2} \n> {P = \\ ZUZU => \\ ZAZA => ZUZU = ZAZA}\n> (multCommutative m1 (S n1)) (multCommutative m2 (S n2)) s0\n> s2 : m1 + n1 * m1 = m2 + n2 * m2\n> s2 = s1\n> s3 : n1 * m1 = n2 * m2\n> s3 = plusPlusElimLeft s2 m1EQm2\n> s4 : m1 * n1 = m2 * n2\n> s4 = replace2 {a = Nat} {a1 = n1 * m1} {a2 = m1 * n1}\n> {b = Nat} {b1 = n2 * m2} {b2 = m2 * n2}\n> {P = \\ ZUZU => \\ ZAZA => ZUZU = ZAZA}\n> (multCommutative n1 m1) (multCommutative n2 m2) s3\n> s5 : n1 = n2\n> s5 = multMultElimLeft m1 m2 n1 n2 m1EQm2 nm1EQZ s4\n> %freeze multMultElimLeft --\n\n> |||\n> multMultElimRight : (m1 : Nat) -> (m2 : Nat) -> (n1 : Nat) -> (n2 : Nat) ->\n> n1 = n2 -> Not (n1 = Z) -> m1 * n1 = m2 * n2 -> \n> m1 = m2\n> multMultElimRight m1 m2 n1 n2 n1EQn2 nn1EQZ prf =\n> multMultElimLeft n1 n2 m1 m2 n1EQn2 nn1EQZ prf' where\n> prf' : n1 * m1 = n2 * m2\n> prf' = replace2 (multCommutative m1 n1) (multCommutative m2 n2) prf\n> %freeze multMultElimRight --\n\n> |||\n> multElim1 : (m : Nat) -> (n : Nat) -> (S m) * n = S m -> n = S Z\n> multElim1 m Z p = absurd s1 where\n> s1 : Z = S m\n> s1 = replace {x = (S m) * Z} {y = Z} {P = \\ ZUZU => ZUZU = S m} (multZeroRightZero (S m)) p\n> multElim1 m (S Z) _ = Refl\n> multElim1 m (S (S n)) p = void (multSuccNotZero n m s5) where\n> s1 : (S (S n)) * (S m) = S m\n> s1 = replace {x = (S m) * (S (S n))}\n> {y = (S (S n)) * (S m)}\n> {P = \\ ZUZU => ZUZU = S m}\n> (multCommutative (S m) (S (S n))) p\n> s2 : S m + (S n) * (S m) = S m\n> s2 = replace {x = (S (S n)) * (S m)}\n> {y = S m + (S n) * (S m)}\n> {P = \\ ZUZU => ZUZU = S m}\n> Refl s1\n> s5 : (S n) * (S m) = Z\n> s5 = plusLeftLeftRightZero (S m) ((S n) * (S m)) s2\n> %freeze multElim1\n\n> |||\n> multSwapLeft : (a, b, c : Nat) -> a * b * c = b * a * c\n> multSwapLeft a b c = ( a * b * c )\n> ={ Refl }=\n> ( (a * b) * c )\n> ={ cong {f = \\ ZUZU => ZUZU * c} (multCommutative a b) }=\n> ( (b * a) * c )\n> ={ Refl }=\n> ( b * a * c )\n> QED\n> %freeze multSwapLeft\n\n> |||\n> multSwapRight : (a, b, c : Nat) -> a * b * c = a * c * b\n> multSwapRight a b c = ( a * b * c )\n> ={ Refl }=\n> ( (a * b) * c )\n> ={ sym (multAssociative a b c) }=\n> ( a * (b * c) )\n> ={ cong (multCommutative b c) }=\n> ( a * (c * b) )\n> ={ multAssociative a c b }=\n> ( (a * c) * b )\n> ={ Refl }=\n> ( a * c * b )\n> QED\n> %freeze multSwapRight\n\n> |||\n> multSwap23 : (a, b, c, d : Nat) -> (a * b) * (c * d) = (a * c) * (b * d)\n> multSwap23 a b c d = ( (a * b) * (c * d) )\n> ={ Refl }=\n> ( a * b * (c * d) )\n> ={ sym (multAssociative a b (c * d)) }=\n> ( a * (b * (c * d)) )\n> ={ cong {f = \\ ZUZU => a * ZUZU} (multAssociative b c d) }=\n> ( a * ((b * c) * d) )\n> ={ cong {f = \\ ZUZU => a * ZUZU} (multSwapLeft b c d) }=\n> ( a * ((c * b) * d) )\n> ={ cong {f = \\ ZUZU => a * ZUZU} (sym (multAssociative c b d)) }=\n> ( a * (c * (b * d)) )\n> ={ multAssociative a c (b * d) }=\n> ( a * c * (b * d) )\n> ={ Refl }=\n> ( (a * c) * (b * d) )\n> QED\n> %freeze multSwap23\n\n> |||\n> multSwap24 : (a, b, c, d : Nat) -> (a * b) * (c * d) = (a * d) * (c * b)\n> multSwap24 a b c d = ( (a * b) * (c * d) )\n> ={ cong {f = \\ ZUZU => (a * b) * ZUZU} (multCommutative c d) }=\n> ( (a * b) * (d * c) )\n> ={ multSwap23 a b d c }=\n> ( (a * d) * (b * c) )\n> ={ cong {f = \\ ZUZU => (a * d) * ZUZU} (multCommutative b c) }=\n> ( (a * d) * (c * b) )\n> QED\n> %freeze multSwap24\n\n> |||\n> multFlipCentre : (m1 : Nat) -> (m2 : Nat) -> (n1 : Nat) -> (n2 : Nat) ->\n> (m1 * m2) * (n1 * n2) = (m1 * n1) * (m2 * n2)\n> multFlipCentre = multSwap23\n> %freeze multFlipCentre\n\n> |||\n> multOneRightNeutralPlusMultZeroLeftZero : (m : Nat) -> (n : Nat) -> m * 1 + 0 * n = m\n> multOneRightNeutralPlusMultZeroLeftZero m n =\n> ( m * 1 + 0 * n )\n> ={ cong (multZeroLeftZero n) }=\n> ( m * 1 + 0 )\n> ={ cong {f = \\ ZUZU => ZUZU + 0} (multOneRightNeutral m) }=\n> ( m + 0 )\n> ={ plusZeroRightNeutral m }= \n> ( m )\n> QED\n> %freeze multOneRightNeutralPlusMultZeroLeftZero\n\n\nProperties of |sum|:\n\n> ||| |sum| is monotone\n> -- sumMon : Monotone {B = Nat} {C = Nat} {F = List} LTE LTE sum \n> sumMon : {A : Type} ->\n> (f : A -> Nat) -> (g : A -> Nat) ->\n> (p : (a : A) -> f a `LTE` g a) ->\n> (as : List A) ->\n> sum (map f as) `LTE` sum (map g as) \n> sumMon {A} f g p Nil = LTEZero\n> sumMon {A} 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 = sumMon f g p as\n> s5 : sum (map f (a :: as)) `LTE` sum (map g (a :: as))\n> s5 = monotoneNatPlusLTE s3 s4\n> %freeze sumMon\n\n\n> {-\n\nTest:\n\n> CLTtoLT : {m, n : Nat} -> compare m n = LT -> m `LT` n\n\n> LTtoCLT : {m, n : Nat} -> m `LT` n -> compare m n = LT\n\n> CEQtoEQ : {m, n : Nat} -> compare m n = EQ -> m = n\n\n> EQtoCEQ : {m, n : Nat} -> m = n -> compare m n = EQ\n\n\n> anyPlusPreservesOrd : {x, y, z : Nat} -> {ORD : Ordering} -> \n> compare x y = ORD -> compare (z + x) (z + y) = ORD\n\n> plusAnyPreservesOrd : {x, y, z : Nat} -> {ORD : Ordering} -> \n> compare x y = ORD -> compare (z + x) (z + y) = ORD\n\n> LTinLTE : {m, n : Nat} -> LT m n -> LTE m n\n\n> pLTpEQpLTE : (LT x1 x2 -> LT y1 y2) -> (x1 = x2 -> y1 = y2) -> (LTE x1 x2 -> LTE y1 y2)\n\n> anyPlusPreservesLT : LT x y -> LT (z + x) (z + y)\n> anyPlusPreservesLT {x} {y} {z} prf = s3 where\n> s1 : compare x y = LT\n> s1 = LTtoCLT prf\n> s2 : compare (z + x) (z + y) = LT\n> s2 = anyPlusPreservesOrd s1\n> s3 : (z + x) `LT` (z + y) \n> s3 = CLTtoLT s2\n\n> anyPlusPreservesEQ : {x, y, z : Nat} -> x = y -> (z + x) = (z + y)\n> anyPlusPreservesEQ {x} {y} {z} prf = s3 where\n> s1 : compare x y = EQ\n> s1 = EQtoCEQ prf\n> s2 : compare (z + x) (z + y) = EQ\n> s2 = anyPlusPreservesOrd s1\n> s3 : (z + x) = (z + y) \n> s3 = CEQtoEQ s2\n\n> anyPlusPreservesLTE : LTE x y -> LTE (z + x) (z + y)\n> anyPlusPreservesLTE = pLTpEQpLTE anyPlusPreservesLT anyPlusPreservesEQ\n\n> ---}\n", "meta": {"hexsha": "f706338bae07d0a35da4de8af01b5b1f31369199", "size": 19030, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/OperationsProperties.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/OperationsProperties.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/OperationsProperties.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": 34.78976234, "max_line_length": 107, "alphanum_fraction": 0.468943773, "num_tokens": 7916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6895443656906414}} {"text": "module Labelling\n\nimport Control.Monad.State\n\n-- 12.1.4 Exercises\nupdate : (stateType -> stateType) -> State stateType ()\nupdate f = do state <- get\n put $ f state\n\nincrease' : Nat -> State Nat ()\nincrease' inc = update (+inc)\n\n-- *Labelling> runState (increase' 5) 89\n-- ((), 94) : ((), Nat)\n\n-- Tree Labelling\n\ndata Tree a = Empty\n | Node (Tree a) a (Tree a)\n\n\ncountEmpty : Tree a -> State Nat ()\ncountEmpty Empty = do update (+ 1)\ncountEmpty (Node l v r) = do countEmpty l\n countEmpty r\n\n\ncountEmptyNode : Tree a -> State (Nat, Nat) ()\ncountEmptyNode Empty = do update (\\p => (fst p, snd p + 1))\ncountEmptyNode (Node l v r) = do update (\\p => (fst p + 1, snd p))\n countEmptyNode l\n countEmptyNode r\n\n -- *Labelling> execState (countEmpty testTree) 0\n -- 7 : Nat\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\n\nflatten : Tree a -> List a\nflatten Empty = []\nflatten (Node left val right) = flatten left ++ val :: flatten right\n\ntreeLabelWith : Stream labelType ->\n Tree a ->\n (Stream labelType, Tree (labelType, a))\ntreeLabelWith lbls Empty = (lbls, Empty)\ntreeLabelWith lbls (Node left val right)\n = let (this :: lblsLeft, left_labelled) = treeLabelWith lbls left\n (lblsRight, right_labelled) = treeLabelWith lblsLeft right\n in\n (lblsRight, Node left_labelled (this, val) right_labelled)\n\ntreeLabel : Tree a -> Tree (Integer, a)\ntreeLabel tree = snd (treeLabelWith [1..] tree)\n\nincrease : Nat -> State Nat ()\nincrease inc = do current <- get\n put (current + inc)\n\ntLabelWith : Tree a -> State (Stream labelType) (Tree (labelType, a))\ntLabelWith Empty = pure Empty\ntLabelWith (Node left val right)\n = do left_labelled <- tLabelWith left\n (h :: t) <- get\n put t\n right_labelled <- tLabelWith right\n pure (Node left_labelled (h, val) right_labelled)\n", "meta": {"hexsha": "4e78c9574fb76b0f3c0cae7bcedf780857bca807", "size": 2197, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "12-state/Labelling.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": "12-state/Labelling.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": "12-state/Labelling.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": 30.5138888889, "max_line_length": 74, "alphanum_fraction": 0.5798816568, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6895012389643711}} {"text": "module Decidable.Equality.Core\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Decidable equality\n--------------------------------------------------------------------------------\n\n||| Decision procedures for propositional equality\npublic export\ninterface DecEq t where\n ||| Decide whether two elements of `t` are propositionally equal\n decEq : (x1 : t) -> (x2 : t) -> Dec (x1 = x2)\n\n--------------------------------------------------------------------------------\n-- Utility lemmas\n--------------------------------------------------------------------------------\n\n||| The negation of equality is symmetric (follows from symmetry of equality)\nexport\nnegEqSym : Not (a = b) -> Not (b = a)\nnegEqSym p h = p (sym h)\n\n||| Everything is decidably equal to itself\nexport\ndecEqSelfIsYes : DecEq a => {x : a} -> decEq x x = Yes Refl\ndecEqSelfIsYes with (decEq x x)\n decEqSelfIsYes | Yes Refl = Refl\n decEqSelfIsYes | No contra = absurd $ contra Refl\n\n||| If you have a proof of inequality, you're sure that `decEq` would give a `No`.\nexport\ndecEqContraIsNo : DecEq a => {x, y : a} -> Not (x = y) -> (p ** decEq x y = No p)\ndecEqContraIsNo uxy with (decEq x y)\n decEqContraIsNo uxy | Yes xy = absurd $ uxy xy\n decEqContraIsNo _ | No uxy = (uxy ** Refl)\n", "meta": {"hexsha": "1d814b60fd1af556eb794921ce1f9a107a0f0055", "size": 1304, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Decidable/Equality/Core.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/base/Decidable/Equality/Core.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/base/Decidable/Equality/Core.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": 35.2432432432, "max_line_length": 82, "alphanum_fraction": 0.5130368098, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6889909909658336}} {"text": "> module SequentialDecisionProblems.OptDefaults\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.FullTheory\n> import SequentialDecisionProblems.Utils\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Opt.Operations\n> import Rel.TotalPreorder\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\nWe implement |cvalmax|, |cvalargmax|, |cvalmaxSpec| and |cvalargmaxSpec|\nby exhaustive search (see |Opt|) if we can show that |LTE| is a total\npreorder\n\n> totalPreorderLTE : TotalPreorder SequentialDecisionProblems.CoreTheory.LTE\n\n, that |GoodCtrl t x n| is finite and that, for every |t : Nat|, |x :\nState t| such that |Viable (S n) x|, its cardinality is not zero.\n\nIn typical applications, finiteness and non-emptyness of |GoodCtrl t x\nn| are going to be deduced (see Utils) from finiteness of |All| and\n|NotEmpty| (see, for instance, NonDeterministicDefaults), finiteness of\n|Viable| (see ViabilityDefaults) and finiteness of controls.\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> {-\n\n> ---}\n", "meta": {"hexsha": "d38ec0383ef219968942dbbde7e9284e2a6d86bf", "size": 1704, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/OptDefaults.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/OptDefaults.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/OptDefaults.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.2553191489, "max_line_length": 108, "alphanum_fraction": 0.7687793427, "num_tokens": 500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6889909847516503}} {"text": "> module Functions\n> %access public export\n\nIn this module we present types for basic proofs about functions between sets, such as\n\n- injectivity, surjectivity, bijectivity\n- quotienting by totality (\"squashing\")\n\n> ||| The type of proofs that a given function is injective. \n> ||| A function `f: t -> u` is injective if, given a proof that `f x = f y`,\n> ||| we can prove `x=y`. An implementation of `Injective f` is a function that\n> ||| returns an `(x = y)` proof given an `(f x = f y)` proof.\n> Injective : {t,u:Type} -> (t -> u) -> Type\n> Injective f {t} = (x,y:t) -> (f x = f y) -> (x = y)\n\n> ||| The type of proofs that a given function is surjective. \n> ||| A function `f: t -> u` is injective if, given any `y: u`, we can find \n> ||| `x: t` with a proof `f x = y`. An implementation of `Surjective f` is a \n> ||| function that returns a dependent pair `(x ** f x = y)` given an \n> ||| `(f x = f y)` proof. Note that there is no proof of uniqueness.\n> Surjective : {t,u:Type} -> (t -> u) -> Type\n> Surjective f {t} {u} = (y:u) -> (x:t ** f x = y)\n\n> ||| The type of proofs that a given function is bijective.\n> ||| Since this is equivalent to being both injective and surjective, that is\n> ||| the definition we are using. \n> Bijective : {t,u : Type} -> (t -> u) -> Type\n> Bijective f {t} {u} = (Injective f, Surjective f)\n\n> ||| The type of proofs that two types `t` and `u`, considered as simple sets \n> ||| built by their constructible members, have the same cardinality. For our \n> ||| purposes, this is equivalent to existential quantification on the type of\n> ||| bijections between `t` and `u`.\n> SameCardinality : Type -> Type -> Type\n> SameCardinality t u = (f:(t->u) ** Bijective f)\n\nNote that, for finite sets, the notion of `SameCardinality` collapses in the\nobvious way; the problem of finding a bijection is equivalent to putting the \nelements of the sets into two lists with the same length. We will formally prove\nthis later.\n\n> ||| Proof that a type is a \"mere proposition\" (i.e. it only has one inhabitant\n> ||| up to decidable equality.)\n> Prop : (t:Type) -> Type\n> Prop t = (p1:t) -> (p2:t) -> (p1=p2)\n\nIf P is a decidable proposition, we can quotient P by the totality equivalence \nrelation and get a \"squashed\" type. By \"totality equivalence relation\" we mean\na partition of the elements of $P : Type -> Type$ into two sets, one containing\nconstructible instances $P x$, the other containing unconstructible instances\n$P y$. In NuPRL this is called \"squash\" so that is the name we will use here.\n\n> squash : {p:Type} -> Dec p -> Type\n> squash (Yes _) = Unit\n> squash (No _) = Void\n\n Note that any two squashed values are trivially equal:\n\n> ||| Any two squashed values of a given decidable proposition are equal.\n> propSquash : {p: Type} -> (d : Dec p) -> Prop (squash d)\n> propSquash (Yes prf) () () = Refl\n> propSquash (No contra) v1 _ = absurd v1\n\n> ||| Given a squashed proposition, obtain the original proposition.\n> fromSquash : {p:Type} -> (d : Dec p) -> squash d -> p\n> fromSquash (Yes prf) () = prf\n\nNote that fromSquash can only ever accept a unit value since that is the only \nvalue that is constructible.\n\n> ||| Simple helper for projecting the first part of a dependent pair.\n> proj1DP : (DPair a b) -> a\n> proj1DP (x ** y) = x\n\n> ||| Simple helper for projecting the second part of a dependent pair.\n> proj2DP : (x : (DPair a b)) -> b (proj1DP x)\n> proj2DP (x ** y) = y", "meta": {"hexsha": "dfdf694b989f7d5b8b7d659a18bf085986017a64", "size": 3414, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Functions.lidr", "max_stars_repo_name": "nicklecompte/idris-finite-sets", "max_stars_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Functions.lidr", "max_issues_repo_name": "nicklecompte/idris-finite-sets", "max_issues_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Functions.lidr", "max_forks_repo_name": "nicklecompte/idris-finite-sets", "max_forks_repo_head_hexsha": "de247371fb125f84b32b50f805095e677d30c93b", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.3376623377, "max_line_length": 86, "alphanum_fraction": 0.665787932, "num_tokens": 1031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6886017917159909}} {"text": "In : (x : a) -> (l : List a) -> Type\nIn x [] = Void\nIn x (x' :: xs) = (x' = x) `Either` In x xs\n\nappendEmpty : (xs : List a) -> xs ++ [] = xs\nappendEmpty [] = Refl\nappendEmpty (x :: xs) = rewrite appendEmpty xs in Refl\n\nin_app_iff : {l : List b} -> {l' : List b} -> In a (l++l') -> (In a l `Either` In a l')\nin_app_iff {l = []} { l' = []} x = Left x\nin_app_iff {l = []} { l' = (y :: xs)} x = Right x\nin_app_iff {l = (y::xs)} { l' = []} x = rewrite sym (appendEmpty xs) in Left x\nin_app_iff {l = (y::xs)} {l' = (z::ys)} (Left prf) = Left (Left prf)\nin_app_iff {l = (y::xs)} {l' = (z::ys)} (Right prf) =\n let induc : Either (In a xs) (Either (z = a) (In a ys))= in_app_iff {l = xs} {l' = z :: ys} prf in\n case induc of\n (Left l) => Left $ Right l\n (Right r) => Right r\n\n", "meta": {"hexsha": "34fc4fdb099a6412863cc94277dcc66f20940119", "size": 948, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic065/Issue215.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/tests/idris2/basic065/Issue215.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/tests/idris2/basic065/Issue215.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 47.4, "max_line_length": 141, "alphanum_fraction": 0.4198312236, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6885455378753419}} {"text": "module Addition.Adhoc\n\nimport Common.Abbrev\nimport Common.Interfaces\nimport Specifications.Ring\nimport Proofs.RingTheory\n\n%default total\n%access export\n\nadhocIdentity1 : Ringops s => RingSpec {s} (+) Zero Ng (*) -> (b,x,y,z : s) ->\n a = b + c -> x + y * z + y * a = x + y * (z + b + c)\nadhocIdentity1 spec {a} b {c} x y z given = o3 where\n o1 : z + a = z + b + c\n o1 = cong given === associative (monoid (group spec)) z b c\n o2 : y * z + y * a = y * (z + b + c)\n o2 = distributativeL spec y z a @== cong o1\n o3 : x + y * z + y * a = x + y * (z + b + c)\n o3 = associative (monoid (group spec)) x _ _ @== cong o2\n\n\nadhocIdentity2 : Ringops s => RingSpec {s} (+) Zero Ng (*) -> (x,a : s) ->\n x = x + a * Zero\nadhocIdentity2 spec x a = sym (o1 === o2) where\n o1 : x + a * Zero = x + Zero\n o1 = cong $ zeroAbsorbsR spec a\n o2 : x + Zero = x\n o2 = neutralR (monoid (group spec)) x\n", "meta": {"hexsha": "c816f73090759a67627e82c0e0ed3cdeda9ba13a", "size": 887, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Addition/Adhoc.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/Adhoc.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/Adhoc.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": 30.5862068966, "max_line_length": 78, "alphanum_fraction": 0.5693348365, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.688387100205051}} {"text": "-- ------------------------------------------------------ [ Tree.idr ]\n-- Module : Tree.idr\n-- License : see LICENSE\n-- --------------------------------------------------------------------- [ EOH ]\n-- http://www.cs.kent.ac.uk/people/staff/smk/redblack/Untyped.hs\nmodule Data.RedBlack.Tree\n\n%access export\n\nprivate\ndata Colour = R | B\n\ndata Tree : Type -> Type where\n Empty : Tree a\n Node : Colour -> a -> Tree a -> Tree a -> Tree a\n\n\nbalance : a -> Tree a -> Tree a -> Tree a\nbalance y (Node R x a b) (Node R z c d) = Node R y (Node B x a b) (Node B z c d)\nbalance z (Node R y (Node R x a b) c) d = Node R y (Node B x a b) (Node B z c d)\nbalance z (Node R x a (Node R y b c)) d = Node R y (Node B x a b) (Node B z c d)\nbalance x a (Node R y b (Node R z c d)) = Node R y (Node B x a b) (Node B z c d)\nbalance x a (Node R z (Node R y b c) d) = Node R y (Node B x a b) (Node B z c d)\nbalance x a b = Node B x a b\n\nprivate\nins : Ord a => a -> Tree a -> Tree a\nins x Empty = Node R x Empty Empty\nins x t@(Node B y a b) =\n case compare x y of\n LT => balance y (ins x a) b\n GT => balance y a (ins x b)\n EQ => t\nins x t@(Node R y a b) =\n case compare x y of\n LT => Node R y (ins x a) b\n GT => Node R y a (ins x b)\n EQ => t\n\n\nfoldr : (step : a -> p -> p) -> (init : p) -> Tree a -> p\nfoldr step init n = foldr' step init n\n where\n foldr' : (a -> p -> p) -> p -> Tree a -> p\n foldr' step' init' Empty = init'\n foldr' step' init' (Node _ val l r) = foldr' step' (step' val (foldr' step' init' r)) l\n\n\nsize : Tree a -> Nat\nsize t = Tree.foldr (\\_,res => S res) Z t\n\ncontains : Ord a => a -> Tree a -> Bool\ncontains x Empty = False\ncontains x (Node _ y l r) =\n case compare x y of\n LT => contains x l\n GT => contains x r\n EQ => True\n\n\nempty : Tree a\nempty = Empty\n\ninsert : Ord a => a -> Tree a -> Tree a\ninsert x s = let Node _ z l r = ins x s in Node B z l r\n\ntoList : Tree a -> List a\ntoList Empty = Nil\ntoList (Node _ y l r) = Tree.toList l ++ [y] ++ Tree.toList r\n\nfromList : Ord a => List a -> Tree a\nfromList xs = foldl (flip $ insert) empty xs\n", "meta": {"hexsha": "a62a2615c77e0b01c2f2467c34202cd948d4e47a", "size": 2272, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/RedBlack/Tree.idr", "max_stars_repo_name": "MarcelineVQ/idris-containers", "max_stars_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data/RedBlack/Tree.idr", "max_issues_repo_name": "MarcelineVQ/idris-containers", "max_issues_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Data/RedBlack/Tree.idr", "max_forks_repo_name": "MarcelineVQ/idris-containers", "max_forks_repo_head_hexsha": "3cca9329e5eaa04a98fc3ab521986b8d3c035567", "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": 31.1232876712, "max_line_length": 106, "alphanum_fraction": 0.4977992958, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6883258833922825}} {"text": "\nmodule Foldable\n\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n\ntotLen : List String -> Nat\ntotLen xs = foldr (\\str, acc => acc + length str) 0 xs\n\nFoldable Tree where\n foldr func acc Empty = acc\n foldr func acc (Node l e r)\n = let leftFold = foldr func acc l\n rightFold = foldr func leftFold r in\n func e rightFold\n", "meta": {"hexsha": "1939e03c0907cdb8f6cd2d31dc386ddfe0f87f74", "size": 380, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter7/Foldable.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": "Chapter7/Foldable.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": "Chapter7/Foldable.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.75, "max_line_length": 54, "alphanum_fraction": 0.6078947368, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6880861335497508}} {"text": "import Data.List -- for testing using sort\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\noccurrences : Eq ty => (item : ty) -> (values : List ty) -> Nat\noccurrences item [] = 0\noccurrences item (x :: xs) = case item == x of\n False => occurrences item xs\n True => 1 + occurrences item xs\n\n-- 7.1 exercises\n\ndata Shape = Triangle Double Double \n | Rectangle Double Double\n | Circle Double\n\narea : Shape -> Double\narea (Triangle b h) = b * h * 0.5\narea (Rectangle w h) = w * h\narea (Circle r) = pi * pow r 2\n\nEq Shape where\n (==) (Triangle b h) (Triangle b' h') = b == b' && h == h'\n (==) (Rectangle w h) (Rectangle w' h') = w == w' && h == h'\n (==) (Circle r) (Circle r') = r == r'\n (==) _ _ = False\n\nOrd Shape where\n compare x y = compare (area x) (area y)\n\ntestShapes : List Shape\ntestShapes = [Circle 3, Triangle 3 9, Rectangle 2 6, Circle 4, Rectangle 2 7]", "meta": {"hexsha": "ef6977b74d28e4467981525cff8caabe95d8a9e9", "size": 1070, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch7/EqOrd.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/ch7/EqOrd.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/ch7/EqOrd.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": 28.1578947368, "max_line_length": 77, "alphanum_fraction": 0.5439252336, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6876013093172908}} {"text": "module AddTwoNumbers\n\ndata Digit = D Int\n\nofIntHelp : Int -> List Digit\nofIntHelp 0 = []\nofIntHelp i = D (i `mod` 10) :: ofIntHelp (i `div` 10)\n\nofInt : Int -> List Digit\nofInt 0 = [D 0]\nofInt i = ofIntHelp i\n\naddHelp : Bool -> List Digit -> List Digit -> List Digit\naddHelp carry [] [] = if carry then [D 1] else []\naddHelp False [] ys = ys\naddHelp True [] ys = addHelp False [D 1] ys\naddHelp False xs [] = xs\naddHelp True xs [] = addHelp False [D 1] xs\naddHelp carry (D x :: xs) (D y :: ys) =\n let sum = x + y + if carry then 1 else 0 in\n if sum >= 10 then\n D (sum `mod` 10) :: addHelp True xs ys\n else\n D sum :: addHelp False xs ys\n\nadd : List Digit -> List Digit -> List Digit\nadd = addHelp False\n\ntest1 : add (ofInt 342) (ofInt 465) = ofInt 807\ntest1 = Refl\ntest2 : add [D 0] [D 0] = [D 0]\ntest2 = Refl\ntest3 : add (map D [9,9,9,9,9,9,9]) (map D [9,9,9,9]) = map D [8,9,9,9,0,0,0,1]\ntest3 = Refl\n", "meta": {"hexsha": "4e53b086c38583274d90d7fc8ead39922bb8a3ce", "size": 910, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "AddTwoNumbers.idr", "max_stars_repo_name": "Smaug123/leetcode-idris", "max_stars_repo_head_hexsha": "6df26ef8875d83443cd2c35a7290d88f071ae33d", "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": "AddTwoNumbers.idr", "max_issues_repo_name": "Smaug123/leetcode-idris", "max_issues_repo_head_hexsha": "6df26ef8875d83443cd2c35a7290d88f071ae33d", "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": "AddTwoNumbers.idr", "max_forks_repo_name": "Smaug123/leetcode-idris", "max_forks_repo_head_hexsha": "6df26ef8875d83443cd2c35a7290d88f071ae33d", "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.0, "max_line_length": 79, "alphanum_fraction": 0.610989011, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6873497121182158}} {"text": "module ABMinus\n\nmm : (a, b : Nat) -> a `minus` b = (S a `minus` b) `minus` 1\nmm Z Z = Refl\nmm Z (S _) = Refl\nmm (S a) Z = Refl\nmm (S a) (S b) = rewrite mm a b in Refl\n\nms : (a, b : Nat) -> a `minus` S b = (a `minus` b) `minus` 1\nms Z b = Refl\nms (S _) Z = Refl\nms (S a) (S b) = rewrite ms a b in Refl\n\nabm : (a, b : Nat) -> a `minus` (b + 1) = (a `minus` b) `minus` 1\nabm Z Z = Refl\nabm (S k) Z = Refl\nabm Z (S _) = Refl\nabm (S a) (S b) = rewrite abm a b in Refl\n", "meta": {"hexsha": "468f357f62bb3c3f6d550d94db0d00eee6bbba88", "size": 507, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ABMinus.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": "ABMinus.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": "ABMinus.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.6842105263, "max_line_length": 65, "alphanum_fraction": 0.4753451677, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6873375761096513}} {"text": "-- Matrix.idr\n--\n-- Matrix arithmetics with dependent types\n\nmodule Matrix\n\nimport Data.Vect\n\n||| A type alias for nested Vect\n||| @ n number of rows\n||| @ m number of columns\nMatrix : (n : Nat) -> (m : Nat) -> Type -> Type\nMatrix n m elem = Vect n (Vect m elem)\n\ntestMatrix : Matrix 2 3 Int\ntestMatrix = [[0, 0, 0], [0, 0, 0]]\n\n-- matrix addition\naddMatrix : Num numType =>\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType)\n\n-- matrix multiplication\nmultMatrix : Num numType =>\n Vect n (Vect m numType) ->\n Vect m (Vect p numType) ->\n Vect n (Vect p numType)\n\n-- transpose matrix\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntransposeHelper : (x : Vect n elem) -> (xsTrans : Vect n (Vect len elem)) ->\n Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n transposeHelper x xsTrans\n\n\n", "meta": {"hexsha": "3dc3e09e778d1b9c2f7d2f0f5f1486751db79687", "size": 1197, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_6/Matrix.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Idris/TDD/Chapter_6/Matrix.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Idris/TDD/Chapter_6/Matrix.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6, "max_line_length": 76, "alphanum_fraction": 0.5981620718, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746092, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6871843795540734}} {"text": "data BST : a -> Type where\n Leaf : BST a\n Node : (root : a) -> (lt : BST a) -> (rt : BST a) -> BST a\n\n-- Checking that we can look under the @ to get rt and lt\ntotal\ninsert : Ord a => a -> BST a -> BST a\ninsert p Leaf = Node p Leaf Leaf\ninsert p tree@(Node root lt rt) =\n case p `compare` root of\n GT => Node root lt (insert p rt)\n EQ => tree\n LT => Node root (insert p lt) rt\n", "meta": {"hexsha": "53fecd4a6734a09d92afc45ee15eb12fae0c7172", "size": 389, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/total009/tree.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/total009/tree.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/total009/tree.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": 27.7857142857, "max_line_length": 60, "alphanum_fraction": 0.5861182519, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6871678097750487}} {"text": "-- 依赖类型\n-- 一等类型\n-- 在 idris 中,类型是一等的,即它们可以像其它的语言构造那样被计算和操作\n\nisSingleton : 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-- sum' False 1\n-- will return\n-- When checking an application of function Main.sum:\n-- isSingleton False is not a numeric type", "meta": {"hexsha": "357536f5e27cb98c111aec0f08c527b2ba520f7a", "size": 469, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "fp/idris/tutorial/src/dependentType.idr", "max_stars_repo_name": "lonelyhentai/workspace", "max_stars_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-26T16:37:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T01:26:19.000Z", "max_issues_repo_path": "fp/idris/tutorial/src/dependentType.idr", "max_issues_repo_name": "lonelyhentai/workspace", "max_issues_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "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": "fp/idris/tutorial/src/dependentType.idr", "max_forks_repo_name": "lonelyhentai/workspace", "max_forks_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-15T01:26:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T01:26:23.000Z", "avg_line_length": 22.3333333333, "max_line_length": 53, "alphanum_fraction": 0.6823027719, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6870962357239138}} {"text": "module Dec2\n\nimport Data.Vect\nimport Data.String\nimport Utils\n\ndec2a : (Ord a, Neg a) => List (List a) -> a\ndec2a xs = foldl f 0 xs where\n g : List a -> a\n g [] = 0\n g (x :: []) = 0\n g (x :: (y :: ys)) = let xs = fromList (y :: ys) in\n max' (x :: xs) - min' (x :: xs)\n\n f : a -> List a -> a\n f x xs = x + g xs\n\ndivEvenly : (Integral a, Eq a) => (dividend : a) -> (divisor : a) -> Maybe a\ndivEvenly dividend divisor = do divisor' <- case divisor of\n 0 => Nothing\n _ => Just divisor\n if mod dividend divisor' == 0\n then Just (div dividend divisor')\n else Nothing\n\nreduceAllPairs : Monoid a => (a -> a -> Maybe a) -> Vect (S n) a -> Maybe a\nreduceAllPairs f xs = let ys = map (uncurry f) $ concat $ allPairs xs in\n foldl (<+>) neutral ys\n\ndec2b : (Integral a, Eq a, Monoid a) => List (List a) -> a\ndec2b xs = foldl f 0 xs where\n g : List a -> a\n g [] = 0\n g (x :: xs) = fromMaybe 0 $ reduceAllPairs divEvenly (x :: fromList xs)\n\n f : a -> List a -> a\n f x xs = x + g xs\n\nSemigroup Int where\n (<+>) = (+)\n\nMonoid Int where\n neutral = 0\n\ninput : String\ninput = \"\"\"278\t1689\t250\t1512\t1792\t1974\t175\t1639\t235\t1635\t1690\t1947\t810\t224\t928\t859\n160\t50\t55\t81\t68\t130\t145\t21\t211\t136\t119\t78\t174\t155\t149\t72\n4284\t185\t4499\t273\t4750\t4620\t4779\t4669\t2333\t231\t416\t1603\t197\t922\t5149\t2993\n120\t124\t104\t1015\t1467\t110\t299\t320\t1516\t137\t1473\t132\t1229\t1329\t1430\t392\n257\t234\t3409\t2914\t2993\t3291\t368\t284\t259\t3445\t245\t1400\t3276\t339\t2207\t233\n1259\t78\t811\t99\t2295\t1628\t3264\t2616\t116\t3069\t2622\t1696\t1457\t1532\t268\t82\n868\t619\t139\t522\t168\t872\t176\t160\t1010\t200\t974\t1008\t1139\t552\t510\t1083\n1982\t224\t3003\t234\t212\t1293\t1453\t3359\t326\t3627\t3276\t3347\t1438\t2910\t248\t2512\n4964\t527\t5108\t4742\t4282\t4561\t4070\t3540\t196\t228\t3639\t4848\t152\t1174\t5005\t202\n1381\t1480\t116\t435\t980\t1022\t155\t1452\t1372\t121\t128\t869\t1043\t826\t1398\t137\n2067\t2153\t622\t1479\t2405\t1134\t2160\t1057\t819\t99\t106\t1628\t1538\t108\t112\t1732\n4535\t2729\t4960\t241\t4372\t3960\t248\t267\t230\t5083\t827\t1843\t3488\t4762\t2294\t3932\n3245\t190\t2249\t2812\t2620\t2743\t2209\t465\t139\t2757\t203\t2832\t2454\t177\t2799\t2278\n1308\t797\t498\t791\t1312\t99\t1402\t1332\t521\t1354\t1339\t101\t367\t1333\t111\t92\n149\t4140\t112\t3748\t148\t815\t4261\t138\t1422\t2670\t32\t334\t2029\t4750\t4472\t2010\n114\t605\t94\t136\t96\t167\t553\t395\t164\t159\t284\t104\t530\t551\t544\t18\"\"\"\n\ndec2 : String -> Maybe (Int, Int)\ndec2 str = map (\\xs => (dec2a xs, dec2b xs)) $ f str where\n g : (Neg a) => String -> Maybe (List a)\n g str = traverse parseInteger $ words str\n\n f : (Neg a) => String -> Maybe (List (List a))\n f str = traverse g $ lines str\n", "meta": {"hexsha": "290d8128314df950ee206687b1284c2fad5f0507", "size": 2704, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Dec2.idr", "max_stars_repo_name": "tscholak/AoC2017", "max_stars_repo_head_hexsha": "983eda0e6260e9cb22577e5f055ba1442f1e36ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-04T13:14:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-04T13:14:53.000Z", "max_issues_repo_path": "Dec2.idr", "max_issues_repo_name": "tscholak/AoC2017", "max_issues_repo_head_hexsha": "983eda0e6260e9cb22577e5f055ba1442f1e36ee", "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": "Dec2.idr", "max_forks_repo_name": "tscholak/AoC2017", "max_forks_repo_head_hexsha": "983eda0e6260e9cb22577e5f055ba1442f1e36ee", "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.6285714286, "max_line_length": 82, "alphanum_fraction": 0.6087278107, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6870962339562625}} {"text": "||| An order is a particular kind of binary relation. The order\n||| relation is intended to proceed in some direction, though not\n||| necessarily with a unique path.\n|||\n||| Orders are often defined simply as bundles of binary relation\n||| properties.\n|||\n||| A prominent example of an order relation is LTE over Nat.\n\nmodule Control.Order\n\nimport Control.Relation\n\n||| A preorder is reflexive and transitive.\npublic export\ninterface (Reflexive ty rel, Transitive ty rel) => Preorder ty rel where\n\n||| A partial order is an antisymmetrics preorder.\npublic export\ninterface (Preorder ty rel, Antisymmetric ty rel) => PartialOrder ty rel where\n\n||| A relation is connex if for any two distinct x and y, either x ~ y or y ~ x.\n|||\n||| This can also be stated as a trichotomy: x ~ y or x = y or y ~ x.\npublic export\ninterface Connex ty rel where\n connex : {x, y : ty} -> Not (x = y) -> Either (rel x y) (rel y x)\n\n||| A relation is strongly connex if for any two x and y, either x ~ y or y ~ x.\npublic export\ninterface StronglyConnex ty rel where\n order : (x, y : ty) -> Either (rel x y) (rel y x)\n\n||| A linear order is a connex partial order.\npublic export\ninterface (PartialOrder ty rel, Connex ty rel) => LinearOrder ty rel where\n\n----------------------------------------\n\n||| Every equivalence relation is a preorder.\npublic export\n[EP] Equivalence ty rel => Preorder ty rel where\n", "meta": {"hexsha": "4d19e58131b64dc8062d4be62e64b61bf9612e49", "size": 1384, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Control/Order.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/base/Control/Order.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/base/Control/Order.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 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.1860465116, "max_line_length": 80, "alphanum_fraction": 0.6921965318, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6870913239284455}} {"text": "module algebraic\n\n-- Algebraic laws\n\ndata Bit = O | I\n\nor : Bit -> Bit -> Bit\nor 0 x1 = x1\nor I x1 = I\n\norAssociative : (a : Bit) ->\n (b : Bit) ->\n (c : Bit) -> \n (a `or` b) `or` c = a `or` (b `or` c)\n-- or = ?orAssociative_rhs_1\norAssociative O b c = refl\n-- or = ?orAssociative_rhs_2 \norAssociative I b c = refl\n\n\nBitString : Type\n-- list of bits\nBitString = List Bit\n\nbsor : BitString -> BitString -> BitString\nbsor [] x1 = x1\nbsor xs [] = xs\nbsor (x :: xs) (y :: ys) = (x `or` y) :: (xs `bsor` ys)\n", "meta": {"hexsha": "4a43e29000816e00a9974be1abe9f953a23c0808", "size": 568, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "algebraic.idr", "max_stars_repo_name": "ExpandingShapes/idris-experiments", "max_stars_repo_head_hexsha": "7ad15a66af0d3671d56325c7e7ab2116b81fc8e4", "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": "algebraic.idr", "max_issues_repo_name": "ExpandingShapes/idris-experiments", "max_issues_repo_head_hexsha": "7ad15a66af0d3671d56325c7e7ab2116b81fc8e4", "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": "algebraic.idr", "max_forks_repo_name": "ExpandingShapes/idris-experiments", "max_forks_repo_head_hexsha": "7ad15a66af0d3671d56325c7e7ab2116b81fc8e4", "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": 19.5862068966, "max_line_length": 55, "alphanum_fraction": 0.5105633803, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6870370831842595}} {"text": "\nmodule Term\n\n-- Simply-typed lambda calculus with \n-- (1) natural numbers as the only base type, and\n-- (2) general recursion.\n-- This calculus is also referred to as PCF.\n--\n-- Note that variables in the lambda calculus are not\n-- named but identified by their de Bruijn index.\n\n\n%default total\n%access public export\n\n\n---------------------------------------------------\n-- Begin: TYPES IN THE SIMPLY-TYPED LAMBDA CALCULUS\n\n-- Data type 'Ty' represents the types in the\n-- simply-typed lambda calculus:\n-- (1) Base type 'TyNat' of natural numbers.\n-- (2) Type constructor 'TyFun' for forming\n-- function types.\ndata Ty = TyNat | TyFun Ty Ty\n\n\n-- Simplified syntax for function types:\ninfixr 10 :->:\n(:->:) : Ty -> Ty -> Ty\n(:->:) t1 t2 = TyFun t1 t2\n\n-- End: TYPES IN THE SIMPLY-TYPED LAMBDA CALCULUS\n-------------------------------------------------\n\n\n\n---------------------------------------------------------\n-- Begin: CONTEXT FOR TYPING TERMS IN THE LAMBDA CALCULUS\n\nContext : Type\nContext = List Ty\n\n\n-- de Bruijn indices constitute proofs that type\n-- 't' occurs at a certain position in context 'ctx':\ndata HasType : Context -> Ty -> Type where\n First : HasType (t::ctx) t\n Next : HasType ctx t -> HasType (s::ctx) t\n\n\nremove : (ctx : Context) -> HasType ctx t -> Context\nremove (_::ctx') First = ctx'\nremove (s::ctx') (Next ht) = s::remove ctx' ht\n\n-- End: CONTEXT FOR TYPING TERMS IN THE LAMBDA CALCULUS\n-------------------------------------------------------\n\n\n\n-------------------------------------------------\n-- Begin: WELL-TYPED TERMS OF THE LAMBDA CALCULUS\n\n-- Data type of well-typed terms in the \n-- simply-typed lambda calculus:\ndata Term : Context -> Ty -> Type where\n -- Variable:\n -- The data constructor for variables ('Var') takes as\n -- argument a de Bruijn index (of type 'HasType ctx t'),\n -- which is proof that the context 'ctx' contains type\n -- 't' at the position given by the de Bruijn index:\n TVar : HasType ctx t ->\n Term ctx t\n -- Abstraction:\n -- The data constructor for abstractions ('Abs')\n -- takes as its first (implicit) argument the\n -- type of the variable that is bound by this\n -- abstraction.\n TAbs : {s : Ty} -> Term (s::ctx) t ->\n Term ctx (s :->: t)\n -- Application:\n TApp : Term ctx (s :->: t) -> Term ctx s -> \n Term ctx t \n -- Fix-point operator:\n TFix : Term ctx (t :->: t) -> \n Term ctx t\n -- Constant 'Zero' (natural number):\n TZero : Term ctx TyNat\n -- Successor:\n TSucc : Term ctx TyNat ->\n Term ctx TyNat\n -- Predecessor:\n TPred : Term ctx TyNat ->\n Term ctx TyNat\n -- Test for equality with 'Zero' \n -- (with terms for the \"then\" and\n -- \"else\" branches):\n TIfz : Term ctx TyNat -> Term ctx t -> Term ctx t ->\n Term ctx t\n\n-- End: WELL-TYPED TERMS OF THE LAMBDA CALCULUS\n-----------------------------------------------\n\n\n\n---------------------------------------\n-- Begin: VALUES IN THE LAMBDA CALCULUS \n\n-- The following lambda calculus terms\n-- are values (i.e. normal forms for \n-- reduction under the \"Step\" relation):\n-- (1) lambda abstractions (that are\n-- not applied),\n-- (2) the constant 'Zero',\n-- (3) the natural number constants\n-- (formed by applying 'Succ' to\n-- another value). \ndata Value : Term [] t -> Type where\n VZero : Value TZero\n VSucc : Value e -> Value (TSucc e)\n VAbs : Value (TAbs e)\n\n\nvalueTerm : {e : Term [] t} -> Value e -> Term [] t\nvalueTerm {e = e} _ = e\n\n-- End: VALUES IN THE LAMBDA CALCULUS \n-------------------------------------\n", "meta": {"hexsha": "98514e4ee8ebf71e096522ac5e6ff9c5b4aee993", "size": 3574, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "conventional/src/Term.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "conventional/src/Term.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "conventional/src/Term.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7054263566, "max_line_length": 58, "alphanum_fraction": 0.5649132625, "num_tokens": 957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6866561400874326}} {"text": "\n\nmodule Expr\n\ndata Expr num = Val num\n | Add (Expr num) (Expr num)\n | Sub (Expr num) (Expr num)\n | Mul (Expr num) (Expr num)\n\nNum ty => Num (Expr ty) where\n (+) = Add\n (*) = Mul\n fromInteger = Val . fromInteger\n\n-- Ex 7.2 #1\nCast ty String => Show (Expr ty) where\n show (Val x) = cast 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\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\n\n-- Ex 7.2 #2\n(Neg num, Integral num, Eq num) => Eq (Expr num) where\n (==) x y = eval x == eval y\n\n-- Ex 7.2 #3\n(Neg num, Integral num) => Cast (Expr num) num where\n cast orig = eval orig\n\n-- Ex 7.3 #1\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\n-- Ex 7.3 #2\ndata Vect : (size : Nat) -> (ty : Type) -> Type where\n Nil : Vect Z ty\n (::) : ty -> Vect size ty -> Vect (S size) ty\n\nEq ty => Eq (Vect n ty) where\n (==) [] [] = True\n (==) (x :: z) (y :: w) = x == y && z == w\n\nFoldable (Vect n) where\n foldr func acc [] = acc\n foldr func acc (x :: xs) = func x (foldr func acc xs)\n foldl func acc [] = acc\n foldl func acc (x :: xs) = func (foldl func acc xs) x\n\n", "meta": {"hexsha": "39e82a8d09a69f60a3ba4587531db72a9637fe48", "size": 1502, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter7/Expr.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": "Chapter7/Expr.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": "Chapter7/Expr.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 25.8965517241, "max_line_length": 60, "alphanum_fraction": 0.5219707057, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6866351862179325}} {"text": "module HandMadeVectorStuff\n\nimport Data.Fin\n\n%default total\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : (x : a) -> (xs : Vect n a) -> Vect (S n) a\n\n%name Vect xs, ys, zs\n\nappend : Vect m a -> Vect n a -> Vect (m + n) a\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n\nzip : Vect m a -> Vect m b -> Vect m (a, b)\nzip [] [] = []\nzip (x :: xs) (y :: ys) = (x, y) :: zip xs ys\n\nvectTake : (n : Fin m) -> Vect m a -> Vect (finToNat n) a\nvectTake FZ xs = []\nvectTake (FS x) (y :: xs) = y :: vectTake x xs\n\nvectGet : (x : Fin n) -> Vect n a -> a\nvectGet FZ (x :: xs) = x\nvectGet (FS x) (y :: xs) = vectGet x xs\n\nsumEntries : Num e => Integer -> Vect n e -> Vect n e -> Maybe e\nsumEntries {n} i xs ys = map sumAtIndex (integerToFin i n)\n where sumAtIndex fin = vectGet fin xs + (vectGet fin ys)\n\n\n-- tryIndex : Integer -> Vect n a -> Maybe a\n-- tryIndex {n} x xs = map (\\fin => ?index fin xs) (integerToFin x n)\n\n\n", "meta": {"hexsha": "cb18233ee2ba49ec7510c316128d2cf86b246882", "size": 938, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "vect.idr", "max_stars_repo_name": "GustavoMF31/TDDwithIdrisExercises", "max_stars_repo_head_hexsha": "22b7c2802e1d8fd102a5b9b70d024205b3f35a74", "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": "vect.idr", "max_issues_repo_name": "GustavoMF31/TDDwithIdrisExercises", "max_issues_repo_head_hexsha": "22b7c2802e1d8fd102a5b9b70d024205b3f35a74", "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": "vect.idr", "max_forks_repo_name": "GustavoMF31/TDDwithIdrisExercises", "max_forks_repo_head_hexsha": "22b7c2802e1d8fd102a5b9b70d024205b3f35a74", "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.6842105263, "max_line_length": 69, "alphanum_fraction": 0.5682302772, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6864105342478054}} {"text": "module Data.List.AtIndex\n\nimport Data.DPair\nimport Data.List.HasLength\nimport Data.Nat\nimport Decidable.Equality\n\n%default total\n\n||| @AtIndex witnesses the fact that a natural number encodes a membership proof.\n||| It is meant to be used as a runtime-irrelevant gadget to guarantee that the\n||| natural number is indeed a valid index.\npublic export\ndata AtIndex : a -> List a -> Nat -> Type where\n Z : AtIndex a (a :: as) Z\n S : AtIndex a as n -> AtIndex a (b :: as) (S n)\n\n||| Inversion principle for Z constructor\nexport\ninverseZ : AtIndex x (y :: xs) Z -> x === y\ninverseZ Z = Refl\n\n||| inversion principle for S constructor\nexport\ninverseS : AtIndex x (y :: xs) (S n) -> AtIndex x xs n\ninverseS (S p) = p\n\n||| An empty list cannot possibly have members\nexport\nUninhabited (AtIndex a [] n) where\n uninhabited Z impossible\n uninhabited (S _) impossible\n\n||| For a given list and a given index, there is only one possible value\n||| stored at that index in that list\nexport\natIndexUnique : AtIndex a as n -> AtIndex b as n -> a === b\natIndexUnique Z Z = Refl\natIndexUnique (S p) (S q) = atIndexUnique p q\n\n||| Provided that equality is decidable, we can look for the first occurence\n||| of a value inside of a list\npublic export\nfind : DecEq a => (x : a) -> (xs : List a) -> Dec (Subset Nat (AtIndex x xs))\nfind x [] = No (\\ p => void (absurd (snd p)))\nfind x (y :: xs) with (decEq x y)\n find x (x :: xs) | Yes Refl = Yes (Element Z Z)\n find x (y :: xs) | No neqxy = case find x xs of\n Yes (Element n prf) => Yes (Element (S n) (S prf))\n No notInxs => No $ \\case\n (Element Z p) => void (neqxy (inverseZ p))\n (Element (S n) prf) => absurd (notInxs (Element n (inverseS prf)))\n\n||| If the equality is not decidable, we may instead rely on interface resolution\npublic export\ninterface Member (0 t : a) (0 ts : List a) where\n isMember' : Subset Nat (AtIndex t ts)\n\npublic export\nisMember : (0 t : a) -> (0 ts : List a) -> Member t ts =>\n Subset Nat (AtIndex t ts)\nisMember t ts @{p} = isMember' @{p}\n\npublic export\nMember t (t :: ts) where\n isMember' = Element 0 Z\n\npublic export\nMember t ts => Member t (u :: ts) where\n isMember' = let (Element n prf) = isMember t ts in\n Element (S n) (S prf)\n\n||| Given an index, we can decide whether there is a value corresponding to it\npublic export\nlookup : (n : Nat) -> (xs : List a) -> Dec (Subset a (\\ x => AtIndex x xs n))\nlookup n [] = No (\\ p => void (absurd (snd p)))\nlookup Z (x :: xs) = Yes (Element x Z)\nlookup (S n) (x :: xs) = case lookup n xs of\n Yes (Element x p) => Yes (Element x (S p))\n No notInxs => No (\\ (Element x p) => void (notInxs (Element x (inverseS p))))\n\n||| An AtIndex proof implies that n is less than the length of the list indexed into\npublic export\ninRange : (n : Nat) -> (xs : List a) -> (0 _ : AtIndex x xs n) -> LTE n (length xs)\ninRange n [] p = void (absurd p)\ninRange Z (x :: xs) p = LTEZero\ninRange (S n) (x :: xs) p = LTESucc (inRange n xs (inverseS p))\n\n|||\nexport\nweakenR : AtIndex x xs n -> AtIndex x (xs ++ ys) n\nweakenR Z = Z\nweakenR (S p) = S (weakenR p)\n\nexport\nweakenL : (p : Subset Nat (HasLength ws)) -> AtIndex x xs n -> AtIndex x (ws ++ xs) (fst p + n)\nweakenL m p = case view m of\n Z => p\n (S m) => S (weakenL m p)\n\nexport\nstrengthenL : (p : Subset Nat (HasLength xs)) ->\n lt n (fst p) === True ->\n AtIndex x (xs ++ ys) n -> AtIndex x xs n\nstrengthenL m lt idx = case view m of\n S m => case idx of\n Z => Z\n S idx => S (strengthenL m lt idx)\n\nexport\nstrengthenR : (p : Subset Nat (HasLength ws)) ->\n lte (fst p) n === True ->\n AtIndex x (ws ++ xs) n -> AtIndex x xs (minus n (fst p))\nstrengthenR m lt idx = case view m of\n Z => rewrite minusZeroRight n in idx\n S m => case idx of S idx => strengthenR m lt idx\n", "meta": {"hexsha": "db145ce131d8ff56ee7dc236404728828aaa7212", "size": 3828, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/List/AtIndex.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/contrib/Data/List/AtIndex.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/contrib/Data/List/AtIndex.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 32.7179487179, "max_line_length": 95, "alphanum_fraction": 0.6256530825, "num_tokens": 1220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6859954101518667}} {"text": "> module Identity.Operations\n\n\n> import Control.Monad.Identity\n\n\n> import Sigma.Sigma\n\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n\n> |||\n> unwrap : Identity a -> a\n> unwrap {a} (Id x) = x\n\n\n* |Identity| is a functor:\n\n> ||| fmap\n> fmap : {A, B : Type} -> (A -> B) -> Identity A -> Identity B\n> fmap = map {f = Identity}\n\n\n* |Identity| is a monad:\n\n> ||| ret\n> ret : {A : Type} -> A -> Identity A\n> ret = pure\n\n> ||| bind\n> bind : {A, B : Type} -> Identity A -> (A -> Identity B) -> Identity B\n> bind = (>>=)\n\n\n* |Identity| is a container monad:\n\n> ||| Membership\n> Elem : {A : Type} -> A -> Identity A -> Type\n> Elem a1 (Id a2) = a1 = a2\n\n> ||| Non emptiness\n> NonEmpty : {A : Type} -> Identity A -> Type\n> NonEmpty _ = Unit\n\n> ||| \n> All : {A : Type} -> (P : A -> Type) -> Identity A -> Type\n> All P = P . unwrap\n\n> ||| Tagging\n> tagElem : {A : Type} -> (ia : Identity A) -> Identity (Sigma A (\\ a => a `Elem` ia))\n> tagElem (Id a) = Id (MkSigma a Refl)\n\n\n> |||\n> unwrapElemLemma : (ia : Identity a) -> Elem (unwrap ia) ia\n> unwrapElemLemma (Id a) = Refl\n", "meta": {"hexsha": "198e86cc99663c3e04872b15c41252c68f585b9b", "size": 1079, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Identity/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": "Identity/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": "Identity/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": 17.9833333333, "max_line_length": 88, "alphanum_fraction": 0.5523632994, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6859826844174453}} {"text": "> module NonNegDouble.MeasureProperties\n\n> import Syntax.PreorderReasoning\n\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.Constants\n> import NonNegDouble.Measures\n> import NonNegDouble.Operations\n> import NonNegDouble.Properties\n> import NonNegDouble.Predicates\n> import NonNegDouble.LTEProperties\n> import List.Properties\n \n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Properties of |average|:\n\n> %freeze monotoneSum\n\n> using implementation NumNonNegDouble\n> using implementation FractionalNonNegDouble\n> ||| |average| is monotone\n> monotoneAverage : {A : Type} ->\n> (f : A -> NonNegDouble) -> (g : A -> NonNegDouble) ->\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 = one / fromNat (length (map f as))} \n> {d = one / fromNat (length (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 : one / fromNat (length (map f as)) `LTE` one / fromNat (length (map f as))\n> s2 = reflexiveLTE (one / fromNat (length (map f as)))\n> s3 : one / fromNat (length (map f as)) `LTE` one / fromNat (length (map g as))\n> s3 = replace {P = \\ X => one / fromNat (length (map f as)) `LTE` one / fromNat X} (lengthLemma as f g) s2\n\n\n> {-\n\n> ---}\n \n", "meta": {"hexsha": "f5e12c05b20336d61f323f221b56c527ccd166c1", "size": 1687, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegDouble/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": "NonNegDouble/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": "NonNegDouble/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": 35.1458333333, "max_line_length": 113, "alphanum_fraction": 0.5334914049, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6859292783450129}} {"text": "import Common\n\ndepVect : (init: Iso a b) ->\n (step: a -> Iso a b) ->\n Iso (Vect n a) (Vect n b)\ndepVect init step = MkIso (to init) (from init) (tf init) (ft init)\n where\n to : Iso a b -> Vect n a -> Vect n b\n to s [] = []\n to s (x::xs) = appIso s x :: to (step x) xs\n from : Iso a b -> Vect n b -> Vect n a\n from s [] = []\n from s (x::xs) = unappIso s x :: from (step (unappIso s x)) xs\n tf : (step : Iso a b) -> (v : Vect n b) -> to step (from step v) = v\n tf i [] = Refl\n tf i (x::xs) = rewrite (tf (step (unappIso i x)) xs) in case i of\n (MkIso ito ifrom itf ift) => cong (itf x) {f=flip (::) xs}\n ft : (step : Iso a b) -> (v : Vect n a) -> from step (to step v) = v\n ft i [] = Refl\n ft (MkIso ito ifrom itf ift) (x::xs) = rewrite (ift x) in cong (ft (step x) xs) {f=(::) x}\n\nstateVect : (init: Iso a b) ->\n (initS: s) ->\n (step: s -> a -> s) ->\n (gen: s -> Iso a b) ->\n Iso (Vect n a) (Vect n b)\nstateVect {s=s} i is step gen = MkIso (to is i) (from is i) (tf is i) (ft is i)\n where\n to : s -> Iso a b -> Vect n a -> Vect n b\n to _ _ [] = []\n to st iso (x::xs) = appIso iso x :: to (step st x) (gen (step st x)) xs\n from : s -> Iso a b -> Vect n b -> Vect n a\n from st iso [] = []\n from st iso (x::xs) = unappIso iso x :: from (step st (unappIso iso x)) (gen (step st (unappIso iso x))) xs\n tf : (st : s) -> (iso : Iso a b) -> (v : Vect n b) -> to st iso (from st iso v) = v\n tf _ _ [] = Refl\n tf st iso (x::xs) = rewrite (tf (step st (unappIso iso x)) (gen (step st (unappIso iso x))) xs) in\n case iso of\n (MkIso ito ifrom itf ift) => cong (itf x) {f=flip (::) xs}\n ft : (st : s) -> (iso : Iso a b) -> (v : Vect n a) -> from st iso (to st iso v) = v\n ft _ _ [] = Refl\n ft st (MkIso ito ifrom itf ift) (x::xs) = rewrite (ift x) in\n cong (ft (step st x) (gen (step st x)) xs) {f=(::) x}\n\n\n\n\n-- examples\n\n\n\nxor : Bool -> Bool -> Bool\nxor = (/=)\n\nxorTwice : (x,y : Bool) -> xor x (xor x y) = y\nxorTwice True True = Refl\nxorTwice False False = Refl\nxorTwice False True = Refl\nxorTwice True False = Refl\n\ntest : Iso (Vect n Bool) (Vect n Bool)\ntest = stateVect idIso False step gen\n where\n idIso = (MkIso id id (\\x => Refl) (\\x => Refl))\n -- change state when state and value match\n step True True = False\n step False False = True\n step s _ = s\n -- just xor with state\n gen s = MkIso (xor s) (xor s) (xorTwice s) (xorTwice s)\n\n-- λΠ> appIso test [True, True, True, True, True, True, True]\n-- [True, True, True, True, True, True, True] : Vect 7 Bool\n-- λΠ> appIso test [False, True, False, True, False, True, False]\n-- [False, False, False, False, False, False, False] : Vect 7 Bool\n-- λΠ> appIso test [False, True, False, False, False, True, False]\n-- [False, False, False, True, True, False, False] : Vect 7 Bool\n\ntest2 : Iso (Vect n Bool) (Vect n Bool)\ntest2 = stateVect idIso Z step gen\n where\n idIso = (MkIso id id (\\x => Refl) (\\x => Refl))\n step Z False = Z\n step (S n) False = n\n step n True = S n\n gen s = MkIso (xor (s == 0)) (xor (s == 0)) (xorTwice (s == 0)) (xorTwice (s == 0))\n\n-- λΠ> appIso test2 [True, True, True, False, False, False, False]\n-- [True, True, True, False, False, False, True] : Vect 7 Bool\n\n", "meta": {"hexsha": "232406f5ceff2ed1069596e53d3b6a7bade44d0f", "size": 3251, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Vect.idr", "max_stars_repo_name": "defanor/morphisms", "max_stars_repo_head_hexsha": "57ec23fc955dc69300d6fbd394cb9ac3209ff76b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-10T20:58:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-10T20:58:11.000Z", "max_issues_repo_path": "src/Vect.idr", "max_issues_repo_name": "defanor/morphisms", "max_issues_repo_head_hexsha": "57ec23fc955dc69300d6fbd394cb9ac3209ff76b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Vect.idr", "max_forks_repo_name": "defanor/morphisms", "max_forks_repo_head_hexsha": "57ec23fc955dc69300d6fbd394cb9ac3209ff76b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7252747253, "max_line_length": 109, "alphanum_fraction": 0.5515226084, "num_tokens": 1237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6856714706990907}} {"text": "import Decidable.Equality\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n%name Vect xs, ys, zs\n\nexactLength : {m : _} ->\n (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": "c988ffa1f47922257a901df88784755ff9f3cd6e", "size": 405, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter08/ExactLengthDec.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "idris2/tests/typedd-book/chapter08/ExactLengthDec.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "idris2/tests/typedd-book/chapter08/ExactLengthDec.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.9285714286, "max_line_length": 69, "alphanum_fraction": 0.4765432099, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6853406015268652}} {"text": "-- examples in \"Type-Driven Development with Idris\"\n-- chapter 6\n\nimport Data.Vect\n\n-- check that all functions are total\n%default total\n\n--\n-- section 6.1\n--\n\nPosition : Type\nPosition = (Double, Double)\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\nStringOrInt : Bool -> Type\nStringOrInt False = String\nStringOrInt True = Int\n\ngetStringOrInt : (isInt : Bool) -> StringOrInt isInt\ngetStringOrInt False = \"Ninety-four\"\ngetStringOrInt True = 94\n\nvalToString : (isInt : Bool) -> StringOrInt isInt -> String\nvalToString False x = trim x\nvalToString True x = cast x\n\n--\n-- section 6.2\n--\n\n||| defines types of functions with n arguments of kind t -> t -> ... -> t\nAdderType : (n : Nat) -> Type -> Type\nAdderType Z t = t\nAdderType (S k) t = (next : t) -> AdderType k t\n\n-- > :let A2 = AdderType 2\n-- > :let A4 = AdderType 4\n-- > A2 Nat\n-- Nat -> Nat -> Nat : Type\n-- > A4 Int\n-- Int -> Int -> Int -> Int -> Int : Type\n\n||| generic adder of type t -> (t -> t -> ... -> t)\n||| where the first argument is the accumulator\nadder : Num t => (n : Nat) -> (acc : t) -> AdderType n t\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (next + acc)\n\n||| adder for 3 naturals\nadd3Nat : AdderType 3 Nat\nadd3Nat = adder 3 0\n\nval1 : Nat\nval1 = add3Nat 1 2 3\n\nval2 : Int\nval2 = (adder 4 0) 1 2 3 4\n\n-- > val1\n-- 6 : Nat\n-- > val2\n-- 10 : Int\n\n--\n-- section 6.3\n-- see DataStore.idr\n--\n", "meta": {"hexsha": "ee2d1dd3534b69d0598e3d72d95427625c9c2d4f", "size": 1433, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter6/examples.idr", "max_stars_repo_name": "pascalpoizat/idris-book", "max_stars_repo_head_hexsha": "f1ef0ed0a8b8c1690d7ce65258f04322b37ff956", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-08-16T00:58:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T01:07:37.000Z", "max_issues_repo_path": "chapter6/examples.idr", "max_issues_repo_name": "pascalpoizat/idris-book", "max_issues_repo_head_hexsha": "f1ef0ed0a8b8c1690d7ce65258f04322b37ff956", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter6/examples.idr", "max_forks_repo_name": "pascalpoizat/idris-book", "max_forks_repo_head_hexsha": "f1ef0ed0a8b8c1690d7ce65258f04322b37ff956", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-23T03:15:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-23T03:15:39.000Z", "avg_line_length": 19.1066666667, "max_line_length": 74, "alphanum_fraction": 0.6182833217, "num_tokens": 516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6851504210587912}} {"text": "import Data.Vect\n\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", "meta": {"hexsha": "3d59094b5b2974396ec43a52202724a27f63a603", "size": 209, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter04/TryIndex.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TypeDrivenDevelopment/Chapter04/TryIndex.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypeDrivenDevelopment/Chapter04/TryIndex.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.125, "max_line_length": 58, "alphanum_fraction": 0.5167464115, "num_tokens": 50, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6849436036790905}} {"text": "module Algebraic\n\n-- Example functions\n\nor : Bool -> Bool -> Bool\nor p q = p || q\n\nxor : Bool -> Bool -> Bool\nxor p q = (p || q) && not (p && q)\n\n-- Idempotency\n\nIdempotent : (a -> a) -> a -> Type\nIdempotent f a = f (f a) = f a\n\n-- Involution\n\nnotNotTrue : not (not True) = True\nnotNotTrue = Refl\n\nnotNotFalse : not (not False) = False\nnotNotFalse = Refl\n\nnotNot : (b : Bool) -> not (not b) = b\nnotNot False = Refl\nnotNot True = Refl\n\nInvolution : (a -> a) -> a -> Type\nInvolution f a = f (f a) = a\n\nxorInvolution : (a : Bool) -> (b : Bool) -> xor a (xor a b) = b\nxorInvolution False False = Refl\nxorInvolution False True = Refl\nxorInvolution True False = Refl\nxorInvolution True True = Refl\n\n-- Uninhabited\n\nnotNotIdempotent : (b : Bool) -> Idempotent not b -> Void\nnotNotIdempotent False Refl impossible\nnotNotIdempotent True Refl impossible\n\nsuccNotIdempotent : (n : Nat) -> Idempotent S n -> Void\nsuccNotIdempotent Z Refl impossible\nsuccNotIdempotent (S k) prf =\n succNotIdempotent k (succInjective (S (S k)) (S k) prf)\n\n-- Both\n\nidempotentInvolution : Idempotent f a -> Involution f a -> f a = a\nidempotentInvolution idem invo = ?idempotentInvolution\n\n---------- Proofs ----------\n\nAlgebraic.idempotentInvolution1 = proof\n intros\n rewrite idem\n rewrite sym invo\n trivial\n\n", "meta": {"hexsha": "56077fc38379104e6854716507cffe30811af881", "size": 1282, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "speakers/puffnfresh/Algebraic.idr", "max_stars_repo_name": "nuttycom/lambdaconf-2015-upstream", "max_stars_repo_head_hexsha": "1c768a5d0d86b7391635c54ff5c951dd786113ad", "max_stars_repo_licenses": ["Artistic-2.0"], "max_stars_count": 100, "max_stars_repo_stars_event_min_datetime": "2015-05-19T21:02:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T01:30:39.000Z", "max_issues_repo_path": "speakers/puffnfresh/Algebraic.idr", "max_issues_repo_name": "rtfeldman/lambdaconf-2015", "max_issues_repo_head_hexsha": "62396a8656df5e1e11a92c0fcfbb9398a10fd956", "max_issues_repo_licenses": ["Artistic-2.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2015-05-12T00:22:15.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-31T00:51:49.000Z", "max_forks_repo_path": "speakers/puffnfresh/Algebraic.idr", "max_forks_repo_name": "rtfeldman/lambdaconf-2015", "max_forks_repo_head_hexsha": "62396a8656df5e1e11a92c0fcfbb9398a10fd956", "max_forks_repo_licenses": ["Artistic-2.0"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2015-05-06T23:17:26.000Z", "max_forks_repo_forks_event_max_datetime": "2017-04-09T06:48:05.000Z", "avg_line_length": 21.0163934426, "max_line_length": 66, "alphanum_fraction": 0.6692667707, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771661, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.684831497808059}} {"text": "-- --------------------------------------------------------------- [ Day03.idr ]\n-- Module : Data.Advent.Day03\n-- Description : My solution to the Day 3 puzzle of the 2016 Advent of Code.\n-- Copyright : Copyright (c) 2016, Eric Bailey\n-- License : MIT\n-- Link : http://adventofcode.com/2016/day/3\n-- --------------------------------------------------------------------- [ EOH ]\n||| Day 3: Squares with Three Sides\nmodule Data.Advent.Day03\n\nimport public Data.Advent.Day\n\nimport Data.Vect\n\n-- -------------------------------------------------------------- [ Data Types ]\n\n%access export\n\n||| A triangle, comprised of three side lengths, is equilateral or il/logical.\ndata Triangle : Type where\n\n ||| Given side lengths `a`, `b` and `c`, and proofs that `a = b`\n ||| and `b = c`, return a `Triangle.`\n Equilateral : (a, b, c : Integer) -> a = b -> b = c -> Triangle\n\n ||| Given side lengths `a`, `b` and `c`, and proofs that they satisfy the\n ||| triangle inequality theorem, return a `Triangle`.\n ||| @ p1 a proof that `a` is strictly less than `b + c`\n ||| @ p2 a proof that `b` is strictly less than `a + c`\n ||| @ p3 a proof that `c` is strictly less than `a + b`\n Logical : (a, b, c : Integer) ->\n (p1 : LT (fromIntegerNat a) (fromIntegerNat (b + c))) ->\n (p2 : LT (fromIntegerNat b) (fromIntegerNat (a + c))) ->\n (p3 : LT (fromIntegerNat c) (fromIntegerNat (a + b))) ->\n Triangle\n\n ||| Construct a triangle that is neither equilateral nor logical.\n Illogical : (a, b, c : Integer) -> Triangle\n\n||| Given side lengths `a`, `b` and `c`, if they are all equal,\n||| return `Just` a `Triangle`, otherwise `Nothing`.\nequilateral : (a, b, c : Integer) -> Maybe Triangle\nequilateral a b c with (decEq a b)\n equilateral _ _ _ | No _ = Nothing\n equilateral a b c | Yes ab with (decEq b c)\n equilateral _ _ _ | _ | No _ = Nothing\n equilateral a b c | Yes ab | Yes bc = Just (Equilateral a b c ab bc)\n\n||| Given side lengths `a`, `b` and `c`, return `Just` a `Triangle` if they\n||| satisfy the triangle inequality theorem, otherwise `Nothing`.\nlogical : (a, b, c : Integer) -> Maybe Triangle\nlogical a b c with (isLTE (S (fromIntegerNat a)) (fromIntegerNat (b + c)))\n logical _ _ _| No _ = Nothing\n logical a b c | Yes abc with (isLTE (S (fromIntegerNat b))\n (fromIntegerNat (a + c)))\n logical _ _ _| _ | No _ = Nothing\n logical a b c | Yes abc | Yes bac with (isLTE (S (fromIntegerNat c))\n (fromIntegerNat (a + b)))\n logical _ _ _ | _ | _ | No _ = Nothing\n logical a b c | Yes abc | Yes bac | Yes cab =\n Just (Logical a b c abc bac cab)\n\nnamespace Triangle\n\n ||| Construct a `Triangle` from the given side lengths.\n triangle : (a, b, c : Integer) -> Triangle\n triangle a b c = fromMaybe (Illogical a b c) $\n equilateral a b c <|> logical a b c\n\n ||| Construct a `Triangle` from a `Vect` of (three) side lengths (integers).\n fromVect : Vect 3 Integer -> Triangle\n fromVect [a,b,c] = triangle a b c\n\n-- ----------------------------------------------------------------- [ Parsers ]\n\n||| Parse three side lengths.\npartial sides : Parser (Vect 3 Integer)\nsides = ntimes 3 (spaces *> integer)\n\n{-\n||| Parse three side lengths and construct a `Triangle`.\npartial triangle : Parser Triangle\ntriangle = do [a,b,c] <- sides\n pure $ triangle a b c\n-}\n\n-- ------------------------------------------------------------------- [ Logic ]\n\n||| Given a foldable structure containing `Triangle`s,\n||| count which of them are not `Illogical`.\ncountPossible : Foldable t => t Triangle -> Nat\ncountPossible = foldl go 0\n where\n go : Nat -> Triangle -> Nat\n go n (Illogical _ _ _) = n\n go n _ = S n\n\n-- ---------------------------------------------------------------- [ Part One ]\n\npartial partOne : List (Vect 3 Integer) -> IO String\npartOne = pure . show . countPossible . map fromVect\n\n-- ---------------------------------------------------------------- [ Part Two ]\n\npartial partTwo : List (Vect 3 Integer) -> IO String\npartTwo = pure . show . countPossible .\n concatMap (toList . map fromVect . transpose) .\n go\n where\n go : List (Vect 3 Integer) -> List (Vect 3 (Vect 3 Integer))\n go (x::y::z::zs) = [x,y,z] :: go zs\n go _ = []\n\n-- -------------------------------------------------------------------- [ Main ]\n\nnamespace Main\n\n partial main : IO ()\n main = runDay $ MkDay 3\n (some (sides <* spaces))\n partOne\n partTwo\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "2d18d8546ed68683f18e6cb3fcda9f52e998f8ef", "size": 4829, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Advent/Day03.idr", "max_stars_repo_name": "yurrriq/advent-of-code", "max_stars_repo_head_hexsha": "ee83efa138322b5dbbda9f4aeac75481a9cd49fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-11-04T10:32:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-05T07:36:22.000Z", "max_issues_repo_path": "src/Data/Advent/Day03.idr", "max_issues_repo_name": "yurrriq/aoc19", "max_issues_repo_head_hexsha": "ee83efa138322b5dbbda9f4aeac75481a9cd49fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Data/Advent/Day03.idr", "max_forks_repo_name": "yurrriq/aoc19", "max_forks_repo_head_hexsha": "ee83efa138322b5dbbda9f4aeac75481a9cd49fe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-26T19:27:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-26T19:27:21.000Z", "avg_line_length": 38.632, "max_line_length": 80, "alphanum_fraction": 0.5067301719, "num_tokens": 1218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6847621433225076}} {"text": "> module FastSimpleProb.MonadicProperties\n\n> import Data.List\n> import Data.List.Quantifiers\n> import Syntax.PreorderReasoning\n\n> import FastSimpleProb.SimpleProb\n> import FastSimpleProb.BasicOperations\n> import FastSimpleProb.BasicProperties\n> import FastSimpleProb.MonadicOperations\n> import FastSimpleProb.MonadicPostulates\n> import FastSimpleProb.Predicates\n> import FastSimpleProb.Functor\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.Postulates\n> import NonNegDouble.Constants\n> import NonNegDouble.BasicOperations\n> import NonNegDouble.Operations\n> import NonNegDouble.Properties\n\n> import Double.Predicates\n> import Num.Refinements\n> import Num.Properties\n> import Fun.Operations\n> import List.Operations\n> import List.Properties\n> import Unique.Predicates\n> import Finite.Predicates\n> import Sigma.Sigma\n> import Pairs.Operations\n> import Functor.Predicates\n\n\n> %default total\n> %access public export\n> -- %access export\n> %auto_implicits off\n\n\n* Monadic properties of |support|, |normalize|:\n\n> |||\n> supportRetLemma : {A : Type} -> \n> (a : A) -> support (ret a) = ret a\n> supportRetLemma a = ( support (ret a) )\n> ={ Refl }=\n> ( map fst (toList (ret a)) )\n> ={ Refl }=\n> ( map fst (toList (MkSimpleProb [(a, one)] positiveOne)) )\n> ={ Refl }=\n> ( map fst [(a, one)] ) \n> ={ Refl }=\n> ( [a] ) \n> ={ Refl }=\n> ( ret a )\n> QED \n\n> ||| |normalize| is a natural transformation\n> normalizeNatural : Natural {F = SimpleProb} {G = SimpleProb} normalize\n> normalizeNatural = fmapNormalizeLemma\n\n\n* |SimpleProb| is a container monad:\n\n> |||\n> elemNonEmptySpec0 : {A : Type} ->\n> (a : A) -> (sp : SimpleProb A) -> a `Elem` sp -> NonEmpty sp\n> elemNonEmptySpec0 {A} a sp aesp = List.Properties.elemNonEmptySpec0 a (support sp) aesp\n\n> |||\n> elemNonEmptySpec1 : {A : Type} ->\n> (sp : SimpleProb A) -> NonEmpty sp -> Sigma A (\\ a => a `Elem` sp)\n> elemNonEmptySpec1 {A} sp nesp = List.Properties.elemNonEmptySpec1 (support sp) nesp\n\n> |||\n> containerMonadSpec1 : {A : Type} -> {a : A} -> a `FastSimpleProb.MonadicOperations.Elem` (ret a)\n> containerMonadSpec1 {A} {a} = s3 where\n> s1 : a `Data.List.Elem` (List.Operations.ret a)\n> s1 = List.Properties.containerMonadSpec1\n> s2 : a `Data.List.Elem` (support (FastSimpleProb.MonadicOperations.ret a))\n> s2 = replace {P = \\ X => a `Data.List.Elem` X} (sym (supportRetLemma a)) s1\n> s3 : a `FastSimpleProb.MonadicOperations.Elem` (ret a)\n> s3 = s2\n\n> |||\n> containerMonadSpec3 : {A : Type} -> {P : A -> Type} ->\n> (a : A) -> (sp : SimpleProb A) ->\n> All P sp -> a `Elem` sp -> P a\n> containerMonadSpec3 {A} {P} a sp allp elemp = List.Properties.containerMonadSpec3 a (support sp) allp elemp\n\n\n* Specific container monad properties\n\n> |||\n> uniqueAllLemma : {A : Type} -> {P : A -> Type} -> \n> Unique1 P -> (sp : SimpleProb A) -> Unique (All P sp)\n> uniqueAllLemma u1P sp = List.Properties.uniqueAllLemma u1P (support sp)\n\n> |||\n> finiteAll : {A : Type} -> {P : A -> Type} -> \n> Finite1 P -> (sp : SimpleProb A) -> Finite (All P sp)\n> finiteAll f1P sp = List.Properties.finiteAll f1P (support sp)\n\n> ||| All is decidable\n> decidableAll : {A : Type} -> {P : A -> Type} -> \n> (dec : (a : A) -> Dec (P a)) -> (sp : SimpleProb A) -> Dec (All P sp)\n> decidableAll dec sp = List.Properties.decidableAll dec (support sp)\n\n> ||| NotEmpty is finite\n> finiteNonEmpty : {A : Type} -> (sp : SimpleProb A) -> Finite (FastSimpleProb.MonadicOperations.NonEmpty sp)\n> finiteNonEmpty sp = List.Properties.finiteNonEmpty (support sp)\n\n> ||| NotEmpty is decidable\n> decidableNonEmpty : {A : Type} -> (sp : SimpleProb A) -> Dec (FastSimpleProb.MonadicOperations.NonEmpty sp)\n> decidableNonEmpty sp = List.Properties.decidableNonEmpty (support sp)\n\n\n* |SimpleProb|s are never empty\n\n> using implementation NumNonNegDouble\n> |||\n> nonEmptyLemma1 : {A : Type} -> (sp : SimpleProb A) -> List.Operations.NonEmpty (toList sp)\n> nonEmptyLemma1 {A} (MkSimpleProb Nil psum) = s4 where\n> s1 : sumMapSnd {A = A} {B = NonNegDouble} Nil = zero\n> s1 = sumMapSndNilLemma {A = A} {B = NonNegDouble}\n> s2 : Positive (toDouble (sumMapSnd {A = A} {B = NonNegDouble} Nil))\n> s2 = psum\n> s3 : Positive (toDouble zero)\n> s3 = replace {P = \\ X => Positive (toDouble X)} s1 s2 \n> s4 : List.Operations.NonEmpty {A = (A, NonNegDouble)} (toList (MkSimpleProb Nil psum))\n> s4 = notPositiveZero s3\n> nonEmptyLemma1 (MkSimpleProb (ap :: aps) psum) = () \n\n> |||\n> nonEmptyLemma : {A : Type} -> (sp : SimpleProb A) -> NonEmpty sp\n> nonEmptyLemma {A} sp = s4 where\n> s1 : List.Operations.NonEmpty (toList sp)\n> s1 = nonEmptyLemma1 sp\n> s2 : List.Operations.NonEmpty (map fst (toList sp))\n> s2 = mapPreservesNonEmpty fst (toList sp) s1\n> s3 : List.Operations.NonEmpty (support sp) \n> s3 = s2\n> s4 : NonEmpty sp\n> s4 = s3\n\n\n* Properies of |fmap| and |toList|\n\n> using implementation NumNonNegDouble\n> |||\n> toListFmapLemma : {A, B : Type} -> \n> (f : A -> B) -> (sp : SimpleProb A) ->\n> toList (fmap f sp) = fmap (cross f id) (toList sp)\n> toListFmapLemma f (MkSimpleProb aps psum) = \n> ( toList (fmap f (MkSimpleProb aps psum)) )\n> ={ Refl }=\n> ( toList (MkSimpleProb \n> (fmap (cross f id) aps) \n> (replace {P = \\ X => Positive (toDouble X)} (cong {f = sum} (sym (mapSndMapCrossAnyIdLemma f aps))) psum)) )\n> ={ Refl }= \n> ( fmap (cross f id) aps )\n> ={ Refl }=\n> ( fmap (cross f id) (toList (MkSimpleProb aps psum)) )\n> QED\n\n\n> {-\n\n> ---}\n", "meta": {"hexsha": "70d9db25ebfa89f535105a663b8c4fff5a0f79b5", "size": 5881, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "FastSimpleProb/MonadicProperties.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": "FastSimpleProb/MonadicProperties.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": "FastSimpleProb/MonadicProperties.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": 34.5941176471, "max_line_length": 126, "alphanum_fraction": 0.6073796973, "num_tokens": 1805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488296, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6846434485470351}} {"text": "module Data.List.Quantifiers\n\nimport Data.List\nimport Data.List.Elem\n\n||| A proof that some element of a list satisfies some property\n|||\n||| @ p the property to be satisfied\npublic export\ndata Any : (0 p : a -> Type) -> List a -> Type where\n ||| A proof that the satisfying element is the first one in the `List`\n Here : {0 xs : List a} -> p x -> Any p (x :: xs)\n ||| A proof that the satisfying element is in the tail of the `List`\n There : {0 xs : List a} -> Any p xs -> Any p (x :: xs)\n\nexport\nUninhabited (Any p Nil) where\n uninhabited (Here _) impossible\n uninhabited (There _) impossible\n\n||| Given a decision procedure for a property, determine if an element of a\n||| list satisfies it.\n|||\n||| @ p the property to be satisfied\n||| @ dec the decision procedure\n||| @ xs the list to examine\nexport\nany : (dec : (x : a) -> Dec (p x)) -> (xs : List a) -> Dec (Any p xs)\nany _ Nil = No uninhabited\nany p (x::xs) with (p x)\n any p (x::xs) | Yes prf = Yes (Here prf)\n any p (x::xs) | No ctra =\n case any p xs of\n Yes prf' => Yes (There prf')\n No ctra' => No $ \\case\n Here px => ctra px\n There pxs => ctra' pxs\n\n||| A proof that all elements of a list satisfy a property. It is a list of\n||| proofs, corresponding element-wise to the `List`.\npublic export\ndata All : (0 p : a -> Type) -> List a -> Type where\n Nil : All p Nil\n (::) : {0 xs : List a} -> p x -> All p xs -> All p (x :: xs)\n\n||| Given a decision procedure for a property, decide whether all elements of\n||| a list satisfy it.\n|||\n||| @ p the property\n||| @ dec the decision procedure\n||| @ xs the list to examine\nexport\nall : (dec : (x : a) -> Dec (p x)) -> (xs : List a) -> Dec (All p xs)\nall _ Nil = Yes Nil\nall d (x::xs) with (d x)\n all d (x::xs) | No ctra = No $ \\(p::_) => ctra p\n all d (x::xs) | Yes prf =\n case all d xs of\n Yes prf' => Yes (prf :: prf')\n No ctra' => No $ \\(_::ps) => ctra' ps\n\n||| If there does not exist an element that satifies the property, then it is\n||| the case that all elements do not satisfy it.\nexport\nnegAnyAll : {xs : List a} -> Not (Any p xs) -> All (Not . p) xs\nnegAnyAll {xs=Nil} _ = Nil\nnegAnyAll {xs=x::xs} f = (f . Here) :: negAnyAll (f . There)\n\n||| If there exists an element that doesn't satify the property, then it is\n||| not the case that all elements satisfy it.\nexport\nanyNegAll : Any (Not . p) xs -> Not (All p xs)\nanyNegAll (Here ctra) (p::_) = ctra p\nanyNegAll (There np) (_::ps) = anyNegAll np ps\n\n||| Given a proof of membership for some element, extract the property proof for it\nexport\nindexAll : Elem x xs -> All p xs -> p x\nindexAll Here (p::_ ) = p\nindexAll (There e) ( _::ps) = indexAll e ps\n\n||| Modify the property given a pointwise function\nexport\nmapProperty : (f : {0 x : a} -> p x -> q x) -> All p l -> All q l\nmapProperty f [] = []\nmapProperty f (p::pl) = f p :: mapProperty f pl\n", "meta": {"hexsha": "2f3c835bb646f353d8b18e746b5195992399a16e", "size": 2877, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/List/Quantifiers.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/libs/base/Data/List/Quantifiers.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/libs/base/Data/List/Quantifiers.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": 33.0689655172, "max_line_length": 83, "alphanum_fraction": 0.6155717762, "num_tokens": 937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289535, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6845783960102321}} {"text": "data Maybe a = Nothing\n | Just a\n\ninfixl 1 >>=\n\n(>>=) : Maybe a -> (a -> Maybe b) -> Maybe b\n(>>=) Nothing k = Nothing\n(>>=) (Just x) k = k x\n\ndata Nat : Type where\n Z : Nat\n S : Nat -> Nat\n\nplus : Nat -> Nat -> Nat\nplus Z y = y\nplus (S k) y = S (plus k y)\n\nmaybeAdd' : Maybe Nat -> Maybe Nat -> Maybe Nat\nmaybeAdd' x y\n = x >>= \\x' =>\n y >>= \\y' =>\n Just (plus x' y')\n\nmaybeAdd : Maybe Nat -> Maybe Nat -> Maybe Nat\nmaybeAdd x y\n = do x' <- x\n y' <- y\n Just (plus x' y')\n\ndata Either : Type -> Type -> Type where\n Left : a -> Either a b\n Right : b -> Either a b\n\nmEmbed : Maybe a -> Maybe (Either String a)\nmEmbed Nothing = Just (Left \"FAIL\")\nmEmbed (Just x) = Just (Right x)\n\nmPatBind : Maybe Nat -> Maybe Nat -> Maybe Nat\nmPatBind x y\n = do Right res <- mEmbed (maybeAdd x y)\n | Left err => Just Z\n Just res\n\nmLetBind : Maybe Nat -> Maybe Nat -> Maybe Nat\nmLetBind x y\n = do let Just res = maybeAdd x y\n | Nothing => Just Z\n Just res\n\n", "meta": {"hexsha": "b40056a5268d302407b33db974f5105912e1172d", "size": 1048, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic028/Do.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/basic028/Do.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/basic028/Do.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": 20.96, "max_line_length": 47, "alphanum_fraction": 0.5209923664, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6844256588645498}} {"text": "> module Fun.MathExpr\n\nfrom https://github.com/DSLsofMath/DSLsofMath/blob/master/L/DSLsofMath/FunExp.lhs\n\n> import Interfaces.Math\n\n> %default total\n> %access public export\n> %auto_implicits on -- off\n\n\n> ||| Functions as expressions\n> data MathExpr : Type -> Type where\n> Id : MathExpr t\n> Neg : MathExpr t\n> Exp : MathExpr t\n> Sin : MathExpr t\n> Cos : MathExpr t\n> Const : t -> MathExpr t\n> (+) : MathExpr t -> MathExpr t -> MathExpr t\n> (-) : MathExpr t -> MathExpr t -> MathExpr t\n> (*) : MathExpr t -> MathExpr t -> MathExpr t\n> (/) : MathExpr t -> MathExpr t -> MathExpr t\n> (.) : MathExpr t -> MathExpr t -> MathExpr t\n\n\n> ||| Evaluation\n> eval : (Num t, Fractional t, Neg t, Math t) => MathExpr t -> t -> t\n> eval Id x = id x\n> eval Neg x = - x\n> eval Exp x = exp x\n> eval Sin x = sin x\n> eval Cos x = cos x\n> eval (Const c) x = (const c) x \n> eval (e1 + e2) x = (eval e1 x) + (eval e2 x)\n> eval (e1 - e2) x = (eval e1 x) - (eval e2 x)\n> eval (e1 * e2) x = (eval e1 x) * (eval e2 x)\n> eval (e1 / e2) x = (eval e1 x) / (eval e2 x)\n> eval (e1 . e2) x = (eval e1 (eval e2 x))\n\n\n> ||| Differentiation\n> derivative : (Num t, Fractional t, Neg t) => MathExpr t -> MathExpr t\n> derivative Id = Const 1\n> derivative Neg = Const (negate 1)\n> derivative Exp = Exp\n> derivative Sin = Cos\n> derivative Cos = Neg . Sin\n> derivative (Const c) = Const 0\n> derivative (e1 + e2) = derivative e1 + derivative e2\n> derivative (e1 - e2) = derivative e1 - derivative e2 \n> derivative (e1 * e2) = (derivative e1) * e2 + e1 * (derivative e2) \n> derivative (e1 / e2) = (derivative e1) / e2 - e1 * (derivative e2) / (e2 * e2)\n> derivative (e1 . e2) = ((derivative e1) . e2) * (derivative e2) \n\nThis needs to be tested!\n", "meta": {"hexsha": "986b61462000542d64129ad1f4c2bbeedf9a8473", "size": 1809, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fun/MathExpr.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fun/MathExpr.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fun/MathExpr.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.7368421053, "max_line_length": 81, "alphanum_fraction": 0.5787728027, "num_tokens": 650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6843841270459444}} {"text": "||| A Shape\ndata Shape = ||| A triangle\n Triangle Double Double\n | ||| A rectangle\n Rectangle Double Double\n | ||| A circle\n Circle Double\n\n%name Shape shape, shape1, shape2\n\ntotal area : Shape -> Double\narea (Triangle x y) = 0.5 * x * y\narea (Rectangle x y) = x * y\narea (Circle x) = pi * x * x\n\ndata Picture = ||| A primitive shape\n Primitive Shape\n | ||| A combination of pictures\n Combine Picture Picture\n | ||| A rotated picture\n Rotate Double Picture\n | ||| A translated picture\n Translate Double Double Picture\n\n%name Picture pic, pic1, pic2\n\n--- %name directives are _awesome_\npictureArea : Picture -> Double\npictureArea (Primitive shape) = area shape\npictureArea (Combine pic pic1) = pictureArea pic + pictureArea pic1\npictureArea (Rotate x pic) = pictureArea pic\npictureArea (Translate x y pic) = pictureArea pic\n\nrectangle : Picture\nrectangle = Primitive (Rectangle 20 10)\n\ncircle : Picture\ncircle = Primitive (Circle 5)\n\ntriangle : Picture\ntriangle = Primitive (Triangle 10 10)\n\ntestPicture : Picture\ntestPicture = Combine (Translate 5 5 rectangle)\n (Combine (Translate 35 5 circle)\n (Rotate 5 (Translate 15 25 triangle)))\n", "meta": {"hexsha": "ad6c05f3e4c62e6d295bbf2313424b85f6259a7f", "size": 1334, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/4.1-RecursiveTypes.idr", "max_stars_repo_name": "ostera/asdf", "max_stars_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-03-02T22:25:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T18:22:11.000Z", "max_issues_repo_path": "idris/4.1-RecursiveTypes.idr", "max_issues_repo_name": "ostera/asdf", "max_issues_repo_head_hexsha": "adec59de04ce1c2994db60b92f693e621bf68850", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-05T22:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T22:45:58.000Z", "max_forks_repo_path": "idris/4.1-RecursiveTypes.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": 28.3829787234, "max_line_length": 69, "alphanum_fraction": 0.616191904, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545333502202, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6843241043155774}} {"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 context 'ctx' and a variable with\n-- de Bruijn index 'i'. Given further the terms\n-- ts : Term [] s, and\n-- tt : Term (insertAt i s ctx) t.\n-- Then 'subst ts i tt' has type 't' in context 'ctx'.\"\n--\n-- Note that 'subst ts i tt' is typically written as \"tt[ts/(Var i)]\".\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-- ans casually summarized as \n-- \n-- *** substitution preserves type ***.\n--\n\n\nimport FinCmp\nimport Term\n\n\n%default total\n\n\n-------------------------------------------------------------\n-- Begin: WEAKENING, I.E. ADDING UNUSED VARIABLES TO CONTEXTS\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 \n-- Note that we only require weakening of a context 'ctx'\n-- by appending another context on the right only.\nweakeningPreservesType : {ctx : Context m} -> {ctx' : Context n} -> \n {i : Fin m} ->\n (index i ctx = t) -> \n (index (wkN n i) (ctx ++ ctx') = t)\nweakeningPreservesType {ctx = (_::_)} {i = FZ} eq = eq\nweakeningPreservesType {ctx = (_:: xs)} {i = (FS i')} eq =\n weakeningPreservesType {i = i'} eq\n\n\nweakenContext : {m : Nat} -> (ctx : Context m) ->\n {n : Nat} -> (ctx' : Context n) -> \n Term ctx t -> \n Term (ctx ++ ctx') t\nweakenContext ctx {n = n} ctx' (TVar i {prf = p}) = \n TVar (wkN n i) {prf = weakeningPreservesType p}\n--\nweakenContext ctx ctx' (TAbs {s} e) = TAbs (weakenContext (s::ctx) ctx' e)\nweakenContext ctx ctx' (TApp e1 e2) = TApp (weakenContext ctx ctx' e1)\n (weakenContext ctx ctx' e2)\nweakenContext ctx ctx' (TRec {t} e e0 e1) = TRec (weakenContext ctx ctx' e)\n (weakenContext ctx ctx' e0)\n (weakenContext (t::TyNat::ctx) ctx' e1)\nweakenContext _ _ TZero = TZero\nweakenContext ctx ctx' (TSucc e) = TSucc (weakenContext ctx ctx' e)\nweakenContext ctx ctx' (TPred e) = TPred (weakenContext ctx ctx' e)\nweakenContext ctx ctx' (TIfz e1 e2 e3) = TIfz (weakenContext ctx ctx' e1)\n (weakenContext ctx ctx' e2)\n (weakenContext ctx ctx' e3)\n\n-- End: WEAKENING, I.E. ADDING UNUSED VARIABLES TO CONTEXTS\n-----------------------------------------------------------\n\n\n\n \n-----------------------------------------------------------------\n-- Begin: TECHNICAL LEMMATA ABOUT INDEXING INTO MODIFIED CONTEXTS\n\n-- Function 'lookupInserted' yields a proof of the following:\n--\n-- \"Let ctx' = insertAt i s ctx, and let i = j.\n-- If (index j ctx' = t), then t = s.\"\n-- \nlookupInserted : {ctx : Context n} -> {s : Ty} -> {t : Ty} ->\n {i : Fin (S n)} -> {j : Fin (S n)} ->\n i = j ->\n index j (insertAt i s ctx) = t ->\n t = s \nlookupInserted {i = FZ} {j = FZ} _ prf = sym prf\nlookupInserted {ctx} {s} {t} {i = FZ} {j = (FS j')} eq prf = \n sym $ replace {P = \\k => index k (insertAt FZ s ctx) = t} (sym eq) prf\n--\nlookupInserted {ctx} {s} {t} {i = (FS i')} {j = FZ} eq prf =\n sym $ replace {P = \\k => index FZ (insertAt k s ctx) = t} eq prf\n-- \nlookupInserted {ctx = (_::_)} {i = (FS i')} {j = (FS j')} eq prf = \n lookupInserted (FSinjective eq) prf\n\n\n-- Function 'shiftDown' yields a proof of the following:\n--\n-- \"Let ctx' = insertAt i s ctx, and let i < (j+1).\n-- If (index (j+1) ctx' = t), then (index j ctx = t).\"\n--\nshiftDown : {ctx : Context n} -> {s : Ty} ->\n {i : Fin (S n)} -> {j : Fin n} ->\n i :<: (FS j) -> \n index (FS j) (insertAt i s ctx) = t ->\n index j ctx = t\n-- \nshiftDown {i = FZ} {j = _} _ prf = prf\nshiftDown {i = (FS _)} {j = FZ} lt prf = \n absurd $ finNotLtZ $ finLtPred lt\n--\nshiftDown {ctx = (_::xs)} {s} {i = (FS i')} {j = (FS j')} lt prf =\n shiftDown {ctx = xs} {s} {i = i'} {j = j'} (finLtPred lt) prf\n\n\n-- Function 'indexZeroLemma' yields a proof of the following: \n--\n-- \"Let ctx a non-empty context, and let ctx' = insertAt t (i+1) ctx.\n-- Then, (index 0 ctx') = (index 0 ctx).\"\n--\nindexZeroLemma : {ctx : Context (S n)} -> \n (i : Fin (S n)) -> \n index FZ (insertAt (FS i) t ctx) = index FZ ctx\n--\nindexZeroLemma {ctx = (_::_)} _ = Refl\n\n\n-- Function 'pushLemma' yields a proof of the following:\n--\n-- \"Let ctx be a context, and let (index i ctx = t).\n-- Then, index (i+1) (s::ctx) = t.\"\n--\npushLemma : (s : Ty) -> \n index i ctx = t -> \n index (FS i) (s::ctx) = t\npushLemma _ eq = eq\n\n\n-- Function 'tightenBound' yields a proof of the following:\n--\n-- \"Let ctx be a context, and let ctx' = insertAt i s ctx.\n-- If (j < i) and (index j ctx' = t), then index j ctx = t.\"\n--\n-- The function 'tightenBound' returns a dependent pair.\n--\n-- The first component of the pair is 'j_', which represents\n-- the same value as the function argument 'j' (as natural\n-- numbers); but note that the bound on the ordinal 'j_' has\n-- been tightened (by using the assumption \"j < i\"):\n-- \"j_ : Fin n\" while \"j : Fin (S n)\".\n-- \n-- The second component of the dependent pair is a proof of\n-- \"index j_ ctx = t\".\n--\ntightenBound : {n : Nat} -> {ctx : Context n} -> \n (j : Fin (S n)) -> {i : Fin (S n)} -> \n j :<: i ->\n index j (insertAt i s ctx) = t ->\n (j_ : Fin n ** (index j_ ctx = t))\n-- \ntightenBound _ {i = FZ} lt _ =\n absurd $ finNotLtZ lt\n--\ntightenBound {n = (S n')} FZ {i = (FS i')} _ eq = \n let izl = indexZeroLemma i'\n eq_ = trans (sym izl) eq\n in (FZ ** eq_)\n--\ntightenBound {ctx = (x::xs)} (FS j') {i = (FS i')} lt eq =\n let (j_ ** eq_) = tightenBound {ctx = xs} j' (finLtPred lt) eq\n in (FS j_ ** pushLemma x eq_)\n\n-- End: TECHNICAL LEMMATA ABOUT INDEXING INTO MODIFIED CONTEXTS\n---------------------------------------------------------------\n\n\n\n-----------------------------------------------------------------------------\n-- Begin: SUBSTITUTION PRESERVES TYPING OF EXPRESSIONS IN THE LAMBDA CALCULUS\n\nsubst_var : Term [] s -> -- Term of type 's' 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 index j (insertAt i s ctx) = t ->\n Term ctx t\n--\n-- An actual substitution occurs only if \"i = j\".\n--\n-- For \"i /= j\" no substitution occurs, but the proof 'prf'\n-- in the returned expression 'TVar _ {prf}' has to be \n-- adjusted to account for the fact that the context has\n-- been shortened from (insertAt s i ctx) to 'ctx'.\nsubst_var {ctx} {s} ts i j prf = case finCmpDec i j of\n CmpEq eq => let ts' = weakenContext [] ctx ts\n in rewrite (lookupInserted eq prf) in ts'\n CmpLt lt => case j of\n FZ => absurd $ finNotLtZ lt \n FS j' => TVar j' {prf = shiftDown lt prf}\n CmpGt gt => case i of\n FZ => absurd $ finNotLtZ gt\n FS i' => let (j_ ** prf_) = tightenBound j gt prf\n in TVar j_ {prf = prf_}\n\n\nexport subst : Term [] s -> -- Term of type 's' is substituted in.\n (i : Fin (S n)) -> -- The i-th varibale (Var i) is substituted for.\n Term (insertAt i s ctx) t -> -- Substitution takes place inside this\n -- term of type 't'\n Term ctx t -- The resulting term is again of type 't'.\n--\n-- The hard part is substitution in expressions that \n-- are variables, i.e. substitution in 'Var j'.\nsubst ts i (TVar j {prf}) = subst_var ts i j prf\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 ts i (TRec e e0 e1) = TRec (subst ts i e) (subst ts i e0) (subst ts (FS $ FS i) e1)\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 TYPING OF EXPRESSIONS IN THE LAMBDA CALCULUS\n---------------------------------------------------------------------------\n", "meta": {"hexsha": "795e45710c80b4d60e1970486aae7a53019c70fd", "size": 9114, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "total/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": "total/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": "total/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.2941176471, "max_line_length": 93, "alphanum_fraction": 0.5198595567, "num_tokens": 2710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6842733678110624}} {"text": "= Induction : Proof by Induction\n\n> module Induction\n\nFirst, we import all of our definitions from the previous chapter.\n\n> import Basics\n\nNext, we import the following \\idr{Prelude} modules, since we'll be dealing with\nnatural numbers.\n\n> import Prelude.Interfaces\n> import Prelude.Nat\n\nFor \\idr{import Basics} to work, you first need to use `idris` to compile\n`Basics.lidr` into `Basics.ibc`. This is like making a .class file from a .java\nfile, or a .o file from a .c file. There are at least two ways to do it:\n\n - In your editor with an Idris plugin, e.g. [Emacs][idris-mode]:\n\n Open `Basics.lidr`. Evaluate \\idr{idris-load-file}.\n\n There exists similar support for [Vim][idris-vim], [Sublime\n Text][idris-sublime] and [Visual Studio Code][idris-vscode] as well.\n\n [idris-mode]: https://github.com/idris-hackers/idris-mode\n [idris-vim]: https://github.com/idris-hackers/idris-vim\n [idris-sublime]: https://github.com/idris-hackers/idris-sublime\n [idris-vscode]: https://github.com/zjhmale/vscode-idris\n\n - From the command line:\n\n Run \\mintinline[]{sh}{idris --check --total --noprelude src/Basics.lidr}.\n\n Refer to the Idris man page (or \\mintinline[]{sh}{idris --help} for\n descriptions of the flags.\n\n> %access public export\n\n> %default total\n\n\n== Proof by Induction\n\nWe proved in the last chapter that \\idr{0} is a neutral element for \\idr{+} on\nthe left using an easy argument based on simplification. The fact that it is\nalso a neutral element on the _right_...\n\n```coq\nTheorem plus_n_O_firsttry : forall n:nat,\n n = n + 0.\n```\n\n... cannot be proved in the same simple way in Coq, but as we saw in `Basics`,\nIdris's \\idr{Refl} just works.\n\nTo prove interesting facts about numbers, lists, and other inductively defined\nsets, we usually need a more powerful reasoning principle: _induction_.\n\nRecall (from high school, a discrete math course, etc.) the principle of\ninduction over natural numbers: If \\idr{p n} is some proposition involving a\nnatural number \\idr{n} and we want to show that \\idr{p} holds for _all_ numbers\n\\idr{n}, we can reason like this:\n\n - show that \\idr{p Z} holds;\n - show that, for any \\idr{k}, if \\idr{p k} holds, then so does \\idr{p (S k)};\n - conclude that \\idr{p n} holds for all \\idr{n}.\n\nIn Idris, the steps are the same and can often be written as function clauses by\ncase splitting. Here's how this works for the theorem at hand.\n\n> plus_n_Z : (n : Nat) -> n = n + 0\n> plus_n_Z Z = Refl\n> plus_n_Z (S k) =\n> let inductiveHypothesis = plus_n_Z k in\n> rewrite inductiveHypothesis in Refl\n\nIn the first clause, \\idr{n} is replaced by \\idr{Z} and the goal becomes \\idr{0\n= 0}, which follows by \\idr{Refl}exivity. In the second, \\idr{n} is replaced by\n\\idr{S k} and the goal becomes \\idr{S k = S (plus k 0)}. Then we define the\ninductive hypothesis, \\idr{k = k + 0}, which can be written as \\idr{plus_n_Z k},\nand the goal follows from it.\n\n> minus_diag : (n : Nat) -> minus n n = 0\n> minus_diag Z = Refl\n> minus_diag (S k) = minus_diag k\n\n\n==== Exercise: 2 stars, recommended (basic_induction)\n\nProve the following using induction. You might need previously proven results.\n\n> mult_0_r : (n : Nat) -> n * 0 = 0\n> mult_0_r n = ?mult_0_r_rhs\n\n> plus_n_Sm : (n, m : Nat) -> S (n + m) = n + (S m)\n> plus_n_Sm n m = ?plus_n_Sm_rhs\n\n> plus_comm : (n, m : Nat) -> n + m = m + n\n> plus_comm n m = ?plus_comm_rhs\n\n> plus_assoc : (n, m, p : Nat) -> n + (m + p) = (n + m) + p\n> plus_assoc n m p = ?plus_assoc_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars (double_plus)\n\nConsider the following function, which doubles its argument:\n\n> double : (n : Nat) -> Nat\n> double Z = Z\n> double (S k) = S (S (double k))\n\nUse induction to prove this simple fact about \\idr{double}:\n\n> double_plus : (n : Nat) -> double n = n + n\n> double_plus n = ?double_plus_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional (evenb_S)\n\nOne inconvenient aspect of our definition of \\idr{evenb n} is that it may need\nto perform a recursive call on \\idr{n - 2}. This makes proofs about \\idr{evenb\nn} harder when done by induction on \\idr{n}, since we may need an induction\nhypothesis about \\idr{n - 2}. The following lemma gives a better\ncharacterization of \\idr{evenb (S n)}:\n\n> evenb_S : (n : Nat) -> evenb (S n) = not (evenb n)\n> evenb_S n = ?evenb_S_rhs\n\n$\\square$\n\n\n== Proofs Within Proofs\n\n\\ \\todo[inline]{Edit the section}\n\nIn Coq, as in informal mathematics, large proofs are often broken into a\nsequence of theorems, with later proofs referring to earlier theorems. But\nsometimes a proof will require some miscellaneous fact that is too trivial and\nof too little general interest to bother giving it its own top-level name. In\nsuch cases, it is convenient to be able to simply state and prove the needed\n\"sub-theorem\" right at the point where it is used. The `assert` tactic allows us\nto do this. For example, our earlier proof of the \\idr{mult_0_plus} theorem\nreferred to a previous theorem named \\idr{plus_Z_n}. We could instead use\n`assert` to state and prove \\idr{plus_Z_n} in-line:\n\n> mult_0_plus' : (n, m : Nat) -> (0 + n) * m = n * m\n> mult_0_plus' n m = Refl\n\nThe `assert` tactic introduces two sub-goals. The first is the assertion itself;\nby prefixing it with `H:` we name the assertion `H`. (We can also name the\nassertion with `as` just as we did above with `destruct` and `induction`, i.e.,\n`assert (0 + n = n) as H`.) Note that we surround the proof of this assertion\nwith curly braces `{ ... }`, both for readability and so that, when using Coq\ninteractively, we can see more easily when we have finished this sub-proof. The\nsecond goal is the same as the one at the point where we invoke `assert` except\nthat, in the context, we now have the assumption `H` that `0 + n = n`. That is,\n`assert` generates one subgoal where we must prove the asserted fact and a\nsecond subgoal where we can use the asserted fact to make progress on whatever\nwe were trying to prove in the first place.\n\nThe `assert` tactic is handy in many sorts of situations. For example, suppose\nwe want to prove that `(n + m) + (p + q) = (m + n) + (p + q)`. The only\ndifference between the two sides of the `=` is that the arguments `m` and `n` to\nthe first inner `+` are swapped, so it seems we should be able to use the\ncommutativity of addition (`plus_comm`) to rewrite one into the other. However,\nthe `rewrite` tactic is a little stupid about _where_ it applies the rewrite.\nThere are three uses of `+` here, and it turns out that doing `rewrite ->\nplus_comm` will affect only the _outer_ one...\n\n```idris\nplus_rearrange_firsttry : (n, m, p, q : Nat) ->\n (n + m) + (p + q) = (m + n) + (p + q)\nplus_rearrange_firsttry n m p q = rewrite plus_comm in Refl\n```\n```\nWhen checking right hand side of plus_rearrange_firsttry with expected type\n n + m + (p + q) = m + n + (p + q)\n\n_ does not have an equality type ((n1 : Nat) ->\n(n1 : Nat) -> plus n1 m1 = plus m1 n1)\n```\n\nTo get \\idr{plus_comm} to apply at the point where we want it to, we can\nintroduce a local lemma using the \\idr{where} keyword stating that \\idr{n + m =\nm + n} (for the particular \\idr{m} and \\idr{n} that we are talking about here),\nprove this lemma using \\idr{plus_comm}, and then use it to do the desired\nrewrite.\n\n> plus_rearrange : (n, m, p, q : Nat) ->\n> (n + m) + (p + q) = (m + n) + (p + q)\n> plus_rearrange n m p q = rewrite plus_rearrange_lemma n m in Refl\n> where\n> plus_rearrange_lemma : (n, m : Nat) -> n + m = m + n\n> plus_rearrange_lemma = plus_comm\n\n== More Exercises\n\n\n==== Exercise: 3 stars, recommended (mult_comm)\n\nUse \\idr{rewrite} to help prove this theorem. You shouldn't need to use\ninduction on \\idr{plus_swap}.\n\n> plus_swap : (n, m, p : Nat) -> n + (m + p) = m + (n + p)\n> plus_swap n m p = ?plus_swap_rhs\n\nNow prove commutativity of multiplication. (You will probably need to define and\nprove a separate subsidiary theorem to be used in the proof of this one. You may\nfind that \\idr{plus_swap} comes in handy.)\n\n> mult_comm : (m, n : Nat) -> m * n = n * m\n> mult_comm m n = ?mult_comm_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars, optional (more_exercises)\n\n\\ \\todo[inline]{Edit}\n\nTake a piece of paper. For each of the following theorems, first _think_ about\nwhether (a) it can be proved using only simplification and rewriting, (b) it\nalso requires case analysis (`destruct`), or (c) it also requires induction.\nWrite down your prediction. Then fill in the proof. (There is no need to turn in\nyour piece of paper; this is just to encourage you to reflect before you hack!)\n\n> lte_refl : (n : Nat) -> True = lte n n\n> lte_refl n = ?lte_refl_rhs\n\n> zero_nbeq_S : (n : Nat) -> 0 == (S n) = False\n> zero_nbeq_S n = ?zero_nbeq_S_rhs\n\n> andb_false_r : (b : Bool) -> b && False = False\n> andb_false_r b = ?andb_false_r_rhs\n\n> plus_ble_compat_l : (n, m, p : Nat) ->\n> lte n m = True -> lte (p + n) (p + m) = True\n> plus_ble_compat_l n m p prf = ?plus_ble_compat_l_rhs\n\n> S_nbeq_0 : (n : Nat) -> (S n) == 0 = False\n> S_nbeq_0 n = ?S_nbeq_0_rhs\n\n> mult_1_l : (n : Nat) -> 1 * n = n\n> mult_1_l n = ?mult_1_l_rhs\n\n> all3_spec : (b, c : Bool) ->\n> (b && c) || ((not b) || (not c)) = True\n> all3_spec b c = ?all3_spec_rhs\n\n> mult_plus_distr_r : (n, m, p : Nat) -> (n + m) * p = (n * p) + (m * p)\n> mult_plus_distr_r n m p = ?mult_plus_distr_r_rhs\n\n> mult_assoc : (n, m, p : Nat) -> n * (m * p) = (n * m) * p\n> mult_assoc n m p = ?mult_assoc_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional (beq_nat_refl)\n\n\\ \\todo[inline]{Edit}\n\nProve the following theorem. (Putting the \\idr{True} on the left-hand side of\nthe equality may look odd, but this is how the theorem is stated in the Coq\nstandard library, so we follow suit. Rewriting works equally well in either\ndirection, so we will have no problem using the theorem no matter which way we\nstate it.)\n\n> beq_nat_refl : (n : Nat) -> True = n == n\n> beq_nat_refl n = ?beq_nat_refl_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional (plus_swap')\n\n\\ \\todo[inline]{Edit}\n\nThe `replace` tactic allows you to specify a particular subterm to rewrite and\nwhat you want it rewritten to: `replace (t) with (u)` replaces (all copies of)\nexpression `t` in the goal by expression `u`, and generates `t = u` as an\nadditional subgoal. This is often useful when a plain \\idr{rewrite} acts on the\nwrong part of the goal.\n\nUse the `replace` tactic to do a proof of \\idr{plus_swap'}, just like\n\\idr{plus_swap} but without needing `assert (n + m = m + n)`.\n\n> plus_swap' : (n, m, p : Nat) -> n + (m + p) = m + (n + p)\n> plus_swap' n m p = ?plus_swap__rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars, recommended (binary_commute)\n\nRecall the \\idr{incr} and \\idr{bin_to_nat} functions that you wrote for the\n\\idr{binary} exercise in the `Basics` chapter. Prove that the following diagram\ncommutes:\n\n bin --------- incr -------> bin\n | |\n bin_to_nat bin_to_nat\n | |\n v v\n nat ---------- S ---------> nat\n\nThat is, incrementing a binary number and then converting it to a (unary)\nnatural number yields the same result as first converting it to a natural number\nand then incrementing. Name your theorem \\idr{bin_to_nat_pres_incr} (\"pres\" for\n\"preserves\").\n\nBefore you start working on this exercise, please copy the definitions from your\nsolution to the \\idr{binary} exercise here so that this file can be graded on\nits own. If you find yourself wanting to change your original definitions to\nmake the property easier to prove, feel free to do so!\n\n$\\square$\n\n\n==== Exercise: 5 stars, advanced (binary_inverse)\n\nThis exercise is a continuation of the previous exercise about binary numbers.\nYou will need your definitions and theorems from there to complete this one.\n\n(a) First, write a function to convert natural numbers to binary numbers. Then\n prove that starting with any natural number, converting to binary, then\n converting back yields the same natural number you started with.\n\n(b) You might naturally think that we should also prove the opposite direction:\n that starting with a binary number, converting to a natural, and then back\n to binary yields the same number we started with. However, this is not true!\n Explain what the problem is.\n\n(c) Define a \"direct\" normalization function -- i.e., a function \\idr{normalize}\n from binary numbers to binary numbers such that, for any binary number b,\n converting to a natural and then back to binary yields \\idr{(normalize b)}.\n Prove it. (Warning: This part is tricky!)\n\nAgain, feel free to change your earlier definitions if this helps here.\n\n$\\square$\n", "meta": {"hexsha": "d25db307fe6434e9d297e8dbc74c8e9bfde60109", "size": 12708, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Induction.lidr", "max_stars_repo_name": "diseraluca/software-foundations", "max_stars_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 452, "max_stars_repo_stars_event_min_datetime": "2016-06-23T10:03:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T22:25:00.000Z", "max_issues_repo_path": "src/Induction.lidr", "max_issues_repo_name": "diseraluca/software-foundations", "max_issues_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 53, "max_issues_repo_issues_event_min_datetime": "2016-06-27T07:14:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-23T06:16:57.000Z", "max_forks_repo_path": "src/Induction.lidr", "max_forks_repo_name": "diseraluca/software-foundations", "max_forks_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2016-11-21T10:55:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T00:21:55.000Z", "avg_line_length": 36.5172413793, "max_line_length": 80, "alphanum_fraction": 0.6841359773, "num_tokens": 3752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6842661788300588}} {"text": "import TypedContainers.LawfulOrd\n\n%default total\n\nLawfulOrd Nat where\n compare Z Z = EQ\n compare Z (S _) = LT\n compare (S _) Z = GT\n compare (S x) (S y) = TypedContainers.LawfulOrd.compare x y\n \n reflexivity Z = Refl\n reflexivity (S x) = reflexivity x\n\n reversion1 Z Z p impossible\n reversion1 (S _) Z p impossible\n reversion1 Z (S _) p = Refl\n reversion1 (S x) (S y) p =\n let rec = reversion1 x y in\n rec p\n\n reversion2 Z Z p impossible\n reversion2 (S _) Z p = Refl\n reversion2 Z (S _) p impossible\n reversion2 (S x) (S y) p =\n let rec = reversion2 x y in\n rec p\n\n reversion3 Z Z p = Refl\n reversion3 (S _) Z p impossible\n reversion3 Z (S _) p impossible\n reversion3 (S x) (S y) p =\n let rec = reversion3 x y in\n rec p\n\n transitivity Z Z Z p0 p1 impossible\n transitivity Z Z (S z) p0 p1 impossible\n transitivity Z (S y) Z p0 p1 impossible\n transitivity Z (S y) (S z) p0 p1 = Refl\n transitivity (S x) Z Z p0 p1 impossible\n transitivity (S x) Z (S z) p0 p1 impossible\n transitivity (S x) (S y) Z p0 p1 impossible\n transitivity (S x) (S y) (S z) p0 p1 =\n let rec = transitivity x y z p0 p1 in\n rec\n\n equality1 Z Z z p = Refl\n equality1 Z (S y) Z p impossible\n equality1 Z (S y) (S z) p impossible\n equality1 (S x) Z Z p impossible\n equality1 (S x) Z (S z) p impossible\n equality1 (S x) (S y) Z p = Refl\n equality1 (S x) (S y) (S z) p =\n let rec = equality1 x y z p in\n rec\n\n equality2 Z Z z p = Refl\n equality2 Z (S y) Z p impossible\n equality2 Z (S y) (S z) p impossible\n equality2 (S x) Z Z p impossible\n equality2 (S x) Z (S z) p impossible\n equality2 (S x) (S y) Z p = Refl\n equality2 (S x) (S y) (S z) p =\n let rec = equality2 x y z p in\n rec\n\nLawfullerOrd Nat where\n realEquality Z Z p = Refl\n realEquality Z (S _) p impossible\n realEquality (S _) Z p impossible\n realEquality (S x) (S y) p =\n let rec = realEquality x y p in\n cong S rec\n", "meta": {"hexsha": "1f2f4be62c94bf1cd85507b096d1af52a1fe43d5", "size": 2057, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypedContainers/LawfulOrd/Nat.idr", "max_stars_repo_name": "L-as/idris-rbtree", "max_stars_repo_head_hexsha": "1c9bab3c5f54ab431c379bf54cec5b548e09f0d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-08-25T15:48:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-10T05:31:53.000Z", "max_issues_repo_path": "TypedContainers/LawfulOrd/Nat.idr", "max_issues_repo_name": "L-as/idris-rbtree", "max_issues_repo_head_hexsha": "1c9bab3c5f54ab431c379bf54cec5b548e09f0d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypedContainers/LawfulOrd/Nat.idr", "max_forks_repo_name": "L-as/idris-rbtree", "max_forks_repo_head_hexsha": "1c9bab3c5f54ab431c379bf54cec5b548e09f0d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1780821918, "max_line_length": 61, "alphanum_fraction": 0.6008750608, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6842615062728686}} {"text": "-- Classical logic, PHOAS approach, initial encoding\n\nmodule Pi.C\n\n%default total\n\n\n-- Types\n\ndata Indiv : Type where\n TODO : Indiv\n\nTy : Type\n\nPred : Type\nPred = Indiv -> Ty\n\ninfixl 2 :&&\ninfixl 1 :||\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n (:&&) : Ty -> Ty -> Ty\n (:||) : Ty -> Ty -> Ty\n FALSE : Ty\n FORALL : Pred -> Ty\n EXISTS : Pred -> Ty\n\ninfixr 0 :<=>\n(:<=>) : Ty -> Ty -> Ty\n(:<=>) a b = (a :=> b) :&& (b :=> a)\n\nNOT : Ty -> Ty\nNOT a = a :=> FALSE\n\nTRUE : Ty\nTRUE = FALSE :=> FALSE\n\n\n-- Context and truth judgement\n\ndata El : Type where\n mkTrue : Ty -> El\n mkIndiv : Indiv -> El\n\nCx : Type\nCx = El -> Type\n\nisTrue : Ty -> Cx -> Type\nisTrue a tc = tc (mkTrue a)\n\nisIndiv : Indiv -> Cx -> Type\nisIndiv x tc = tc (mkIndiv x)\n\n\n-- Terms\n\ninfixl 2 :$$\ninfixl 1 :$\n\ndata Tm : Cx -> Ty -> Type where\n var : isTrue a tc -> Tm tc a\n lam' : (isTrue a tc -> Tm tc b) -> Tm tc (a :=> b)\n (:$) : Tm tc (a :=> b) -> Tm tc a -> Tm tc b\n pair : Tm tc a -> Tm tc b -> Tm tc (a :&& b)\n fst : Tm tc (a :&& b) -> Tm tc a\n snd : Tm tc (a :&& b) -> Tm tc b\n left : Tm tc a -> Tm tc (a :|| b)\n right : Tm tc b -> Tm tc (a :|| b)\n case' : Tm tc (a :|| b) -> (isTrue a tc -> Tm tc c) -> (isTrue b tc -> Tm tc c) -> Tm tc c\n pi' : ({x : Indiv} -> isIndiv x tc -> Tm tc (p x)) -> Tm tc (FORALL p)\n (:$$) : Tm tc (FORALL p) -> isIndiv x tc -> Tm tc (p x)\n sig : isIndiv x tc -> Tm tc (p x) -> Tm tc (EXISTS p)\n split' : Tm tc (EXISTS p) -> (isTrue (p x) tc -> Tm tc a) -> Tm tc a\n abort' : (isTrue (NOT a) tc -> Tm tc FALSE) -> Tm tc a\n\nlam'' : (Tm tc a -> Tm tc b) -> Tm tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\ncase'' : Tm tc (a :|| b) -> (Tm tc a -> Tm tc c) -> (Tm tc b -> Tm tc c) -> Tm tc c\ncase'' xy f g = case' xy (\\x => f (var x)) (\\y => g (var y))\n\nsplit'' : Tm tc (EXISTS p) -> (Tm tc (p x) -> Tm tc a) -> Tm tc a\nsplit'' x f = split' x $ \\y => f (var y)\n\nabort'' : (Tm tc (NOT a) -> Tm tc FALSE) -> Tm tc a\nabort'' f = abort' $ \\na => f (var na)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\nsyntax \"[\" [a] \",\" [b] \"]\" = pair a b\nsyntax \"case\" [ab] \"of\" {a} \":=>\" [c1] or {b} \":=>\" [c2] = case'' ab (\\a => c1) (\\b => c2)\nsyntax \"pi\" {x} \":=>\" [y] = pi' (\\x => y)\nsyntax \"[\" [x] \",,\" [y] \"]\" = sig x y\nsyntax \"split\" [x] as {y} \":=>\" [z] = split'' x (\\y => z)\nsyntax \"abort\" {a} \":=>\" [b] = abort'' (\\a => b)\n\nThm : Ty -> Type\nThm a = {tc : Cx} -> Tm tc a\n\n\n-- Example theorems\n\nt214 : Thm (NOT (FORALL (\\x => NOT (p x))) :=> EXISTS p)\nt214 =\n lam f :=>\n abort g :=>\n f :$ (pi x :=>\n lam p :=> g :$ [ x ,, p ])\n", "meta": {"hexsha": "4ee523e037a6282e3d41937ba39a7a4c92bf4a34", "size": 2910, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pi/C.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/C.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/C.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": 26.4545454545, "max_line_length": 94, "alphanum_fraction": 0.4140893471, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6842614957040783}} {"text": "module Eq \n\nimport Data.List\n\n%default total\n\noccurrences : Eq ty => ty -> List ty -> Nat\noccurrences _ [] = 0\noccurrences v (x :: xs) = case v == x of\n False => occurrences v xs\n True => 1 + occurrences v xs\n\ndata Matter = Solid | Liquid | Gas\n\n{-\n interface Eq ty where\n (==) :: ty -> ty -> Bool\n (/=) :: ty -> ty -> Bool\n\n (==) x y = not (x /= y)\n (/=) x y = not (x == y)\n\n-}\n\nEq Matter where\n (==) Solid Solid = True\n (==) Liquid Liquid = True\n (==) Gas Gas = True\n (==) _ _ = False\n\ndata Tree elem = Empty | Node (Tree elem) elem (Tree elem)\n\nEq ty => Eq (Tree ty) where\n (==) Empty Empty = True\n (==) (Node l v r) (Node l' v' r') = l == l' && v == v' && r == r'\n (==) _ _ = False\n\npartial\nfromList : List ty -> Tree ty\nfromList [] = Empty\nfromList [x] = Node Empty x Empty\nfromList (x :: xs) = Node (fromList left) x (fromList right)\n where\n len : Nat\n len = integerToNat $ (natToInteger (length xs)) `div` 2\n\n left : List ty\n left = take len xs\n\n right : List ty\n right = drop len xs\n", "meta": {"hexsha": "94f8c5ef7c2fff63e135f64323081833188cc154", "size": 1140, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter7/Eq.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/Eq.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/Eq.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": 21.9230769231, "max_line_length": 67, "alphanum_fraction": 0.498245614, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.6839591740244017}} {"text": "module Bisim\n\n%default total\n\ncorecord Stream' : Type -> Type where\n hd : Stream' a -> a\n tl : Stream' a -> Stream' a\n constructor (::) (hd tl)\n\nssucc : Stream' Nat -> Stream' Nat\nssucc s = (S (hd s)) :: (ssucc (tl s))\n\nzeros : Stream' Nat\nzeros = 0 :: zeros\n\nones : Stream' Nat\nones = 1 :: ones\n\ntwos : Stream' Nat\ntwos = 2 :: twos\n\ncodata BisimStream : Stream' a -> Stream' a -> Type where\n MkBisimStream : (phd : (hd s) = (hd s')) -> (ptl : BisimStream (tl s) (tl s')) -> BisimStream s s'\n\ncorecord BisimStream' : (a : Type) -> Stream' a -> Stream' a -> Type where\n phd : BisimStream' a s s' -> (hd s) = (hd s')\n ptl : BisimStream' a s s' -> BisimStream' a (tl s) (tl s')\n constructor MkBisimStream'\n\nbisimsucconestwos : BisimStream' Nat (ssucc ones) twos\nbisimsucconestwos = MkBisimStream' Refl bisimsucconestwos\n\nbisim_eq : BisimStream' a s s' -> s = s'\nbisim_eq = believe_me\n\n-- repeat : Vect (S n) a -> Stream' a\n-- repeat xs = repeat' xs xs\n-- where\n-- repeat' : Vect (S n) a -> Vect (S m) a -> Stream' a\n-- repeat' xs (x :: []) = x :: (repeat' xs xs)\n-- repeat' xs (x :: (y :: ys)) = x :: (repeat' xs (y :: ys))\n \n-- zeroone : Vect 2 Nat\n-- zeroone = [0, 1] \n\n-- onetwo : Vect 2 Nat\n-- onetwo = [1, 2]\n\n-- bisim_succ_repeat_zeroone__repeat_onetwo : BisimStream' Nat (ssucc (repeat zeroone)) (repeat onetwo)\n-- bisim_succ_repeat_zeroone__repeat_onetwo = MkBisimStream' Refl help\n-- where\n-- help : BisimStream' Nat (tl (ssucc (repeat (zeroone)))) (tl (repeat onetwo))\n-- help = MkBisimStream' Refl bisim_succ_repeat_zeroone__repeat_onetwo\n\n-- bisim_succ_repeat_zeroone__repeat_onetwo' : BisimStream (ssucc (repeat zeroone)) (repeat onetwo)\n-- bisim_succ_repeat_zeroone__repeat_onetwo' = MkBisimStream Refl (MkBisimStream Refl bisim_succ_repeat_zeroone__repeat_onetwo') \n", "meta": {"hexsha": "35c0abe52ddf5dfc14d2115e0eee6e2f899198f8", "size": 1801, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples/Bisim.idr", "max_stars_repo_name": "sualitu/thesis", "max_stars_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/Bisim.idr", "max_issues_repo_name": "sualitu/thesis", "max_issues_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "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/Bisim.idr", "max_forks_repo_name": "sualitu/thesis", "max_forks_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "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.5964912281, "max_line_length": 129, "alphanum_fraction": 0.6551915602, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.6836874913563645}} {"text": "import Data.Vect \n\nMatrix : Nat -> Nat -> Type -> Type \nMatrix m n elem = Vect m (Vect n elem)\n\nqualify : (name : String) -> (adjective : String) -> String\nqualify name adjective = name ++ \" is \" ++ adjective\n\nrepeat : (n : Nat) -> a -> Vect n a\nrepeat Z x = []\nrepeat (S k) x = x :: repeat k x\n\ninsertCol : (x : Vect n elem)\n -> (xs : Matrix n len elem)\n -> Matrix n (S len) elem\ninsertCol [] [] = []\ninsertCol (x :: xs) (y :: ys) = (x :: y) :: insertCol xs ys\n\ninsertCol' : (x : Vect n elem) -> (xs : Matrix n len elem) -> Matrix n (S len) elem\ninsertCol' = zipWith (::)\n\n-- The tutorial shows that just putting an underscore instead\n-- of n does the job in this case\n-- (An there would be no need for the {n} there)\ntranspose' : Matrix m n elem -> Matrix n m elem\ntranspose' {n} [] = repeat n []\ntranspose' (x :: xs) = insertCol x $ transpose' xs\n\naddMatrix : Num e => Matrix m n e -> Matrix m n e -> Matrix m n e\naddMatrix [] [] = []\naddMatrix (x :: xs) (y :: ys) = [| x + y |] :: addMatrix xs ys \n\nproductSum : Num e => Vect n e -> Vect n e -> e\nproductSum xs ys = sum [| xs * ys |]\n\ndistributeOver : (a -> a -> c)\n -> a -> Vect m a -> Vect m c\ndistributeOver f x xs = map (f x) xs\n\nmultMatrixHelper : Num e => Matrix m n e\n -> Matrix o n e\n -> Matrix m o e\nmultMatrixHelper [] [] = []\nmultMatrixHelper [] (x :: xs) = []\nmultMatrixHelper (x :: xs) ys =\n -- let distributed = distributeOver productSum x ys\n let distributed = map (productSum x) ys\n in distributed :: multMatrixHelper xs ys\n\nmultMatrix : Num e => Matrix m n e\n -> Matrix n o e\n -> Matrix m o e\nmultMatrix x y = multMatrixHelper x (transpose' y)\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "2de526bd462e001efcfd02eac888030a5d6e0514", "size": 1749, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "matrices.idr", "max_stars_repo_name": "GustavoMF31/TDDwithIdrisExercises", "max_stars_repo_head_hexsha": "22b7c2802e1d8fd102a5b9b70d024205b3f35a74", "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": "matrices.idr", "max_issues_repo_name": "GustavoMF31/TDDwithIdrisExercises", "max_issues_repo_head_hexsha": "22b7c2802e1d8fd102a5b9b70d024205b3f35a74", "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": "matrices.idr", "max_forks_repo_name": "GustavoMF31/TDDwithIdrisExercises", "max_forks_repo_head_hexsha": "22b7c2802e1d8fd102a5b9b70d024205b3f35a74", "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.2096774194, "max_line_length": 83, "alphanum_fraction": 0.5648942253, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6835688875703052}} {"text": "module Rationals\n\nimport NonZeroInt\n\n-- contrib\nimport Control.Algebra\n\n%access export\n%default total\n\nprivate\nrecord FreeRational where\n constructor MkFreeRational\n num : Int\n den : NonZeroInt\n \nRational : Type\nRational = FreeRational\n\nrational : Int -> NonZeroInt -> Rational\nrational = MkFreeRational\n\nintAsRational : Int -> Rational\nintAsRational n = rational n (MkNonZeroInt 1 oneNotZero)\n where\n distinguish : Int -> Type\n distinguish 0 = Void\n distinguish _ = ()\n oneNotZero = \\oneEqualsZero => replace {P=distinguish} oneEqualsZero ()\n\npostulate\nrationalQuotient :\n (num1, num2 : Int)\n -> (den1, den2 : NonZeroInt)\n -> (num1 * (num den2) = num2 * (num den1))\n -> rational num1 den1 = rational num2 den2\n\nfold :\n (map : Int -> NonZeroInt -> a)\n -> ( (num1, num2 : Int)\n -> (den1, den2 : NonZeroInt)\n -> (num1 * (num den2) = num2 * (num den1))\n -> map num1 den1 = map num2 den2)\n -> Rational\n -> a\nfold map mapCoherence (MkFreeRational num den) = map num den\n\n-- operations on rationals\n\nrationalEq : Rational -> Rational -> Bool\nrationalEq (MkFreeRational num1 den1) (MkFreeRational num2 den2) = num1 * (num den2) == num2 * (num den1)\n\nimplementation Eq Rational where\n (==) = rationalEq\n\nrationalCompare : Rational -> Rational -> Ordering\nrationalCompare (MkFreeRational num1 den1) (MkFreeRational num2 den2) = compare (num1 * (num den2)) (num2 * (num den1))\n\nimplementation Ord Rational where\n compare = rationalCompare\n\nrationalAddition : Rational -> Rational -> Rational\nrationalAddition (MkFreeRational num1 den1) (MkFreeRational num2 den2) = MkFreeRational\n (num1 * (num den2) + num2 * (num den1)) (productOfNonZeroIsNonZero den1 den2)\n \n[additiveRationalSemigroup] Semigroup Rational where\n (<+>) = rationalAddition\n \n-- the additive monoid is actually unlawful\n-- because, in Rational, 0/m + 0/n = 0/(m * n)\n-- so the identity laws do not hold\n[additiveRationalMonoid] Monoid Rational using additiveRationalSemigroup where\n neutral = intAsRational 0\n \nrationalOpposite : Rational -> Rational\nrationalOpposite (MkFreeRational num1 den1) = MkFreeRational (-num1) den1\n\n[additiveRationalGroup] Group Rational using additiveRationalMonoid where\n inverse = rationalOpposite\n \n[additiveRationalAbelianGroup] AbelianGroup Rational using additiveRationalGroup where\n\nrationalMultiplication : Rational -> Rational -> Rational\nrationalMultiplication (MkFreeRational num1 den1) (MkFreeRational num2 den2) =\n MkFreeRational (num1 * num2) (productOfNonZeroIsNonZero den1 den2)\n \n[multiplicativeRationalSemigroup] Semigroup Rational where\n (<+>) = rationalMultiplication\n \n[multiplicativeRationalMonoid] Monoid Rational using multiplicativeRationalSemigroup where\n neutral = intAsRational 1\n \n[rationalRing] Ring Rational using additiveRationalAbelianGroup where\n (<.>) = rationalMultiplication\n \n[rationalRingWithUnity] RingWithUnity Rational using rationalRing where\n unity = intAsRational 1\n \nIsNonZero : Rational -> Type\nIsNonZero (MkFreeRational 0 den) = Void\nIsNonZero a = Not (num a = 0)\n \nrationalReciprocal : (a : Rational) -> {auto isNonZero : IsNonZero a} -> Rational\nrationalReciprocal (MkFreeRational num1 den1) {isNonZero} = MkFreeRational (num den1) den\n where\n den = MkNonZeroInt num1 (\\num1IsZero => replace {P=\\n => IsNonZero (MkFreeRational n den1)} num1IsZero isNonZero)\n \n-- the fact that the additive monoid in unlawful forbids us to define a field instance\n-- because we have more that one zero", "meta": {"hexsha": "b33a6ce279d5959c5748a4f0c587a4fa8a7e70c6", "size": 3507, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Rationals.idr", "max_stars_repo_name": "marcosh/idris-rationals", "max_stars_repo_head_hexsha": "eb3a8fca148bd2483bc96be15675c24937a95ffe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-13T18:58:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-13T18:58:44.000Z", "max_issues_repo_path": "src/Rationals.idr", "max_issues_repo_name": "marcosh/idris-rationals", "max_issues_repo_head_hexsha": "eb3a8fca148bd2483bc96be15675c24937a95ffe", "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/Rationals.idr", "max_forks_repo_name": "marcosh/idris-rationals", "max_forks_repo_head_hexsha": "eb3a8fca148bd2483bc96be15675c24937a95ffe", "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.1743119266, "max_line_length": 119, "alphanum_fraction": 0.7382378101, "num_tokens": 1041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6834704080147445}} {"text": "module Main\n\n%default total\n\ndata PowerSource = Petrol | Pedal\n\n{-\n4.2 Defining dependent data types\n---------------------------------\n\nA dependent data type is a *type* computed from a value.\n\nE.g., : Vect : type of Vect depends on its length.\n\ncore idea : because there is no syntactic distinction between types and expressions,\n types can be computed from any expression.\n\nFamilies of types\n-----------------\n\nVehicle : defines two (i.e., \"family\") types in one declaration : Vehicle Pedal and Vehicle Petrol.\nDefining multiple related types at the same time.\nPower source is an index of the Vehicle family.\nThe index tells you exactly which Vehicle type you mean.\n-}\ndata Vehicle : PowerSource -> Type where\n Bicycle : Vehicle Pedal\n Car : (fuel : Nat) -> Vehicle Petrol\n Bus : (fuel : Nat) -> Vehicle Petrol\n\nwheels : Vehicle _ -> Nat\nwheels Bicycle = 2\nwheels (Car fuel) = 4\nwheels (Bus fuel) = 4\n\nrefuel : Vehicle Petrol -> Vehicle Petrol\nrefuel Bicycle impossible\nrefuel (Car fuel) = Car 100\nrefuel (Bus fuel) = Bus 200\n", "meta": {"hexsha": "c8f712ddfe526771037499a1772178b13e027217", "size": 1069, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris/book/2017-Type_Driven_Development_with_Idris/src/P102_dependent_indexed_types_vehicle.idr", "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_issues_repo_path": "idris/book/2017-Type_Driven_Development_with_Idris/src/P102_dependent_indexed_types_vehicle.idr", "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris/book/2017-Type_Driven_Development_with_Idris/src/P102_dependent_indexed_types_vehicle.idr", "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "avg_line_length": 26.725, "max_line_length": 99, "alphanum_fraction": 0.6735266604, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347124, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6832920757931628}} {"text": "-- Example of a recursive type.\ndata MyNat = Z | S MyNat\n\n-- Example of a union type.\n||| Represents shapes.\ndata Shape = ||| A triangle, with its base length and height\n Triangle Double Double\n | ||| A rectangle, with its lengths and height\n Rectangle Double Double\n | ||| A circle, with its radius\n Circle Double\n\narea : Shape -> Double\narea (Triangle base height) = base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\ndata Picture = ||| Uses the Shape type defined as the primitive.\n Primitive Shape\n | ||| Builds a picture by combining two smaller pictures.\n Combine Picture Picture\n | ||| Builds a picture by rotating another picture through an angle.\n Rotate Double Picture\n | ||| Builds a picture by moving to another location.\n Translate Double Double Picture\n\nrectangle : Picture\nrectangle = Primitive (Rectangle 20 10)\n\ncircle : Picture\ncircle = Primitive (Circle 5)\n\ntriangle : Picture\ntriangle = Primitive (Triangle 10 10)\n\ntestPicture : Picture\ntestPicture = Combine (Translate 5 5 rectangle)\n (Combine (Translate 35 5 circle)\n (Translate 15 25 triangle))\n\n%name Shape shape, shape1, shape2\n%name Picture pic, pic1, pic2\n\npictureArea : Picture -> Double\npictureArea (Primitive shape) = area shape\npictureArea (Combine pic1 pic2) = pictureArea pic1 + pictureArea pic2\npictureArea (Rotate x pic) = pictureArea pic\npictureArea (Translate x y pic) = pictureArea pic\n\nmaybeMax : Ord a => Maybe a -> Maybe a -> Maybe a\nmaybeMax Nothing Nothing = Nothing\nmaybeMax Nothing (Just x) = Just x\nmaybeMax (Just x) Nothing = Just x\nmaybeMax (Just x) (Just y) = Just $ max x y\n\nbiggestTriangle : Picture -> Maybe Double\nbiggestTriangle (Primitive tri@(Triangle x y)) = Just $ area tri\nbiggestTriangle (Primitive _) = Nothing\nbiggestTriangle (Combine pic1 pic2) = maybeMax (biggestTriangle pic1) (biggestTriangle pic2)\nbiggestTriangle (Rotate x pic) = biggestTriangle pic\nbiggestTriangle (Translate x y pic) = biggestTriangle pic\n", "meta": {"hexsha": "46c3b1c69b9e91a13a4d509531e85239588b525c", "size": 2157, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter04/Picture.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TypeDrivenDevelopment/Chapter04/Picture.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypeDrivenDevelopment/Chapter04/Picture.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7903225806, "max_line_length": 92, "alphanum_fraction": 0.6866017617, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6832099308437932}} {"text": "module Data.ZZ.ZZModulo\n\nimport Control.Algebra\nimport Classes.Verified\n\nimport Data.ZZ\nimport Control.Algebra.NumericInstances\n\nimport Data.Fin.FinOrdering\nimport Data.Fin.Structural\n\nimport Control.Algebra.ZZDivisors\nimport Data.ZZ.ModuloVerification\n\n\n\n{-\nTable of contents\n\n* Modulo for naturals\n* Lemmas for applying (modNatFnIsRemainder)\n* Derived modulo for ZZ\n-}\n\n\n\n{-\nModulo for naturals\n-}\n\n\n\n||| A manually verifiably total modulo for naturals:\n||| It recurses precisely when\n||| \t( Not (x `LT` m) ) & ( m, x > 0 ).\n||| Not (x `LT` m) -> Either (x = m) (m `LT` x),\n||| in former case ((x `minus` m) `modNat` m) is defined,\n||| & latter case cannot hold indefinitely since\n||| m > 0\n||| ==>\n||| the iterates of (`minus` m) are decreasing.\n%reflection\nmodNatT : Nat -> Nat -> Nat\nmodNatT Z _ = Z\nmodNatT x Z = x\nmodNatT (S predx) (S predm) with (decLT (S predx) (S predm))\n\t| No notlt = ((S predx) `minus` (S predm)) `modNatT` (S predm)\n\t| Yes prlt = S predx\n\n\n\n{-\nLemmas for applying (modNatFnIsRemainder)\n-}\n\n\n\ntotal\nmodNatTIdModZero : (x : Nat) -> x `modNatT` Z = x\nmodNatTIdModZero Z = Refl\nmodNatTIdModZero (S predx) = Refl\n\n-- The LT implies subtracting m is reversible\ntotal\nmodNatTCharizLT :\n\t(x, m : Nat)\n\t-> (x `LT` m)\n\t-> x `modNatT` m = x\nmodNatTCharizLT Z _ _ = Refl\nmodNatTCharizLT x Z ltpr = void $ succNotLTEzero ltpr\nmodNatTCharizLT (S predx) (S predm) ltpr with (decLT (S predx) (S predm))\n\t| No notlt = void $ notlt ltpr\n\t| Yes prlt = Refl\n\ntotal\nmodNatTCharizEq : (m : Nat) -> m `modNatT` m = Z\nmodNatTCharizEq Z = Refl\nmodNatTCharizEq (S predm) with (decLT (S predm) (S predm))\n\t| No notlt = rewrite sym $ minusZeroN predm in Refl\n\t| Yes prlt = void $ notLTSelf prlt\n\ntotal\nmodNatTCharizGTE :\n\t(x, m : Nat)\n\t-> (m `plus` x) `modNatT` m = x `modNatT` m\nmodNatTCharizGTE Z m\n\t= trans (rewrite plusZeroRightNeutral m in Refl)\n\t$ modNatTCharizEq m\nmodNatTCharizGTE x Z = Refl\nmodNatTCharizGTE (S predx) (S predm) with (decLT (S predm `plus` S predx) (S predm))\n\t| No notlt = rewrite natPlusInvertibleL (S predx) predm in Refl\n\t| Yes prlt = void $ notLTSelf $ lteUnsumLeftSummandLeft {y=S predx} prlt\n\ntotal\nmodNatTIsRemainder :\n\t(x, m : Nat)\n\t-> (d : Nat ** (d `mult` m) `plus` (x `modNatT` m) = x)\nmodNatTIsRemainder =\n\tmodNatFnIsRemainder\n\t\tmodNatT\n\t\tmodNatTIdModZero\n\t\tmodNatTCharizLT\n\t\tmodNatTCharizGTE\n\n\n\n{-\n-- Totally superfluous\nmodNatTCharizSucc :\n\t(x, m : Nat)\n\t-> S x `modNatT` m = (S $ x `modNatT` m) `modNatT` m\nmodNatTCharizSucc Z _ = ?modNatTCharizSucc_rhs_1\nmodNatTCharizSucc (S predx) m = ?modNatTCharizSucc_rhs_2\n-}\n\n\n\n{-\nDerived modulo for ZZ\n-}\n\n\n\ntotal\nmodZT : ZZ -> ZZ -> ZZ\nmodZT = modZGenFn modNatT modNatTIsRemainder\n\nquotientPartModZT :\n\t(x, m : ZZ)\n\t-> (x <-> (x `modZT` m)) `quotientOverZZ` m\nquotientPartModZT = modZGenQuot modNatT modNatTIsRemainder\n", "meta": {"hexsha": "de10463b3b583a4e35e65e76851e15e0a4119d77", "size": 2805, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/ZZ/ZZModulo.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/ZZ/ZZModulo.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/ZZ/ZZModulo.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": 21.25, "max_line_length": 84, "alphanum_fraction": 0.6877005348, "num_tokens": 1098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6831572382682017}} {"text": "module Data.Vect.Quantifiers\n\nimport Data.Vect\n\n||| A proof that some element of a vector satisfies some property\n|||\n||| @ p the property to be satsified\npublic export\ndata Any : (0 p : a -> Type) -> Vect n a -> Type where\n ||| A proof that the satisfying element is the first one in the `Vect`\n Here : {0 xs : Vect n a} -> p x -> Any p (x :: xs)\n ||| A proof that the satsifying element is in the tail of the `Vect`\n There : {0 xs : Vect n a} -> Any p xs -> Any p (x :: xs)\n\nexport\nimplementation Uninhabited (Any p Nil) where\n uninhabited (Here _) impossible\n uninhabited (There _) impossible\n\n||| Eliminator for `Any`\npublic export\nanyElim : {0 xs : Vect n a} -> {0 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\n||| Given a decision procedure for a property, determine if an element of a\n||| vector satisfies it.\n|||\n||| @ p the property to be satisfied\n||| @ dec the decision procedure\n||| @ xs the vector to examine\nexport\nany : (dec : (x : a) -> Dec (p x)) -> (xs : Vect n a) -> Dec (Any p xs)\nany _ Nil = No uninhabited\nany p (x::xs) with (p x)\n any p (x::xs) | Yes prf = Yes (Here prf)\n any p (x::xs) | No prf =\n case any p xs of\n Yes prf' => Yes (There prf')\n No prf' => No (anyElim prf' prf)\n\n||| A proof that all elements of a vector satisfy a property. It is a list of\n||| proofs, corresponding element-wise to the `Vect`.\npublic export\ndata All : (0 p : a -> Type) -> Vect n a -> Type where\n Nil : All p Nil\n (::) : {0 xs : Vect n a} -> p x -> All p xs -> All p (x :: xs)\n\n||| If there does not exist an element that satifies the property, then it is\n||| the case that all elements do not satisfy.\nexport\nnegAnyAll : {xs : Vect n a} -> Not (Any p xs) -> All (Not . p) xs\nnegAnyAll {xs=Nil} _ = Nil\nnegAnyAll {xs=(x::xs)} f = (f . Here) :: negAnyAll (f . There)\n\nexport\nnotAllHere : {0 p : a -> Type} -> {xs : Vect n a} -> Not (p x) -> All p (x :: xs) -> Void\nnotAllHere _ Nil impossible\nnotAllHere np (p :: _) = np p\n\nexport\nnotAllThere : {0 p : a -> Type} -> {xs : Vect n a} -> Not (All p xs) -> All p (x :: xs) -> Void\nnotAllThere _ Nil impossible\nnotAllThere np (_ :: ps) = np ps\n\n||| Given a decision procedure for a property, decide whether all elements of\n||| a vector satisfy it.\n|||\n||| @ p the property\n||| @ dec the decision procedure\n||| @ xs the vector to examine\nexport\nall : (dec : (x : a) -> Dec (p x)) -> (xs : Vect n a) -> Dec (All p xs)\nall _ Nil = Yes Nil\nall d (x::xs) with (d x)\n all d (x::xs) | No prf = No (notAllHere prf)\n all d (x::xs) | Yes prf =\n case all d xs of\n Yes prf' => Yes (prf :: prf')\n No prf' => No (notAllThere prf')\n", "meta": {"hexsha": "ca400d291f31d5a86774436c89a4c684ff40befa", "size": 2692, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/Vect/Quantifiers.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/libs/base/Data/Vect/Quantifiers.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/libs/base/Data/Vect/Quantifiers.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": 33.2345679012, "max_line_length": 105, "alphanum_fraction": 0.6040118871, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.6831501193888441}} {"text": "\nmodule Andb3\n\nandb3 : (a : Bool) -> (b : Bool) -> (c : Bool) -> Bool\nandb3 True True True = True\nandb3 a b c = False\n\n\ntabt1 : (andb3 True True True) = True\ntabt1 = Refl\n\ntabt2 : (andb3 False True True) = False\ntabt2 = Refl\n\ntabt3 : (andb3 True False True) = False\ntabt3 = Refl\n\ntabt4 : (andb3 True True False) = False\ntabt4 = Refl\n\ntabt5 : (andb3 True False False) = False\ntabt5 = Refl\n\ntabt6 : (andb3 False True False) = False\ntabt6 = Refl\n\ntabt7 : (andb3 False False True) = False\ntabt7 = Refl\n\ntabt8 : (andb3 False False False) = False\ntabt8 = Refl\n\ntabt9 : (andb3 False True True) = False\ntabt9 = Refl\n\n\n", "meta": {"hexsha": "24d233ded58d22c717e057e3f91be9194a7f7bdc", "size": 610, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Answers/Chapter_2/andb3.idr", "max_stars_repo_name": "robkorn/idris-software-foundations-problems", "max_stars_repo_head_hexsha": "bd5b10c9c361ac8feea29f41745f4bb386c3b06d", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Answers/Chapter_2/andb3.idr", "max_issues_repo_name": "robkorn/idris-software-foundations-problems", "max_issues_repo_head_hexsha": "bd5b10c9c361ac8feea29f41745f4bb386c3b06d", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Answers/Chapter_2/andb3.idr", "max_forks_repo_name": "robkorn/idris-software-foundations-problems", "max_forks_repo_head_hexsha": "bd5b10c9c361ac8feea29f41745f4bb386c3b06d", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.4864864865, "max_line_length": 54, "alphanum_fraction": 0.6639344262, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.68253724883016}} {"text": "module Quantities.Core\n\nimport public Quantities.FreeAbelianGroup\nimport public Quantities.Power\n\n%default total\n%access public export\n\n||| Elementary quantities\nrecord Dimension where\n constructor MkDimension\n name : String\n\nimplementation Eq Dimension where\n (MkDimension a) == (MkDimension b) = a == b\n\nimplementation Ord Dimension where\n compare (MkDimension a) (MkDimension b) = compare a b\n\n\n-- Compound quantities\n\n||| A quantity is a property that can be measured.\nQuantity : Type\nQuantity = FreeAbGrp Dimension\n\n||| The trivial quantity\nScalar : Quantity\nScalar = unit\n\n||| Create a new quantity.\nmkQuantity : List (Dimension, Integer) -> Quantity\nmkQuantity = mkFreeAbGrp\n\ninfixl 6 \n\n-- Synonyms (quantites are multiplied, not added!)\n||| Product quantity\n(<*>) : Ord a => FreeAbGrp a -> FreeAbGrp a -> FreeAbGrp a\n(<*>) = (<<+>>)\n\n||| Quotient quantity\n() : Ord a => FreeAbGrp a -> FreeAbGrp a -> FreeAbGrp a\na b = a <*> freeAbGrpInverse b\n\n||| Convert dimensions to quantities\nimplicit\ndimensionToQuantity : Dimension -> Quantity\ndimensionToQuantity = inject\n\n\n||| Elementary Unit\nrecord ElemUnit (q : Quantity) where\n constructor MkElemUnit\n name : String\n conversionRate : Double\n\n-- ElemUnit with its quantity hidden\ndata SomeElemUnit : Type where\n MkSomeElemUnit : (q : Quantity) -> ElemUnit q -> SomeElemUnit\n\nquantity : SomeElemUnit -> Quantity\nquantity (MkSomeElemUnit q _) = q\n\nelemUnit : (seu : SomeElemUnit) -> ElemUnit (quantity seu)\nelemUnit (MkSomeElemUnit _ u) = u\n\nname : SomeElemUnit -> String\nname x = name (elemUnit x)\n\nimplementation Eq SomeElemUnit where\n a == b = quantity a == quantity b && name a == name b\n\nimplementation Ord SomeElemUnit where\n compare a b with (compare (quantity a) (quantity b))\n | LT = LT\n | GT = GT\n | EQ = compare (name a) (name b)\n\nimplicit\nelemUnitToSomeElemUnitFreeAbGrp : ElemUnit q -> FreeAbGrp SomeElemUnit\nelemUnitToSomeElemUnitFreeAbGrp {q} u = inject (MkSomeElemUnit q u)\n\nconversionRate : SomeElemUnit -> Double\nconversionRate u = conversionRate (elemUnit u)\n\njoinedQuantity : FreeAbGrp SomeElemUnit -> Quantity\njoinedQuantity = lift quantity\n\ndata Unit : Quantity -> Type where\n MkUnit : (exponent : Integer) -> (elemUnits : FreeAbGrp SomeElemUnit) ->\n Unit (joinedQuantity elemUnits)\n\nrewriteUnit : r = q -> Unit q -> Unit r\nrewriteUnit eq unit = rewrite eq in unit\n\nbase10Exponent : Unit q -> Integer\nbase10Exponent (MkUnit e _) = e\n\nsomeElemUnitFreeAbGrp : Unit q -> FreeAbGrp SomeElemUnit\nsomeElemUnitFreeAbGrp (MkUnit _ us) = us\n\nimplementation Eq (Unit q) where\n x == y = base10Exponent x == base10Exponent y &&\n someElemUnitFreeAbGrp x == someElemUnitFreeAbGrp y\n\n||| The trivial unit\nOne : Unit Scalar\nOne = MkUnit 0 neutral\n\n||| Multiples of ten\nTen : Unit Scalar\nTen = MkUnit 1 neutral\n\n||| One hundredth\nPercent : Unit Scalar\nPercent = MkUnit (-2) neutral\n\n||| One thousandth\nPromille : Unit Scalar\nPromille = MkUnit (-3) neutral\n\n||| The trivial unit (synonymous with `one`)\nUnitLess : Unit Scalar\nUnitLess = One\n\nimplicit\nelemUnitToUnit : {q : Quantity} -> ElemUnit q -> Unit q\nelemUnitToUnit {q} u = rewriteUnit eq (MkUnit 0 (inject (MkSomeElemUnit q u)))\n where eq = sym (inject_lift_lem quantity (MkSomeElemUnit q u))\n\n||| Compute conversion factor from the given unit to the base unit of the\n||| corresponding quantity.\njoinedConversionRate : Unit q -> Double\njoinedConversionRate (MkUnit e (MkFreeAbGrp us)) = fromUnits * fromExponent\n where fromUnits = product $ map (\\(u, i) => ((^) @{floatmultpower}) (conversionRate u) i) us\n fromExponent = ((^) @{floatmultpower}) 10 e\n\n||| Constructs a new unit given a name and conversion factor from an existing unit.\ndefineAsMultipleOf : String -> Double -> Unit q -> ElemUnit q\ndefineAsMultipleOf name factor unit = MkElemUnit name (factor * joinedConversionRate unit)\n\n-- Syntax sugar for defining new units\nsyntax \"< one\" [name] equals [factor] [unit] \">\" = defineAsMultipleOf name factor unit\n\nimplementation Show (Unit q) where\n show (MkUnit 0 (MkFreeAbGrp [])) = \"unitLess\"\n show (MkUnit e (MkFreeAbGrp [])) = \"ten ^^ \" ++ show e\n show (MkUnit e (MkFreeAbGrp (u :: us))) = if e == 0 then fromUnits\n else \"ten ^^ \" ++ show e ++ \" <**> \" ++ fromUnits\n where monom : (SomeElemUnit, Integer) -> String\n monom (unit, 1) = name unit\n monom (unit, i) = name unit ++ \" ^^ \" ++ show i\n fromUnits = monom u ++ concatMap ((\" <**> \" ++) . monom) us\n\n||| Pretty-print a unit (using only ASCII characters)\nshowUnit : Unit q -> String\nshowUnit (MkUnit 0 (MkFreeAbGrp [])) = \"\"\nshowUnit (MkUnit e (MkFreeAbGrp [])) = \"10^\" ++ show e\nshowUnit (MkUnit e (MkFreeAbGrp (u :: us))) = if e == 0 then fromUnits\n else \"10^\" ++ show e ++ \" \" ++ fromUnits\n where monom : (SomeElemUnit, Integer) -> String\n monom (unit, 1) = name unit\n monom (unit, i) = name unit ++ \"^\" ++ show i\n fromUnits = monom u ++ concatMap ((\" \" ++) . monom) us\n\ntoSuperScript : Char -> Char\ntoSuperScript '1' = '¹'\ntoSuperScript '2' = '²'\ntoSuperScript '3' = '³'\ntoSuperScript '4' = '⁴'\ntoSuperScript '5' = '⁵'\ntoSuperScript '6' = '⁶'\ntoSuperScript '7' = '⁷'\ntoSuperScript '8' = '⁸'\ntoSuperScript '9' = '⁹'\ntoSuperScript '0' = '⁰'\ntoSuperScript '-' = '⁻'\ntoSuperScript x = x\n\ntoSuper : String -> String\ntoSuper = pack . map toSuperScript . unpack\n\n||| Pretty-print a unit\nshowUnitUnicode : Unit q -> String\nshowUnitUnicode (MkUnit 0 (MkFreeAbGrp [])) = \"\"\nshowUnitUnicode (MkUnit e (MkFreeAbGrp [])) = \"10\" ++ toSuper (show e)\nshowUnitUnicode (MkUnit e (MkFreeAbGrp (u :: us))) = if e == 0 then fromUnits\n else \"10\" ++ toSuper (show e) ++ \" \" ++ fromUnits\n where monom : (SomeElemUnit, Integer) -> String\n monom (unit, 1) = name unit\n monom (unit, i) = name unit ++ toSuper (show i)\n fromUnits = monom u ++ concatMap ((\" \" ++) . monom) us\n\ninfixr 10 ^^\n||| Power unit\n(^^) : Unit q -> (i : Integer) -> Unit (q ^ i)\n(^^) (MkUnit e us) i = rewriteUnit eq (MkUnit (i*e) (us ^ i))\n where eq = sym (lift_power_lem quantity us i)\n\n||| Inverse unit (e.g. the inverse of `second` is `one second` a.k.a. `hertz`)\nunitInverse : {q : Quantity} -> Unit q -> Unit (freeAbGrpInverse q)\nunitInverse {q} u = rewrite (freeabgrppower_correct q (-1))\n in u ^^ (-1)\n\ninfixl 6 <**>,\n\n||| Product unit\n(<**>) : Unit r -> Unit s -> Unit (r <*> s)\n(<**>) (MkUnit e rs) (MkUnit f ss) = rewriteUnit eq (MkUnit (e+f) (rs <*> ss))\n where eq = sym (lift_mult_lem quantity rs ss)\n\n||| Quotient unit\n() : Unit r -> Unit s -> Unit (r s)\n() a b = a <**> unitInverse b\n\ninfixl 5 =| -- sensible?\n||| Numbers tagged with a unit\ndata Measurement : {q : Quantity} -> Unit q -> Type -> Type where\n (=|) : a -> (u : Unit q) -> Measurement u a\n\n||| Extract the number\ngetValue : {q : Quantity} -> {u : Unit q} ->\n Measurement {q} u a -> a\ngetValue (x =| _) = x\n\nimplementation Functor (Measurement {q} u) where\n map f (x =| _) = f x =| u\n\nimplementation Eq a => Eq (Measurement {q} u a) where\n (x =| _) == (y =| _) = x == y\n\nimplementation Ord a => Ord (Measurement {q} u a) where\n compare (x =| _) (y =| _) = compare x y\n\nimplementation Show a => Show (Measurement {q} u a) where\n show (x =| _) = show x ++ \" =| \" ++ show u\n\nimplementation Num a => Semigroup (Measurement {q} u a) where\n (x =| _) <+> (y =| _) = (x + y) =| u\n\nimplementation Num a => Monoid (Measurement {q} u a) where\n neutral = fromInteger 0 =| u\n\nimplementation (Neg a, Num a) => Group (Measurement {q} u a) where\n inverse (x =| _) = (-x) =| u\n\nimplementation (Neg a, Num a) => AbelianGroup (Measurement {q} u a) where\n\n||| Pretty-print a measurement (using only ASCII characters)\nshowMeasurement : Show a => {q : Quantity} -> {u : Unit q} ->\n (Measurement u a) -> String\nshowMeasurement (x =| u) =\n show x ++ (if base10Exponent u == 0 then \" \" else \"*\") ++ showUnit u\n\n||| Pretty-print a measurement (using only ASCII characters)\nshowMeasurementUnicode : Show a => {q : Quantity} -> {u : Unit q} ->\n (Measurement u a) -> String\nshowMeasurementUnicode (x =| u) =\n show x ++ (if base10Exponent u == 0 then \" \" else \"·\") ++ showUnit u\n\ninfixl 5 :|\n\n||| Type synonym for `Measurement`\n(:|) : Unit q -> Type -> Type\n(:|) = Measurement\n\n||| Flatten nested measurements\njoinUnits : {q : Quantity} -> {r : Quantity} -> {u : Unit q} -> {v : Unit r} ->\n (u :| (v :| a)) -> (u <**> v) :| a\njoinUnits ((x =| v) =| u) = x =| (u <**> v)\n\n\n||| Double with a unit\nF : Unit q -> Type\nF u = Measurement u Double\n\n\ninfixl 9 |*|,|/|\n\n||| Product measurement\n(|*|) : Num a => {q : Quantity} -> {r : Quantity} -> {u : Unit q} -> {v : Unit r} ->\n u :| a -> v :| a -> (u <**> v) :| a\n(|*|) (x =| u) (y =| v) = (x*y) =| (u <**> v)\n\n||| Quotient measurement (the second measurement mustn't be zero!)\n(|/|) : {q : Quantity} -> {r : Quantity} -> {u : Unit q} -> {v : Unit r} ->\n F u -> F v -> F (u v)\n(|/|) (x =| u) (y =| v) = (x/y) =| (u v)\n\ninfixl 10 |^|\n\n||| Power measurement\n(|^|) : {q : Quantity} -> {u : Unit q} -> F u -> (i : Integer) -> F (u ^^ i)\n(|^|) (x =| u) i = (((^) @{floatmultpower}) x i) =| u ^^ i\n\n||| Square root measurement\nsqrt : {q : Quantity} -> {u : Unit q} -> F (u ^^ 2) -> F u\nsqrt {q} {u} (x =| _) = (sqrt x) =| u\n\n||| Round measurement to the next integer below\nfloor : {q : Quantity} -> {u : Unit q} -> F u -> F u\nfloor = map floor\n\n||| Round measurement to the next integer above\nceiling : {q : Quantity} -> {u : Unit q} -> F u -> F u\nceiling = map ceiling\n\n||| Convert measurements to a given unit\nconvertTo : {from : Unit q} -> (to : Unit q) -> F from -> F to\nconvertTo to (x =| from) = (x * (rateFrom / rateTo)) =| to\n where rateFrom = joinedConversionRate from\n rateTo = joinedConversionRate to\n\n||| Flipped version of `convertTo`\nas : {from : Unit q} -> F from -> (to : Unit q) -> F to\nas x u = convertTo u x\n\n||| Convert with implicit target unit\nconvert : {from : Unit q} -> {to : Unit q} -> F from -> F to\nconvert {to=to} x = convertTo to x\n\n||| Promote values to measurements of the trivial quantity\nimplicit\ntoUnitLess : a -> Measurement unitLess a\ntoUnitLess x = x =| unitLess\n\nimplementation Num a => Num (Measurement unitLess a) where\n x + y = (getValue x + getValue y) =| unitLess\n x * y = (getValue x * getValue y) =| unitLess\n fromInteger i = fromInteger i =| unitLess\n\nimplementation Neg a => Neg (Measurement unitLess a) where\n negate x = negate (getValue x) =| unitLess\n x - y = (getValue x - getValue y) =| unitLess\n\nimplementation Abs a => Abs (Measurement unitLess a) where\n abs x = abs (getValue x) =| unitLess\n", "meta": {"hexsha": "3897eb6250bae6f9a986787828be9c4e298a9ed7", "size": 10652, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Quantities/Core.idr", "max_stars_repo_name": "timjb/quantities", "max_stars_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 112, "max_stars_repo_stars_event_min_datetime": "2015-01-18T13:52:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T14:15:46.000Z", "max_issues_repo_path": "Quantities/Core.idr", "max_issues_repo_name": "timjb/quantities", "max_issues_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-04T08:51:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-17T09:52:29.000Z", "max_forks_repo_path": "Quantities/Core.idr", "max_forks_repo_name": "timjb/quantities", "max_forks_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-04-28T23:49:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T17:28:34.000Z", "avg_line_length": 31.4218289086, "max_line_length": 97, "alphanum_fraction": 0.6295531356, "num_tokens": 3412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6825372454030357}} {"text": "> module CoinductiveCalculus.CoinductiveCalculus\n\n> import Syntax.PreorderReasoning\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n> %hide Stream\n> %hide head\n> %hide tail\n> %hide (+)\n> %hide plusZeroRightNeutral\n\n\n* Streams\n\nFor a type |T|, streams of values of type |T| can be described by values\nof type |Stream T| with\n\n> Stream : Type -> Type\n\nThe idea is that any |Stream T| has a head and a tail\n\n> head : {T : Type} -> Stream T -> T\n> tail : {T : Type} -> Stream T -> Stream T\n\nand that piecing together a |T| with a |Stream T| yields a |Stream T|:\n\n> cons : {T : Type} -> T -> Stream T -> Stream T\n\nThe stream operations |head|, |tail| and |cons| are required to fulfil\nthree properties:\n\n> headConsProp : {T : Type} -> (t : T) -> (s : Stream T) -> head (cons t s) = t \n\n> tailConsProp : {T : Type} -> (t : T) -> (s : Stream T) -> tail (cons t s) = s\n\n> consHeadTailProp : {T : Type} -> (s : Stream T) -> cons (head s) (tail s) = s \n\n\n* Differentiation and integration\n\nWe want to look at differentiation and integration of functions of real\nvariables from the point of view of streams. More specifically, we want\nto understand which properties differentiation and integration have to\nfulfill when we consider these operations as operations on streams of\ntype |Stream R = R -> R|. Here\n\n> R : Type\n\nis meant to represent real numbers and\n\n> F : Type\n> F = R -> R\n\nare differentiable and integrable functions on |R|. For the time being,\nwe represent differentiation and integration through functions\n\n> D : F -> F\n> S : R -> R -> F -> R\n\nwith |D f| and |S a b f| representing the derivative of |f| and the\nintegral of |f| on |[a,b]|. \n\n\n* Head, tail and cons for functions/streams\n\nHow can we implement |head| for |Stream R = F|? We have\n\n> headF : F -> R\n\nThe natural way to compute a real number from a |f : F| is to simply\nevaluate |f|. We require our \"real numbers\" to contain a zero element\n\n> zero : R\n\nand we define\n\n> headF f = f zero\n\nWhat about the tail of a function |f|?\n\n> tailF : F -> F\n\nThe type of |tailF| is |F -> F|, just like the type of |D|. Thus, we\ntake\n\n> tailF = D\n\nWe are left with the implementation of |consF|:\n\n> consF : R -> F -> F\n\nOf course, we want |headF|, |tailF| and |consF| to fulfill the\nproperties of stream operations. In particular, we want\n\n< consF (headF f) (tailF f) = f\n\nFor |f = consF a g| and our definitions of |headF| and |tailF|, this is\nequivalent to\n\n< consF (headF f) (tailF f) = f\n<\n< ={ def. of f }=\n<\n< consF (headF (consF a g)) (tailF (consF a g)) = consF a g\n<\n< ={ def. of consF, tailF }=\n<\n< consF ((consF a g) zero) (D (consF a g)) = consF a g\n\nSufficient conditions for the last equality to hold are\n\n< (consF a g) zero = a \n\nand \n\n< D (consF a g) = g\n\nThe first condition could be fulfilled by defining |consF a g| to be\n|const a|. But the second condition requires |consF a g| has to be an\nanti-derivative of |g|. This suggests the definition\n\n> (+) : R -> R -> R\n\n> consF a f = \\ x => a + S zero x f\n\nwhere we can think of |(+)| as representing the standard addition on\nreal numbers.\n\n\n* Properties of |R|, |D| and |S|\n\nWhich properties do |R|, |D| and |S| have to satisfy for |headF|,\n|tailF| and |consF| to be stream operations? Our definition already\nrequires |R| to be equipped with a zero element and with a |(+)|:\n\n< R : Type\n< zero : R\n< (+) : R -> R -> R\n\nIf we also require integration to fulfill\n\n> intProp1 : (a : R) -> (f : F) -> S a a f = zero\n\nand |zero| to be a\n\n> plusZeroRightNeutral : (left : R) -> left + zero = left \n\nWe can derive a formal proof of |headF (consF a f) = a|:\n\n> headConsPropF : (a : R) -> (f : F) -> headF (consF a f) = a \n> headConsPropF a f = ( headF (consF a f) )\n> ={ Refl }=\n> ( headF (\\ x => a + S zero x f) )\n> ={ Refl }=\n> ( a + S zero zero f )\n> ={ cong (intProp1 zero f) }= \n> ( a + zero )\n> ={ plusZeroRightNeutral a }=\n> ( a )\n> QED\n\nSatisfying |tailF (consF a f) = f| requires some more assumptions.\nConsistently with the interpretation of |D f| representing the\nderivative of |f|, we need\n\n> derConstZero : (a : R) -> D (const a) = const zero\n\nand\n\n> derLinear1 : (f, g : F) -> D (\\ x => f x + g x) = \\ x => (D f) x + (D g) x\n\nMoreover |S| has to be an \"anti-derivative\"\n\n> intAntiDer : (f : F) -> D (\\ x => S zero x f) = f\n\nWe also need |zero| to be left-neutral\n\n> plusZeroLeftNeutral : (right : R) -> zero + right = right \n\nand equality on |F| to be extensional:\n\n> extEqF : (f, g : F) -> ((x : R) -> f x = g x) -> f = g\n\nWith these assumptions, we can derive\n\n> lemma : (f : F) -> (x : R) -> zero + f x = f x\n> lemma f x = ( zero + f x )\n> ={ plusZeroLeftNeutral (f x) }=\n> ( f x )\n> QED\n\nand, finally\n\n> tailConsPropF : (a : R) -> (f : F) -> tailF (consF a f) = f \n> tailConsPropF a f = ( tailF (consF a f) )\n> ={ Refl }=\n> ( tailF (\\ x => a + S zero x f) )\n> ={ Refl }=\n> ( D (\\ x => a + S zero x f) ) \n> ={ Refl }=\n> ( D (\\ x => (const a) x + (\\ y => S zero y f) x) ) \n> ={ derLinear1 (const a) (\\ y => S zero y f) }=\n> ( \\ x => (D (const a)) x + (D (\\ y => S zero y f)) x ) \n> ={ cong {f = \\ h => \\ x => h x + (D (\\ y => S zero y f)) x } (derConstZero a) }=\n> ( \\ x => (const zero) x + (D (\\ y => S zero y f)) x )\n> ={ cong {f = \\ h => \\ x => (const zero) x + h x} (intAntiDer f) }=\n> ( \\ x => (const zero) x + f x )\n> ={ Refl }=\n> ( \\ x => zero + f x )\n> ={ extEqF (\\ x => zero + f x) (\\ x => f x) (lemma f) }=\n> ( \\ x => f x )\n> ={ Refl }= \n> ( f )\n> QED\n\nWe are left with the last property: |consF (headF f) (tailF f) = f|. To\nprove this property, we need three more assumptions\n\n> (-) : R -> R -> R\n\n> plusAnyMinus : (x, y : R) -> x + (y - x) = y\n\n> derAntiInt : (f : F) -> (a : R) -> (b : R) -> S a b (D f) = f b - f a\n\nWith these, one has\n\n> lemma1 : (c : R) -> (f : F) -> (x : R) -> (c + (f x - c) = f x)\n> lemma1 c f x = plusAnyMinus c (f x)\n\n> lemma2 : (f : F) -> (c : R) -> (a : R) -> (b : R) -> c + S a b (D f) = c + (f b - f a)\n> lemma2 f c a b = ( c + S a b (D f) )\n> ={ cong (derAntiInt f a b) }=\n> ( c + (f b - f a) )\n> QED\n\n> consHeadTailPropF : (f : F) -> consF (headF f) (tailF f) = f \n> consHeadTailPropF f = ( consF (headF f) (tailF f) )\n> ={ Refl }=\n> ( consF (f zero) (D f) )\n> ={ Refl }=\n> ( \\ x => f zero + S zero x (D f) )\n> ={ extEqF (\\ x => f zero + S zero x (D f))\n> (\\ x => f zero + (f x - f zero))\n> (lemma2 f (f zero) zero) }=\n> ( \\ x => f zero + (f x - f zero) )\n> ={ extEqF (\\ x => f zero + (f x - f zero)) \n> (\\ x => f x) \n> (lemma1 (f zero) f) }=\n> ( \\ x => f x ) \n> ={ Refl }=\n> ( f )\n> QED\n\n\n* Properties of |R|, |D| and |S| (wrap up)\n\n ( 1) R : Type\n ( 2) zero : R\n ( 3) (+) : R -> R -> R\n ( 4) (-) : R -> R -> R\n ( 5) plusAnyMinus : (x, y : R) -> x + (y - x) = y\n ( 6) plusZeroLeftNeutral : (right : R) -> zero + right = right \n ( 7) plusZeroRightNeutral : ( left : R) -> left + zero = left \n\n ( 8) derConstZero : (a : R) -> D (const a) = const zero\n ( 9) derLinear1 : (f, g : F) -> D (\\ x => f x + g x) = \\ x => (D f) x + (D g) x\n\n (10) intProp1 : (a : R) -> (f : F) -> S a a f = zero\n (11) intAntiDer : (f : F) -> D (\\ x => S zero x f) = f\n (12) derAntiInt : (f : F) -> (a : R) -> (b : R) -> S a b (D f) = f b - f a\n\n (13) extEqF : (f, g : F) -> ((x : R) -> f x = g x) -> f = g\n\n\nProperties (1-7) follow from standard axioms on real numbers. (8-9)\nfollow from the standard definition of derivative. (10-12) follows from ?\n \n \n\n> {-\n\n> ---}\n \n", "meta": {"hexsha": "75fe9833729b9c8f55789187548b85fe424b1353", "size": 8327, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "CoinductiveCalculus/CoinductiveCalculus.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": "CoinductiveCalculus/CoinductiveCalculus.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": "CoinductiveCalculus/CoinductiveCalculus.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.0139372822, "max_line_length": 100, "alphanum_fraction": 0.4924942957, "num_tokens": 2748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6823315053956158}} {"text": "module Addition.Lemmas.Carry\n\nimport Common.Util\nimport Specifications.DiscreteOrderedGroup\nimport Proofs.GroupCancelationLemmas\nimport Proofs.GroupCancelMisc\nimport Proofs.GroupTheory\nimport Proofs.TranslationInvarianceTheory\nimport Proofs.Interval\n\n%default total\n%access export\n\n||| Adhoc lemma.\n||| Start with `computeCarry` to understand where it fits.\nshiftToLeft : {(+) : Binop s} ->\n PartiallyOrderedGroupSpec (+) _ neg leq ->\n (u,a,x : s) ->\n Between leq (neg (u + u), neg u) x ->\n Between leq (a + neg u, a) (a + u + x)\nshiftToLeft spec u a x given = rewriteBetween o2 o3 o1 where\n o1 : Between leq (a + u + neg (u + u), a + u + neg u) (a + u + x)\n o1 = translateIntervalL (invariantOrder spec) (a + u) given\n o2 : a + u + neg (u + u) = a + neg u\n o2 = groupCancelMisc2 (group spec) a u _\n o3 : a + u + neg u = a\n o3 = groupCancel3bis (group spec) a u\n\n||| Adhoc lemma.\n||| Start with `computeCarry` to understand where it fits.\nshiftLeftToSymRange : {(+) : Binop s} ->\n PartiallyOrderedGroupSpec (+) _ neg leq ->\n (u,a,x : s) ->\n leq a (u + neg a) ->\n Between leq (neg (u + u), neg u) x ->\n InSymRange leq neg (u + neg a) (a + u + x)\nshiftLeftToSymRange {s} spec u a x bound given = o4 where\n sx : s\n sx = a + u + x\n o1 : Between leq (a + neg u, a) sx\n o1 = shiftToLeft spec u a x given\n o2 : Between leq (a + neg u, u + neg a) sx\n o2 = weakenR (order spec) bound o1\n o3 : neg (u + neg a) = a + neg u\n o3 = groupInverseAntiInverse (group spec) u a\n o4 : Between leq (neg (u + neg a), u + neg a) sx\n o4 = rewriteBetween (sym o3) Refl o2\n\n||| Adhoc lemma.\n||| Start with `computeCarry` to understand where it fits.\n||| Derived from `shiftLeftToSymRange` using symmetry.\nshiftRightToSymRange : {(+) : Binop s} ->\n PartiallyOrderedGroupSpec (+) _ neg leq ->\n (u,a,x : s) ->\n leq a (u + neg a) ->\n Between leq (u, u + u) x ->\n InSymRange leq neg (u + neg a) (x + neg (a + u))\nshiftRightToSymRange spec u a x bound given = rewrite sym o2 in o1 where\n o1 : InSymRange leq neg (u + neg a) (neg (a + u + neg x))\n o1 = invertSymRange spec $\n shiftLeftToSymRange spec u a (neg x) bound $\n invertBetween spec given\n o2 : neg (a + u + neg x) = x + neg (a + u)\n o2 = groupInverseAntiInverse (group spec) (a + u) x\n\n||| Lemma: turn an interval into a proper SymRange.\ntoSymRange : {(+) : Binop s} ->\n PartiallyOrderedGroupSpec (+) _ neg leq ->\n isAbelian (+) ->\n Between leq (a + neg b, neg a + b) x ->\n InSymRange leq neg (b + neg a) x\ntoSymRange spec abel =\n rewriteBetween (sym $ groupInverseAntiInverse (group spec) _ _) (abel _ _)\n", "meta": {"hexsha": "f076b6f952cbb8141d60f8259a008cbd4d8b6d2e", "size": 2609, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Addition/CarryLemmas.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/CarryLemmas.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/CarryLemmas.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": 35.2567567568, "max_line_length": 76, "alphanum_fraction": 0.6351092373, "num_tokens": 897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6822971340832629}} {"text": "module Elem\n\ndata Elem : a -> List a -> Type where\n Here : Elem x (x :: xs)\n There : Elem x xs -> Elem x (y :: xs)\n\nelem_test : Elem 2 [1..4]\nelem_test = There Here\n\nisElem : DecEq a => (x : a) -> (xs : List a) -> Maybe (Elem x xs)\nisElem x [] = Nothing \nisElem x (y :: xs) = case decEq x y of\n Yes Refl => Just Here\n No contra => do p <- isElem x xs\n Just (There p)\n\n", "meta": {"hexsha": "b5192a051631093825a7fbae5c51e101da8af762", "size": 467, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Intro/Elem.idr", "max_stars_repo_name": "idris-hackers/idris-demos", "max_stars_repo_head_hexsha": "356a5aa1dbd43f869b0eebd8b8fec15f790cc0dc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 132, "max_stars_repo_stars_event_min_datetime": "2016-01-25T22:35:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T17:23:06.000Z", "max_issues_repo_path": "Intro/Elem.idr", "max_issues_repo_name": "idris-hackers/idris-demos", "max_issues_repo_head_hexsha": "356a5aa1dbd43f869b0eebd8b8fec15f790cc0dc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-05-18T03:40:01.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-07T12:21:55.000Z", "max_forks_repo_path": "Intro/Elem.idr", "max_forks_repo_name": "idris-hackers/idris-demos", "max_forks_repo_head_hexsha": "356a5aa1dbd43f869b0eebd8b8fec15f790cc0dc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-10-25T07:58:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-08T19:22:51.000Z", "avg_line_length": 27.4705882353, "max_line_length": 65, "alphanum_fraction": 0.4582441113, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6822664504211903}} {"text": "{- Example (modified) by Chris Done,\n - from: https://gist.github.com/chrisdone/672efcd784528b7d0b7e17ad9c115292\n\n - This files gives an example of a dependently typed printf function. printf\n - takes a format string as its first argument, for example:\n \"This is a format string with an int %d and a string %s.\"\n - Our printf has the following type:\n printf : (s : String) -> interpFormat ( formatString s )\n - Here, the type of the expression `printf s` for a format string `s` is calculated\n - from the value of the format string. `interpFormat ( formatString s)` is a function\n - whose number of arguments and their types are determined by the format string's\n - value. Thus, a compiler error is thrown if the wrong arguments are passed\n - for a given format string. -}\n\n%default total -- turns on totality checking for all functions\n\n{- Idris can try and check that functions are total, i.e. that they terminate.\n - This is too hard a problem in general, but Idris can check totality for the\n - specific class of recursive functions which shrink toward a base case on\n - every call. -}\n\n-- Formatting AST.\ndata Format\n = FInt Format\n | FString Format\n | FOther Char Format\n | FEnd\n\n-- Parse the format string (list of characters) into an AST.\n-- Example: \"%d,%s\" → (FInt (FOther ',' (FString FEnd)))\nformat : List Char -> Format\nformat ('%' :: 'd' :: cs ) = FInt ( format cs )\nformat ('%' :: 's' :: cs ) = FString ( format cs )\nformat ( c :: cs ) = FOther c ( format cs )\nformat [] = FEnd\n\n-- Convenience function to unpack a string into a list of chars, then\n-- run format on it. Note that in Idris strings are not lists of characters.\nformatString : String -> Format\nformatString s = format ( unpack s )\n\n-- Convert a format AST into a type.\n-- Example: FInt (FOther ',' (FString FEnd)) → Int -> String -> String\ninterpFormat : Format -> Type\ninterpFormat (FInt f) = Int -> interpFormat f\ninterpFormat (FString f) = String -> interpFormat f\ninterpFormat (FOther _ f) = interpFormat f\ninterpFormat FEnd = String\n\n-- Dependently-typed part: turn a formatting AST into a well-typed\n-- function accepting n arguments.\n-- Example:\n-- toFunction (FInt (FString FEnd))\n-- →\n-- \\a i s => a ++ (show i) ++ s\n{-\n-}\ntoFunction : (fmt : Format) -> String -> interpFormat fmt\ntoFunction ( FInt f ) a = \\i => toFunction f ( a ++ show i )\ntoFunction ( FString f ) a = \\s => toFunction f ( a ++ s )\ntoFunction ( FOther c f ) a = toFunction f ( a ++ pack [c])\ntoFunction FEnd a = a\n\n-- Dependently-typed part: turn a formatting string into a well-typed\n-- function accepting n arguments.\n-- Example: printf \"%d%s\" → \\i s => (show i) ++ s\nprintf : (s : String) -> interpFormat ( formatString s )\nprintf s = toFunction ( formatString s ) \"\"\n\n{- Now we can see printf in action. The following typechecks: -}\n\noutput : String\noutput = printf \"My name is %s, and I am %d years old\" \"Isaac\" 22\n\n{- The following does not: -}\n\noutputBad : String\noutputBad = printf \"My name is %s, and I am %d years old\" 22 \"Isaac\"\n\n{- Indeed, the compiler error is:\n\n Mismatch between: String and Int\n\n -}\n", "meta": {"hexsha": "2b4b1b63d127dfcbbe8c507e829f1e847e0e490d", "size": 3159, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Lecture20/4_Printf.idr", "max_stars_repo_name": "ischeinfeld/cs43-lectures", "max_stars_repo_head_hexsha": "24be3bf03995bf60eb1ff8413177cdcdc3cf2058", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-01-15T07:45:56.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-16T15:38:21.000Z", "max_issues_repo_path": "src/Lecture20/4_Printf.idr", "max_issues_repo_name": "ischeinfeld/cs43-lectures", "max_issues_repo_head_hexsha": "24be3bf03995bf60eb1ff8413177cdcdc3cf2058", "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/Lecture20/4_Printf.idr", "max_forks_repo_name": "ischeinfeld/cs43-lectures", "max_forks_repo_head_hexsha": "24be3bf03995bf60eb1ff8413177cdcdc3cf2058", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1647058824, "max_line_length": 86, "alphanum_fraction": 0.6714150047, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6822268084746177}} {"text": "> module Rel.TotalPreorder\n\n> -- import Rel.Preorder\n\n> %default total\n\n> %access public export\n\n\n> ||| TotalPreorder\n> data TotalPreorder : {A : Type} -> (A -> A -> Type) -> Type where\n> MkTotalPreorder : {A : Type} ->\n> (R : A -> A -> Type) ->\n> (reflexive : (x : A) -> R x x) ->\n> (transitive : (x : A) -> (y : A) -> (z : A) -> R x y -> R y z -> R x z) ->\n> (totalPre : (x : A) -> (y : A) -> Either (R x y) (R y x)) ->\n> TotalPreorder R\n\n\n> {-\n\n> ||| TotalPreorder\n> data TotalPreorder : Type -> Type where\n> MkTotalPreorder : {A : Type} ->\n> (R : A -> A -> Type) ->\n> (reflexive : (x : A) -> R x x) ->\n> (transitive : (x : A) -> (y : A) -> (z : A) -> R x y -> R y z -> R x z) ->\n> (totalPre : (x : A) -> (y : A) -> Either (R x y) (R y x)) ->\n> TotalPreorder A\n\n> ---}\n", "meta": {"hexsha": "d1561df986471f77bf5be16f413c8f3ea93c1cda", "size": 976, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Rel/TotalPreorder.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/TotalPreorder.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/TotalPreorder.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.5, "max_line_length": 96, "alphanum_fraction": 0.3790983607, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.682226798971209}} {"text": "> module SequentialDecisionProblems.applications.FreezeOrIncrease\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Sigma.Sigma\n\n> %default total\n> %auto_implicits off\n> %access public export\n\n\n* Freeze / Increase options:\n\n> data FreezeOrIncrease = Freeze | Increase \n\n\n* |FreezeOrIncrease| is finite and non-empty:\n\n> to : FreezeOrIncrease -> Fin 2\n> to Freeze = FZ\n> to Increase = FS FZ\n\n> from : Fin 2 -> FreezeOrIncrease\n> from FZ = Freeze\n> from (FS FZ) = Increase\n> from (FS (FS k)) = absurd k\n\n> toFrom : (k : Fin 2) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS FZ) = Refl\n> toFrom (FS (FS k)) = absurd k\n\n> fromTo : (a : FreezeOrIncrease) -> from (to a) = a\n> fromTo Freeze = Refl\n> fromTo Increase = Refl\n\n> ||| \n> finiteFreezeOrIncrease : Finite FreezeOrIncrease\n> finiteFreezeOrIncrease = MkSigma 2 (MkIso to from toFrom fromTo)\n\n> |||\n> cardNotZFreezeOrIncrease : CardNotZ finiteFreezeOrIncrease\n> cardNotZFreezeOrIncrease = cardNotZLemma finiteFreezeOrIncrease Freeze\n\n\n> {-\n\n> ---}\n\n\n \n", "meta": {"hexsha": "e6fefc347708028eee39254d06201115bdfc6bd7", "size": 1159, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/FreezeOrIncrease.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/FreezeOrIncrease.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/FreezeOrIncrease.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6964285714, "max_line_length": 72, "alphanum_fraction": 0.6678170837, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.6815818669138065}} {"text": "\nCBool : Type\nCBool = (B : Type) -> B -> B -> B\n\ntoBool : CBool -> Bool\ntoBool = \\b => b Bool True False\n\nctrue : CBool\nctrue = \\b, t, f => t\n\nand : CBool -> CBool -> CBool\nand = \\a, b, bb, t, f => a bb (b bb t f) f\n\nCNat : Type\nCNat = (n : Type) -> (n -> n) -> n -> n\n\nadd : CNat -> CNat -> CNat\nadd = \\a, b, n, s, z => a n s (b n s z)\n\ncmul : CNat -> CNat -> CNat\ncmul = \\a, b, n, s => a n (b n s)\n\nsuc : CNat -> CNat\nsuc = \\a, n, s, z => s (a n s z)\n\nCEq : {A : Type} -> A -> A -> Type\nCEq = \\x, y => (P : A -> Type) -> P x -> P y\n\ncrefl : {A : Type} -> {x : A} -> CEq {A} x x\ncrefl = \\p, px => px\n\nn2 : CNat\nn2 = \\n, s, z => s (s z)\n\nn3 : CNat\nn3 = \\n, s, z => s (s (s z))\n\nn4 : CNat\nn4 = \\n, s, z => s (s (s (s z)))\n\nn5 : CNat\nn5 = \\n, s, z => s (s (s (s (s z))))\n\nn10 : CNat\nn10 = cmul n2 n5\n\nn10b : CNat\nn10b = cmul n5 n2\n\nn15 : CNat\nn15 = add n10 n5\n\nn15b : CNat\nn15b = add n10b n5\n\nn18 : CNat\nn18 = add n15 n3\n\nn18b : CNat\nn18b = add n15b n3\n\nn19 : CNat\nn19 = add n15 n4\n\nn19b : CNat\nn19b = add n15b n4\n\nn20 : CNat\nn20 = cmul n2 n10\n\nn20b : CNat\nn20b = cmul n2 n10b\n\nn21 : CNat\nn21 = suc n20\n\nn21b : CNat\nn21b = suc n20b\n\nn22 : CNat\nn22 = suc n21\n\nn22b : CNat\nn22b = suc n21b\n\nn23 : CNat\nn23 = suc n22\n\nn23b : CNat\nn23b = suc n22b\n\nn100 : CNat\nn100 = cmul n10 n10\n\nn100b : CNat\nn100b = cmul n10b n10b\n\nn10k : CNat\nn10k = cmul n100 n100\n\nn10kb : CNat\nn10kb = cmul n100b n100b\n\nn100k : CNat\nn100k = cmul n10k n10\n\nn100kb : CNat\nn100kb = cmul n10kb n10b\n\nn1M : CNat\nn1M = cmul n10k n100\n\nn1Mb : CNat\nn1Mb = cmul n10kb n100b\n\nn5M : CNat\nn5M = cmul n1M n5\n\nn5Mb : CNat\nn5Mb = cmul n1Mb n5\n\nn10M : CNat\nn10M = cmul n5M n2\n\nn10Mb : CNat\nn10Mb = cmul n5Mb n2\n\nTree : Type\nTree = (T : Type) -> (T -> T -> T) -> T -> T\n\nleaf : Tree\nleaf = \\t, n, l => l\n\nnode : Tree -> Tree -> Tree\nnode = \\t1, t2, t, n, l => n (t1 t n l) (t2 t n l)\n\nfullTree : CNat -> Tree\nfullTree = \\n => n Tree (\\t => node t t) leaf\n\n-- full tree with given trees at bottom level\nfullTreeWithLeaf : Tree -> CNat -> Tree\nfullTreeWithLeaf = \\bottom, n => n Tree (\\t => node t t) bottom\n\nforceTree : Tree -> CBool\nforceTree = \\t => t CBool and ctrue\n\nt15 : Tree\nt15 = fullTree n15\nt15b : Tree\nt15b = fullTree n15b\nt18 : Tree\nt18 = fullTree n18\nt18b : Tree\nt18b = fullTree n18b\nt19 : Tree\nt19 = fullTree n19\nt19b : Tree\nt19b = fullTree n19b\nt20 : Tree\nt20 = fullTree n20\nt20b : Tree\nt20b = fullTree n20b\nt21 : Tree\nt21 = fullTree n21\nt21b : Tree\nt21b = fullTree n21b\nt22 : Tree\nt22 = fullTree n22\nt22b : Tree\nt22b = fullTree n22b\nt23 : Tree\nt23 = fullTree n23\nt23b : Tree\nt23b = fullTree n23b\n\n-- CNat conversion\n--------------------------------------------------------------------------------\n\n-- convn1M : CEq Main.n1M Main.n1Mb\n-- convn1M = crefl\n\n-- convn5M : CEq Main.n5M Main.n5Mb\n-- convn5M = crefl\n\n-- convn10M : CEq Main.n10M Main.n10Mb\n-- convn10M = crefl\n\n-- Full tree conversion\n--------------------------------------------------------------------------------\n\n-- convt15 : CEq Main.t15 Main.t15b\n-- convt15 = crefl\n-- convt18 : CEq Main.t18 Main.t18b\n-- convt18 = crefl\n-- convt19 : CEq Main.t19 Main.t19b\n-- convt19 = crefl\n-- convt20 : CEq Main.t20 Main.t20b\n-- convt20 = crefl\n-- convt21 : CEq Main.t21 Main.t21b\n-- convt21 = crefl\n-- convt22 : CEq Main.t22 Main.t22b\n-- convt22 = crefl\n-- convt23 : CEq Main.t23 Main.t23b\n-- convt23 = crefl\n\n-- Full meta-containing tree conversion\n--------------------------------------------------------------------------------\n\n-- convmt15 : CEq Main.t15b (fullTreeWithLeaf ? Main.n15 )\n-- convmt15 = crefl\n-- convmt18 : CEq Main.t18b (fullTreeWithLeaf ? Main.n18 )\n-- convmt18 = crefl\n-- convmt19 : CEq Main.t19b (fullTreeWithLeaf ? Main.n19 )\n-- convmt19 = crefl\n-- convmt20 : CEq Main.t20b (fullTreeWithLeaf ? Main.n20 )\n-- convmt20 = crefl\n-- convmt21 : CEq Main.t21b (fullTreeWithLeaf ? Main.n21 )\n-- convmt21 = crefl\n-- convmt22 : CEq Main.t22b (fullTreeWithLeaf ? Main.n22 )\n-- convmt22 = crefl\n-- convmt23 : CEq Main.t23b (fullTreeWithLeaf ? Main.n23 )\n-- convmt23 = crefl\n\n-- Full tree forcing\n--------------------------------------------------------------------------------\n\n-- forcet15 : CEq (toBool (forceTree Main.t15)) True\n-- forcet15 = crefl\n-- forcet18 : CEq (toBool (forceTree Main.t18)) True\n-- forcet18 = crefl\n-- forcet19 : CEq (toBool (forceTree Main.t19)) True\n-- forcet19 = crefl\n-- forcet20 : CEq (toBool (forceTree Main.t20)) True\n-- forcet20 = crefl\n-- forcet21 : CEq (toBool (forceTree Main.t21)) True\n-- forcet21 = crefl\nforcet22 : CEq (toBool (forceTree Main.t22)) True\nforcet22 = crefl\n-- forcet23 : CEq (toBool (forceTree Main.t23)) True\n-- forcet23 = crefl\n", "meta": {"hexsha": "c1f9e64fba8e2769b2f09eaeaa235dde63ecf749", "size": 4712, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "bench/conv_eval.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/conv_eval.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/conv_eval.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": 19.5518672199, "max_line_length": 80, "alphanum_fraction": 0.5708828523, "num_tokens": 1957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6813491208362854}} {"text": "{- Another feature of the Idris2 type system, which comes from the underlying\n - Quantitative Type Theory, are quantities. Each value in a type can be annotated\n - as follows:\n - 0 - Argument erased at runtime, i.e. is only available at type-checking\n - 1 - Argument must be used exactly once each time the function is called.\n - No annotation means the argument can be used any number of times\n - The full inferred type of `id` below is shown in `id2`. -}\n\nid : a -> a\nid x = x\n\nid2 : {0 a : Type} -> (1 x : a) -> a -- implicit eraced argument,\nid2 x = x\n\n{- We can see the effect of quantities (although not yet why they are useful)\n - through the following example. Consider the following definition. -}\n\nduplicate : (1 x : a) -> (a, a)\nduplicate x = ?hole\n\n{- Inspecting ?hole above yields\n\n 0 a : Type\n 1 x : a\n -------------------------------------\n hole : (a, a)\n\n - Thus, idris is telling us we cannot use `a` in a term (only a type) and\n - we can use `x` exactly once. Say we do use it once:\n\n-}\n\nduplicate2 : (1 x : a) -> (a, a)\nduplicate2 x = (?hole2, x)\n\n{- On the hole `?hole2` above, we get the following. Note how the quantity of `x`\n - has changed from 1 to 0, since it has been used once.\n\n 0 a : Type\n 0 x : a\n -------------------------------------\n hole2 : a\n\n - Thus, this function is impossible to write without removing the quanity\n - constraint. We cannot use `x` twice.\n -}\n\nduplicate3 : (x : a) -> (a, a)\nduplicate3 x = (x, x)\n\n{- Watch the following talk by the creator of Idris, starting at 26:15 for an\n - example of how quantities could be useful in practice. Or watch the whole\n - video, it gives a bunch of cool examples and should be accessible after\n - reading these notes.\n\n - https://www.youtube.com/watch?v=DRq2NgeFcO0}\n", "meta": {"hexsha": "234baae74962b9963589674ae85f3bef0e4ab88e", "size": 1766, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Lecture20/5_Quantities.idr", "max_stars_repo_name": "ischeinfeld/cs43-lectures", "max_stars_repo_head_hexsha": "24be3bf03995bf60eb1ff8413177cdcdc3cf2058", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-01-15T07:45:56.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-16T15:38:21.000Z", "max_issues_repo_path": "src/Lecture20/5_Quantities.idr", "max_issues_repo_name": "ischeinfeld/cs43-lectures", "max_issues_repo_head_hexsha": "24be3bf03995bf60eb1ff8413177cdcdc3cf2058", "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/Lecture20/5_Quantities.idr", "max_forks_repo_name": "ischeinfeld/cs43-lectures", "max_forks_repo_head_hexsha": "24be3bf03995bf60eb1ff8413177cdcdc3cf2058", "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.9824561404, "max_line_length": 82, "alphanum_fraction": 0.6489241223, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6813049269196141}} {"text": "module AssRecRule\n\nimport Data.Fin\nimport Data.Vect\n\n% access public export\n\n\n\nrecList : (a: Type) -> (x: Type) -> x -> (a -> List a -> x -> x) -> (List a -> x)\nrecList a x base step [] = base\nrecList a x base step (y :: xs) = step y xs previous where\n previous = recList a x base step xs\n\nmapList : (a: Type) -> (b: Type) -> (f: a -> b) -> List a -> List b\nmapList a b f = recList a (List b) base step where\n base = []\n step head tail prev = (f head) :: prev\n\nfoldList : (a: Type) -> (init: a) -> (op : a -> a -> a) -> List a -> a\nfoldList a init op = recList a a base step where\n base = init\n step head tail prev = op head prev\n\n\nrecFin : (x: Type) ->\n (Nat -> x) ->\n ((n: Nat) -> Fin n -> x -> x) ->\n ((n: Nat) -> Fin n -> x)\nrecFin x base _ (S k) FZ = base k\nrecFin x base step (S k) (FS y) = step k y previous where\n previous = recFin x base step k y\n\ninducFin : (xs : (n: Nat) -> Fin n -> Type) ->\n (base : (m: Nat) -> xs (S m) FZ) ->\n (step : (p: Nat) -> (k: Fin p) -> (prev: xs p k) -> (xs (S p) (FS k))) ->\n (q: Nat) -> (j: Fin q) -> xs q j\ninducFin xs base step (S l) FZ = base l\ninducFin xs base step (S l) (FS x) =\n step l x prev where\n prev = inducFin xs base step l x\n\nfetchFamily: (a: Type) -> (n: Nat) -> Fin n -> Type\nfetchFamily a n x = ((Vect n a) -> a)\n\nfetchElem : (a: Type) -> (q: Nat) -> (j: Fin q) -> (Vect q a -> a)\nfetchElem a = inducFin (fetchFamily a) base step where\n base m (x :: xs) = x\n step p k prev (x :: xs) =\n fetchElem a p k xs\n", "meta": {"hexsha": "8ca6a4de0f0e27deccb9cfdb71df9f424d5e485d", "size": 1491, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/AssRecRule.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/AssRecRule.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/AssRecRule.idr", "max_forks_repo_name": "anotherArka/LTS2019", "max_forks_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2019-01-08T05:56:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-31T03:58:00.000Z", "avg_line_length": 29.2352941176, "max_line_length": 82, "alphanum_fraction": 0.5492957746, "num_tokens": 560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.681121668484525}} {"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\nreplicate : {m : Nat} -> a -> Vect m a\n\ntranspose : {m : Nat} -> Vect n (Vect m a) -> Vect m (Vect n a)\ntranspose [] = ?transpose_rhs_1\ntranspose (x :: xs) = ?transpose_rhs_2\n", "meta": {"hexsha": "c4db518efbeabe62cb57423970d8d6d31c1bac61", "size": 299, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive038/IEdit.idr", "max_stars_repo_name": "chrrasmussen/Idris2-Erlang", "max_stars_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "idris2/tests/idris2/interactive038/IEdit.idr", "max_issues_repo_name": "chrrasmussen/Idris2-Erlang", "max_issues_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "idris2/tests/idris2/interactive038/IEdit.idr", "max_forks_repo_name": "chrrasmussen/Idris2-Erlang", "max_forks_repo_head_hexsha": "dfa38cd866fd683d4bdda49fc0bf2f860de273b4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 24.9166666667, "max_line_length": 63, "alphanum_fraction": 0.5585284281, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6810502091743186}} {"text": "> module SequentialDecisionProblems.ViabilityDefaults\n\n> import SequentialDecisionProblems.CoreTheory\n> import SequentialDecisionProblems.Utils\n\n> import Unit.Properties\n\n> %default total\n> %auto_implicits off\n\n\nThis is the default implementation of |Viable|: all states are viable\nfor 0 steps; a state is viable for |n + 1| steps iff it has a control\nsuch that 1) the set of next possible states is not empty and 2) all\nnext possible states are viable for |n| steps. These two conditions are\nencoded in the notion of \"good\" control, see |Utils|:\n\n> -- Viable : (n : Nat) -> State t -> Type\n> SequentialDecisionProblems.CoreTheory.Viable {t} Z _ = Unit\n> SequentialDecisionProblems.CoreTheory.Viable {t} (S n) x = GoodCtrl t x n\n\nTrivially, for every state that is viable for |n + 1| steps we can\ncompute a good control\n\n> -- viableSpec0 : (x : State t) -> Viable Z x\n> SequentialDecisionProblems.CoreTheory.viableSpec0 x = ()\n\n> -- viableSpec1 : (x : State t) -> Viable (S n) x -> GoodCtrl t x n\n> SequentialDecisionProblems.CoreTheory.viableSpec1 {t} {n} x v = v\n\n> -- viableSpec2 : (x : State t) -> GoodCtrl t x n -> Viable (S n) x\n> SequentialDecisionProblems.CoreTheory.viableSpec2 {t} {n} x gy = gy\n\n\nIf users can show that ..., see |Utils|. For |M = List|, for instance,\n... are implemented in |NonDeterministic Defaults|:\n\n> -- finiteViable : {t : Nat} -> \n> -- (n : Nat) -> (x : State t) -> Finite (Viable n x)\n> SequentialDecisionProblems.Utils.finiteViable Z _ = finiteUnit\n> SequentialDecisionProblems.Utils.finiteViable (S m) x = finiteGoodCtrl m x\n\n> -- decidableViable : {t : Nat} -> \n> -- (n : Nat) -> (x : State t) -> Dec (Viable n x)\n> SequentialDecisionProblems.Utils.decidableViable Z _ = Yes MkUnit\n> SequentialDecisionProblems.Utils.decidableViable (S m) x = decidableGoodCtrl m x\n\n\n> {-\n\n> ---}\n\n", "meta": {"hexsha": "22866c1498753fc7d679cddb17a692446a7998b5", "size": 1864, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/ViabilityDefaults.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/ViabilityDefaults.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/ViabilityDefaults.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.1698113208, "max_line_length": 82, "alphanum_fraction": 0.6915236052, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6809649066787206}} {"text": "module Shape\n\nexport\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\nexport\ntriangle : Double -> Double -> Shape\ntriangle = Triangle\n\nexport\nrectangle : Double -> Double -> Shape\nrectangle = Rectangle\n\nexport\ncircle : Double -> Shape\ncircle = Circle\n\ndata ShapeView : Shape -> Type where\n STriangle : ShapeView (triangle base height)\n SRectangle : ShapeView (rectangle width height)\n SCircle : ShapeView (circle radius)\n\nshapeView : (s: Shape) -> ShapeView s\nshapeView (Triangle x y) = STriangle\nshapeView (Rectangle x y) = SRectangle\nshapeView (Circle x) = SCircle\n\narea : Shape -> Double\narea x with (shapeView x)\n area (triangle base height) | STriangle = 0.5 * base * height\n area (rectangle width height) | SRectangle = width * height\n area (circle radius) | SCircle = pi * radius * radius\n", "meta": {"hexsha": "52d3e857e2a5c36f0abb981465e0f6dcf55e421f", "size": 898, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Shape.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": "Shape.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": "Shape.idr", "max_forks_repo_name": "coffius/idris-exercises", "max_forks_repo_head_hexsha": "77cb2ab7247890ba38376b753611284458cece17", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6571428571, "max_line_length": 70, "alphanum_fraction": 0.6748329621, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6809536619547736}} {"text": "-- ------------------------------------------------------------ [ Literals.idr ]\n||| Module : Literals.idr\n||| Copyright : (c) Jan de Muijnck-Hughes\n||| License : see LICENSE\n|||\n||| Deal with literal values at the type-level.\nmodule Commons.Data.Literals\n\n%default total\n%access public export\n\n\n||| Proof that the given value level `b` of type `ty` has value `a`.\ndata Literal : (ty : Type)\n -> (a : ty)\n -> Type\n where\n MkLiteral : (b : ty)\n -> (prf : b = a)\n -> Literal ty a\n\nnewLiteral : (b : ty) -> Literal ty b\nnewLiteral b = MkLiteral b Refl\n\n||| Representation of String literals.\nLitString : String -> Type\nLitString str = Literal String str\n\n||| Proof that the given natural `o` is the successor of `n`.\ndata Next : (n : Nat) -> Type where\n MkNext : (o : Nat) -> (prf : o = S n) -> Next n\n\nnewNext : (o,n : Nat) -> (prf : o = S n) -> Next n\nnewNext o _ prf = MkNext o prf\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "c99ef39ac7f2bfa4350bb0ea560f65f22319f393", "size": 1020, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Commons/Data/Literals.idr", "max_stars_repo_name": "jfdm/idris-common", "max_stars_repo_head_hexsha": "df32dc33c253709751fe0f9f2b57cd5d497eccd4", "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": "Commons/Data/Literals.idr", "max_issues_repo_name": "jfdm/idris-common", "max_issues_repo_head_hexsha": "df32dc33c253709751fe0f9f2b57cd5d497eccd4", "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": "Commons/Data/Literals.idr", "max_forks_repo_name": "jfdm/idris-common", "max_forks_repo_head_hexsha": "df32dc33c253709751fe0f9f2b57cd5d497eccd4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-17T14:43:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-17T14:43:42.000Z", "avg_line_length": 27.5675675676, "max_line_length": 80, "alphanum_fraction": 0.5107843137, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6808906069601307}} {"text": "||| Mathematicians often make an appeal to 'symmetry' to derive\n||| variations on a lemma or theorem.\nmodule Symmetry.Opposite\n\nimport Specifications.TranslationInvariance\nimport Specifications.Ring\n\n%default total\n%access export\n\nprivate\noppAssoc : isAssociative op -> isAssociative (flip op)\noppAssoc spec x y z = sym (spec z y x)\n\nnamespace Monoid\n opposite : MonoidSpec op e -> MonoidSpec (flip op) e\n opposite (MkMonoid a l r) = MkMonoid (oppAssoc a) r l\n\nnamespace Group\n opposite : GroupSpec op e inv -> GroupSpec (flip op) e inv\n opposite (MkGroup m l r) = MkGroup (opposite m) r l\n\nnamespace PreRing\n multiplicativeOpposite : PreRingSpec add mul -> PreRingSpec add (flip mul)\n multiplicativeOpposite {add} {mul} (MkPreRing l r abel) =\n MkPreRing rop lop abel where\n rop : isDistributativeL add (flip mul)\n rop a x y = r x y a\n lop : isDistributativeR add (flip mul)\n lop x y a = l a x y\n\nnamespace Ring\n multiplicativeOpposite : RingSpec add zero neg mul ->\n RingSpec add zero neg (flip mul)\n multiplicativeOpposite (MkRing pre grp multassoc) =\n MkRing (multiplicativeOpposite pre) grp (oppAssoc multassoc)\n\nnamespace PartiallyOrderedMagma\n opposite : PartiallyOrderedMagmaSpec op leq ->\n PartiallyOrderedMagmaSpec (flip op) leq\n opposite (MkPartiallyOrderedMagma o l r) = MkPartiallyOrderedMagma o r l\n\nnamespace PartiallyOrderedGroup\n opposite : PartiallyOrderedGroupSpec op inv e leq ->\n PartiallyOrderedGroupSpec (flip op) inv e leq\n opposite (MkPartiallyOrderedGroup g m) =\n MkPartiallyOrderedGroup (opposite g) (opposite m)\n", "meta": {"hexsha": "0d1e5af7c46b939465f888ba26921dbf196419dd", "size": 1589, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Symmetry/Opposite.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/Opposite.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/Opposite.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.1041666667, "max_line_length": 76, "alphanum_fraction": 0.7476400252, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.6808906069601305}} {"text": "%default total\n\n%hide Prelude.Nat.LT\n%hide Prelude.Interfaces.LT\n%hide Prelude.Interfaces.(<=)\n%hide Prelude.Interfaces.(>)\n%hide Prelude.List.filter\n%hide Prelude.List.merge\n%hide Prelude.List.splitAt\n%hide Prelude.WellFounded.Smaller\n\nsomeList : List Nat\nsomeList = [9,1,5,5,0,2,3,7,6,11,1]\n\ndata Acc : (lessThan : a -> a -> Type) -> (x : a) -> Type where\n MkAcc :\n -- potentially infinite tuple\n -- potentially infinite number of children in the tree\n -- but each subtree has a finite depth\n (acc : (y : a) -> (y `lessThan` x) -> Acc lessThan y)\n -> Acc lessThan x\n\ninterface WF (lt : a -> a -> Type) where\n wf : (x : _) -> Acc lt x\n\n------------------------------------------\n\ndata LE : Nat -> Nat -> Type where\n LEZ : Z `LE` n\n LES : m `LE` n -> S m `LE` S n\n\nLT : Nat -> Nat -> Type\nLT m n = LE (S m) n\n\nleRefl : x `LE` x\nleRefl {x = Z} = LEZ\nleRefl {x = (S x)} = LES leRefl\n\nleTrans : (x `LE` y) -> (y `LE` z) -> (x `LE` z)\nleTrans LEZ _ = LEZ\nleTrans (LES xLEy) (LES yLEz) = LES $ leTrans xLEy yLEz\n\nwfLT : (x : Nat) -> Acc LT x\nwfLT x = MkAcc (f x)\n where\n f : (x : Nat) -> (y : Nat) -> (y `LT` x) -> Acc LT y\n f (S x) y (LES yLEx) = MkAcc (\\z, zLTy => f x z $ leTrans zLTy yLEx)\n -- LEZ cannot prove \"strictly smaller than\" because LT has (S _) on the LHS\n -- and LEZ has Z on the LHS\n\n{-\ndecLE : (m, n : Nat) -> Dec (m `LE` n)\ndecLE Z n = Yes LEZ\ndecLE (S k) Z = No lemmaLTZ\ndecLE (S k) (S j) with (decLE k j)\n | Yes yep = Yes $ LES yep\n | No nope = No $ f nope\n where\n f : (LE k j -> Void) -> LE (S k) (S j) -> Void\n f nope (LES pf) = nope pf\n-}\n\n(<=) : Nat -> Nat -> Bool\n(<=) Z n = True\n(<=) (S m) Z = False\n(<=) (S m) (S n) = m <= n\n\n(>) : Nat -> Nat -> Bool\n(>) m n = not (m <= n)\n\nfilter : (a -> Bool) -> List a -> List a\nfilter p [] = []\nfilter p (x :: xs) with (p x)\n | True = x :: filter p xs\n | False = filter p xs\n\n------------------------------------------\n\nshorter : List a -> List a -> Type\nshorter xs ys = length xs `LT` length ys\n\nwfShorter : (xs : List a) -> Acc Main.shorter xs\nwfShorter xs = MkAcc (f xs)\n where\n f : (xs : List a) -> (ys : List a) -> (ys `Main.shorter` xs) -> Acc Main.shorter ys\n f (x :: xs) ys (LES ysLExs) = MkAcc (\\zs, zsLTys => f xs zs $ leTrans zsLTys ysLExs)\n\n-----------------------------------------\n\n{- Comes from Prelude now\ninterface Sized a where\n size : a -> Nat\n-}\n\nSmaller : Sized a => a -> a -> Type\nSmaller x y = size x `LT` size y\n\nSizeAcc : Sized a => a -> Type\nSizeAcc x = Acc Smaller x\n\nwfSmaller : Sized a => (x : a) -> SizeAcc x\nwfSmaller x = MkAcc $ f (size x)\n where\n f : (sizeX : Nat) -> (y : a) -> (size y `LT` sizeX) -> SizeAcc y\n f (S n) y (LES yLEx)\n = MkAcc (\\z, zLTy =>\n f n z (leTrans zLTy yLEx)\n )\n\n{- comes from Prelude now\nimplementation Sized (List a) where\n size = length\n-}\n\n{-\nwfSmaller : Sized a => (x : a) -> Acc Smaller x\nwfSmaller x = MkAcc (f x)\n where\n f : (x, y : a) -> (y `Smaller` x) -> Acc Smaller y\n f x y pf with (size x) proof xSize\n f x y pf | Z = lemmaLTZ pf\n f x y (LES yLEx) | S n = MkAcc (\\z, zLTy => f x z $ leTrans zLTy ?rhs)\n -- we cannot do this because for the inductive step, we need a subterm of x\n -- but we have no way to obtain it\n-}\n\n-----------------------------------------\n\n-- qSort with Acc\n\nleS : (m `LE` n) -> (m `LE` S n)\nleS LEZ = LEZ\nleS (LES x) = LES (leS x)\n\nfilterLen : {p : a -> Bool} -> {xs : List a} -> length (filter p xs) `LE` length xs\nfilterLen {xs = []} = LEZ\nfilterLen {p} {xs = x :: xs} with (p x)\n | True = LES $ filterLen\n | False = leS $ filterLen\n\nqsort' : (xs : List Nat) -> (Acc Main.shorter xs) -> List Nat\nqsort' [] acc = []\nqsort' (x :: xs) (MkAcc acc) =\n qsort' (filter (<= x) xs) (acc _ $ LES filterLen)\n ++ [x]\n ++ qsort' (filter (> x) xs) (acc _ $ LES filterLen)\n\nqsort : List Nat -> List Nat\nqsort xs = qsort' xs (wfShorter xs)\n\n------------------------\n\n-- QSortAcc directly\n\ndata QSortAcc : List Nat -> Type where\n QNil : QSortAcc []\n QCons : QSortAcc (filter (<= x) xs) -> QSortAcc (filter (> x) xs) -> QSortAcc (x :: xs)\n\nqsortAccLo : (x : _) -> QSortAcc xs -> QSortAcc (filter (<= x) xs)\nqsortAccLo x pf = ?rhsX1\n\nqsortAccHi : (x : _) -> QSortAcc xs -> QSortAcc (filter (> x) xs)\nqsortAccHi x pf = ?rhsX2\n\nqsortA' : (xs : List Nat) -> QSortAcc xs -> List Nat\nqsortA' [] QNil = []\nqsortA' (x :: xs) (QCons lo hi)\n = qsortA' (filter (<= x) xs) lo\n ++ [x]\n ++ qsortA' (filter (> x) xs) hi\n\nobsBool : (x : Bool) -> Either (x = True) (x = False)\nobsBool True = Left Refl\nobsBool False = Right Refl\n\nfilterDbl : (p : a -> Bool) -> (xs : List a) -> filter p (filter p xs) = filter p xs\nfilterDbl p xs = ?filterDblHole\n\nqsortAcc : (xs : List Nat) -> QSortAcc xs\nqsortAcc [] = QNil\nqsortAcc (x :: xs) = QCons (f x xs) ?rhsX3\n where\n f : (x : Nat) -> (xs : List Nat) -> QSortAcc (filter (<= x) xs)\n f x [] = QNil\n f x (y :: xs) with (y <= x)\n | True = ?qSortAccA\n | False = ?qSortAccB\n\n{-\n f x [y] with (y <= x)\n | True = QCons QNil QNil\n | False = QNil\n f x (y :: z :: xs) with (y <= x)\n | True = ?rhs\n | False = ?rhs2\n-}\n\nqsortA : List Nat -> List Nat\nqsortA xs = qsortA' xs (qsortAcc xs)\n\n---\n\n-- via Acc\n\nqsortAcc' : (xs : List Nat) -> Acc Main.shorter xs -> QSortAcc xs\nqsortAcc' [] acc = QNil\nqsortAcc' (x :: xs) (MkAcc acc)\n = QCons\n (qsortAcc' _ (acc _ $ LES filterLen))\n (qsortAcc' _ (acc _ $ LES filterLen))\n\nqsort2 : List Nat -> List Nat\nqsort2 xs = qsortA' xs $ qsortAcc' xs (wfShorter xs)\n\n---\n\ndata Split : List a -> Type where\n SNil : Split []\n SOne : (x : a) -> Split [x]\n SMore :\n (x : a) -> (xs : List a)\n -> (y : a) -> (ys : List a)\n -> Split (x :: xs ++ y :: ys)\n\npushL : (x : a) -> Split xs -> Split (x :: xs)\npushL x SNil = SOne x\npushL x (SOne y) = SMore x [] y []\npushL x (SMore y ys z zs) = SMore x (y :: ys) z zs\n\n{-\nsplit : (xs : List a) -> Split xs\nsplit [] = SNil\nsplit [x] = SOne x\nsplit (x :: y :: xs) = step (1 + length xs) x y xs\n where\n step : (counter : Nat) -> (x, y : a) -> (xs : List a) -> Split (x :: y :: xs)\n step Z x y xs = SMore x [] y xs\n step (S Z) x y xs = SMore x [] y xs\n step (S (S k)) x y [] = SMore x [] y []\n step (S (S k)) x y (z :: xs) = pushL x $ step k y z xs\n-}\n\nhalve : (xs : List a) -> Split xs\nhalve [] = SNil\nhalve [x] = SOne x\nhalve (x :: y :: xs) with (1 + length xs)\n halve (x :: y :: xs) | Z = SMore x [] y xs\n halve (x :: y :: xs) | S Z = SMore x [] y xs\n halve (x :: y :: []) | S (S k) = SMore x [] y []\n halve (x :: y :: z :: zs) | S (S k) = pushL x (halve (y :: z :: zs) | k)\n\nshorterL : xs `shorter` (xs ++ y :: ys)\nshorterL {xs = []} = LES LEZ\nshorterL {xs = (x :: xs)} = LES shorterL\n\nshorterR : ys `shorter` (x :: xs ++ ys)\nshorterR {xs = []} = LES leRefl\nshorterR {xs = x :: xs} = leS $ shorterR {x=x}\n\nmerge : List Nat -> List Nat -> List Nat\nmerge (x :: xs) (y :: ys) with (x <= y)\n | True = x :: merge xs (y :: ys)\n | False = y :: merge (x :: xs) ys\nmerge [] ys = ys\nmerge xs [] = xs\n\nmsort1' : (xs : List Nat) -> (Acc Main.shorter xs) -> List Nat\nmsort1' xs acc with (halve xs)\n msort1' [] acc | SNil = []\n msort1' [x] acc | SOne x = [x]\n msort1' (y :: ys ++ z :: zs) (MkAcc acc) | SMore y ys z zs\n = merge\n (msort1' (y :: ys) (acc _ $ shorterL {xs = y::ys}))\n (msort1' (z :: zs) (acc _ $ shorterR {ys = z::zs}))\n\nmsort1 : List Nat -> List Nat\nmsort1 xs = msort1' xs (wfShorter xs)\n\n---------------------------\n\nmutual\n data MSAcc' : Split xs -> Type where\n MSNil : MSAcc' SNil\n MSOne : MSAcc' (SOne x)\n MSMore :\n MSAcc (x :: xs)\n -> MSAcc (y :: ys)\n -> MSAcc' (SMore x xs y ys)\n\n MSAcc : List a -> Type\n MSAcc xs = MSAcc' (halve xs)\n\nmsAcc : (xs : List Nat) -> MSAcc xs\nmsAcc xs with (wfShorter xs)\n msAcc xs | acc with (halve xs)\n msAcc [] | acc | SNil = MSNil\n msAcc [x] | acc | SOne x = MSOne\n msAcc (y :: ys ++ z :: zs) | MkAcc acc | SMore y ys z zs\n = MSMore\n (msAcc _ | acc _ (shorterL {xs = y :: ys}))\n (msAcc _ | acc _ (shorterR {ys = z :: zs}))\n\nmsort2' : (xs : List Nat) -> MSAcc xs -> List Nat\nmsort2' xs acc with (halve xs)\n msort2' [] MSNil | SNil = []\n msort2' [x] MSOne | SOne x = [x]\n msort2' (y :: ys ++ z :: zs) (MSMore accL accR) | SMore y ys z zs\n = merge\n (msort2' (y :: ys) accL)\n (msort2' (z :: zs) accR)\n\nmsort2 : List Nat -> List Nat\nmsort2 xs = msort2' xs (msAcc xs)\n\n-- views for convenience\n-- views for termination\n\n-- Acc is more general induction hypothesis than QSortAcc\n-- more general => easier to work with (easier to prove from)\n -- probably a bit harder to prove BUT\n -- still obviously true\n -- and proving the inductive step may be easier (actually feasible at all)\n\n-- end up with views\n\n-----------------------------------------------\n\n%default total\n\nsubst : (f : a -> Type) -> x = y -> f x -> f y\nsubst f Refl = \\x => x\n\ndata SplitC : (List a -> Type) -> List a -> Type where\n SCNil : SplitC srg []\n SCOne : (x : a) -> SplitC srg [x]\n SCMore :\n (x : a) -> (xs : List a)\n -> (y : a) -> (ys : List a)\n -> (rxs : srg (x :: xs))\n -> (rys : srg (y :: ys))\n -> SplitC srg (x :: xs ++ y :: ys)\n\ndata SplitRecC : List a -> Type where\n SRC : ((n : Nat) -> SplitC SplitRecC xs) -> SplitRecC xs\n\npushSC : (x : a) -> SplitC (const ()) xs -> SplitC (const ()) (x :: xs)\npushSC x SCNil = SCOne x\npushSC x (SCOne y) = SCMore x [] y [] () ()\npushSC x (SCMore y ys z zs () ()) = SCMore x (y::ys) z zs () ()\n\nsplitAt : (n : Nat) -> (xs : List a) -> SplitC (const ()) xs\nsplitAt n [] = SCNil\nsplitAt n [x] = SCOne x\nsplitAt Z (x :: y :: ys) = SCMore x [] y ys () ()\nsplitAt (S k) (x :: y :: ys) = pushSC x $ splitAt k (y :: ys)\n\nlemmaApp : (xs : List a) -> (ys : List a) -> length ys `LE` length (xs ++ ys)\nlemmaApp [] ys = leRefl\nlemmaApp (x::xs) ys = leS $ lemmaApp xs ys\n\nsplitC : (xs : List a) -> (n : Nat) -> SplitC SplitRecC xs\nsplitC xs n with (wfSmaller xs)\n splitC xs n | acc with (splitAt n xs)\n splitC [] n | acc | SCNil = SCNil\n splitC [x] n | acc | SCOne x = SCOne x\n splitC (y :: ys ++ z :: zs) n | MkAcc acc | SCMore y ys z zs () ()\n = SCMore y ys z zs\n (SRC $ \\n' => splitC (y :: ys) n' | acc _ (LES shorterL))\n (SRC $ \\n' => splitC (z :: zs) n' | acc _ (LES $ lemmaApp ys (z::zs)))\n\nsplitRecC : (xs : List a) -> SplitRecC xs\nsplitRecC xs = SRC $ splitC xs\n\nunpack' : Nat -> List Nat -> List (List Nat)\nunpack' x xs with (splitRecC (x :: xs))\n unpack' x xs | SRC splitAt with (splitAt x)\n unpack' x [] | SRC splitAt | SCOne x = [] -- dangling length tag\n unpack' x (ys ++ z :: zs) | SRC splitAt | SCMore x ys z zs rys rzs\n = ys :: unpack' z zs | rzs\n\nunpackL : List Nat -> List (List Nat)\nunpackL [] = []\nunpackL (x :: xs) = unpack' x xs\n\npackL : List (List Nat) -> List Nat\npackL [] = [0]\npackL (xs :: xss) = length xs :: xs ++ packL xss\n\n{-\n*views> unpackL [1,3,0,3,1,2,3,2,0,1,4,1,2,3,4,0]\n[[3], [1, 2, 3], [0, 1], [1, 2, 3, 4]] : List (List Nat)\n-}\n\n---------------------------------------------------------\n\n{-\ndata ModView : Nat -> Nat -> Type where\n Base : ModView x y\n Step : ModView x y -> ModView x (x + y)\n\nmodView : (x', y : Nat) -> ModView (S x') y\nmodView x' Z = Base\nmodView Z (S y') = ?rhs_1 -- dividing by 1\nmodView (S k) (S y') = ?rhs_3\n-}\n\n{-\nmod : (x : Nat) -> (y : Nat) -> Nat\nmod x y acc with\n-}\n\ndata SplitRec : List a -> Type where\n SRNil : SplitRec []\n SROne : (x : a) -> SplitRec [x]\n SRMore :\n (x : a) -> (xs : List a) \n -> (y : a) -> (ys : List a)\n -> (sxs : SplitRec (x :: xs))\n -> (sys : SplitRec (y :: ys))\n -> SplitRec (x :: xs ++ y :: ys)\n\nsplitRec : (xs : List a) -> SplitRec xs\nsplitRec xs with (wfSmaller xs)\n splitRec xs | acc with (halve xs)\n splitRec [] | acc | SNil = SRNil\n splitRec [x] | acc | SOne x = SROne x\n splitRec (y :: ys ++ z :: zs) | MkAcc acc | SMore y ys z zs\n = SRMore y ys z zs\n (splitRec _ | acc _ (shorterL {xs = y::ys}))\n (splitRec _ | acc _ (shorterR {x=z} {ys = z::zs}))\n\nmsortR : List Nat -> List Nat\nmsortR xs with (splitRec xs)\n msortR [] | SRNil = []\n msortR [x] | SROne x = [x]\n msortR (y :: ys ++ z :: zs) | SRMore y ys z zs sys szs\n = merge\n (msortR (y :: ys) | sys)\n (msortR (z :: zs) | szs)\n\n------------------------\n\ndata SnocViewRec : List a -> Type where\n SVRNil : SnocViewRec (Nil {elem=a})\n SVRSnoc : (sxs : SnocViewRec xs)\n -> (x : a)\n -> SnocViewRec (xs ++ [x])\n\n%hide Prelude.Basics.cong\n\ncong : {f : a -> b} -> x = y -> f x = f y\ncong Refl = Refl\n \nappNil : (xs : List a) -> xs ++ [] = xs\nappNil [] = Refl\nappNil (x :: xs) = cong $ appNil xs\n\nappAssoc : (xs : List a) -> (ys : List a) -> (zs : List a) -> xs ++ (ys ++ zs) = (xs ++ ys) ++ zs \nappAssoc [] ys zs = Refl\nappAssoc (x :: xs) ys zs = cong $ appAssoc xs ys zs\n\nsr : (sxs : SnocViewRec xs) -> (ys : List a) -> SnocViewRec (xs ++ ys)\nsr {xs} sxs [] = rewrite appNil xs in sxs\nsr {xs} sxs (y :: ys) = rewrite appAssoc xs [y] ys in sr (SVRSnoc sxs y) ys\n\nsnocViewRec : (xs : List a) -> SnocViewRec xs\nsnocViewRec = sr SVRNil\n\n--------------------\n\ndata VList : List a -> Type where\n VNil : VList []\n VOne : (x : a) -> VList [x]\n VMore : (x : a) -> VList xs -> (y : a) -> VList (x :: xs ++ [y])\n\npushV : (x : a) -> VList xs -> VList (x :: xs)\npushV x VNil = VOne x\npushV x (VOne y) = VMore x VNil y\npushV x (VMore y ys z) = VMore x (pushV y ys) z\n\nvList : (xs : List a) -> VList xs\nvList [] = VNil\nvList (x :: xs) = pushV x (vList xs)\n\n{-\nvStep : SnocViewRec (x :: xs ++ [y]) -> SnocViewRec (x :: xs)\nvStep {x} {xs} {y} (SVRSnoc {xs = x :: xs} sxs y) = sxs\n-}\n", "meta": {"hexsha": "639992402621f82656ca4bba9e05348864c52f56", "size": 13715, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples-thesis/views.idr", "max_stars_repo_name": "MaxDesiatov/ttstar", "max_stars_repo_head_hexsha": "4ac6e124bddfbeaa133713d829dccaa596626be6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2015-06-12T14:58:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-31T14:36:48.000Z", "max_issues_repo_path": "examples-thesis/views.idr", "max_issues_repo_name": "MaxDesiatov/ttstar", "max_issues_repo_head_hexsha": "4ac6e124bddfbeaa133713d829dccaa596626be6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-02-03T12:43:32.000Z", "max_issues_repo_issues_event_max_datetime": "2017-09-12T17:13:40.000Z", "max_forks_repo_path": "examples-thesis/views.idr", "max_forks_repo_name": "MaxDesiatov/ttstar", "max_forks_repo_head_hexsha": "4ac6e124bddfbeaa133713d829dccaa596626be6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-31T19:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T19:08:56.000Z", "avg_line_length": 28.0470347648, "max_line_length": 98, "alphanum_fraction": 0.5224207073, "num_tokens": 5191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6808832415561501}} {"text": "module EqualityIn\n\ninterface Preorder t (po : t -> t -> Type) where\n transitive : (0 a, b, c : t) -> po a b -> po b c -> po a c\n reflexive : (0 a : t) -> po a a\n\ninterface Preorder t eq => Equivalence t (eq : t -> t -> Type) where\n symmetric : (0 a, b : t) -> eq a b -> eq b a\n\ninterface Equivalence t eq => Congruence t (f : t -> t) (eq : t -> t -> Type) where\n congruent : (0 a, b : t) -> eq a b -> eq (f a) (f b)\n\nPreorder t Equal where\n transitive _ _ _ ab bc = trans ab bc\n reflexive _ = Refl\n\nEquivalence t Equal where\n symmetric _ _ ab = sym ab\n\nCongruence t f Equal where\n congruent _ _ ab = cong f ab\n\nabba : a = b -> b = a\nabba = symmetric a b\n", "meta": {"hexsha": "bef10e72a6c89401f9de642ddf932e94805670af", "size": 662, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "EqualityIn.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": "EqualityIn.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": "EqualityIn.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.48, "max_line_length": 83, "alphanum_fraction": 0.5936555891, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813513911654, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6808806976716985}} {"text": "module Poly\n\n%access public export\n\n%default total\n\nrepeat : (x : x_ty) -> (count : Nat) -> List x_ty\nrepeat x Z = []\nrepeat x (S k) = x :: repeat x k\n\ntest_repeat1 : repeat 4 2 = [4, 4]\ntest_repeat1 = Refl\n\ntest_repeat2 : repeat False 1 = [False]\ntest_repeat2 = Refl\n\nnamespace MumbleGrumble\n data Mumble : Type where\n A : Mumble\n B : Mumble -> Nat -> Mumble\n C : Mumble\n\n data Grumble : (x : Type) -> Type where\n D : Mumble -> Grumble x\n E : x -> Grumble x\n\nrev : (l : List a) -> List a\nrev [] = []\nrev (h :: t) = (rev t) ++ [h]\n\ntest_rev1 : rev [1, 2] = [2, 1]\ntest_rev1 = Refl\n\ntest_rev2 : rev [True] = [True]\ntest_rev2 = Refl\n\nlen : (l : List a) -> Nat\nlen [] = Z\nlen (h :: t) = S (len t)\n\ntest_length1 : length [1, 2, 3] = 3\ntest_length1 = Refl\n\napp_nil_r : (l : List a) -> l ++ [] = l\napp_nil_r [] = Refl\napp_nil_r (x :: xs) = rewrite app_nil_r xs in Refl\n\napp_nil : (l : List a) -> [] ++ l = l\napp_nil l = Refl\n\napp_assoc : (l, m, n : List a) -> l ++ m ++ n = (l ++ m) ++ n\napp_assoc [] m n = Refl\napp_assoc (x :: xs) m n = rewrite app_assoc xs m n in Refl\n\napp_length : (l1, l2 : List a) -> length (l1 ++ l2) = length l1 + length l2\napp_length [] l2 = Refl\napp_length (x :: xs) l2 = rewrite app_length xs l2 in Refl\n\nrev_app_distr : (l1, l2 : List a) -> rev (l1 ++ l2) = rev l2 ++ rev l1\nrev_app_distr [] l2 = rewrite app_nil_r (rev l2) in Refl\nrev_app_distr (x :: xs) l2 =\n rewrite rev_app_distr xs l2 in\n rewrite sym $ app_assoc (rev l2) (rev xs) [x] in\n Refl\n\nrev_involutive : (l : List a) -> rev (rev l) = l\nrev_involutive [] = Refl\nrev_involutive (x :: xs) =\n rewrite rev_app_distr (rev xs) [x] in\n rewrite rev_involutive xs in\n Refl\n\nsplit : (l : List (x, y)) -> (List x, List y)\nsplit [] = ([], [])\nsplit ((a, b) :: xs) =\n let\n (ys, zs) = split xs\n in\n (a :: ys, b :: zs)\n\ntest_split : split [(1, False), (2, False)] = ([1, 2], [False, False])\ntest_split = Refl\n\nnth_error : (l : List a) -> (n : Nat) -> Maybe a\nnth_error [] n = Nothing\nnth_error (x :: xs) Z = Just x\nnth_error (x :: xs) (S k) = nth_error xs k\n\ntest_nth_error1 : nth_error [4, 5, 6, 7] 0 = Just 4\ntest_nth_error1 = Refl\n\ntest_nth_error2 : nth_error [[1], [2]] 1 = Just [2]\ntest_nth_error2 = Refl\n\ntest_nth_error3 : nth_error [True] 2 = Nothing\ntest_nth_error3 = Refl\n\nhd_error : (l : List a) -> Maybe a\nhd_error [] = Nothing\nhd_error (x :: xs) = Just x\n\ntest_hd_error1 : hd_error [1, 2] = Just 1\ntest_hd_error1 = Refl\n\ntest_hd_error2 : hd_error [[1], [2]] = Just [1]\ntest_hd_error2 = Refl\n\nmap_rev : (f : x -> y) -> (l : List x) -> map f (rev l) = rev (map f l)\nmap_rev f [] = Refl\nmap_rev f (x :: xs) = ?map_rev_rhs_2\n", "meta": {"hexsha": "cdb54f08f0c314e7757cc61137e681f7cec0a8f9", "size": 2705, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/SF5.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/SF5.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/SF5.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": 24.3693693694, "max_line_length": 75, "alphanum_fraction": 0.5818853974, "num_tokens": 1010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.6808738979043691}} {"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\nimport Data.Vect\n\n-- 6.1.1\n\nPosition : Type\nPosition = (Double, Double)\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\ntri2 : Polygon 3\ntri2 = [(0, 0), (0, 0), (0, 0)]\n\n-- 6.1.2\n\nStringOrInt : Bool -> Type\nStringOrInt True = Int\nStringOrInt False = String\n\nvalToString\n : (isInt : Bool)\n -> (case isInt of\n True => Int\n False => String)\n -> String\nvalToString False x = trim x\nvalToString True x = cast x\n\n-- 6.2.1\n\nAdderType : (numargs : Nat) -> Type -> Type\nAdderType Z t = t\nAdderType (S k) t = (next : t) -> AdderType k t\n\nadder : Num numType => (numargs : Nat) -> (acc : numType) -> AdderType numargs numType\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (next + acc)\n\nadder1 : (numargs : Nat) -> (acc : Int) -> AdderType numargs Int\nadder1 = adder\n\n-- 6.2.2\n\ndata Format : Type where\n Number : Format -> Format\n Str : Format -> Format\n Lit : String -> Format -> Format\n End : Format\n\nPrintfType : Format -> Type\nPrintfType (Number x) = Int -> PrintfType x\nPrintfType (Str x) = String -> PrintfType x\nPrintfType (Lit x y) = PrintfType y\nPrintfType End = String\n\ntoFormat : 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 l f => Lit (strCons c l) f\n fmt => Lit (strCons c \"\") fmt\n\nprintFmt : (fmt : Format) -> (acc : String) -> PrintfType fmt\nprintFmt (Number x) acc = \\num => printFmt x (acc ++ show num)\nprintFmt (Str x) acc = \\str => printFmt x (acc ++ str)\nprintFmt (Lit x y) acc = printFmt y (acc ++ x)\nprintFmt End acc = acc\n\nprintf : (s : String) -> (PrintfType (toFormat (unpack s)))\nprintf fmt = printFmt (toFormat (unpack fmt)) \"\"\n\nmain : IO ()\nmain = do\n printLn tri\n printLn tri2\n printLn (valToString False \" string \")\n printLn (valToString True 42)\n printLn (adder1 0 10)\n printLn (adder1 1 10 15)\n printLn (adder1 2 1 4 7)\n putStrLn (printf \"Hello!\")\n putStrLn (printf \"Answer : %d\" 42)\n putStrLn (printf \"%s numner %d\" \"Page\" 97)\n", "meta": {"hexsha": "3fd5ce914193362079025d827792df3b5a23374c", "size": 2604, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/tdd/chapter06/01TypeLevelFuns.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/chapter06/01TypeLevelFuns.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/chapter06/01TypeLevelFuns.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": 26.303030303, "max_line_length": 99, "alphanum_fraction": 0.6390168971, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321703143953, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.6798690429887053}} {"text": "module Data.List.Elem.Extra\n\nimport Data.List\nimport Data.List.Elem\n\n%default total\n\n||| Proof that an element is still inside a list if we append to it.\npublic export\nelemAppLeft : (xs, ys : List a) -> (prf : Elem x xs) -> Elem x (xs ++ ys)\nelemAppLeft (x :: xs) ys Here = Here\nelemAppLeft (x :: xs) ys (There prf2) = There $ elemAppLeft xs ys prf2\n\n\n||| Proof that an element is still inside a list if we prepend to it.\npublic export\nelemAppRight : (ys, xs : List a) -> (prf : Elem x xs) -> Elem x (ys ++ xs)\nelemAppRight [] xs prf = prf\nelemAppRight (y :: ys) xs prf = There $ elemAppRight ys xs prf\n\n||| Proof that membership on append implies membership in left or right sublist.\npublic export\nelemAppLorR : (xs, ys : List a)\n -> (prf : Elem k (xs ++ ys))\n -> Either (Elem k xs) (Elem k ys)\nelemAppLorR [] [] prf = absurd prf\nelemAppLorR [] _ prf = Right prf\nelemAppLorR (x :: xs) [] prf =\n Left $ rewrite sym $ appendNilRightNeutral xs in prf\nelemAppLorR (x :: xs) _ Here = Left Here\nelemAppLorR (x :: xs) ys (There prf) = mapFst There $ elemAppLorR xs ys prf\n\n\n||| Proof that x is not in (xs ++ ys) implies proof that x is not in xs.\npublic export\nnotElemAppLeft : (xs, ys : List a)\n -> (prf : Not (Elem x (xs ++ ys)))\n -> Not (Elem x xs)\nnotElemAppLeft xs ys prf = prf . elemAppLeft xs ys\n\n||| Proof that x is not in (xs ++ ys) implies proof that x is not in ys.\npublic export\nnotElemAppRight : (ys, xs : List a)\n -> (prf : Not (Elem x (xs ++ ys)))\n -> Not (Elem x ys)\nnotElemAppRight ys xs prf = prf . elemAppRight xs ys\n", "meta": {"hexsha": "d5c44bbd0ef4a87df4873ee8007d824a77a762e6", "size": 1606, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/List/Elem/Extra.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/contrib/Data/List/Elem/Extra.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/contrib/Data/List/Elem/Extra.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 34.170212766, "max_line_length": 80, "alphanum_fraction": 0.6326276463, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818987, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.679859249588077}} {"text": "> module Functor.Properties\n\n> import Functor.Predicates\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Monotonicity and naturality:\n\n> ||| Composing a monotone measure with a natural transformation\n> ||| yields a monotone measure\n> monotoneNaturalLemma: {B, C : Type} -> {F : Type -> Type} -> (Functor F) => \n> (LTE_B : B -> B -> Type) -> \n> (LTE_C : C -> C -> Type) -> \n> (measure : F B -> C) ->\n> Monotone LTE_B LTE_C measure -> \n> (t : {A : Type} -> F A -> F A) -> \n> Natural t -> \n> Monotone LTE_B LTE_C (measure . t)\n> monotoneNaturalLemma LTE_B LTE_C m mm t nt = mmt where\n> mmt f g p x = let s1 = mm f g p (t x) in\n> let s2 = replace {P = \\ X => m X `LTE_C` m (map g (t x))} (sym (nt f x)) s1 in\n> let s3 = replace {P = \\ X => m (t (map f x)) `LTE_C` m X} (sym (nt g x)) s2 in\n> s3\n\n> {-\n> monotoneNaturalLemma {B} {C} {F} LTE_B LTE_C m mm t nt = mmt where\n> mmt : Monotone {B} {C} {F} LTE_B LTE_C (m . (t {A = B}))\n> mmt = ?lala\n> mmt A f g p x = s3 where\n> s1 : m (map f (t A x)) `LTE_C` m (map g (t A x))\n> s1 = mm A f g p (t A x)\n> s2 : m ((t B) (map f x)) `LTE_C` m (map g (t A x))\n> s2 = replace {P = \\ X => m X `LTE_C` m (map g (t A x))} (sym (nt f x)) s1\n> s3 : m ((t B) (map f x)) `LTE_C` m ((t B) (map g x))\n> s3 = replace {P = \\ X => m ((t B) (map f x)) `LTE_C` m X} (sym (nt g x)) s2\n> ---}\n", "meta": {"hexsha": "e8c53cc5de74eca954ccf03331c85a4b611da0be", "size": 1566, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Functor/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": "Functor/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": "Functor/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": 39.15, "max_line_length": 96, "alphanum_fraction": 0.4642401022, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6797252026797633}} {"text": "import Data.Vect\n\nPosition : Type\nPosition = (Double, Double)\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": "7d6d4847d65ff3518d8d5af54a74b2766e3310a1", "size": 173, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp6/TypeSynonym.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/TypeSynonym.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/TypeSynonym.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": 15.7272727273, "max_line_length": 42, "alphanum_fraction": 0.6184971098, "num_tokens": 67, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6796789399714709}} {"text": "module NonZeroInt\n\n%access public export\n%default total\n%auto_implicits off\n\nrecord NonZeroInt where\n constructor MkNonZeroInt\n num : Int\n nonZero : Not (num = 0)\n\npostulate\nzeroProductProperty : (a, b : Int) -> a * b = 0 -> Either (a = 0) (b = 0)\n \nproductOfNonZeroIsNonZero : NonZeroInt -> NonZeroInt -> NonZeroInt\nproductOfNonZeroIsNonZero (MkNonZeroInt num1 nonZero1) (MkNonZeroInt num2 nonZero2) = MkNonZeroInt (num1 * num2) prf\n where\n prf = \\prodIsZero => case zeroProductProperty num1 num2 prodIsZero of\n Left aIsZero => nonZero1 aIsZero\n Right bIsZero => nonZero2 bIsZero\n", "meta": {"hexsha": "99e9ef372b1e068b928b78c5589e77d05e4cdc64", "size": 600, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/NonZeroInt.idr", "max_stars_repo_name": "marcosh/idris-rationals", "max_stars_repo_head_hexsha": "eb3a8fca148bd2483bc96be15675c24937a95ffe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-13T18:58:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-13T18:58:44.000Z", "max_issues_repo_path": "src/NonZeroInt.idr", "max_issues_repo_name": "marcosh/idris-rationals", "max_issues_repo_head_hexsha": "eb3a8fca148bd2483bc96be15675c24937a95ffe", "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/NonZeroInt.idr", "max_forks_repo_name": "marcosh/idris-rationals", "max_forks_repo_head_hexsha": "eb3a8fca148bd2483bc96be15675c24937a95ffe", "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.5714285714, "max_line_length": 116, "alphanum_fraction": 0.73, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.679602208029791}} {"text": "-- DepPairs.idr\n\n-- Demonstrates dependendent pairs by reading\n-- 2 Vect of variable length\n-- and zip them together\n\n\nimport Data.Vect\n\n||| Reads a Vect of unknown length\nreadVect : IO (len ** Vect len String)\nreadVect = do\n x <- getLine\n if x == \"\"\n then pure (_ ** [])\n else do (_ ** xs) <- readVect\n pure (_ ** x :: xs)\n\n||| Zip to Vect of unknown length\nzipInputs : IO ()\nzipInputs = do putStrLn \"Enter first vector (blank line to end):\"\n (len1 ** vec1) <- readVect\n putStrLn \"Enter second vector (blank line to end):\"\n (len2 ** vec2) <- readVect\n case exactLength len1 vec2 of\n Nothing => putStrLn \"Vectors have different length\"\n Just vec2' => printLn (zip vec1 vec2')\n\n\n\n", "meta": {"hexsha": "edf7f4f01c3ae17b2c88b662f15338826ec041f6", "size": 795, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_5/DepPairs.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/DepPairs.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/DepPairs.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": 25.6451612903, "max_line_length": 71, "alphanum_fraction": 0.572327044, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6795213383003953}} {"text": "data SnocList: List a -> Type where\n Empty: SnocList []\n Snoc: (rec: SnocList xs) -> SnocList (xs ++ [x])\n\nsnocListHelp: (snoc: SnocList input) -> (rest: List a) -> SnocList (input ++ rest)\nsnocListHelp {input} snoc [] = rewrite appendNilRightNeutral input in snoc\nsnocListHelp {input} snoc (x :: xs) =\n rewrite appendAssociative input [x] xs in\n snocListHelp (Snoc snoc) xs\n-- snocListHelp {input} snoc [] = ?noRewrite1 snoc\n-- snocListHelp {input} snoc (x :: xs) = ?noRewrite2 (snocListHelp (Snoc snoc {x}) xs)\n\nsnocList: (xs: List a) -> SnocList xs\nsnocList xs = snocListHelp Empty xs\n\ntotal myReverseHelper: (input: List a) -> SnocList input -> List a\nmyReverseHelper [] Empty = []\nmyReverseHelper (xs ++ [x]) (Snoc rec) = x :: myReverseHelper xs rec\n\ntotal myReverse: List a -> List a\nmyReverse input with (snocList input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (Snoc rec) = x :: myReverse xs | rec\n\ntotal isSuffix: Eq a => List a -> List a -> Bool\nisSuffix input1 input2 with (snocList input1)\n isSuffix [] input2 | Empty = True\n isSuffix (xs ++ [x]) input2 | (Snoc xsrec) with (snocList input2)\n isSuffix (xs ++ [x]) [] | (Snoc xsrec) | Empty = False\n isSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec) =\n if x == y\n then isSuffix xs ys | xsrec | ysrec\n else False\n\nlist100: List Int\nlist100 = [1..100]\n\nsuffix: List Int\nsuffix = [90..100]\n\nnotSuffix: List Int\nnotSuffix = [1..10]\n", "meta": {"hexsha": "1091ff2124fb6562614ec495083650962d745616", "size": 1510, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "SnocList.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": "SnocList.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": "SnocList.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": 35.1162790698, "max_line_length": 86, "alphanum_fraction": 0.621192053, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6794679105917223}} {"text": "module RecRule\n\nrecNat : (x : Type) -> x -> (Nat -> x -> x) -> (Nat -> x)\nrecNat x base step Z = base\nrecNat x base step (S k) = step k (recNat x base step k)\n\nfctl : Nat -> Nat\nfctl = recNat Nat (S Z) step where\n step = \\n: Nat => \\y : Nat => (S n) * y\n\nrecListNat : (x: Type) -> x -> (Nat -> List Nat -> x -> x) -> (List Nat -> x)\nrecListNat x base step [] = base\nrecListNat x base step (y :: xs) = step y xs previous where\n previous = recListNat x base step xs\n\nlsum : List Nat -> Nat\nlsum = recListNat Nat base step where\n base = Z\n step = \\h : Nat => \\t : List Nat => \\accum : Nat => h + accum\n", "meta": {"hexsha": "3a82aa1df158ad8c59b1b80b0f781b52d515e4e9", "size": 603, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/RecRule.idr", "max_stars_repo_name": "AR-MA210/LTS2019", "max_stars_repo_head_hexsha": "28b7bb2bcc9c68915d58b7d03193e1a54fe4b0f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Code/RecRule.idr", "max_issues_repo_name": "AR-MA210/LTS2019", "max_issues_repo_head_hexsha": "28b7bb2bcc9c68915d58b7d03193e1a54fe4b0f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Code/RecRule.idr", "max_forks_repo_name": "AR-MA210/LTS2019", "max_forks_repo_head_hexsha": "28b7bb2bcc9c68915d58b7d03193e1a54fe4b0f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.15, "max_line_length": 77, "alphanum_fraction": 0.5804311774, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947101574298, "lm_q2_score": 0.7185943865443349, "lm_q1q2_score": 0.6790678940332199}} {"text": "myReplace : forall p . (0 rule : x = y) -> (1 val : p y) -> p x\nmyReplace Refl prf = prf\n\nbad : (0 x : Bool) -> Bool\nbad False = True\nbad True = False\n\ndata LT : Nat -> Nat -> Type where\n LeZ : LT Z (S k)\n LeS : LT j k -> LT (S j) (S k)\n\n-- prf isn't used in the run time case tree, so erasure okay\nminus : (x : Nat) -> (y : Nat) -> (0 prf : LT y x) -> Nat\nminus (S k) Z LeZ = S k\nminus (S k) (S j) (LeS p) = minus k j p\n\n-- y is used in the run time case tree, so erasure not okay\nminusBad : (x : Nat) -> (0 y : Nat) -> (0 prf : LT y x) -> Nat\nminusBad (S k) Z LeZ = S k\nminusBad (S k) (S j) (LeS p) = minusBad k j p\n\nprf : {k : _} -> LT k (S (S k))\nprf {k=Z} = LeZ\nprf {k=S _} = LeS prf\n", "meta": {"hexsha": "d833a0a435c5798432bb737b420caa781df40e47", "size": 697, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/basic022/Erase.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/basic022/Erase.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/basic022/Erase.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": 27.88, "max_line_length": 63, "alphanum_fraction": 0.5394548063, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6789610164900749}} {"text": "-- Minimal implicational logic, PHOAS approach, final encoding\n\nmodule Pf.ArrMp\n\n%default total\n\n\n-- Types\n\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n\n\n-- Context and truth judgement\n\nCx : Type\nCx = Ty -> Type\n\nisTrue : Ty -> Cx -> Type\nisTrue a tc = tc a\n\n\n-- Terms\n\nTmRepr : Type\nTmRepr = Cx -> Ty -> Type\n\ninfixl 1 :$\nclass ArrMpTm (tr : TmRepr) where\n var : isTrue a tc -> tr tc a\n lam' : (isTrue a tc -> tr tc b) -> tr tc (a :=> b)\n (:$) : tr tc (a :=> b) -> tr tc a -> tr tc b\n\nlam'' : {tr : TmRepr} -> ArrMpTm tr => (tr tc a -> tr tc b) -> tr tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\n\nThm : Ty -> Type\nThm a = {tr : TmRepr} -> {tc : Cx} -> ArrMpTm tr => tr tc a\n\n\n-- Example theorems\n\naI : Thm (a :=> a)\naI =\n lam x :=> x\n\naK : Thm (a :=> b :=> a)\naK =\n lam x :=>\n lam y :=> x\n\naS : Thm ((a :=> b :=> c) :=> (a :=> b) :=> a :=> c)\naS =\n lam f :=>\n lam g :=>\n lam x :=> f :$ x :$ (g :$ x)\n\n-- TODO:\n-- ./src/Pf/ArrMp.idr:63:6:When checking right hand side of tSKK:\n-- Can't resolve type class ArrMpTm tr\n-- tSKK : Thm (a :=> a)\n-- tSKK {a} =\n-- aS {b = a :=> a} :$ aK :$ aK\n", "meta": {"hexsha": "83a75575ccfcba3f7644a66408c3082457d56f9f", "size": 1210, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pf/ArrMp.idr", "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": ["X11"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_issues_repo_path": "src/Pf/ArrMp.idr", "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_licenses": ["X11"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Pf/ArrMp.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": 17.7941176471, "max_line_length": 78, "alphanum_fraction": 0.4801652893, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6786537661905708}} {"text": "module Data.Fin\n\nimport public Data.Maybe\nimport Data.Nat\nimport Decidable.Equality\n\n%default total\n\n||| Numbers strictly less than some bound. The name comes from \"finite sets\".\n|||\n||| It's probably not a good idea to use `Fin` for arithmetic, and they will be\n||| exceedingly inefficient at run time.\n||| @ n the upper bound\npublic export\ndata Fin : (n : Nat) -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\nexport\nUninhabited (Fin Z) where\n uninhabited FZ impossible\n uninhabited (FS f) impossible\n\nexport\nUninhabited (FZ = FS k) where\n uninhabited Refl impossible\n\nexport\nUninhabited (FS k = FZ) where\n uninhabited Refl impossible\n\nexport\nfsInjective : FS m = FS n -> m = n\nfsInjective Refl = Refl\n\nexport\nEq (Fin n) where\n (==) FZ FZ = True\n (==) (FS k) (FS k') = k == k'\n (==) _ _ = False\n\n||| Convert a Fin to a Nat\npublic export\nfinToNat : Fin n -> Nat\nfinToNat FZ = Z\nfinToNat (FS k) = S $ finToNat k\n\n||| `finToNat` is injective\nexport\nfinToNatInjective : (fm : Fin k) -> (fn : Fin k) -> (finToNat fm) = (finToNat fn) -> fm = fn\nfinToNatInjective FZ FZ _ = Refl\nfinToNatInjective (FS _) FZ Refl impossible\nfinToNatInjective FZ (FS _) Refl impossible\nfinToNatInjective (FS m) (FS n) prf =\n cong FS $ finToNatInjective m n $ succInjective (finToNat m) (finToNat n) prf\n\nexport\nCast (Fin n) Nat where\n cast = finToNat\n\n||| Convert a Fin to an Integer\npublic export\nfinToInteger : Fin n -> Integer\nfinToInteger FZ = 0\nfinToInteger (FS k) = 1 + finToInteger k\n\nexport\nCast (Fin n) Integer where\n cast = finToInteger\n\n||| Weaken the bound on a Fin by 1\npublic export\nweaken : Fin n -> Fin (S n)\nweaken FZ = FZ\nweaken (FS k) = FS $ weaken k\n\n||| Weaken the bound on a Fin by some amount\npublic export\nweakenN : (n : Nat) -> Fin m -> Fin (m + n)\nweakenN n FZ = FZ\nweakenN n (FS f) = FS $ weakenN n f\n\n||| Weaken the bound on a Fin using a constructive comparison\npublic export\nweakenLTE : Fin n -> LTE n m -> Fin m\nweakenLTE FZ LTEZero impossible\nweakenLTE (FS _) LTEZero impossible\nweakenLTE FZ (LTESucc _) = FZ\nweakenLTE (FS x) (LTESucc y) = FS $ weakenLTE x y\n\n||| Attempt to tighten the bound on a Fin.\n||| Return `Left` if the bound could not be tightened, or `Right` if it could.\nexport\nstrengthen : {n : _} -> Fin (S n) -> Either (Fin (S n)) (Fin n)\nstrengthen {n = S _} FZ = Right FZ\nstrengthen {n = S _} (FS i) with (strengthen i)\n strengthen (FS _) | Left x = Left $ FS x\n strengthen (FS _) | Right x = Right $ FS x\nstrengthen f = Left f\n\n||| Add some natural number to a Fin, extending the bound accordingly\n||| @ n the previous bound\n||| @ m the number to increase the Fin by\npublic export\nshift : (m : Nat) -> Fin n -> Fin (m + n)\nshift Z f = f\nshift (S m) f = FS $ shift m f\n\n||| The largest element of some Fin type\npublic export\nlast : {n : _} -> Fin (S n)\nlast {n=Z} = FZ\nlast {n=S _} = FS last\n\nexport\nOrd (Fin n) where\n compare FZ FZ = EQ\n compare FZ (FS _) = LT\n compare (FS _) FZ = GT\n compare (FS x) (FS y) = compare x y\n\npublic export\nnatToFin : Nat -> (n : Nat) -> Maybe (Fin n)\nnatToFin Z (S _) = Just FZ\nnatToFin (S k) (S j)\n = case natToFin k j of\n Just k' => Just (FS k')\n Nothing => Nothing\nnatToFin _ _ = Nothing\n\n||| Convert an `Integer` to a `Fin`, provided the integer is within bounds.\n||| @n The upper bound of the Fin\npublic export\nintegerToFin : Integer -> (n : Nat) -> Maybe (Fin n)\nintegerToFin x Z = Nothing -- make sure 'n' is concrete, to save reduction!\nintegerToFin x n = if x >= 0 then natToFin (fromInteger x) n else Nothing\n\n||| Allow overloading of Integer literals for Fin.\n||| @ x the Integer that the user typed\n||| @ prf an automatically-constructed proof that `x` is in bounds\npublic export\nfromInteger : (x : Integer) -> {n : Nat} ->\n {auto prf : (IsJust (integerToFin x n))} ->\n Fin n\nfromInteger {n} x {prf} with (integerToFin x n)\n fromInteger {n} x {prf = ItIsJust} | Just y = y\n\n||| Convert an Integer to a Fin in the required bounds/\n||| This is essentially a composition of `mod` and `fromInteger`\npublic export\nrestrict : (n : Nat) -> Integer -> Fin (S n)\nrestrict n val = let val' = assert_total (abs (mod val (cast (S n)))) in\n -- reasoning about primitives, so we need the\n -- 'believe_me'. It's fine because val' must be\n -- in the right range\n fromInteger {n = S n} val'\n {prf = believe_me {a=IsJust (Just val')} ItIsJust}\n\n--------------------------------------------------------------------------------\n-- DecEq\n--------------------------------------------------------------------------------\n\nexport\nDecEq (Fin n) where\n decEq FZ FZ = Yes Refl\n decEq FZ (FS f) = No absurd\n decEq (FS f) FZ = No absurd\n decEq (FS f) (FS f')\n = case decEq f f' of\n Yes p => Yes $ cong FS p\n No p => No $ p . fsInjective\n", "meta": {"hexsha": "51e2bcf133056f27e81719ddf5310f49c1e47664", "size": 4962, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/Fin.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/libs/base/Data/Fin.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/libs/base/Data/Fin.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8488372093, "max_line_length": 92, "alphanum_fraction": 0.6098347441, "num_tokens": 1568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6782018325418061}} {"text": "module Data.Morphisms\n\npublic export\nrecord Morphism a b where\n constructor Mor\n applyMor : a -> b\n\ninfixr 1 ~>\n\npublic export\n(~>) : Type -> Type -> Type\n(~>) = Morphism\n\npublic export\nrecord Endomorphism a where\n constructor Endo\n applyEndo : a -> a\n\npublic export\nrecord Kleislimorphism (f : Type -> Type) a b where\n constructor Kleisli\n applyKleisli : a -> f b\n\nexport\nFunctor (Morphism r) where\n map f (Mor a) = Mor $ f . a\n\nexport\nApplicative (Morphism r) where\n pure a = Mor $ const a\n (Mor f) <*> (Mor a) = Mor $ \\r => f r $ a r\n\nexport\nMonad (Morphism r) where\n (Mor h) >>= f = Mor $ \\r => applyMor (f $ h r) r\n\nexport\nSemigroup a => Semigroup (Morphism r a) where\n f <+> g = Mor $ \\r => (applyMor f) r <+> (applyMor g) r\n\nexport\nMonoid a => Monoid (Morphism r a) where\n neutral = Mor \\r => neutral\n\nexport\nSemigroup (Endomorphism a) where\n (Endo f) <+> (Endo g) = Endo $ g . f\n\nexport\nMonoid (Endomorphism a) where\n neutral = Endo id\n\nexport\nFunctor f => Functor (Kleislimorphism f a) where\n map f (Kleisli g) = Kleisli (map f . g)\n\nexport\nApplicative f => Applicative (Kleislimorphism f a) where\n pure a = Kleisli $ const $ pure a\n (Kleisli f) <*> (Kleisli a) = Kleisli $ \\r => f r <*> a r\n\nexport\nMonad f => Monad (Kleislimorphism f a) where\n (Kleisli f) >>= g = Kleisli $ \\r => do\n k1 <- f r\n applyKleisli (g k1) r\n\n-- Applicative is a bit too strong, but there is no suitable superclass\nexport\n(Semigroup a, Applicative f) => Semigroup (Kleislimorphism f r a) where\n f <+> g = Kleisli \\r => (<+>) <$> (applyKleisli f) r <*> (applyKleisli g) r\n\nexport\n(Monoid a, Applicative f) => Monoid (Kleislimorphism f r a) where\n neutral = Kleisli \\r => pure neutral\n\nexport\nCast (Endomorphism a) (Morphism a a) where\n cast (Endo f) = Mor f\n\nexport\nCast (Morphism a a) (Endomorphism a) where\n cast (Mor f) = Endo f\n\nexport\nCast (Morphism a (f b)) (Kleislimorphism f a b) where\n cast (Mor f) = Kleisli f\n\nexport\nCast (Kleislimorphism f a b) (Morphism a (f b)) where\n cast (Kleisli f) = Mor f\n", "meta": {"hexsha": "8fb22d9704cac53226bcc214675bf4cff0626c7e", "size": 2023, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/Morphisms.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/libs/base/Data/Morphisms.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/libs/base/Data/Morphisms.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": 21.9891304348, "max_line_length": 77, "alphanum_fraction": 0.6515076619, "num_tokens": 733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6779220006215494}} {"text": "module Exercises.Chapter7\n\nimport Exercises.Chapter4 -- For Shape\n\n%access public export\n\n\n-- Exercise 7.1.6.1\n\nEq Shape where\n (==) (Triangle b1 h1) (Triangle b2 h2) = b1 == b2 && h1 == h2\n (==) (Triangle _ _) _ = False\n (==) (Rectangle w1 h1) (Rectangle w2 h2) = w1 == w2 && h1 == h2\n (==) (Rectangle _ _) _ = False\n (==) (Circle r1) (Circle r2) = r1 == r2\n (==) (Circle _) _ = False\n\n\n-- Exercise 7.1.6.2\n\nOrd Shape where\n compare x y = compare (area x) (area y)\n\n\ndata 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 : (Integral num, Neg 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\n fromInteger = Val . fromInteger\n\nNeg ty => Neg (Expr ty) where\n negate x = 0 - x\n (-) = Sub\n abs = Abs\n\nCast (Maybe elem) (List elem) where\n cast Nothing = []\n cast (Just x) = [x]\n\n\n-- Exercise 7.2.4.1\n\nShow num => Show (Expr num) 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\n-- Exercise 7.2.4.2\n\n(Eq num, Integral num, Neg num) => Eq (Expr num) where\n (==) x y = eval x == eval y\n\n-- textExprEq1 : True = the (Expr _) (2 + 4) == 3 + 3\n-- textExprEq2 : False = the (Expr _) (2 + 4) == 3 + 4\n\n\n-- Exercise 7.2.4.3\n\n(Integral num, Neg num) => Cast (Expr num) num where\n cast = eval\n\n\n-- Exercise 7.3.4.1\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\n\n-- Exercise 7.3.4.2\n\nnamespace MyVect\n data Vect : Nat -> Type -> Type where\n Nil : Vect 0 a\n (::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a\n\n Eq a => Eq (Vect n a) where\n (==) [] [] = True\n (==) (x::xs) (y::ys) = (x == y) && (xs == ys)\n\n Foldable (Vect n) where\n foldl _ z [] = z\n foldl f z (x::xs) = foldl f (f z x) xs\n foldr _ z [] = z\n foldr f z (x::xs) = f x $ foldr f z xs\n", "meta": {"hexsha": "9a82dd9205d473e0b8ea9ebac4f28b7fec1c72aa", "size": 2651, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Exercises/Chapter7.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/Chapter7.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/Chapter7.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": 24.3211009174, "max_line_length": 65, "alphanum_fraction": 0.4832138816, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.677678712573096}} {"text": "module PLFI.Part1.Naturals\n\n-- https://plfa.gihub.io/Naturals\n\ndata Vect : Nat -> (t : Type) -> Type where\n Nil : Vect 0 t\n (::) : (x : t) -> Vect n t -> Vect (1 + n) t\n\nreplicate : Nat -> t -> List t\n\nreplicateV : (n : Nat) -> t -> Vect n t\nreplicateV 0 x = []\nreplicateV (S k) x = x :: replicateV k x\n\n%hide (+)\n%hide (*)\n\n-- %default total\n\n-- data N0 = Zero | Suc N0\n\n{-\n----------- Zero\n Zero : N\n\n m : N\n----------- Suc\n Suc m : N\n-}\n\npublic export\ndata N : Type where\n\n -- Base case\n Zero :\n --------\n N\n\n -- Inductive case\n Suc :\n (m : N) ->\n ----------\n N\n\nexport\nNum N where\n (*) = ?m1\n (+) = ?a1\n fromInteger n with (compare n 0)\n fromInteger n | LT = Zero\n fromInteger n | EQ = Zero\n fromInteger n | GT = Suc (assert_total (fromInteger (n-1)))\n\nex1 : N\nex1 = Suc (Suc (Suc (Suc (Suc (Suc (Suc Zero))))))\n\ntest : N\ntest = (-7)\n\ntotal\npublic export\n(+) : N -> N -> N\nZero + m = m\n(Suc n) + m = Suc (n + m)\n\nexport\naddEquation1 : {n : N} -> (Zero + n) = n -- Refl : Equal x x\naddEquation1 = Refl\n\nexport\naddEquation2 : (Suc m) + n = Suc (m + n)\naddEquation2 = Refl\n\ntotal\npublic export\n(*) : N -> N -> N\nZero * n = Zero\n(Suc m) * n = n + (m * n)\n\n-- N -> Zero * ? = Zero\nmultEquation0 : {n : N} -> Zero * n = Zero\n-- test :: Maybe (Maybe Int)\n-- test : Maybe $ Maybe Int\n-- test : (n : Nat) -> let m = n + n in Vect m Int\n\n\nexport\nmultEquation1 : Zero * n = Zero\nmultEquation1 = Refl\n\nexport\nmultEquation2 : (Suc m) * n = n + (m * n)\nmultEquation2 = Refl\n\ninfixr 8 ^\n\n-- Exercise: recommended\n\ntotal\nexport\n(^) : N -> N -> N\nm ^ Zero = Suc Zero\nm ^ (Suc n) = m * (m ^ n)\n\n-- m ^ 0 = 1\n-- m ^ (1 + n) = m * (m ^ n)\n\nexport\nexpEquation1 : m ^ Zero = Suc Zero\nexpEquation1 = Refl\n\nexport\nexpEquation2 : m ^ (Suc n) = m * (m ^ n)\nexpEquation2 = Refl\n\n-- monus\n\ninfixl 6 -*\n\ntotal\nexport\n(-*) : N -> N -> N\nm -* Zero = m\nZero -* (Suc n) = Zero\n(Suc m) -* (Suc n) = m -* n\n\n-- Exercise: strech\n\npublic export\ndata Bin : Type where\n E : Bin\n O : Bin -> Bin\n I : Bin -> Bin\n\n-- 1101 is encoded as\n-- IOIIE this needs to be read reversed:\n-- EIIOI\n\nexport\ninc : Bin -> Bin\n\nexport\nto : N -> Bin\n\nexport\nfrom : Bin -> N\n", "meta": {"hexsha": "522316922d42d231c57b32cac1be3ebe20c7d629", "size": 2204, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "PLFI/Part1/Naturals.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/Naturals.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/Naturals.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": 14.9931972789, "max_line_length": 64, "alphanum_fraction": 0.52676951, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6772097162110018}} {"text": "module Data.VectorSpace\n\nimport Data.Vect\n\ninfixr 9 *^\ninfixl 9 ^/\ninfixl 6 ^+^, ^-^\ninfix 7 `dot`\n\npublic export\ninterface VectorSpace v where\n ||| Vector with no magnitude (unit for addition).\n zeroVector : v\n\n ||| Multiplication by a scalar.\n (*^) : Double -> v -> v\n\n ||| Division by a scalar.\n (^/) : v -> Double -> v\n\n ||| Vector addition\n (^+^) : v -> v -> v\n\n ||| Vector subtraction\n (^-^) : v -> v -> v\n\n ||| Vector negation. Addition with a negated vector should\n ||| be same as subtraction.\n negateVector : v -> v\n negateVector v = zeroVector ^-^ v\n\n ||| Dot product (also known as scalar or inner product).\n ||| For two vectors, mathematically represented as a = a1,a2,...,an and b = b1,b2,...,bn,\n ||| the dot product is a . b = a1*b1 + a2*b2 + ... + an*bn.\n dot : v -> v -> Double\n\n ||| Vector's norm (also known as magnitude).\n ||| For a vector represented mathematically\n ||| as a = a1,a2,...,an, the norm is the square root of a1^2 + a2^2 + ... + an^2.\n norm : v -> Double\n norm v = sqrt $ dot v v\n\n ||| Return a vector with the same origin and orientation (angle),\n ||| but such that the norm is one (the unit for multiplication by a scalar).\n normalize : v -> v\n normalize v = let n = norm v in if n == 0 then v else v ^/ n\n\n--------------------------------------------------------------------------------\n-- Implementations\n--------------------------------------------------------------------------------\n\npublic export\nVectorSpace Double where\n zeroVector = 0.0\n (^-^) = (-)\n (^+^) = (+)\n (^/) = (/)\n (*^) = (*)\n dot = (*)\n\npublic export\n{n : _} -> VectorSpace (Vect n Double) where\n zeroVector = replicate n 0.0\n (^-^) = zipWith (-)\n (^+^) = zipWith (+)\n v ^/ s = map (/ s) v\n s *^ v = map (* s) v\n dot a b = sum $ zipWith (*) a b\n", "meta": {"hexsha": "1654dfa51afd9e2fba79ed08ce06e814597ffb9b", "size": 1811, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/VectorSpace.idr", "max_stars_repo_name": "stefan-hoeck/idris2-rhone", "max_stars_repo_head_hexsha": "be8f65a096cfb17f62282df45b1a3f6617138438", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-07-25T08:43:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T23:21:44.000Z", "max_issues_repo_path": "src/Data/VectorSpace.idr", "max_issues_repo_name": "stefan-hoeck/idris2-rhone", "max_issues_repo_head_hexsha": "be8f65a096cfb17f62282df45b1a3f6617138438", "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/VectorSpace.idr", "max_forks_repo_name": "stefan-hoeck/idris2-rhone", "max_forks_repo_head_hexsha": "be8f65a096cfb17f62282df45b1a3f6617138438", "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.2463768116, "max_line_length": 91, "alphanum_fraction": 0.5196024296, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6772028956474612}} {"text": "-- exercises in \"Type-Driven Development with Idris\"\n-- chapter 7\n\n-- check that all functions are total\n%default total\n\n--\n-- Expressions\n--\ndata 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, Abs 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 num => Num (Expr num) where\n (+) = Add\n (*) = Mul\n fromInteger = Val . fromInteger\n\nNeg num => Neg (Expr num) where\n negate x = 0 - x\n (-) = Sub\n\nAbs num => Abs (Expr num) where\n abs = Abs\n\nshowHelper : Show a => String -> a -> a -> String\nshowHelper op x y = \"(\" ++ show x ++ op ++ show y ++ \")\"\n\nShow num => Show (Expr num) where\n show (Val x) = show x\n show (Add x y) = showHelper \" + \" x y\n show (Sub x y) = showHelper \" - \" x y\n show (Mul x y) = showHelper \" * \" x y\n show (Div x y) = showHelper \" `div`\" x y\n show (Abs x) = \"(\" ++ \"abs \" ++ show x ++ \")\"\n\n(Neg num, Integral num, Abs num, Eq num) => Eq (Expr num) where\n (==) x y = (eval x) == (eval y)\n\n(Neg num, Integral num, Abs num) => Cast (Expr num) num where\n cast orig = eval orig\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": "2bf531787cbdd5194338a7818ee0db785baaf915", "size": 1674, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter7/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": "chapter7/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": "chapter7/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": 27.4426229508, "max_line_length": 63, "alphanum_fraction": 0.5591397849, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.677186239369435}} {"text": "data BSTree : Type -> Type where\n Empty : Ord elem => BSTree elem\n Node : Ord elem => (left : BSTree elem) -> (val : elem) ->\n (right : BSTree elem) -> BSTree elem\n\n%name BSTree tree, tree1\n\ninsert : elem -> BSTree elem -> BSTree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left val right) = case compare x val of\n LT => Node (insert x left) val right\n EQ => orig\n GT => Node left val (insert x right)\n\nlistToTree : Ord a => List a -> BSTree a\nlistToTree [] = Empty\nlistToTree (x :: xs) = insert x (listToTree xs)\n\ntreeToList : BSTree a -> List a\ntreeToList Empty = []\ntreeToList (Node left val right) = treeToList left ++ [val] ++ treeToList right\n", "meta": {"hexsha": "3b8b50375b8d01cfd1b9144d99a466d2d854a155", "size": 799, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/Tree.idr", "max_stars_repo_name": "DimaSamoz/idris-book", "max_stars_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter4/Tree.idr", "max_issues_repo_name": "DimaSamoz/idris-book", "max_issues_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter4/Tree.idr", "max_forks_repo_name": "DimaSamoz/idris-book", "max_forks_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3181818182, "max_line_length": 79, "alphanum_fraction": 0.5581977472, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6767151306533777}} {"text": "module Vec3\n\n%access export\n\npublic export\n-- To RECORD ?\nVec3 : Type\nVec3 = (Double, Double, Double)\n\ntoColor : Int -> Int -> Double\ntoColor value size = 255.999 * (cast value / cast size)\n\ngetX : Vec3 -> Double\ngetX (x, _, _) = x\n\ngetY : Vec3 -> Double\ngetY (_, y, _) = y\n\ngetZ : Vec3 -> Double\ngetZ (_, _, z) = z\n\n(+) : Vec3 -> Vec3 -> Vec3\n(+) (x1, y1, z1) (x2, y2, z2) = (x1 + x2, y1 + y2, z1 + z2)\n\n(-) : Vec3 -> Vec3 -> Vec3\n(-) (x1, y1, z1) (x2, y2, z2) = (x1 - x2, y1 - y2, z1 - z2)\n\n-- (*) : Vec3 -> Vec3 -> Vec3\n-- (*) (x1, y1, z1) (x2, y2, z2) = (x1 * x2, y1 * y2, z1 * z2)\n\n(*) : Double -> Vec3 -> Vec3\n(*) t (x2, y2, z2) = (t * x2, t * y2, t * z2)\n\n(/) : Vec3 -> Double -> Vec3\n(/) v t = (1 / t) * v\n\ndot : Vec3 -> Vec3 -> Double\ndot (x1, y1, z1) (x2, y2, z2) = x1 * x2 + y1 * y2 + z1 * z2\n\nlength : Vec3 -> Double\nlength (x, y, z) = sqrt (x*x + y*y + z*z)\n\nlengthSquared : Vec3 -> Double\nlengthSquared (x, y, z) = x*x + y*y + z*z\n\nunitVector : Vec3 -> Vec3\nunitVector v = v / Vec3.length v\n\nvecToStr : Vec3 -> String\nvecToStr (x, y, z) = concat [show $ cast {to=Int} x, \" \", show $ cast {to=Int} y, \" \", show $ cast {to=Int} z]\n", "meta": {"hexsha": "b25b8daaf236fd62dc0104a47f0d236a288430ab", "size": 1143, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Vec3.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": "Vec3.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": "Vec3.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": 22.4117647059, "max_line_length": 110, "alphanum_fraction": 0.52055993, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6766097951969084}} {"text": "module Shape\n\npublic export\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\nprivate\nrectangle_area : Double -> Double -> Double\nrectangle_area width height = width * height\n\nexport\narea : Shape -> Double\narea (Triangle base height) = 0.5 * rectangle_area base height\narea (Rectangle length height) = rectangle_area length height\narea (Circle radius) = pi * radius * radius\n", "meta": {"hexsha": "6a3c6288170ca169272112b09a221f4ed0cfa29a", "size": 426, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/typedd-book/chapter10/Shape.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "tests/typedd-book/chapter10/Shape.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "tests/typedd-book/chapter10/Shape.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": 25.0588235294, "max_line_length": 62, "alphanum_fraction": 0.7276995305, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070158103777, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6762137849623239}} {"text": "import NewEden.Natural\n\n{- Natural Theorems\n \n Basic theorems about the natural numbers expressed in\n terms of operations on Natural p.\n \n-}\n\naddToBothSides : (n : Natural p) -> a = b -> a + n = b + n\naddToBothSides _ Refl = Refl\n\naddRemoveBothSides : (n : Natural p) -> n + a = n + b -> a = b\naddRemoveBothSides {a} {b} n prf =\n let (MkMonomorphicFunction _ mono) = plusMonomorphic p n in\n mono a b prf\n\nmultiplyBothSidesBy : (n : Natural p) -> a = b -> a * n = b * n\nmultiplyBothSidesBy _ Refl = Refl\n\nmultiplyRemoveBothSides : (n : Natural p) -> n * a = n * b -> a = b\nmultiplyRemoveBothSides {a} {b} n prf =\n let (MkMonomorphicFunction _ mono) = multiplyMonomorphic p n in\n mono a b prf\n\npluscom : {a:Natural p}\n -> a + b = c -> b + a = c\npluscom {p} {a} {b} given =\n let (MkCommutativeFunction _ prf) = plusCommutative p in\n let apply = prf b a in\n transitivity apply given\n\nplusass : {a:Natural p}\n -> a + (b + c) = d -> a + b + c = d\nplusass {p} {a} {b} {c} given =\n let (MkAssociativeFunction _ prf) = plusAssociative p in\n let apply = prf a b c in\n transitivity (symmetric apply) given\n\nplusass' : {a:Natural p}\n -> a + b + c = d -> a + (b + c) = d\nplusass' {p} {a} {b} {c} given =\n let (MkAssociativeFunction _ prf) = plusAssociative p in\n let apply = prf a b c in\n transitivity apply given\n\nmultcom : {a : Natural p}\n -> a * b = c -> b * a = c\nmultcom {p} {a} {b} given =\n let (MkCommutativeFunction _ prf) = multiplyCommutative p in\n let apply = prf b a in\n transitivity apply given\n\nmultass : {a : Natural p}\n -> a * (b * c) = d -> a * b * c = d\nmultass {p} {a} {b} {c} given =\n let (MkAssociativeFunction _ prf) = multiplyAssociative p in\n let apply = prf a b c in\n transitivity (symmetric apply) given\n \nmultass' : {a : Natural p}\n -> a * b * c = d -> a * (b * c) = d\nmultass' {p} {a} {b} {c} given =\n let (MkAssociativeFunction _ prf) = multiplyAssociative p in\n let apply = prf a b c in\n transitivity apply given\n\nnothingIsLessThanZero : (a:Natural p) -> LessThan a 0 -> Void\nnothingIsLessThanZero {p} a (MkLessThan a (Z p) (c ** (prf,cNonZero))) =\n let (MkCommutativeFunction _ comm) = NewEden.Natural.plusCommutative p in\n let equation = symmetric $ comm a c in\n let cPlusAIsZero = transitivity equation prf in\n let (MkStrictMonoid _ noInverses) = NewEden.Natural.plusLacksInverses p in \n let cIsZero = noInverses c a cPlusAIsZero in\n cNonZero cIsZero\n\nlessThanImpliesNotEqual : (a:Natural p) -> (b:Natural p) -> LessThan a b -> a = b -> Void\nlessThanImpliesNotEqual a b (MkLessThan a b (c ** (aPlusCIsB,cNonZero))) aEqualsb =\n let step = symmetric aPlusCIsB in\n let step2 = transitivity aEqualsb step in\n let (MkMonoid _ _ mn _) = plusMonoid p in\n let step3 = mn a in\n let step4 = transitivity step3 step2 in\n let mono = plusMonomorphic p in\n let (MkMonomorphicFunction ((+) a) monoprf) = mono a in\n let fin = monoprf 0 c in\n let cIsZero = fin step4 in\n cNonZero $ symmetric cIsZero\n\nlessThanNotSymmetric : {a:Natural p} -> {b:Natural p} -> LessThan a b -> LessThan b a -> Void\nlessThanNotSymmetric {p} (MkLessThan a b (c1 ** (prf1,c1NonZero))) (MkLessThan b a (c2 ** (prf2,c2NonZero))) =\n let (MkCommutativeFunction _ comm) = plusCommutative p in\n let (MkMonoid _ _ mon _) = plusMonoid p in\n let (MkMonomorphicFunction _ mono) = plusMonomorphic p $ b in\n let (MkAssociativeFunction _ ass) = plusAssociative p in\n let comm' = symmetric $ comm a c1 in\n let s1 = substitution ((+) c1) (symmetric prf2) (transitivity comm' prf1) in\n let s2 = symmetric $ comm c1 (b + c2) in\n let s3 = transitivity s2 s1 in\n let but4 = mon b in\n let so5 = transitivity but4 $ symmetric s3 in\n let byMono = mono 0 (c2 + c1) in\n let ass' = ass b c2 c1 in\n let prepare = transitivity so5 (symmetric ass') in\n let therefore = byMono prepare in\n let but6 = mon c2 in\n let (MkMonomorphicFunction _ monoc2) = plusMonomorphic p $ c2 in\n let monoapp = monoc2 0 c1 in\n let (MkStrictMonoid _ noInverses) = plusLacksInverses p in\n let so6 = noInverses c2 c1 in\n let c2IsZero = so6 (symmetric therefore) in\n c2NonZero c2IsZero\n\nlessThanIsTransitive : {x:Natural p} -> {y:Natural p} -> {z:Natural p} ->\n LessThan x y -> LessThan y z -> LessThan x z\nlessThanIsTransitive {p} (MkLessThan x y (c1 ** (eq1,c1NonZero))) (MkLessThan y z (c2 ** (eq2,c2NonZero)))=\n case compare x z of\n Left prf => prf\n Middle xIsZ =>\n let sub = pluscom $ substitution ((+) c1) xIsZ (pluscom eq1) in\n let zLessThany = MkLessThan z y (c1 ** (sub,c1NonZero)) in\n let yLessThanz = MkLessThan y z (c2 ** (eq2,c2NonZero)) in\n absurd $ lessThanNotSymmetric yLessThanz zLessThany\n Right (MkLessThan z x (c3 ** (eq3,c3NonZero))) =>\n let sub = substitution ((+) c1) (symmetric eq3) (pluscom eq1) in\n let s0 = pluscom sub in\n let c4 = c3 + c1 in\n let c4e:(c4 = c3 + c1) = Refl in\n let (MkStrictMonoid _ noInverses) = plusLacksInverses p in\n let c4nz = (\\c4z => c3NonZero $ noInverses c3 c1 c4z) in\n let s1 = plusass' s0 in\n let zlty = MkLessThan z y ((c3+c1) ** (s1,c4nz)) in\n let yltz = MkLessThan y z (c2 ** (eq2,c2NonZero)) in\n absurd $ lessThanNotSymmetric zlty yltz\n\nlessThanAdditionWeakened : LessThan x y -> (z : Natural p) -> LessThan x (y + z)\nlessThanAdditionWeakened {p} {x} {y} (MkLessThan x y (c ** (xpyic,cNotZero))) z =\n let (MkStrictMonoid _ noinv) = plusLacksInverses p in\n let cPlusZIsZeroImpliesCIsZero = noinv c z in\n let cPlusZNotZero = (\\sumZero => cNotZero $ cPlusZIsZeroImpliesCIsZero sumZero) in\n let target = addToBothSides z xpyic in\n let target' = plusass' target in\n MkLessThan x (y + z) ((c + z) ** (target',cPlusZNotZero))\n\n", "meta": {"hexsha": "ff6fbd8d3582c58b393b13b8a11aeadcb1da066c", "size": 5725, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/NewEden/NaturalTheorems.idr", "max_stars_repo_name": "identicalsnowflake/neweden", "max_stars_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-07T15:26:51.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-07T15:26:51.000Z", "max_issues_repo_path": "src/NewEden/NaturalTheorems.idr", "max_issues_repo_name": "identicalsnowflake/neweden", "max_issues_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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/NewEden/NaturalTheorems.idr", "max_forks_repo_name": "identicalsnowflake/neweden", "max_forks_repo_head_hexsha": "d4156eafa5453d9911d5667fb323e3ef75d3264f", "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.4827586207, "max_line_length": 110, "alphanum_fraction": 0.6565938865, "num_tokens": 2101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.676197145078393}} {"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-- Binary Search Trees\n--\n\n||| A binary search tree.\ndata BST : Type -> Type where\n ||| An empty tree.\n Empty : Ord elem =>\n BST elem\n ||| A node with a value, a left subtree, and a right subtree.\n ||| Elements in the left subtree must be strictly lower than the value.\n ||| Elements in the right subtree must be strictly greater than the value.\n Node : Ord elem =>\n (left : BST elem) ->\n (val : elem) ->\n (right : BST elem) ->\n BST elem\n\n||| insert a value in a binary search tree\ninsert : elem -> BST elem -> BST elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left val right)\n = case compare x val of\n LT => Node (insert x left) val right\n EQ => orig\n GT => Node left val (insert x right)\n\nlistToTree : Ord a => List a -> BST a\nlistToTree [] = Empty\nlistToTree (x :: xs) = insert x $ listToTree xs\n\ntreeToList : BST a -> List a\ntreeToList Empty = []\ntreeToList (Node left val right) = treeToList left ++ [val] ++ treeToList right\n", "meta": {"hexsha": "00ba55b4b54aadec819798a8ed99a304dd27dc66", "size": 1133, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter4/BSTree.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/BSTree.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/BSTree.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": 27.6341463415, "max_line_length": 79, "alphanum_fraction": 0.6372462489, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6761505901059646}} {"text": "module Data.Vect.Extra\n\nimport Data.Vect\n\n%access export\n%default total\n\nnamespace Equality\n vecEq : Eq type => Vect n type -> Vect m type -> Bool\n vecEq [] [] = True\n vecEq [] (x :: xs) = False\n vecEq (x :: xs) [] = False\n vecEq (x :: xs) (y :: ys) = x == y && vecEq xs ys\n\nnamespace Decidable\n namespace SameLength\n decEq : DecEq type\n => (n = m)\n -> (xs : Vect n type)\n -> (ys : Vect m type)\n -> Dec (xs = ys)\n decEq Refl xs ys with (decEq xs ys)\n decEq Refl ys ys | (Yes Refl) = Yes Refl\n decEq Refl xs ys | (No contra) = No contra\n\n namespace DiffLength\n\n vectorsDiffLength : DecEq type\n => (contra : (n = m) -> Void)\n -> {xs : Vect n type}\n -> {ys : Vect m type}\n -> (xs = ys) -> Void\n vectorsDiffLength contra Refl = contra Refl\n\n decEq : DecEq type\n => (xs : Vect n type)\n -> (ys : Vect m type)\n -> Dec (xs = ys)\n decEq xs ys {n} {m} with (decEq n m)\n decEq xs ys {n = m} {m = m} | (Yes Refl) = decEq Refl xs ys\n decEq xs ys {n = n} {m = m} | (No contra) = No (vectorsDiffLength contra)\n", "meta": {"hexsha": "c1fb24d06d848c7dc91f8953524a1ee140a7eb6e", "size": 1189, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Vect/Extra.idr", "max_stars_repo_name": "witt3rd/idris-containers", "max_stars_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 99, "max_stars_repo_stars_event_min_datetime": "2015-03-01T20:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:17:39.000Z", "max_issues_repo_path": "Data/Vect/Extra.idr", "max_issues_repo_name": "witt3rd/idris-containers", "max_issues_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2015-03-23T19:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T13:05:44.000Z", "max_forks_repo_path": "Data/Vect/Extra.idr", "max_forks_repo_name": "witt3rd/idris-containers", "max_forks_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-06-02T17:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T14:51:07.000Z", "avg_line_length": 28.3095238095, "max_line_length": 79, "alphanum_fraction": 0.5012615643, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.67597049208484}} {"text": "module TwoVarDiophEq\nimport ZZ\nimport ZZUtils\nimport Divisors\nimport GCDZZ\nimport decDivZ\n%access public export\n%default total\n\n|||Any integer is a solution for c=xa+yb when a=b=c=0\nzeroLinCombZeroZero:a=0->b=0->c=0->(x:ZZ)->(y:ZZ)->c=x*a+y*b\nzeroLinCombZeroZero az bz cz x y = rewrite az in\n rewrite bz in\n rewrite cz in\n rewrite multZeroRightZeroZ x in\n rewrite multZeroRightZeroZ y in\n Refl\n\n|||If a=b=0 and c is not zero, it is impossible that c = xa +yb\nnotZeroNotLinCombZeroZero:a=0->b=0->NotZero c ->\n (x:ZZ)->(y:ZZ)->c=x*a+y*b->Void\nnotZeroNotLinCombZeroZero aZ bZ cnotz x y =\n rewrite aZ in\n rewrite bZ in\n rewrite multZeroRightZeroZ x in\n rewrite multZeroRightZeroZ y in\n (notZeroNonZero cnotz)\n\n\n|||Proves that if d = gcd (a,b) and c= xa +yb , then d|c\ngcdDivLinComb:GCDZ a b d->c=x*a+y*b -> IsDivisibleZ c d\ngcdDivLinComb (dPos,dcommonfactab,fd) prf =\n linCombDivLeftWithProof prf dcommonfactab\n\ngcdDivLinCombContra:GCDZ a b d ->((IsDivisibleZ c d) ->Void)->(x:ZZ)->(y:ZZ)->c=x*a+y*b->Void\ngcdDivLinCombContra gcdpf f x y prf =\n f (gcdDivLinComb gcdpf prf)\n\n\n|||Proves that if d = gcd (a,b) and d|c, then there exists integers x and y\n|||such that c = xa +yb\nmultipleOfGcdLinComb:GCDZ a b d -> IsDivisibleZ c d ->\n (x:ZZ**y:ZZ** (c = x*a + y*b))\nmultipleOfGcdLinComb{a} {d}{b} gcdpf (n**eqpf) =\n (case checkNotBothZero a b of\n (Left (aZ, bZ)) => void (gcdZeroZeroContra (gcdzReplace aZ bZ gcdpf))\n (Right r) =>\n (case gcdIsLinComb gcdpf of\n (j**l**gcdlc) => ((n*j)**(n*l)**\n (rewrite sym $multAssociativeZ n j a in\n rewrite sym $multAssociativeZ n l b in\n rewrite sym $ multDistributesOverPlusRightZ n (j*a) (l*b) in\n rewrite eqpf in\n rewrite multCommutativeZ d n in\n cong gcdlc) )))\n\n|||Extracts a/gcd(a,b) from the definition of GCDZ\naByd:GCDZ a b d ->ZZ\naByd dGcdab = (fst (fst (fst (snd dGcdab))))\n|||Extracts b/gcd(a,b) from the definition of GCDZ\nbByd:GCDZ a b d ->ZZ\nbByd dGcdab = (fst (snd (fst (snd dGcdab))))\n\n|||Proves that (b/gcd(a,b))*a = (a/gcd(a,b))*b\ndivByGcdMultByOtherIsSame:(gcdpf:GCDZ a b d) ->(bByd gcdpf)*a =(aByd gcdpf)*b\ndivByGcdMultByOtherIsSame {a}{b}{d} (dPos, ((abyd**apf),(bbyd**bpf)),fd) =\n multLeftCancelZ d (bbyd*a) (abyd *b) (posThenNotZero dPos)\n (rewrite multAssociativeZ d bbyd a in\n rewrite multAssociativeZ d abyd b in\n rewrite sym $ bpf in\n rewrite sym $ apf in\n rewrite multCommutativeZ b a in\n Refl)\n\n|||Proves that for any integer k, k*(-b/(gcd(a,b))) and k*(a/(gcd(a,b)))\n|||are solutions of 0 = xa + yb\nhomoSolution:(gcdpf:GCDZ a b d)->{k:ZZ}->\n (0 = (k*(-(bByd gcdpf)))*a + (k*((aByd gcdpf)))*b)\nhomoSolution {a}{b}{d}{k} (dPos, ((abyd**apf),(bbyd**bpf)),fd) =\n rewrite sym $ multAssociativeZ k (-bbyd) a in\n rewrite sym $ multAssociativeZ k (abyd) b in\n rewrite sym $ multDistributesOverPlusRightZ k ((-bbyd)*a) ((abyd)*b) in\n rewrite multNegateLeftZ bbyd a in\n rewrite divByGcdMultByOtherIsSame (dPos, ((abyd**apf),(bbyd**bpf)),fd) in\n rewrite plusNegateInverseRZ (abyd*b) in\n rewrite multZeroRightZeroZ k in\n Refl\n\n|||Proves that if 0 = xa +yb, then (-b/gcd(a,b)))*y = (a/(gcd(a,b)))*x\ndivHomoEqByGcd:(gcdpf:GCDZ a b d)->(0 = x*a + y*b)->((-(bByd gcdpf))*y = (aByd gcdpf)*x)\ndivHomoEqByGcd {x}{y}{a}{b}{d}(dPos, ((abyd**apf),(bbyd**bpf)),fd) prf =\n rewrite sym $plusZeroLeftNeutralZ ((-bbyd)*y) in\n rewrite multNegateLeftZ bbyd y in\n subOnBothSides 0 (abyd*x) ((bbyd)*y)\n (multLeftCancelZ d 0 ((abyd*x)+(bbyd*y)) (posThenNotZero dPos)\n (rewrite multZeroRightZeroZ d in\n rewrite multDistributesOverPlusRightZ d (abyd*x) (bbyd*y) in\n rewrite multAssociativeZ d abyd x in\n rewrite multAssociativeZ d bbyd y in\n rewrite sym $ apf in\n rewrite sym $ bpf in\n rewrite multCommutativeZ a x in\n rewrite multCommutativeZ b y in\n prf))\n\n|||Proves that if 0 = xa + yb then there exists an integer k such that\n||| y = k* (a/(gcd(a,b)))\nhomoOnlySolnForY:(gcdpf:GCDZ a b d)->(0 = x*a + y*b) ->\n (k:ZZ**(y = k * (aByd gcdpf)))\nhomoOnlySolnForY{a}{b}{d}{x}{y} (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf =\n (case divHomoEqByGcd (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf of\n eqpf =>\n (case caCoprimeThencDivb (x**eqpf) (negatingPreservesGcdLeft1\n (gcdSymZ (divideByGcdThenGcdOne (dPos, ((abyd**apf),(bbyd**bpf)),fd)))) of\n (quot**divpf) => (quot** (rewrite multCommutativeZ quot abyd in divpf))))\n\n|||Proves that if a is not zero then a/(gcd(a,b)) is not zero\ndivByGcdNotZero:(gcdpf:(GCDZ a b d))->NotZero a ->NotZero (aByd gcdpf)\ndivByGcdNotZero {a = (Pos (S k))}{b = b}{d = d} (dPos, ((abyd**apf),(bbyd**bpf)),fd)\n PositiveZ = posThenNotZero (posDivByPosIsPos{c=(Pos (S k))} Positive dPos apf)\ndivByGcdNotZero {a = (NegS k)}{b = b}{d = d} (dPos, ((abyd**apf),(bbyd**bpf)),fd)\nNegativeZ = NegSThenNotZero (negDivByPosIsNeg Negative dPos apf)\n\n-- The arguments to the function homoOnlySoln need to be explicit because Idris will not\n-- infer the correct arguments in the functions below.\n\n|||Proves that if a is not zero and 0 =xa + yb, then there exists an integer k such that\n||| x = k* (-b/(gcd(a,b))) and y = k* (a/(gcd(a,b)))\nhomoOnlySoln:(x: ZZ) -> (y: ZZ) -> (gcdpf:GCDZ a b d)->(0 = x*a + y*b) ->NotZero a->\n (k:ZZ**((x = k * (-(bByd gcdpf))),(y = k * (aByd gcdpf))))\nhomoOnlySoln {a}{b}{d} x y (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf anotz =\n (case divHomoEqByGcd (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf of\n divgpf =>\n (case homoOnlySolnForY (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf of\n (k**adivy) => (k**((multLeftCancelZ abyd x (k*(-bbyd))\n (divByGcdNotZero (dPos, ((abyd**apf),(bbyd**bpf)),fd) anotz)\n (rewrite multAssociativeZ abyd k (-bbyd) in\n rewrite multCommutativeZ abyd k in\n rewrite sym $ adivy in\n rewrite multCommutativeZ y (-bbyd) in\n sym $ divgpf)),adivy))))\n\n\ngcdSymZwithproof:(gcdpf:GCDZ a b d)->(gcdpf2:(GCDZ b a d)**((aByd gcdpf)=(bByd gcdpf2),(bByd gcdpf)=(aByd gcdpf2)))\ngcdSymZwithproof (dPos, ((abyd**apf),(bbyd**bpf)),fd) =\n ((dPos, ((bbyd**bpf),(abyd**apf)),(genFunctionForGcdSym fd))**(Refl,Refl))\n\n|||Same as homoOnlySolution, NotZero a is replaced with NotBothZeroZ a b\nhomoOnlySolnGen:(x: ZZ) -> (y: ZZ) -> (gcdpf:GCDZ a b d)->(0 = x*a + y*b) ->NotBothZeroZ a b->\n (k:ZZ**((x = k * (-(bByd gcdpf))),(y = k * (aByd gcdpf))))\nhomoOnlySolnGen {a = (Pos (S k))}{b = b}{d = d} x y gcdpf prf LeftPositive =\n homoOnlySoln x y gcdpf prf PositiveZ\nhomoOnlySolnGen {a = (NegS k)}{b = b}{d = d} x y gcdpf prf LeftNegative =\n homoOnlySoln x y gcdpf prf NegativeZ\nhomoOnlySolnGen {a = a}{b = (Pos (S k))}{d = d} x y (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf RightPositive =\n (case gcdSymZwithproof ((dPos, ((abyd**apf),(bbyd**bpf)),fd)) of\n (gcdpf2**(eqpf1,eqpf2)) =>\n (case homoOnlySoln {a=(Pos (S k))}{b=a} {d=d} y x gcdpf2 (rewrite plusCommutativeZ (y*(Pos (S k))) (x*a) in prf ) PositiveZ of\n (j**(ypf,xpf)) => ((-j)**((rewrite multNegNegNeutralZ j bbyd in\n rewrite eqpf2 in\n xpf ),(rewrite multNegateLeftZ j abyd in\n rewrite sym $ multNegateRightZ j abyd in\n rewrite eqpf1 in\n ypf)))))\nhomoOnlySolnGen {a = a}{b = (NegS k)}{d = d} x y (dPos, ((abyd**apf),(bbyd**bpf)),fd) prf RightNegative =\n (case gcdSymZwithproof ((dPos, ((abyd**apf),(bbyd**bpf)),fd)) of\n (gcdpf2**(eqpf1,eqpf2)) =>\n (case homoOnlySoln {a=(NegS k)}{b=a} {d=d} y x gcdpf2 (rewrite plusCommutativeZ (y*(NegS k)) (x*a) in prf ) NegativeZ of\n (j**(ypf,xpf)) => ((-j)**((rewrite multNegNegNeutralZ j bbyd in\n rewrite eqpf2 in\n xpf ),(rewrite multNegateLeftZ j abyd in\n rewrite sym $ multNegateRightZ j abyd in\n rewrite eqpf1 in\n ypf)))))\n\n-- The goal of the following section is to show that the non-homogeneous equation is uniquely solved by the family of\n-- solutions ((x_p+k*x_0), (y_p+k*y_0)).\n\n||| Produces the difference of two solutions. It will used to show that the difference of two particular\n||| solutions satisfies the homogeneous equation.\nsolDifference: (a: ZZ) -> (b: ZZ) -> (c: ZZ) -> (x1: ZZ) -> (y1: ZZ) -> (x2: ZZ) ->\n(y2: ZZ) -> (c=(x1*a+y1*b)) -> (c=(x2*a+y2*b)) -> ( 0= ( ((x1-x2)*a) + ((y1-y2)*b) ))\nsolDifference a b c x1 y1 x2 y2 prf prf1 = rewrite (multDistributesOverPlusLeftZ (x1) (-x2) (a)) in\n rewrite (multDistributesOverPlusLeftZ (y1) (-y2) (b)) in\n rewrite sym (plusAssociativeZ (x1*a) ((-x2)*a) (y1*b+((-y2)*b)) ) in\n rewrite (plusCommutativeZ (y1*b) ((-y2)*b)) in\n rewrite (plusAssociativeZ ((-x2)*a) ((-y2)*b) (y1*b)) in\n rewrite (plusCommutativeZ (((-x2)*a) + ((-y2)*b)) (y1*b)) in\n rewrite (plusAssociativeZ (x1*a) (y1*b) (((-x2)*a) + ((-y2)*b))) in\n rewrite (multNegateLeftZ (x2) (a)) in\n rewrite (multNegateLeftZ (y2) (b)) in\n rewrite sym (negateDistributesPlus (x2*a) (y2*b)) in\n rewrite sym (plusNegateInverseLZ (x2*a+y2*b)) in\n rewrite sym prf in\n rewrite sym prf1 in\n rewrite (plusNegateInverseLZ c) in\n Refl\n\n||| Adding x2 to both sides of the equation:\naddToSol: (x1: ZZ) -> (x2: ZZ) -> (x1-x2=d) -> (x1=x2+d)\naddToSol x1 x2 prf = rewrite sym prf in\n rewrite (plusCommutativeZ (x1) (-x2)) in\n rewrite (plusAssociativeZ (x2) (-x2) (x1)) in\n rewrite (plusNegateInverseLZ (x2)) in\n rewrite (plusZeroLeftNeutralZ (x1)) in\n Refl\n\n||| Proves that two particular solutions differ by a solution of the homogeneous equation.\ndiffIsHomogeneous: {a: ZZ} -> {b: ZZ} -> {c: ZZ} -> {d: ZZ} -> {x1: ZZ} -> {y1: ZZ} -> {x2: ZZ} ->\n{y2: ZZ} -> (IsDivisibleZ c d) -> (gcdpf:GCDZ a b d) -> NotBothZeroZ a b ->\n (c=x1*a+y1*b) -> (c=x2*a+y2*b) ->\n (k:ZZ** (( (x1-x2) = (k * (-(bByd gcdpf)))),( (y1-y2) = (k * (aByd gcdpf)))))\ndiffIsHomogeneous {a}{b}{c}{d}{x1}{y1}{x2}{y2} x gcdpf abnotZ prf prf1 =\n homoOnlySolnGen {a}{b}{d} (x1-x2) (y1-y2) (gcdpf) (solDifference a b c x1 y1 x2 y2 prf prf1) abnotZ\n\n||| Proves that any solution is a particular solution plus a constant multiple of the solution of\n||| the homogeneous equation.\ndifferByHomogeneous: {a: ZZ} -> {b: ZZ} -> {c: ZZ} -> {d: ZZ} -> {x1: ZZ} -> {y1: ZZ} ->\n (IsDivisibleZ c d) -> (gcdpf:GCDZ a b d) -> NotBothZeroZ a b ->\n (c=x1*a+y1*b) ->(x2:ZZ)->(y2:ZZ)-> (c=x2*a+y2*b) ->\n (k:ZZ** (( x2 = x1 + (k * (-(bByd gcdpf)))),( y2 = y1 + (k * (aByd gcdpf)))))\ndifferByHomogeneous {x1}{y1} x gcdpf y prf x2 y2 prf1 =\n (case diffIsHomogeneous x gcdpf y prf1 prf of\n (k**(xpf,ypf)) => (k**((addToSol x2 x1 xpf),(addToSol y2 y1 ypf))))\n\n|||A helper function for allsolutions.\n|||It proves that all x and y of the given form satisfies the equation.\nhelpallsolutions:(gcdpf:(GCDZ a b d))->(bbyd*a=abyd*b)->c = x1*a+y1*b->{k:ZZ}->\n (x3:ZZ)->(y3:ZZ)->(x3=x1+k*(-bbyd))->(y3=y1+k*abyd)->(c=(x3)*a+(y3)*b)\nhelpallsolutions{bbyd}{abyd} {x1}{y1}{a}{b}{d}{c}{k} gcdpf bydpf eqpf x3 y3 xpf ypf =\n rewrite xpf in\n rewrite ypf in\n rewrite multDistributesOverPlusLeftZ x1 (k*(-bbyd)) a in\n rewrite sym $ plusAssociativeZ (x1*a) ((k*(-bbyd))*a) (multZ (plusZ y1 (multZ k abyd)) b) in\n rewrite plusCommutativeZ ((k*(-bbyd))*a) ((y1+ (k*abyd))*b) in\n rewrite plusAssociativeZ (x1*a) ((y1+ (k*abyd))*b) ((k*(-bbyd))*a) in\n rewrite multDistributesOverPlusLeftZ y1 (k*abyd) b in\n rewrite plusAssociativeZ (x1*a) (y1*b) ((k*abyd)*b) in\n rewrite sym $ eqpf in\n rewrite sym $ plusAssociativeZ c ((k*abyd)*b) ((k*(-bbyd))*a) in\n rewrite sym $ multAssociativeZ k abyd b in\n rewrite sym $ multAssociativeZ k (-bbyd) a in\n rewrite sym $ bydpf in\n rewrite sym $ multDistributesOverPlusRightZ k (bbyd*a) ((-bbyd)*a) in\n rewrite multNegateLeftZ bbyd a in\n rewrite plusNegateInverseLZ (bbyd*a) in\n rewrite multZeroRightZeroZ k in\n rewrite plusZeroRightNeutralZ c in\n Refl\n\n|||The function that generates the third case in findAllSolutions function.\nallSolutions:(gcdpf:(GCDZ a b d)) -> IsDivisibleZ c d ->NotBothZeroZ a b ->\n (x1:ZZ**y1:ZZ**pa:ZZ**pb:ZZ**(({k:ZZ}->(x3:ZZ)->(y3:ZZ)->(x3=x1+k*pa)->(y3=y1+k*pb)->(c=x3*a+y3*b)),\n ((x2:ZZ)->(y2:ZZ)->(c=x2*a+y2*b)->(k**((x2=x1+k*pa),(y2=y1+k*pb))))))\nallSolutions{a}{b}{d} (dPos, ((abyd**apf),(bbyd**bpf)),fd) dDivc abnotZ =\n (case ((multipleOfGcdLinComb (dPos, ((abyd**apf),(bbyd**bpf)),fd) dDivc),\n (divByGcdMultByOtherIsSame (dPos, ((abyd**apf),(bbyd**bpf)),fd))) of\n ((x1**y1**eqpf),bydpf) =>(x1**y1**(-bbyd)**abyd**(\n (helpallsolutions (dPos, ((abyd**apf),(bbyd**bpf)),fd) bydpf eqpf ),\n ( (differByHomogeneous dDivc (dPos, ((abyd**apf),(bbyd**bpf)),fd) abnotZ eqpf ) ))))\n\n\n|||Given three integers a, b and c, it outputs either\n|||a proof that c = xa +yb is impossible or\n|||a proof that all integers x and y satisfy the equation (this happens when a=b=c=0)\n|||or 4 integers x1 , y1 , pa and pb such that for any integer k,\n|||x=x1+k*pa y=y1+k*pb is a solution of c=xa+yb\n|||and whenever c=xa+yb ,there exists an integer, k such that\n||| x=x1+k*pa y=y1+k*pb\nfindAllSolutions: (a:ZZ)->(b:ZZ)->(c:ZZ)->\n Either ((x:ZZ)->(y:ZZ)->c=x*a+y*b->Void)\n (Either ((x:ZZ)->(y:ZZ)->c=x*a+y*b)\n (x1:ZZ**y1:ZZ**pa:ZZ**pb:ZZ**(({k:ZZ}->(x:ZZ)->(y:ZZ)->(x=x1+k*pa)->(y=y1+k*pb)->(c=x*a+y*b)),\n ((x:ZZ)->(y:ZZ)->(c=x*a+y*b)->(k**((x=x1+k*pa),(y=y1+k*pb)))))))\nfindAllSolutions a b c =\n (case checkNotBothZero a b of\n (Left (aZ,bZ)) =>\n (case decZero c of\n (Yes cnotz) => Left (notZeroNotLinCombZeroZero aZ bZ cnotz)\n (No ciszero) => Right (Left (zeroLinCombZeroZero aZ bZ\n (notNotZeroThenZero ciszero))))\n (Right abnotZ) =>\n (case gcdZZ a b abnotZ of\n (g**gcdpf) =>\n (case decDivisibleZ c g of\n (Yes prf) => Right (Right (allSolutions gcdpf prf abnotZ ))\n (No contra) => Left (gcdDivLinCombContra gcdpf contra ))))\n", "meta": {"hexsha": "829b05fde24ccf214b69a7ba2a7b4304ee3fcefb", "size": 15152, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/TwoVarDiophEq.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/TwoVarDiophEq.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/TwoVarDiophEq.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": 52.6111111111, "max_line_length": 133, "alphanum_fraction": 0.567779831, "num_tokens": 5546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6759696812396558}} {"text": "module Numeric\nimport Data.Nat\n\n%default total\n\n-- Well-founded Integer\n-- All Integers are either a natural number\n-- or the inversion of a positive number.\npublic export\ndata WFInt : Type where\n Nat : (n : Nat) -> WFInt\n Neg : (n : Nat) -> WFInt --Note: In the negative case, n=Z represents -1.\n\n-- Magnitude of an integer\npublic export\nmag : WFInt -> Nat\nmag (Nat n) = n\nmag (Neg n) = (S n)\n\n\n-- Implement casting back and forth from normal Integer type\npublic export\nCast WFInt Integer where\n cast (Nat n) = cast n\n cast (Neg n) = negate $ cast (S n)\n\n\npublic export\nCast Integer WFInt where\n cast n = case (compare n 0) of\n EQ => Nat (fromInteger n)\n GT => Nat (fromInteger n)\n LT => Neg (fromInteger $ negate $ n + 1)\n\n\n-- For arithmetic operations, cast to Integer and then cast back\npublic export\nNum WFInt where\n (+) a b = cast $ (cast a) + (cast b)\n (*) a b = cast $ (cast a) * (cast b)\n fromInteger a = cast a\n\n\npublic export\nNeg WFInt where\n negate a = cast $ negate $ (the Integer $ cast a)\n (-) a b = cast $ (the Integer $ cast a) - (the Integer $ cast b)\n\npublic export\npartial\nIntegral WFInt where\n div a b = cast $ the Integer $ div (cast a) (cast b)\n mod a b = cast $ the Integer $ mod (cast a) (cast b)\n\n\n-- n-parity, i.e. proof that an integer a is evenly divisible by n (or not).\npublic export\ndata Parity : (a : WFInt) -> (n : WFInt) -> Type where\n -- a has even n-parity if there exists an integer multiple x s.t. x*n = a.\n Factor : (x : WFInt ** (x * n) = a) -> Parity a n\n ModIsZero : (mod n a = 0) -> Parity a n\n\npublic export\ndata OddParity : (a : WFInt) -> (n : WFInt) -> Type where\n -- a has odd n-parity if there exists\n Odd : (b : WFInt ** LT = compare (mag b) (mag n)) -> (Parity (a + b) n) -> OddParity a n\n\n", "meta": {"hexsha": "53293c6c98176c46ae3f8188cb6d79c2e9ad1e2e", "size": 1843, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "experimental/typed-dsl/Numeric.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/typed-dsl/Numeric.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/typed-dsl/Numeric.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": 27.1029411765, "max_line_length": 94, "alphanum_fraction": 0.6109603907, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6759696673356256}} {"text": "module Algebra.Semiring\n\n%default total\n\ninfixl 8 |+|\ninfixl 9 |*|\n\n||| A Semiring has two binary operations and an identity for each\npublic export\ninterface Semiring a where\n (|+|) : a -> a -> a\n plusNeutral : a\n (|*|) : a -> a -> a\n timesNeutral : a\n\n||| Erased linearity corresponds to the neutral for |+|\npublic export\nerased : Semiring a => a\nerased = plusNeutral\n\n||| Purely linear corresponds to the neutral for |*|\npublic export\nlinear : Semiring a => a\nlinear = timesNeutral\n\n||| A semiring eliminator\npublic export\nelimSemi : (Semiring a, Eq a) => (zero : b) -> (one : b) -> (a -> b) -> a -> b\nelimSemi zero one other r {a} =\n if r == Semiring.plusNeutral {a}\n then zero\n else if r == Semiring.timesNeutral {a}\n then one\n else other r\n\nexport\nisErased : (Semiring a, Eq a) => a -> Bool\nisErased = elimSemi True False (const False)\n\nexport\nisLinear : (Semiring a, Eq a) => a -> Bool\nisLinear = elimSemi False True (const False)\n\nexport\nisRigOther : (Semiring a, Eq a) => a -> Bool\nisRigOther = elimSemi False False (const True)\n\nexport\nbranchZero : (Semiring a, Eq a) => Lazy b -> Lazy b -> a -> b\nbranchZero yes no rig = if isErased rig then yes else no\n\nexport\nbranchOne : (Semiring a, Eq a) => Lazy b -> Lazy b -> a -> b\nbranchOne yes no rig = if isLinear rig then yes else no\n\nexport\nbranchVal : (Semiring a, Eq a) => Lazy b -> Lazy b -> a -> b\nbranchVal yes no rig = if isRigOther rig then yes else no\n", "meta": {"hexsha": "cbe0b9f0c3061943333ac9c7128ca6dd7a62dcb0", "size": 1453, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/src/Algebra/Semiring.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/Semiring.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/Semiring.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.6271186441, "max_line_length": 78, "alphanum_fraction": 0.6524432209, "num_tokens": 458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6758093866356031}} {"text": "module Specifications.TranslationInvariance\n\nimport public Specifications.Group\nimport public Specifications.Order\n\n%default total\n%access public export\n\ninfixl 8 #\n\n||| specification\nisTranslationInvariantL : Binop s -> Binrel s -> Type\nisTranslationInvariantL (#) rel = (x,y,a : _) -> rel x y -> rel (a # x) (a # y)\n\n||| specification\nisTranslationInvariantR : Binop s -> Binrel s -> Type\nisTranslationInvariantR (#) rel = (x,y,a : _) -> rel x y -> rel (x # a) (y # a)\n\n||| composed specification\ndata PartiallyOrderedMagmaSpec : Binop s -> Binrel s -> Type where\n MkPartiallyOrderedMagma :\n PartialOrderSpec leq ->\n isTranslationInvariantL op leq ->\n isTranslationInvariantR op leq ->\n PartiallyOrderedMagmaSpec op leq\n\n||| forget\norder : PartiallyOrderedMagmaSpec _ leq -> PartialOrderSpec leq\norder (MkPartiallyOrderedMagma o _ _) = o\n\n||| forget\ntranslationInvariantL : PartiallyOrderedMagmaSpec op leq ->\n isTranslationInvariantL op leq\ntranslationInvariantL (MkPartiallyOrderedMagma _ l _) = l\n\n||| forget\ntranslationInvariantR : PartiallyOrderedMagmaSpec op leq ->\n isTranslationInvariantR op leq\ntranslationInvariantR (MkPartiallyOrderedMagma _ _ r) = r\n\n||| composed specification\ndata PartiallyOrderedGroupSpec :\n Binop s -> s -> (s -> s) -> Binrel s -> Type where\n MkPartiallyOrderedGroup :\n GroupSpec op e inv ->\n PartiallyOrderedMagmaSpec op leq ->\n PartiallyOrderedGroupSpec op e inv leq\n\n||| forget\ninvariantOrder : PartiallyOrderedGroupSpec op _ _ leq ->\n PartiallyOrderedMagmaSpec op leq\ninvariantOrder (MkPartiallyOrderedGroup _ m) = m\n\n||| forget\ngroup : PartiallyOrderedGroupSpec op e inv _ -> GroupSpec op e inv\ngroup (MkPartiallyOrderedGroup g _) = g\n\nnamespace ForgetGroup\n order : PartiallyOrderedGroupSpec _ _ _ leq -> PartialOrderSpec leq\n order = order . invariantOrder\n\n\n||| A symmetric interval [-u, u]\nInSymRange : Binrel s -> (s -> s) -> s -> s -> Type\nInSymRange rel inv u = Between rel (inv u, u)\n", "meta": {"hexsha": "d13ea2232f92399bb59f36b6bcc04081a155f592", "size": 1966, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Specifications/TranslationInvariance.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/TranslationInvariance.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/TranslationInvariance.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": 29.7878787879, "max_line_length": 79, "alphanum_fraction": 0.7380467955, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6757442216457067}} {"text": "module ExpressionParser\n{- As an illustration to show interpreters are not hard to write, we make\nan interpreter for a tiny language with:\n * a single data type: `Nat`\n * arithmetic expressions can have `+`, `*` and parenthesis.\n * assignment statements of the form `let variable = expression`, with variable names being a single character.\n-}\n\nimport Parsers\n\n-- Statements in our language, these are either expressions or definitions.\ndata Statement : Type where\n Expression: (n: Nat) -> Statement\n Definition: (var: Char) -> (value: Nat) -> Statement\n\n-- A block (also called context) which is a list of statements but with the last statement the head of the list.\nBlock : Type\nBlock = List Statement\n\n-- Getting a variable from a block; if it is defined more than once the last definition is used.\ngetVar : Block -> Char -> Maybe Nat\ngetVar [] c = Nothing\ngetVar ((Expression n) :: xs) c = getVar xs c\ngetVar ((Definition var value) :: xs) c =\n if var == c then Just value else getVar xs c\n\n-- Parser for a variable name in a context\nvar : Block -> Parser Nat\nvar bl s = mapMaybe(letter)(getVar bl)(s)\n\n-- Parsing a block of statements recursively\nmutual\n -- A simple term in context: a literal natural number, a variable defined in the context or an expression in parenthesis\n simpleTerm : Block -> Parser Nat\n simpleTerm bl = nat || ((SS \"(\") <+ (expression bl) +> (SS \")\")) || (var bl)\n\n -- A product of simple terms in context, possibly with just one simple term\n term : Block -> Parser Nat\n term bl = map(repSepTrim (simpleTerm bl) '*')(foldl(*)(1))\n\n -- A sum of terms in context, possibly with just one term\n expression: Block -> Parser Nat\n expression bl = map(repSepTrim (term bl) '+')(foldl(+)(0))\n\n -- An arithmetic expression as a statement parsed in context\n expr : Block -> Parser Statement\n expr bl = map(expression bl)(Expression)\n\n -- Parser for LHS and RHS of a definition in context\n defSides: Block -> Parser (Char, Nat)\n defSides bl = ((SS \"let \") <+ letter +> (SS \"=\")) ++ (expression bl)\n\n -- Parser for a definition in a context\n defn : Block -> Parser Statement\n defn bl = map(defSides bl)(\\p => (case p of\n (name, value) => Definition name value))\n\n -- Parser for a statement in context\n stat : Block -> Parser Statement\n stat bl = ((defn bl) || (expr bl)) +> ((SS \";\") || map(eof)(\\u => \";\"))\n\n -- Parser for an empty block in context, returns the given context\n emptyBlock : Block -> Parser Block\n emptyBlock bl = map(rep(SS \" \") <+ eof)(\\u => bl)\n\n -- Recursively parsing a block given a context\n blockRec : Block -> Parser Block\n blockRec bl =\n (emptyBlock bl) ||\n flatMapWithNext(stat bl)(\n \\s => blockRec (s :: bl))\n\n-- Parser for a block, starting with the empty context\nblock: Parser Block\nblock = blockRec []\n\n-- The value of a block: the value/rhs of the last statment, defaulting to 0\nblockValue: Block -> Nat\nblockValue [] = Z\nblockValue ((Expression n) :: xs) = n\nblockValue ((Definition var value) :: xs) = value\n\n-- Interpret a string and getting the value of the result\ninterpret : String -> ParseResult Nat\ninterpret s = parse(map(block)(blockValue)) s\n\n-- An example\neg: ParseResult Nat\neg = interpret \"let a = (1 + 2 * (3 + 1)); let b = a + 3 ; a * (b + 1)\"\n", "meta": {"hexsha": "f7473f335249be40295d93e4a19dfd103037d5fd", "size": 3291, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/ExpressionParser.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/ExpressionParser.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/ExpressionParser.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.5666666667, "max_line_length": 122, "alphanum_fraction": 0.6712245518, "num_tokens": 858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6756172502118309}} {"text": "module Addition.Carry\n\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.DiscreteOrderedGroup\nimport Proofs.GroupCancelationLemmas\nimport Proofs.Interval\nimport Addition.CarryLemmas\n\n%default total\n%access public export\n\ndata Carry = M | O | P\n\nimplementation Show Carry where\n show M = \"M\"\n show O = \"O\"\n show P = \"P\"\n\npublic export\nvalue : Ringops s => Carry -> s\nvalue P = One\nvalue O = Zero\nvalue M = Ng One\n\n||| multiply by Carry\nscale : s -> (s -> s) -> s -> Carry -> s\nscale zero neg x M = neg x\nscale zero neg x O = zero\nscale zero neg x P = x\n\n||| u = radix - 1\n||| radix = u + 1\n||| carry * radix + output = input\n||| output in [-v..v] where v = u - 1\ndata Reduction : \n Binop s -> s -> (s -> s) -> Binrel s -> s -> s -> s -> {input : s} -> Type \n where MkReduction :\n .(input : s) -> (carry : Carry) -> (output : s) ->\n scale zero neg radix carry `add` output = input ->\n InSymRange leq neg (add u (neg unit)) output ->\n Reduction add zero neg leq unit u radix {input}\n\ninput : Reduction {s} _ _ _ _ _ _ _ {input = x} -> s\ninput _ = x\n\ncarry : Reduction _ _ _ _ _ _ _ -> Carry\ncarry (MkReduction _ c _ _ _) = c\n\noutput : Reduction {s} _ _ _ _ _ _ _ -> s\noutput (MkReduction _ _ o _ _) = o\n\nresult : Reduction {s} _ _ _ _ _ _ _ -> (Carry, s)\nresult (MkReduction _ c o _ _) = (c, o)\n\n\n||| See README for a brief introduction.\n||| 1 <= u - 1 means radix >= 3.\ncomputeCarry : (Ringops s, Decidable [s,s] leq) =>\n DiscreteOrderedGroupSpec (+) Zero Ng leq One ->\n (u : s) -> leq One (u + Ng One) ->\n (x : s) -> InSymRange leq Ng (u + u) x ->\n Reduction (+) Zero Ng leq One u (One + u) {input = x}\n\ncomputeCarry spec u bound x range =\n let pog = partiallyOrderedGroup spec\n grp = group (partiallyOrderedGroup spec)\n abel = abelian spec in\n case decidePartition3 spec (Ng u) u x range of\n Left prf\n => MkReduction x M (One + u + x)\n (groupCancel1bis grp _ x)\n (shiftLeftToSymRange pog u One x bound prf)\n Middle prf\n => MkReduction x O x\n (neutralL (monoid grp) _)\n (toSymRange pog abel prf)\n Right prf\n => MkReduction x P (x + Ng (One + u))\n (groupCancelAbelian grp abel _ x)\n (shiftRightToSymRange pog u One x bound prf)\n", "meta": {"hexsha": "de33132f019782ae9b8acc96acf829e4211c8b81", "size": 2259, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Addition/Carry.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/Carry.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/Carry.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": 27.5487804878, "max_line_length": 77, "alphanum_fraction": 0.6139884905, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6756172350554721}} {"text": "module Utils.Matrix\n\nimport Utils.Conjugate\n\n%default total\n%access public export\n\nVector : Type -> Type\nVector = List \n%name Vector xv, yv, zv\n\nMatrix : Type -> Type\nMatrix = Vector . Vector\n%name Matrix xm, ym, zm\n\napply : Num a => Matrix a -> Vector a -> Vector a\napply xm xv = map (\\row => sum (zipWith (*) row xv)) xm \n\ntranspose : Matrix a -> Matrix a\ntranspose [] = []\ntranspose (x :: xs) = zipWith (::) x xs\n\nmmap : (a -> b) -> Matrix a -> Matrix b\nmmap f = map (map f) \n\nimplementation Conjugate space coSpace => Conjugate (Matrix space) (Matrix coSpace) where\n conjug = Utils.Matrix.transpose . mmap conjug \n", "meta": {"hexsha": "cc7a89617a8f3bf31e695785cf040ce088225553", "size": 619, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Utils/Matrix.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/Matrix.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/Matrix.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": 22.1071428571, "max_line_length": 89, "alphanum_fraction": 0.6655896607, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6752557475362583}} {"text": "module Tricho\n\ndata Trichotomy : (eq, lt : a -> a -> Type) -> (a -> a -> Type) where\n LT : {0 x, y : a} -> lt x y -> Trichotomy eq lt x y\n EQ : {0 x, y : a} -> eq x y -> Trichotomy eq lt x x\n GT : {0 x, y : a} -> lt y x -> Trichotomy eq lt x y\n\ninterface Trichotomous (a : Type) (eq, lt : a -> a -> Type) where\n\n trichotomy : (x, y : a) -> Trichotomy eq lt x y\n", "meta": {"hexsha": "6a44808be2928bb8618b2f4ab268ae1df61e341b", "size": 365, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interface017/Tricho.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/interface017/Tricho.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/interface017/Tricho.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 33.1818181818, "max_line_length": 69, "alphanum_fraction": 0.5342465753, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6751275501056069}} {"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\nappend : Vect n a -> Vect m a -> Vect (n + m) a\nappend {n} xs ys = ?foo\n\nvadd : Num a => Vect n a -> Vect n a -> Vect n a\nvadd [] ys = ?bar\nvadd (x :: xs) ys = ?baz\n\nsuc : (x : Nat) -> (y : Nat) -> x = y -> S x = S y\nsuc x y prf = ?quux\n\nsuc' : x = y -> S x = S y\nsuc' {x} {y} prf = ?quuz\n\n", "meta": {"hexsha": "fdeec475523235e60a4f838a20a889df35475e7e", "size": 414, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive002/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": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/tests/idris2/interactive002/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": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/tests/idris2/interactive002/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": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.7, "max_line_length": 50, "alphanum_fraction": 0.4758454106, "num_tokens": 175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425377849805, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6751275501056067}} {"text": "module SizedStrings\r\n\r\nimport Data.Fin\r\nimport MaybeFin\r\n\r\n%default total\r\n%access public\r\n\r\n||| A string with length encoded in the type\r\n||| Need to investigate this PR:\r\n||| https://github.com/idris-lang/Idris-dev/pull/2628\r\n||| It may be that his work, if completed, would make this module obsolete!!\r\nabstract data SizedString : Nat -> Type where\r\n SizedString' : (n : Nat) -> (s : String) -> SizedString n\r\n\r\n%name SizedString str\r\n\r\n||| This is the only was to create a SizedString\r\nsizeString : (s : String) -> SizedString (length s)\r\nsizeString s = SizedString' (length s) s\r\n\r\nempty : SizedString Z\r\nempty = sizeString \"\"\r\n\r\n||| Length of the string, equal to the Nat carried in the type\r\nlength : SizedString n -> Nat\r\nlength {n} _ = n\r\n\r\nlength_is_embedded_in_type : (str : SizedString n) -> length str = n\r\nlength_is_embedded_in_type str = Refl\r\n\r\n||| Typesafe way to get a character from a string at the specified index.\r\n||| The order of arguments is patterned after Strings.strIndex, not, say, List.index.\r\n||| Under the covers it does an assert_total call because the underlying\r\n||| String.strIndex function is partial. However, we know this is safe as long\r\n||| as SizedString is only created via the sizeString function from this module.\r\nstrIndex : SizedString n -> Fin n -> Char\r\nstrIndex (SizedString' _ s) x =\r\n assert_total $ strIndex s $ cast $ finToNat x\r\n\r\nmaybeStrIndex : SizedString n -> MaybeFin n -> Maybe Char\r\nmaybeStrIndex str NoFin = Nothing\r\nmaybeStrIndex str (SomeFin x) = Just $ strIndex str x\r\n\r\ninstance Cast (SizedString n) String where\r\n cast (SizedString' _ s) = s\r\n\r\nreplaceAt : Fin (S n) -> Char -> SizedString (S n) -> SizedString (S n)\r\nreplaceAt {n} i c (SizedString' _ str) =\r\n let charsBefore = finToNat i\r\n indexAfter = S charsBefore\r\n size = S n\r\n firstChunk = substr 0 charsBefore str\r\n secondChunk = substr indexAfter size str\r\n in SizedString' size $ firstChunk ++ (strCons c $ secondChunk)\r\n\r\nmaybeReplaceAt : MaybeFin n -> Char -> SizedString n -> SizedString n\r\nmaybeReplaceAt NoFin _ str = str\r\nmaybeReplaceAt (SomeFin x) c str = replaceAt x c str\r\n\r\n(++) : SizedString n -> SizedString m -> SizedString (n + m)\r\n(SizedString' _ str1) ++ (SizedString' _ str2) = SizedString' _ $ str1 ++ str2\r\n\r\nprivate\r\nsplitAt : Nat -> SizedString n -> (String, String)\r\nsplitAt idx (SizedString' n str) =\r\n (substr 0 idx str, substr idx n str)\r\n\r\ninsertAfter : SizedString n -> (idx : MaybeFin n) -> SizedString m -> SizedString (n + m)\r\ninsertAfter str1 NoFin str2 = str1 ++ str2\r\ninsertAfter str (SomeFin x) (SizedString' _ infixStr) =\r\n let idx = S $ finToNat x\r\n splitStr = splitAt idx str\r\n in SizedString' _ $ (fst splitStr) ++ infixStr ++ (snd splitStr)\r\n\r\ninsertBefore : SizedString n -> (idx : MaybeFin n) -> SizedString m -> SizedString (m + n)\r\ninsertBefore str1 NoFin str2 = str2 ++ str1\r\ninsertBefore str (SomeFin x) (SizedString' _ infixStr) =\r\n let idx = finToNat x\r\n splitStr = splitAt idx str\r\n in SizedString' _ $ (fst splitStr) ++ infixStr ++ (snd splitStr)\r\n\r\ndeleteAt : MaybeFin n -> SizedString n -> SizedString (pred n)\r\ndeleteAt NoFin str = str\r\ndeleteAt (SomeFin x) (SizedString' (S k) str) =\r\n let idx = finToNat x\r\n in SizedString' k $ (substr 0 idx str) ++ (substr (S idx) (S k) str)\r\n\r\n", "meta": {"hexsha": "6db7f8790104ba7cbccf044f07b53e2e782304cf", "size": 3303, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/SizedStrings.idr", "max_stars_repo_name": "PolyglotSymposium/void.idr", "max_stars_repo_head_hexsha": "bdea1aeea6758928d79c47cefc0ac94bb1a7de1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-01T03:17:12.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-01T03:17:12.000Z", "max_issues_repo_path": "src/SizedStrings.idr", "max_issues_repo_name": "PolyglotSymposium/void.idr", "max_issues_repo_head_hexsha": "bdea1aeea6758928d79c47cefc0ac94bb1a7de1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-01-15T02:36:00.000Z", "max_issues_repo_issues_event_max_datetime": "2016-01-15T18:52:24.000Z", "max_forks_repo_path": "src/SizedStrings.idr", "max_forks_repo_name": "PolyglotSymposium/void.idr", "max_forks_repo_head_hexsha": "bdea1aeea6758928d79c47cefc0ac94bb1a7de1e", "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.1123595506, "max_line_length": 91, "alphanum_fraction": 0.6863457463, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6749496568026045}} {"text": "> module FastSimpleProb.Operations\n\n> import FastSimpleProb.SimpleProb\n> import FastSimpleProb.BasicOperations\n> import FastSimpleProb.MonadicProperties\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.BasicOperations\n> import Rel.TotalPreorder\n> import NonNegDouble.LTEProperties\n> import List.Operations\n> import List.Properties\n> import Fun.Operations\n> import Double.Predicates\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n> |||\n> mostProbableProb : {A : Type} -> (Eq A) => SimpleProb A -> (A, NonNegDouble)\n> mostProbableProb {A} sp = argmaxMax totalPreorderLTE aps neaps where\n> aps : List (A, NonNegDouble)\n> aps = map (pair (id, (prob sp))) (nub (support sp))\n> nes : List.Operations.NonEmpty (support sp)\n> nes = mapPreservesNonEmpty fst (toList sp) (nonEmptyLemma1 sp)\n> nens : List.Operations.NonEmpty (nub (support sp))\n> nens = nubPreservesNonEmpty (support sp) nes\n> neaps : List.Operations.NonEmpty aps\n> neaps = mapPreservesNonEmpty (pair (id, (prob sp))) (nub (support sp)) nens \n\n> |||\n> mostProbable : {A : Type} -> (Eq A) => SimpleProb A -> A\n> mostProbable = fst . mostProbableProb\n\n> |||\n> maxProbability : {A : Type} -> (Eq A) => SimpleProb A -> NonNegDouble\n> maxProbability = snd . mostProbableProb\n\n> |||\n> sortToList : {A : Type} -> (Eq A) => SimpleProb A -> List (A, NonNegDouble)\n> sortToList {A} sp = sortBy ord aps where\n> aps : List (A, NonNegDouble)\n> aps = map (pair (id, (prob sp))) (nub (support sp))\n> ord : (A, NonNegDouble) -> (A, NonNegDouble) -> Ordering\n> ord (a1, pa1) (a2, pa2) = compare (toDouble pa1) (toDouble pa2)\n\n> |||\n> naiveMostProbableProb : {A : Type} -> SimpleProb A -> (A, NonNegDouble)\n> naiveMostProbableProb sp = argmaxMax totalPreorderLTE (toList sp) (nonEmptyLemma1 sp)\n\n> |||\n> naiveMostProbable : {A : Type} -> SimpleProb A -> A\n> naiveMostProbable = fst . naiveMostProbableProb\n\n> |||\n> naiveMaxProbability : {A : Type} -> SimpleProb A -> NonNegDouble\n> naiveMaxProbability = snd . naiveMostProbableProb\n\n> |||\n> naiveSortToList : {A : Type} -> SimpleProb A -> List (A, NonNegDouble)\n> naiveSortToList {A} sp = sortBy ord (toList sp) where\n> ord : (A, NonNegDouble) -> (A, NonNegDouble) -> Ordering\n> ord (a1, pa1) (a2, pa2) = if (toDouble pa1) == (toDouble pa2)\n> then EQ\n> else if (toDouble pa1) < (toDouble pa2)\n> then GT\n> else LT\n\n\n> {-\n\n> ---} \n\n\n\n\n", "meta": {"hexsha": "34fc7cf1f49399ac4e3fa0d8966afaef8e4f85f2", "size": 2511, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "FastSimpleProb/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": "FastSimpleProb/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": "FastSimpleProb/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": 32.1923076923, "max_line_length": 87, "alphanum_fraction": 0.6423735564, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6748686218463086}} {"text": "-- Classical propositional logic, PHOAS approach, final encoding\n\nmodule Pf.Cp\n\n%default total\n\n\n-- Types\n\ninfixl 2 :&&\ninfixl 1 :||\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n (:&&) : Ty -> Ty -> Ty\n (:||) : Ty -> Ty -> Ty\n FALSE : Ty\n\ninfixr 0 :<=>\n(:<=>) : Ty -> Ty -> Ty\n(:<=>) a b = (a :=> b) :&& (b :=> a)\n\nNOT : Ty -> Ty\nNOT a = a :=> FALSE\n\nTRUE : Ty\nTRUE = FALSE :=> FALSE\n\n\n-- Context and truth judgement\n\nCx : Type\nCx = Ty -> Type\n\nisTrue : Ty -> Cx -> Type\nisTrue a tc = tc a\n\n\n-- Terms\n\nTmRepr : Type\nTmRepr = Cx -> Ty -> Type\n\ninfixl 1 :$\nclass ArrMpTm (tr : TmRepr) where\n var : isTrue a tc -> tr tc a\n lam' : (isTrue a tc -> tr tc b) -> tr tc (a :=> b)\n (:$) : tr tc (a :=> b) -> tr tc a -> tr tc b\n\nlam'' : {tr : TmRepr} -> ArrMpTm tr => (tr tc a -> tr tc b) -> tr tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\n\nclass ArrMpTm tr => MpTm (tr : TmRepr) where\n pair : tr tc a -> tr tc b -> tr tc (a :&& b)\n fst : tr tc (a :&& b) -> tr tc a\n snd : tr tc (a :&& b) -> tr tc b\n left : tr tc a -> tr tc (a :|| b)\n right : tr tc b -> tr tc (a :|| b)\n case' : tr tc (a :|| b) -> (isTrue a tc -> tr tc c) -> (isTrue b tc -> tr tc c) -> tr tc c\n\ncase'' : {tr : TmRepr} -> MpTm tr => tr tc (a :|| b) -> (tr tc a -> tr tc c) -> (tr tc b -> tr tc c) -> tr tc c\ncase'' xy f g = case' xy (\\x => f (var x)) (\\y => g (var y))\n\nsyntax \"[\" [a] \",\" [b] \"]\" = pair a b\nsyntax \"case\" [ab] \"of\" {a} \":=>\" [c1] or {b} \":=>\" [c2] = case'' ab (\\a => c1) (\\b => c2)\n\nclass MpTm tr => CpTm (tr : TmRepr) where\n abort' : (isTrue (NOT a) tc -> tr tc FALSE) -> tr tc a\n\nabort'' : {tr : TmRepr} -> CpTm tr => (tr tc (NOT a) -> tr tc FALSE) -> tr tc a\nabort'' f = abort' $ \\na => f (var na)\n\nsyntax \"abort\" {a} \":=>\" [b] = abort'' (\\a => b)\n\nThm : Ty -> Type\nThm a = {tr : TmRepr} -> {tc : Cx} -> CpTm tr => tr tc a\n", "meta": {"hexsha": "048e16977a1c19f10b8b3ff8a9683ac1309a9ad8", "size": 2008, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pf/Cp.idr", "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": ["X11"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_issues_repo_path": "src/Pf/Cp.idr", "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_licenses": ["X11"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Pf/Cp.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": 25.1, "max_line_length": 111, "alphanum_fraction": 0.4482071713, "num_tokens": 807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6748527575296138}} {"text": "module WTypes\n\ndata W : (t : Type) -> (p : t -> Type) -> Type where\n Sup : (x : t) -> (p x -> W t p) -> W t p\n\nind : {t : Type} -> {p : t -> Type} -> (pred : W t p -> Type) ->\n ((v : t) -> (f : p v -> W t p) -> ((t' : p v) -> pred (f t')) -> pred (Sup v f)) ->\n (w : W t p) -> pred w\nind _ p (Sup x f) = p x f (\\t => ind _ p (f t))\n\nefq : {a : Type} -> Void -> a\n\n-- Nat encoding\nN : Type\nN = W Bool (\\b => if b then () else Void)\n\nzero : N\nzero = Sup False efq\n\nsucc : N -> N\nsucc n = Sup True (const n)\n\nplus : N -> N -> N\nplus (Sup False f) b = b\nplus (Sup True f) b = Sup True (\\() => plus (f ()) b)\n\n-- Tree encoding\nTree : Type\nTree = W Bool (\\b => if b then Bool else Void)\n\nleaf : Tree\nleaf = Sup False efq\n\nbranch : Tree -> Tree -> Tree\nbranch l r = Sup True (\\b => if b then l else r)\n\nsize : Tree -> N\nsize (Sup False f) = zero\nsize (Sup True f) = plus (size (f True)) (size (f False))\n", "meta": {"hexsha": "0f05443744e5528090a323c25faf43de02b1118d", "size": 908, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/WTypes.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/WTypes.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/WTypes.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": 22.7, "max_line_length": 89, "alphanum_fraction": 0.5, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6747957002582265}} {"text": "module Data.Stream\n\nimport Data.List\nimport Data.List1\nimport public Data.Zippable\n\n%default total\n\n||| Drop the first n elements from the stream\n||| @ n how many elements to drop\npublic export\ndrop : (n : Nat) -> Stream a -> Stream a\ndrop Z xs = xs\ndrop (S k) (x::xs) = drop k xs\n\n||| An infinite stream of repetitions of the same thing\npublic export\nrepeat : a -> Stream a\nrepeat x = x :: repeat x\n\n||| Generate an infinite stream by repeatedly applying a function\n||| @ f the function to iterate\n||| @ x the initial value that will be the head of the stream\npublic export\niterate : (f : a -> a) -> (x : a) -> Stream a\niterate f x = x :: iterate f (f x)\n\npublic export\nunfoldr : (b -> (a, b)) -> b -> Stream a\nunfoldr f c = let (a, n) = f c in a :: unfoldr f n\n\n||| All of the natural numbers, in order\npublic export\nnats : Stream Nat\nnats = iterate S Z\n\n||| Get the nth element of a stream\npublic export\nindex : Nat -> Stream a -> a\nindex Z (x::xs) = x\nindex (S k) (x::xs) = index k xs\n\n---------------------------\n-- Zippable --\n---------------------------\n\npublic export\nZippable Stream where\n zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys\n\n zipWith3 f (x :: xs) (y :: ys) (z :: zs) = f x y z :: zipWith3 f xs ys zs\n\n unzipWith f xs = unzip (map f xs)\n\n unzip xs = (map fst xs, map snd xs)\n\n unzipWith3 f xs = unzip3 (map f xs)\n\n unzip3 xs = (map (\\(x, _, _) => x) xs, map (\\(_, x, _) => x) xs, map (\\(_, _, x) => x) xs)\n\nexport\nzipWithIndexLinear : (0 f : _) -> (xs, ys : Stream a) -> (i : Nat) -> index i (zipWith f xs ys) = f (index i xs) (index i ys)\nzipWithIndexLinear f (_::xs) (_::ys) Z = Refl\nzipWithIndexLinear f (_::xs) (_::ys) (S k) = zipWithIndexLinear f xs ys k\n\nexport\nzipWith3IndexLinear : (0 f : _) -> (xs, ys, zs : Stream a) -> (i : Nat) -> index i (zipWith3 f xs ys zs) = f (index i xs) (index i ys) (index i zs)\nzipWith3IndexLinear f (_::xs) (_::ys) (_::zs) Z = Refl\nzipWith3IndexLinear f (_::xs) (_::ys) (_::zs) (S k) = zipWith3IndexLinear f xs ys zs k\n\n||| Return the diagonal elements of a stream of streams\nexport\ndiag : Stream (Stream a) -> Stream a\ndiag ((x::xs)::xss) = x :: diag (map tail xss)\n\n||| Produce a Stream of left folds of prefixes of the given Stream\n||| @ f the combining function\n||| @ acc the initial value\n||| @ xs the Stream to process\nexport\nscanl : (f : a -> b -> a) -> (acc : a) -> (xs : Stream b) -> Stream a\nscanl f acc (x :: xs) = acc :: scanl f (f acc x) xs\n\n||| Produce a Stream repeating a sequence\n||| @ xs the sequence to repeat\n||| @ ok proof that the list is non-empty\nexport\ncycle : (xs : List a) -> {auto 0 ok : NonEmpty xs} -> Stream a\ncycle (x :: xs) = x :: cycle' xs\n where cycle' : List a -> Stream a\n cycle' [] = x :: cycle' xs\n cycle' (y :: ys) = y :: cycle' ys\n\n--------------------------------------------------------------------------------\n-- Interleavings\n--------------------------------------------------------------------------------\n\n-- zig, zag, and cantor are taken from the paper\n-- Applications of Applicative Proof Search\n-- by Liam O'Connor\n\npublic export\nzig : List1 (Stream a) -> Stream (Stream a) -> Stream a\n\npublic export\nzag : List1 a -> List1 (Stream a) -> Stream (Stream a) -> Stream a\n\nzig xs = zag (head <$> xs) (tail <$> xs)\n\nzag (x ::: []) zs (l :: ls) = x :: zig (l ::: forget zs) ls\nzag (x ::: (y :: xs)) zs ls = x :: zag (y ::: xs) zs ls\n\npublic export\ncantor : Stream (Stream a) -> Stream a\ncantor (l :: ls) = zig (l ::: []) ls\n\n-- Exploring the Nat*Nat top right quadrant of the plane\n-- using Cantor's zig-zag traversal:\nexample :\n let quadrant : Stream (Stream (Nat, Nat))\n quadrant = map (\\ i => map (i,) Stream.nats) Stream.nats\n in\n take 10 (cantor quadrant)\n === [ (0, 0)\n , (1, 0), (0, 1)\n , (2, 0), (1, 1), (0, 2)\n , (3, 0), (2, 1), (1, 2), (0, 3)\n ]\nexample = Refl\n\nnamespace DPair\n\n ||| Explore the plane corresponding to all possible pairings\n ||| using Cantor's zig zag traversal\n public export\n planeWith : {0 p : a -> Type} ->\n ((x : a) -> p x -> c) ->\n Stream a -> ((x : a) -> Stream (p x)) ->\n Stream c\n planeWith k as f = cantor (map (\\ x => map (k x) (f x)) as)\n\n ||| Explore the plane corresponding to all possible pairings\n ||| using Cantor's zig zag traversal\n public export\n plane : {0 p : a -> Type} ->\n Stream a -> ((x : a) -> Stream (p x)) ->\n Stream (x : a ** p x)\n plane = planeWith (\\ x, prf => (x ** prf))\n\nnamespace Pair\n\n ||| Explore the plane corresponding to all possible pairings\n ||| using Cantor's zig zag traversal\n public export\n planeWith : (a -> b -> c) ->\n Stream a -> (a -> Stream b) ->\n Stream c\n planeWith k as f = cantor (map (\\ x => map (k x) (f x)) as)\n\n ||| Explore the plane corresponding to all possible pairings\n ||| using Cantor's zig zag traversal\n public export\n plane : Stream a -> (a -> Stream b) -> Stream (a, b)\n plane = Pair.planeWith (,)\n\n--------------------------------------------------------------------------------\n-- Implementations\n--------------------------------------------------------------------------------\n\nexport\nApplicative Stream where\n pure = repeat\n (<*>) = zipWith apply\n\nexport\nMonad Stream where\n s >>= f = diag (map f s)\n\n--------------------------------------------------------------------------------\n-- Properties\n--------------------------------------------------------------------------------\n\nlengthTake : (n : Nat) -> (xs : Stream a) -> length (take n xs) = n\nlengthTake Z _ = Refl\nlengthTake (S n) (x :: xs) = cong S (lengthTake n xs)\n", "meta": {"hexsha": "e7e64a70c562f1b708ba8e9ef775c2e60302972f", "size": 5635, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/base/Data/Stream.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "libs/base/Data/Stream.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "libs/base/Data/Stream.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": 30.2956989247, "max_line_length": 147, "alphanum_fraction": 0.5329192547, "num_tokens": 1663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.6746924073281435}} {"text": "module Sub05Apply9x6\r\n\r\nimport ProofColDivSeqBase\r\nimport ProofColDivSeqPostulate\r\n\r\n%default total\r\n-- %language ElabReflection\r\n\r\n\r\n-- 3(3x+2) --C[4,-4]--> 3x\r\nc9x6To3x :\r\n (j:Nat) -> P (S (S (plus (plus j j) j))) 2 -> P j 2\r\nc9x6To3x j prf =\r\n let prf2 = lvDown (S (S (plus (plus j j) j))) 2 prf in c9x6To3x' j prf2\r\n\r\nexport\r\napply9x6 : P (S (S (plus (plus j j) j))) 2\r\n -> (m : Nat ** (LTE (S m) (S (S (plus (plus j j) j))), P m 2))\r\napply9x6 {j} col = let col2 = c9x6To3x j col in (j ** (lte9x6 j, col2)) where\r\n lte9x6 : (j:Nat) -> LTE (S j) (S (S (plus (plus j j) j)))\r\n lte9x6 Z = (lteSuccRight . LTESucc) LTEZero\r\n lte9x6 (S j) = let lemma = lte9x6 j in\r\n rewrite (sym (plusSuccRightSucc j j)) in\r\n rewrite (sym (plusSuccRightSucc (plus j j) j)) in\r\n (lteSuccRight . lteSuccRight . LTESucc) lemma\r\n-- ---------------------------\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "634b7ae4872f1d7e2c706c81916c750f1037c2bd", "size": 865, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program/Sub05Apply9x6.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/Sub05Apply9x6.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/Sub05Apply9x6.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": 27.9032258065, "max_line_length": 78, "alphanum_fraction": 0.5722543353, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6742854041268884}} {"text": "-- vim: ft=idris sw=2 ts=2 et\n\n-- exercise of day1\n\n-- find all numbers in a list that are greater than a given one\ngreater : Ord a => a -> List a -> List a\ngreater n ls = filter (\\x => x > n) ls\n\n-- find every other list element, starting from first element\neveryOther : List a -> List a\neveryOther [] = []\neveryOther (x1 :: []) = [x1]\neveryOther (x1 :: x2 :: xs) = x1 :: everyOther xs\n\n-- playcard data type\ndata Color = Kreuz | Pik | Herz | Karo\ndata Value = Sieben | Acht | Neun | Zehn | Bube | Dame | Koenig | Ass\ndata Card = Pair Color Value\ndata Deck = List Card\n\n-- even & odd numbers\nmutual\n data Even = Two | EvenSucc Odd\n data Odd = One | OddSucc Even\n\n-- binary tree\ndata BTree a =\n Node (BTree a) (BTree a) | Leaf\n\n-- reverse a list\nrev : List a -> List a\nrev l = rev' l [] where\n rev' : List a -> List a -> List a\n rev' [] b = b\n rev' (a :: as) b = rev' as (a :: b)\n\n", "meta": {"hexsha": "0947d71a1cee8652a2aafac2a7abb0a54a6d9f7f", "size": 887, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/7lang7weeks/day1/exercises.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/7lang7weeks/day1/exercises.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/7lang7weeks/day1/exercises.idr", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.972972973, "max_line_length": 69, "alphanum_fraction": 0.6166854566, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6740590296387947}} {"text": "\nmodule squareRoot\n\nsquare_root_approx : (number : Double) -> (approx : Double) -> Stream Double\nsquare_root_approx number approx =\n let next = (approx + (number / approx)) / 2 in\n next :: square_root_approx number next\n\nsquare_root_bound : (max : Nat) -> (number : Double) -> (bound : Double) -> (approxs : Stream Double) -> Double\nsquare_root_bound Z number bound (value :: vs) = value\nsquare_root_bound (S k) number bound (v :: vs) =\n case (v * v) < bound of\n False => square_root_bound k number bound vs\n True => v\n\nsquare_root : (number : Double) -> Double\nsquare_root number = square_root_bound 100 number 0.0000000001 (square_root_approx number number)\n", "meta": {"hexsha": "cc7e7f5c02b62d24e2e4bd8ad6d89be515600454", "size": 679, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter 11/squareRoot.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": "Chapter 11/squareRoot.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": "Chapter 11/squareRoot.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": 37.7222222222, "max_line_length": 111, "alphanum_fraction": 0.6951399116, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6739467695182494}} {"text": "data Id : Type where\n MkId : Nat -> Id\n\nbeq_id : (x1, x2 : Id) -> Bool\nbeq_id (MkId n1) (MkId n2) = n1 == n2\n\nbeq_id_refl : (x : Id) -> True = beq_id x x\nbeq_id_refl (MkId Z) = Refl\nbeq_id_refl (MkId (S k)) = rewrite beq_id_refl (MkId k) in Refl\n\ndata PartialMap : Type where\n Empty : PartialMap\n Record : Id -> Nat -> PartialMap -> PartialMap\n\nupdate : (d : PartialMap) -> (x : Id) -> (value : Nat) -> PartialMap\nupdate d x value = Record x value d\n\nfind : (x : Id) -> (d : PartialMap) -> Maybe Nat\nfind x Empty = Nothing\nfind x (Record y v d') =\n if beq_id x y\n then Just v\n else find x d'\n\nupdate_eq : (d : PartialMap) -> (x : Id) -> (v : Nat) -> find x (update d x v) = Just v\nupdate_eq d x v = rewrite sym $ beq_id_refl x in Refl\n\nupdate_neq : (d : PartialMap) -> (x, y : Id) -> (o : Nat) -> beq_id x y = False -> find x (update d y o) = find x d\nupdate_neq d x y o prf = rewrite prf in Refl\n\ndata Baz : Type where\n Baz1 : Baz -> Baz\n Baz2 : Baz -> Bool -> Baz\n", "meta": {"hexsha": "28669b2b9cf2490b48196b8bc5e02449f349f4d3", "size": 998, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/SF45.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/SF45.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/SF45.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": 29.3529411765, "max_line_length": 115, "alphanum_fraction": 0.5951903808, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6736845697370856}} {"text": "module Data.Mod\n\nimport Control.Algebra\nimport Data.Fin\n\n%default total\n%access public export\n\n||| Modular arithmetic\ndata Mod : (n : Nat) -> Type where\n MkMod : (fin : Fin n) -> Mod n\n\nimplementation Eq (Mod n) where\n (==) (MkMod x) (MkMod y) = x == y\n\nimplementation Cast (Mod n) Nat where\n cast (MkMod x) = cast x\n\nimplementation Cast (Mod n) (Fin n) where\n cast (MkMod x) = x\n\nimplementation Ord (Mod (S n)) where\n compare (MkMod x) (MkMod y) = compare x y\n\nimplementation MinBound (Mod (S n)) where\n minBound = MkMod FZ\n\nimplementation MaxBound (Mod (S n)) where\n maxBound = MkMod last\n\nnatToMod : Nat -> Mod (S n)\nnatToMod {n=(S m)} x =\n MkMod (finMod (modNatNZ x (S (S m)) (uninhabited . sym))) where\n finMod : Nat -> Fin (S k)\n finMod Z = FZ\n finMod {k=S k'} (S l) = FS (finMod {k=k'} l)\n finMod _ = FZ\nnatToMod _ = MkMod FZ\n\nmodToInteger : Mod n -> Integer\nmodToInteger (MkMod x) = finToInteger x\n\nmodToNat : Mod n -> Nat\nmodToNat (MkMod x) = finToNat x\n\nrotate : Fin (S n) -> Fin (S n)\nrotate {n=Z} _ = FZ\nrotate {n = S m} FZ = FS FZ\nrotate {n = S m} (FS g) = if (FS g) == last\n then FZ\n else FS (rotate g)\n\nprivate\nmodplus : Mod (S n) -> Mod (S n) -> Mod (S n)\nmodplus (MkMod left) (MkMod right) = MkMod (spin left right)\n where spin : Fin (S n') -> Fin (S n) -> Fin (S n)\n spin FZ right = right\n spin {n' = Z} left right = rotate right\n spin {n' = S m} (FS left) right = rotate (spin left right)\n\nimplementation Semigroup (Mod (S n)) where\n (<+>) = modplus\n\nimplementation Monoid (Mod (S n)) where\n neutral = MkMod FZ\n\nimplementation Group (Mod (S n)) where\n inverse (MkMod FZ) = MkMod FZ\n inverse {n=n} (MkMod m) = natToMod ((S n) `minus` (finToNat m))\n\nimplementation Num (Mod (S n)) where\n (+) = modplus\n (*) (MkMod a) (MkMod b) = fromInteger (finToInteger a * finToInteger b)\n fromInteger {n=n} x = if x < 0\n then inverse (natToMod (modNatNZ (fromInteger (-x)) (S n) (uninhabited . sym)))\n else natToMod (modNatNZ (fromInteger x) (S n) (uninhabited . sym))\n\nimplementation Neg (Mod (S n)) where\n negate = const (MkMod FZ)\n (-) = (<->)\n", "meta": {"hexsha": "1a5f1f2ed26a55a243ee74b741a594e2cbd3ecf2", "size": 2198, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/Mod.idr", "max_stars_repo_name": "idris-hackers/idris-crypto", "max_stars_repo_head_hexsha": "0fb69b76e399f2fa72f338e410504323751843e7", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-01-11T20:37:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T07:41:27.000Z", "max_issues_repo_path": "src/Data/Mod.idr", "max_issues_repo_name": "idris-hackers/idris-crypto", "max_issues_repo_head_hexsha": "0fb69b76e399f2fa72f338e410504323751843e7", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-09-10T20:32:40.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-18T16:27:23.000Z", "max_forks_repo_path": "src/Data/Mod.idr", "max_forks_repo_name": "idris-hackers/idris-crypto", "max_forks_repo_head_hexsha": "0fb69b76e399f2fa72f338e410504323751843e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-04-23T23:09:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T22:30:23.000Z", "avg_line_length": 27.1358024691, "max_line_length": 103, "alphanum_fraction": 0.5996360328, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6736561679888979}} {"text": "module Refined \n\ndata Vect : (len : Nat) -> (elem : Type) -> Type where\n Nil : Vect Z elem\n (::) : (x : elem) -> (xs : Vect len elem) -> Vect (S len) elem\n\n-- Definitions \n\ndigits : List Char\ndigits = ['0'..'9']\n\nlowerCase : List Char\nlowerCase = ['a'..'z']\n\nupperCase : List Char\nupperCase = ['A'..'Z']\n\n-- Elem property\n\ndata Elem : a -> List a -> Type where\n Here : Elem x (x :: xs)\n There : (later : Elem x xs) -> Elem x (y :: xs)\n\n-- Elem examples\n\naIsLC : Elem 'a' Refined.lowerCase\naIsLC = Here \n\nbIsLC : Elem 'b' Refined.lowerCase\nbIsLC = There Here \n\nkIsLC : Elem 'k' Refined.lowerCase\nkIsLC = There (There (There (There (There (There (There (There (There (There Here)))))))))\n\n-- Not true....\nnotA : Not (Elem 'a' ['A'])\nnotA (There Here) impossible\nnotA (There (There _)) impossible\n\n-- Properties\n\nDigits : Char -> Type \nDigits c = Elem c Refined.digits\n\nLowerCase : Char -> Type\nLowerCase c = Elem c Refined.lowerCase \n\nUpperCase : Char -> Type\nUpperCase c = Elem c Refined.upperCase\n\n-- Dependent pairs\n\nx : (n : Nat ** Vect n Int)\nx = (_ ** [1,2,3])\n\n-- Refinement type \n\nRefined : (a: Type) -> ( P : a -> Type ) -> Type \nRefined = DPair \n\nrefbIsLC : Refined Char LowerCase\nrefbIsLC = ('b' ** There Here ) \n\n-- Conversion\n\nimplicit \ntoRefined : { a : Type } -> { P : a -> Type } -> ( x : a) -> { auto property: P x } -> Refined a P \ntoRefined x { property } = ( x ** property ) \n\ntestRefA : Refined Char LowerCase\ntestRefA = 'a'\n\ntestRefB : Char `Refined` LowerCase\ntestRefB = 'b'\n\nimplicit \nfromRefinedChar : { P : Char -> Type } -> Refined Char P -> Char \nfromRefinedChar = fst\n\n-- Examples\n\nprintChar : Char -> IO ()\nprintChar = printLn\n\nmain : IO () \nmain = printChar Refined.testRefA\n\n{-\n\nIdris Refined\nhttps://github.com/janschultecom/idris-refined\n\nIdris UG Dusseldorf\nhttps://www.meetup.com/de-DE/Idris-User-Group-Dusseldorf/\n\n-}\n\n", "meta": {"hexsha": "3e490438e678c5155cf8d44fe873d1adc6f540a4", "size": 1861, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Refined-solution.idr", "max_stars_repo_name": "janschultecom/2017-11-20-Lambda-Meetup-Munich", "max_stars_repo_head_hexsha": "45a77d1b3f9a16fa2d32a410729122f30fc5bd76", "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": "Refined-solution.idr", "max_issues_repo_name": "janschultecom/2017-11-20-Lambda-Meetup-Munich", "max_issues_repo_head_hexsha": "45a77d1b3f9a16fa2d32a410729122f30fc5bd76", "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": "Refined-solution.idr", "max_forks_repo_name": "janschultecom/2017-11-20-Lambda-Meetup-Munich", "max_forks_repo_head_hexsha": "45a77d1b3f9a16fa2d32a410729122f30fc5bd76", "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": 18.9897959184, "max_line_length": 99, "alphanum_fraction": 0.6308436325, "num_tokens": 597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6735859272187632}} {"text": "data Nat : Type where\n Z : Nat\n S : (1 k : Nat) -> Nat\n\ndata Bool : Type where\n False : Bool\n True : Bool\n\ndata Thing : Bool -> Type where\n TF : Thing False\n TT : Thing True\n\ndata Maybe : Type -> Type where\n Nothing : {a : Type} -> Maybe a\n Just : {a : Type} -> a -> Maybe a\n\nok : (0 b : Bool) -> Thing b -> Bool\nok False TF = True\nok True TT = False\n\nid : {a : Type} -> (1 x : a) -> a\nid x = x\n\ntest : (1 x : Nat) -> Nat\ntest x = id x\n\ndata Pair : Type -> Type -> Type where\n MkPair : (1 x : a) -> (0 y : b) -> Pair a b\n\nfst : (1 p : Pair a b) -> a\nfst (MkPair x y) = x\n\nwibble : (1 p : Pair a b) -> a\nwibble {a=a} (MkPair x y)\n = let test : (1 y : a) -> a\n test y = y in\n test x\n\nplus : (1 x : Nat) -> (1 y : Nat) -> Nat\nplus Z y = y\nplus (S k) y = S (plus k y)\n\nholetest1 : (1 x : Nat) -> (1 y : Nat) -> Nat\nholetest1 x y = plus ?this y\n\nholetest2 : (1 x : Nat) -> (1 y : Nat) -> Nat\nholetest2 x y = plus x ?that\n\n", "meta": {"hexsha": "5403711b7a88987d8c6764e9ea7a73bb719ccf6e", "size": 970, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/linear003/Linear.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/linear003/Linear.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/linear003/Linear.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": 19.7959183673, "max_line_length": 48, "alphanum_fraction": 0.5020618557, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6735504764307373}} {"text": "module Utils\nimport Prelude.List as L\nimport Data.Vect as V\n\n%access export\n\npublic export\nMatrix : Nat -> Nat -> Type -> Type\nMatrix n m a = Vect n $ Vect m a\n\ntoList : Matrix m n elem -> List $ List elem\ntoList = L.toList . map L.toList\n\ngroup : (Eq a) => List a -> List $ List a\ngroup [] = []\ngroup (x :: xs) = \n\tlet (ys, zs) = L.span (== x) xs in (x :: ys) :: (group $ assert_smaller (x :: xs) zs) -- Bad\n\nsplitAt' : (n : Nat) -> Vect (1 + n + m) elem -> (Vect n elem, elem, Vect m elem)\nsplitAt' Z (x :: xs) = ([], x, xs)\nsplitAt' (S k) (x :: xs) with (splitAt' k xs) \n\t| (l, m, r) = (x :: l, m, r)\n\nnatToFin' : (n : Nat) -> (m : Nat) -> Maybe (Fin m, LT n m) -- Is there a better way to do this?\nnatToFin' Z (S x) = Just (FZ, LTESucc $ LTEZero)\nnatToFin' (S k1) (S k2) with (natToFin' k1 k2)\n\t| Just (x, p) = Just (FS x, LTESucc p)\n\t| Nothing = Nothing\nnatToFin' _ _ = Nothing\n\nplusMinusNeutral : {n : Nat} -> {m : Nat} -> (p : GTE m n) -> (n + (minus m n)) = m\nplusMinusNeutral {n = Z} {m = m} _ = minusZeroRight m\nplusMinusNeutral {n = (S _)} {m = Z} LTEZero impossible\nplusMinusNeutral {n = (S _)} {m = Z} (LTESucc _) impossible\nplusMinusNeutral {n = (S k1)} {m = (S k2)} p = \n\teqSucc (k1 + (minus k2 k1)) k2 (plusMinusNeutral {n = k1} {m = k2} $ fromLteSucc p)\n\nsuccMinus : {n : Nat} -> {m : Nat} -> (p : GTE n m) -> (1 + minus n m) = (minus (1 + n) m) \nsuccMinus {n = Z} {m = Z} _ = Refl\nsuccMinus {n = Z} {m = (S _)} LTEZero impossible\nsuccMinus {n = Z} {m = (S _)} (LTESucc _) impossible\nsuccMinus {n = (S k)} {m = Z} p = Refl\nsuccMinus {n = (S k1)} {m = S (k2)} p = succMinus {n = k1} {m = k2} (fromLteSucc p)\n\nprivate\nlemma : {n : Nat} -> {x : Maybe $ elem} -> {xs : Vect n $ Maybe $ elem} -> LTE (fst $ catMaybes $ x :: xs) (S $ fst $ catMaybes $ xs)\nlemma {n = Z} {x = Nothing} {xs = []} = LTEZero\nlemma {n = Z} {x = (Just x)} {xs = []} = LTESucc LTEZero\nlemma {n = (S len)} {x = Nothing} = lteSuccRight $ lteRefl\nlemma {n = (S len)} {x = Just x} = ?l -- No idea how to prove this in Idris! The proof involves a case expression.\n\ncatMaybesLTE : {n : Nat} -> {xs : Vect n (Maybe elem)} -> LTE (fst $ catMaybes xs) n\ncatMaybesLTE {n = Z} {xs = []} = LTEZero\ncatMaybesLTE {n = (S len)} {xs = (x :: xs)} = \n\tlteTransitive lemma $ LTESucc $ catMaybesLTE {n = len} {xs = xs}\n", "meta": {"hexsha": "602a5e99dd7206b73a905c58a91af473374cb8c4", "size": 2286, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/utils.idr", "max_stars_repo_name": "Gwin73/idris-four-in-a-row", "max_stars_repo_head_hexsha": "30d1f8c3fbf71c77385ba2e2edb23ef2ea7c86f5", "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.idr", "max_issues_repo_name": "Gwin73/idris-four-in-a-row", "max_issues_repo_head_hexsha": "30d1f8c3fbf71c77385ba2e2edb23ef2ea7c86f5", "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.idr", "max_forks_repo_name": "Gwin73/idris-four-in-a-row", "max_forks_repo_head_hexsha": "30d1f8c3fbf71c77385ba2e2edb23ef2ea7c86f5", "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.8214285714, "max_line_length": 133, "alphanum_fraction": 0.5682414698, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6735504721468095}} {"text": "> module Functor.Predicates\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Naturality\n\n> ||| What it means for a transformation to be natural\n> Natural : {F, G : Type -> Type} -> \n> (Functor F) => (Functor G) =>\n> (t : {A : Type} -> F A -> G A) -> \n> Type \n> \n> Natural {F} {G} t = {A, B : Type} -> \n> (f : A -> B) ->\n> (x : F A) -> \n> t (map f x) = map f (t x) \n\n> {-\n> ||| What it means for a transformation to be natural\n> Natural : {F, G : Type -> Type} -> \n> (Functor F) => (Functor G) =>\n> (t : (A : Type) -> F A -> G A) -> \n> Type \n> \n> Natural {F} {G} t = {A, B : Type} -> \n> (f : A -> B) ->\n> (x : F A) -> \n> t B (map f x) = map f (t A x) \n> -}\n\n\n* Monotonicity\n\n> ||| What it means for a measure to be monotone\n> Monotone : {B, C : Type} -> {F : Type -> Type} -> (Functor F) => \n> (LTE_B : B -> B -> Type) -> \n> (LTE_C : C -> C -> Type) -> \n> (measure : F B -> C) -> \n> Type\n> \n> Monotone {B} {C} {F} LTE_B LTE_C measure =\n> {A : Type} ->\n> (f : A -> B) -> \n> (g : A -> B) -> \n> (p : (a : A) -> f a `LTE_B` g a) -> \n> (x : F A) -> \n> measure (map f x) `LTE_C` measure (map g x) \n\n\n> {-\n\n\n> ---}\n", "meta": {"hexsha": "79d70a4396836fd6e4a73bdd946621793c51bf63", "size": 1419, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Functor/Predicates.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": "Functor/Predicates.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": "Functor/Predicates.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.8947368421, "max_line_length": 67, "alphanum_fraction": 0.3664552502, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6735203126283723}} {"text": "module Ch03.Arith\n\nimport public Ch03.Relations\n\n%default total\n%access public export\n\n----------------------------\n-- Term syntax\n----------------------------\n\nnamespace Terms\n data Term = True\n | False\n | IfThenElse Term Term Term\n | Zero\n | Succ Term\n | Pred Term\n | IsZero Term\n\nnamespace Values\n mutual\n Value : Type\n Value = Either BoolValue NumValue\n\n data BoolValue = True | False\n data NumValue = Zero | Succ NumValue\n\n||| Converts a boolean value to its corresponding term\nbv2t : BoolValue -> Term\nbv2t True = True\nbv2t False = False\n\n||| Converts a numeric value to its corresponding term\nnv2t : NumValue -> Term\nnv2t Zero = Zero\nnv2t (Succ x) = Succ (nv2t x)\n\n||| Converts a value to its corresponding term\nv2t : Value -> Term\nv2t (Left bv) = bv2t bv\nv2t (Right nv) = nv2t nv\n\nnamespace IsValue\n ||| Propositional type describing that a term \"is\" indeed a value\n data IsValue : Term -> Type where\n ConvertedFrom : (v : Value) -> IsValue (v2t v)\n\nnamespace IsNumValue\n ||| Propositional type describing that a term \"is\" indeed a numeric value\n data IsNumValue : Term -> Type where\n ConvertedFrom : (nv : NumValue) -> IsNumValue (v2t (Right nv))\n\nnamespace IsBoolValue\n ||| Propositional type describing that a term \"is\" indeed a boolean value\n data IsBoolValue : Term -> Type where\n ConvertedFrom : (bv : BoolValue) -> IsBoolValue (v2t (Left bv))\n\n----------------------------\n-- Evaluation rules\n----------------------------\n\n||| Propositional type describing that the first term one-step-evaluates to the second\n|||\n||| Explicitly, an inhabitant of `EvalsTo t1 t2` is a proof that `t1` evaluates to `t2` in one step.\ndata EvalsTo : Term -> Term -> Type where\n EIfTrue : EvalsTo (IfThenElse True t2 t3) t2\n EIfFalse : EvalsTo (IfThenElse False t2 t3) t3\n EIf : EvalsTo t1 t1' -> EvalsTo (IfThenElse t1 t2 t3) (IfThenElse t1' t2 t3)\n ESucc : EvalsTo t1 t2 -> EvalsTo (Succ t1) (Succ t2)\n EPredZero : EvalsTo (Pred Zero) Zero\n EPredSucc : {pf : IsNumValue nv1} -> EvalsTo (Pred (Succ nv1)) nv1\n EPred : EvalsTo t1 t2 -> EvalsTo (Pred t1) (Pred t2)\n EIsZeroZero : EvalsTo (IsZero Zero) True\n EIsZeroSucc : {pf : IsNumValue nv1} -> EvalsTo (IsZero (Succ nv1)) False\n EIsZero : EvalsTo t1 t2 -> EvalsTo (IsZero t1) (IsZero t2)\n\n||| Propositional type describing that the first term evaluates to the second in a finite number of steps\n|||\n||| Explicitly, an inhabitant of `EvalToStar t1 t2` is a proof that there is a finite sequence\n||| \n||| t1 = s_0, s_1, ..., s_n = t2\n|||\n||| of terms (where `0 <= n`), such that `s_i` one-step-evaluates to `s_{i+1}`.\nEvalsToStar : Term -> Term -> Type\nEvalsToStar = ReflSymmClos EvalsTo\n\n----------------------------\n-- Big Step Evaluation rules\n----------------------------\n\n||| Propositional type describing that the first term big-step evaluates to the second\ndata BigEvalsTo : Term -> Term -> Type where\n BValue : {pf : IsValue v} -> BigEvalsTo v v\n BIfTrue : {pf : IsValue v2} ->\n BigEvalsTo t1 True ->\n BigEvalsTo t2 v2 -> \n BigEvalsTo (IfThenElse t1 t2 t3) v2\n BIfFalse : {pf : IsValue v3} ->\n BigEvalsTo t1 False ->\n BigEvalsTo t3 v3 -> \n BigEvalsTo (IfThenElse t1 t2 t3) v3\n BSucc : {pf : IsNumValue nv1} ->\n BigEvalsTo t1 nv1 -> \n BigEvalsTo (Succ t1) (Succ nv1)\n BPredZero : BigEvalsTo t1 Zero ->\n BigEvalsTo (Pred t1) Zero\n BPredSucc : {pf : IsNumValue nv1} ->\n BigEvalsTo t1 (Succ nv1) ->\n BigEvalsTo (Pred t1) nv1\n BIsZeroZero : BigEvalsTo t1 Zero ->\n BigEvalsTo (IsZero t1) True\n BIsZeroSucc : {pf : IsNumValue nv1} ->\n BigEvalsTo t1 (Succ nv1) ->\n BigEvalsTo (IsZero t1) False\n\n--------------------------------------------------------------------------------\n-- Some properties of values and evaluation\n--------------------------------------------------------------------------------\n\n||| A numeric value is also a value\nnumValueIsValue : IsNumValue t -> IsValue t\nnumValueIsValue {t = (v2t (Right nv))} (ConvertedFrom nv) = IsValue.ConvertedFrom (Right nv)\n\n||| The successor of a numeric value is a numeric value\nsuccNumValueIsNumValue : IsNumValue t -> IsNumValue (Succ t)\nsuccNumValueIsNumValue {t = (v2t (Right nv))} (ConvertedFrom nv) = ConvertedFrom (Succ nv)\n\n||| A boolean value is also a value\nboolValueIsValue : IsBoolValue t -> IsValue t\nboolValueIsValue {t = (v2t (Left bv))} (ConvertedFrom bv) = IsValue.ConvertedFrom (Left bv)\n\nnumValueEither : IsNumValue t -> Either (t = Zero) (t' : Term ** (IsNumValue t', t = Succ t'))\nnumValueEither (ConvertedFrom nv) = case nv of\n Zero => Left Refl\n (Succ nv') => Right (nv2t nv' ** (ConvertedFrom nv', Refl))\n\nboolValueEither : IsBoolValue t -> Either (t = True) (t = False)\nboolValueEither (ConvertedFrom True) = Left Refl\nboolValueEither (ConvertedFrom False) = Right Refl\n\nzeroNotBool : IsBoolValue Zero -> Void\nzeroNotBool (ConvertedFrom True) impossible\nzeroNotBool (ConvertedFrom False) impossible\n\nsuccNotTrue : {t : Term} -> (Succ t = True) -> Void\nsuccNotTrue Refl impossible\n\nsuccNotFalse : {t : Term} -> (Succ t = False) -> Void\nsuccNotFalse Refl impossible\n\nsuccNotBool : IsBoolValue (Succ t) -> Void\nsuccNotBool {t} x = case boolValueEither x of\n (Left l) => succNotTrue l\n (Right r) => succNotFalse r\n\n||| A value can't be both numeric and boolean at the same time.\nnumNotBool : IsNumValue t -> IsBoolValue t -> Void\nnumNotBool x y = case numValueEither x of\n (Left Refl) => zeroNotBool y\n (Right (_ ** (_, Refl))) => succNotBool y\n\n||| Proof that values don't evaluate to anything in the `E`-calculus.\nvaluesDontEvaluate : {pf : IsValue v} -> EvalsTo v t -> Void\nvaluesDontEvaluate {pf = (ConvertedFrom (Left bv))} {v = (bv2t bv)} x = case bv of\n True => (case x of\n EIfTrue impossible\n EIfFalse impossible\n (EIf _) impossible\n (ESucc _) impossible\n EPredZero impossible\n EPredSucc impossible\n (EPred _) impossible\n EIsZeroZero impossible\n EIsZeroSucc impossible\n (EIsZero _) impossible)\n False => (case x of\n EIfTrue impossible\n EIfFalse impossible\n (EIf _) impossible\n (ESucc _) impossible\n EPredZero impossible\n EPredSucc impossible\n (EPred _) impossible\n EIsZeroZero impossible\n EIsZeroSucc impossible\n (EIsZero _) impossible)\nvaluesDontEvaluate {pf = (ConvertedFrom (Right nv))} {v = (nv2t nv)} x = case nv of\n Zero => (case x of\n EIfTrue impossible\n EIfFalse impossible\n (EIf _) impossible\n (ESucc _) impossible\n EPredZero impossible\n EPredSucc impossible\n (EPred _) impossible\n EIsZeroZero impossible\n EIsZeroSucc impossible\n (EIsZero _) impossible)\n (Succ nv) => (case x of\n (ESucc y) => valuesDontEvaluate {pf=ConvertedFrom (Right nv)} y)\n\n||| Proof that the only derivation of a value term in the reflexive transitive of the `E`-evaluation rules\n||| is the trivial derivation.\nvaluesAreNormal : {pf : IsValue v} -> (r : EvalsToStar v t) -> (r = (Refl {rel=EvalsTo} {x=v}))\nvaluesAreNormal (Refl {x}) = Refl\nvaluesAreNormal {pf} (Cons x y) with (valuesDontEvaluate {pf=pf} x)\n valuesAreNormal {pf} (Cons x y) | with_pat impossible\n\n||| Proof that a value is either\n|||\n||| 1. `True`\n||| 2. `False`\n||| 3. `Zero`\n||| 4. `Succ nv`, with `nv` a numeric value\nvalueIsEither : (v : Term) -> {pf : IsValue v} -> Either (v = True) (Either (v = False) (Either (v = Zero) (nv : Term ** ((v = Succ nv), IsNumValue nv))))\nvalueIsEither (bv2t x) {pf = (ConvertedFrom (Left x))} = case x of\n True => Left Refl\n False => Right (Left Refl)\nvalueIsEither (nv2t x) {pf = (ConvertedFrom (Right x))} = case x of\n Zero => Right (Right (Left Refl))\n (Succ y) => Right (Right (Right (nv2t y ** (Refl, ConvertedFrom y))))\n\n||| Proof that a term of the form `Succ t` is only a value if `t` is a numeric value.\nsuccIsValueIf : IsValue (Succ t) -> IsNumValue t\nsuccIsValueIf (ConvertedFrom (Left Values.True)) impossible\nsuccIsValueIf (ConvertedFrom (Left Values.False)) impossible\nsuccIsValueIf (ConvertedFrom (Right Values.Zero)) impossible\nsuccIsValueIf (ConvertedFrom (Right (Succ nv))) = ConvertedFrom nv\n\n||| Proof that a term of the form `Pred t` is never a value.\npredNotValue : IsValue (Pred t) -> Void\npredNotValue (ConvertedFrom (Left Values.True)) impossible\npredNotValue (ConvertedFrom (Left Values.False)) impossible\npredNotValue (ConvertedFrom (Right Values.Zero)) impossible\npredNotValue (ConvertedFrom (Right (Values.Succ nv))) impossible\n\n||| Proof that a term of the form `IsZero t` is never a value.\nisZeroNotValue : IsValue (IsZero t) -> Void\nisZeroNotValue (ConvertedFrom (Left Values.True)) impossible\nisZeroNotValue (ConvertedFrom (Left Values.False)) impossible\nisZeroNotValue (ConvertedFrom (Right Values.Zero)) impossible\nisZeroNotValue (ConvertedFrom (Right (Values.Succ nv))) impossible\n\n||| Proof that a value only evaluates to itself under the reflexive transitive closure of\n||| the `E`-evaluation rules.\nvaluesAreNormal' : {pf : IsValue v} ->\n EvalsToStar v t ->\n (t = v)\nvaluesAreNormal' {pf} x with (valuesAreNormal {pf=pf} x)\n valuesAreNormal' {pf} x | with_pat = case with_pat of\n Refl => Refl\n\n||| Proof that a term of the form `IfThenElse x y z` is never a value.\nifThenElseNotNormal : (pf : IsValue (IfThenElse x y z)) -> Void\nifThenElseNotNormal {x} {y} {z} pf with (valueIsEither (IfThenElse x y z) {pf=pf})\n ifThenElseNotNormal {x} {y} {z} pf | (Left l) = case l of\n Refl impossible\n ifThenElseNotNormal {x} {y} {z} pf | (Right (Left l)) = case l of\n Refl impossible\n ifThenElseNotNormal {x} {y} {z} pf | (Right (Right (Left l))) = case l of\n Refl impossible\n ifThenElseNotNormal {x} {y} {z} pf | (Right (Right (Right (nv ** (pf1, pf2))))) = case pf1 of\n Refl impossible\n----------------------------\n-- Miscellanea\n----------------------------\n\nt1 : Term\nt1 = IfThenElse False Zero (Succ Zero)\n\nt2 : Term\nt2 = IsZero (Pred (Succ Zero))\n\ntoString : Term -> String\ntoString True = \"true\"\ntoString False = \"false\"\ntoString (IfThenElse x y z) = \"if \" ++ toString x ++\n \" then \" ++ toString y ++\n \" else \" ++ toString z\ntoString Zero = \"0\"\ntoString (Succ x) = \"succ (\" ++ toString x ++ \")\"\ntoString (Pred x) = \"pred (\" ++ toString x ++ \")\"\ntoString (IsZero x) = \"iszero (\" ++ toString x ++ \")\"\n\neval : Term -> Value\neval True = Left True\neval False = Left True\neval (IfThenElse x y z) = case eval x of\n (Left r) => case r of\n True => eval y\n False => eval z\n (Right l) => ?eval_rhs_1\neval Zero = Right Zero\neval (Succ x) = case eval x of\n Left l => ?eval_rhs_4\n Right r => Right (Succ r)\neval (Pred x) = case eval x of\n Left l => ?eval_rhs_5\n Right r => case r of\n Zero => Right Zero\n Succ x => Right x\neval (IsZero x) = case x of\n Zero => Left True\n Succ y => Left False\n _ => ?eval_rhs2\n \n||| The size of a term is the number of constructors it contains.\nsize : Term -> Nat\nsize True = 1 \nsize False = 1\nsize (IfThenElse x y z) = (size x) + (size y) + (size z) + 1\nsize Zero = 1\nsize (Succ x) = S (size x)\nsize (Pred x) = S (size x)\nsize (IsZero x) = S (size x)\n\n||| The depth of a term is depth of its derivation tree.\ndepth : Term -> Nat\ndepth True = 1\ndepth False = 1\ndepth (IfThenElse x y z) = (max (depth x) (max (depth y) (depth z))) + 1\ndepth Zero = 1\ndepth (Succ x) = S (depth x)\ndepth (Pred x) = S (depth x)\ndepth (IsZero x) = S (depth x)\n", "meta": {"hexsha": "1ae5c968957ef0f3098eec9e6f320d4f7c4b6a02", "size": 15634, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Ch03/Arith.idr", "max_stars_repo_name": "mr-infty/tapl", "max_stars_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-02-27T13:52:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:38:28.000Z", "max_issues_repo_path": "Ch03/Arith.idr", "max_issues_repo_name": "mr-infty/tapl", "max_issues_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch03/Arith.idr", "max_forks_repo_name": "mr-infty/tapl", "max_forks_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T04:56:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T07:08:45.000Z", "avg_line_length": 47.8103975535, "max_line_length": 161, "alphanum_fraction": 0.4742228476, "num_tokens": 3576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.673092417653828}} {"text": "module hw1\n\nimport Data.Vect\nimport Data.Fin\n\nswap: Vect n a -> Fin n -> Fin n -> Vect n a\nswap vect i j = set i (at j vect) (set j (at i vect) vect)\n\twhere \n\t\tset: Fin n -> a -> Vect n a -> Vect n a\n\t\tset FZ val (x :: xs) = val :: xs\n\t\tset (FS ind) val (x :: xs) = x :: (set ind val xs)\n\n\t\tat: Fin n -> Vect n a -> a\n\t\tat FZ (x :: xs) = x\n\t\tat (FS ind) (x :: xs) = at ind xs\n\ni : Fin 4\ni = 0\nj : Fin 4\nj = 1\n\n\n--plus_fin: Fin a -> Fin b -> Fin (a + b)\n--plus_fin FZ FZ = FZ\n--plus_fin (FS a) FZ = FS (plus_fin a FZ)\n--plus_fin FZ (FS b) = FS (plus_fin FZ b)\n--plus_fin (FS a) (FS b) = FS (plus_fin a (FS b))\n\n--mul_fin: Fin a -> Fin b -> Fin (a * b)\n--mul_fin FZ b = FZ\n--mul_fin (FS a) b = plus_fin a (mul_fin a b)\n\nc : Fin 3\nc = 2\nd : Fin 4\nd = 0\n\n\ndec_fin: Fin (S a) -> Fin a\ndec_fin (FS a) = a\n\na : Fin 4\na = 3\nb : Fin 5\nb = 2\n\n\nnat_min: Nat -> Nat -> Nat\nnat_min Z (S b) = Z\nnat_min (S a) Z = Z\nnat_min (S a) (S b) = S (nat_min a b)", "meta": {"hexsha": "d62afa9e730124b232d1efda79e6afbd4a07fd00", "size": 939, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Haskell/2ndLab/Idris/hw1.idr", "max_stars_repo_name": "ShuffleZZZ/ITMO", "max_stars_repo_head_hexsha": "29db54d96afef0558550471c58f695c962e1f747", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2020-04-23T15:48:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T10:16:40.000Z", "max_issues_repo_path": "Haskell/2ndLab/Idris/hw1.idr", "max_issues_repo_name": "ShuffleZZZ/ITMO", "max_issues_repo_head_hexsha": "29db54d96afef0558550471c58f695c962e1f747", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-02-28T01:16:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-20T19:05:34.000Z", "max_forks_repo_path": "Haskell/2ndLab/Idris/hw1.idr", "max_forks_repo_name": "ShuffleZZZ/ITMO", "max_forks_repo_head_hexsha": "29db54d96afef0558550471c58f695c962e1f747", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2018-12-02T15:03:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-10T18:31:00.000Z", "avg_line_length": 18.4117647059, "max_line_length": 58, "alphanum_fraction": 0.5378061768, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6730809606939091}} {"text": "module SmallStepExpr\n\nimport Expr\nimport Maps\n\n%access public export\n\n%default total\n\ndata AVal : AExp -> Type where\n AV_Num : (n : Nat) -> AVal (ANum n)\n\ndata AStep : State -> AExp -> AExp -> Type where\n AS_Id : AStep st (AId i) (ANum (st i))\n AS_Plus1 : AStep st a1 a1' -> AStep st (APlus a1 a2) (APlus a1' a2)\n AS_Plus2 : AVal v1 -> AStep st a2 a2' -> AStep st (APlus v1 a2) (APlus v1 a2')\n AS_Plus : AStep st (APlus (ANum n1) (ANum n2)) (ANum (n1 + n2))\n AS_Minus1 : AStep st a1 a1' -> AStep st (AMinus a1 a2) (AMinus a1' a2)\n AS_Minus2 : AVal v1 -> AStep st a2 a2' ->\n AStep st (AMinus v1 a2) (AMinus v1 a2')\n AS_Minus : AStep st (AMinus (ANum n1) (ANum n2)) (ANum (minus n1 n2))\n AS_Mult1 : AStep st a1 a1' -> AStep st (AMult a1 a2) (AMult a1' a2)\n AS_Mult2 : AVal v1 -> AStep st a2 a2' -> AStep st (AMult v1 a2) (AMult v1 a2')\n AS_Mult : AStep st (AMult (ANum n1) (ANum n2)) (ANum (n1 * n2))\n\nsyntax [t] \"/\" [st] \"-+>a\" [t'] = AStep st t t'\n\ndata BStep : State -> BExp -> BExp -> Type where\n BS_Eq1 : AStep st a1 a1' -> BStep st (BEq a1 a2) (BEq a1' a2)\n BS_Eq2 : AVal v1 -> AStep st a2 a2' -> BStep st (BEq v1 a2) (BEq v1 a2')\n BS_Eq : BStep st\n (BEq (ANum n1) (ANum n2))\n (if n1 == n2 then BTrue else BFalse)\n BS_Le1 : AStep st a1 a1' -> BStep st (BLe a1 a2) (BLe a1' a2)\n BS_Le2 : AVal v1 -> AStep st a2 a2' -> BStep st (BLe v1 a2) (BLe v1 a2')\n BS_Le : BStep st\n (BLe (ANum n1) (ANum n2))\n (if lte n1 n2 then BTrue else BFalse)\n BS_NotStep : BStep st b b' -> BStep st (BNot b) (BNot b')\n BS_NotTrue : BStep st (BNot BTrue) BFalse\n BS_NotFalse : BStep st (BNot BFalse) BTrue\n BS_AndStep : BStep st b1 b1' -> BStep st (BAnd b1 b2) (BAnd b1' b2)\n BS_AndTrueStep : BStep st b2 b2' -> BStep st (BAnd BTrue b2) (BAnd BTrue b2')\n BS_AndTrueTrue : BStep st (BAnd BTrue BTrue) BTrue\n BS_AndTrueFalse : BStep st (BAnd BTrue BFalse) BFalse\n BS_AndFalse : BStep st (BAnd BFalse b2) BFalse\n\nsyntax [t] \"/\" [st] \"-+>b\" [t'] = BStep st t t'\n", "meta": {"hexsha": "92cd8c8ed3a3f7b8c52b07ab2b2b67e8395f390d", "size": 2035, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "SmallStepExpr.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": "SmallStepExpr.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": "SmallStepExpr.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": 41.5306122449, "max_line_length": 80, "alphanum_fraction": 0.6068796069, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6725385700775033}} {"text": "module Interfaces\n\n\n%default total\n-- Define function equality\n\npublic export\ndata FuncEqType : func1 -> func2 -> Type where\n funcEqType : (f : a -> b) -> (g : a -> b) -> ((x : a) -> f x = g x) -> FuncEqType f g\n\npublic export\nstateFuncEqTransitive : {f : a -> b} -> {g : a -> b} -> {h : a -> b} -> FuncEqType f g -> FuncEqType g h -> FuncEqType f h\nstateFuncEqTransitive (funcEqType f g f_eq_g) (funcEqType g h g_eq_h) = funcEqType f h (\\z => rewrite f_eq_g z in g_eq_h z)\n\npublic export\nstateFuncEqReflexive : {f : a -> b} -> FuncEqType f f\nstateFuncEqReflexive = funcEqType f f (\\z => Refl)\n\npublic export\nstateFuncEqSymmetry : FuncEqType a b -> FuncEqType b a\nstateFuncEqSymmetry (funcEqType f g a_eq_b) = funcEqType g f (\\z => sym (a_eq_b z))\n\n-- Functor Interface\n\npublic export\ninterface MyFunctor (f : Type -> Type) where\n -- equality\n equalsTo : (x : f a) -> (y : f a) -> Type\n eqReflexive : {x : f a} -> x `equalsTo` x\n eqSymmetry : {x, y : f a} -> x `equalsTo` y -> y `equalsTo` x\n eqTransitive : {x, y, z : f a} -> x `equalsTo` y -> y `equalsTo` z -> x `equalsTo` z\n\n -- map\n myMap : (func : a -> b) -> (x : f a) -> f b\n\n -- functor law\n functorLawIdentity : (x : f a) -> myMap Prelude.id x `equalsTo` x\n functorLawComposition : (v : (b -> c)) -> (u : (a -> b)) -> (x : f a) -> myMap (v . u) x `equalsTo` myMap v (myMap u x)\n\ninfixl 3 <<*>>\n\npublic export\ninterface MyFunctor f => MyApplicative (f : Type -> Type) where\n myPure : a -> f a\n (<<*>>): f (a -> b) -> f a -> f b\n\n -- applicative law\n applicativeLawIdentity : (u : f a) ->\n (myPure Prelude.id <<*>> u) `equalsTo` u\n applicativeLawHomomorphism : (x : a) -> (func : a -> b) ->\n (myPure func <<*>> myPure x) `equalsTo` myPure (func x)\n applicativeLawInterchange : (u : f (a -> b)) -> (x : a) ->\n (u <<*>> myPure x) `equalsTo` (myPure ($ x) <<*>> u)\n applicativeLawComposition : (u : f (b -> c)) -> (v : f (a -> b)) -> (w : f a) ->\n (myPure (\\f => \\g => \\x => f (g x)) <<*>> u <<*>> v <<*>> w) `equalsTo` (u <<*>> (v <<*>> w))\n\ninfixl 1 >>>=\npublic export\ninterface MyFunctor m => MyMonad (m : Type -> Type) where\n myReturn : a -> m a\n (>>>=) : m a -> (a -> m b) -> m b\n\n monadLawIdentityLeft : (x : a) -> (f : a -> m b) -> (myReturn x >>>= f) `equalsTo` (f x)\n monadLawIdentityRight : (n : m a) -> (n >>>= myReturn) `equalsTo` n\n monadLawComposition : (n : m a) -> (f : a -> m b) -> (g : b -> m c) ->\n ((n >>>= f) >>>= g) `equalsTo` (n >>>= \\x => f x >>>= g)\n", "meta": {"hexsha": "d29427a6e0f7e1fd61b950d3536ed054f716b0e3", "size": 2515, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Interfaces.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": "Interfaces.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": "Interfaces.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": 37.5373134328, "max_line_length": 123, "alphanum_fraction": 0.5431411531, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6724742585041237}} {"text": "fiveIsFive : 5 = 5\nfiveIsFive = Refl\n\ntwoPlusTwo : 2 + 2 = 4\ntwoPlusTwo = Refl\n\n-- twoPlusTwoBad : 2 + 2 = 5\n-- twoPlusTwoBad = Refl\n\ndisjoint : (n : Nat) -> Z = S n -> Void\ndisjoint n prf = replace {p = disjointTy} prf ()\n where\n disjointTy : Nat -> Type\n disjointTy Z = ()\n disjointTy (S k) = Void\n\nplusReduces : (n:Nat) -> plus Z n = n\nplusReduces n = Refl\n\nplusReducesR : (n:Nat) -> plus n Z = n\nplusReducesR n = Refl\n\nplusReducesZ : (n:Nat) -> n = plus n Z\nplusReducesZ Z = Refl\nplusReducesZ (S k) = cong S (plusReducesZ k)\n\nplusReducesS : (n:Nat) -> (m:Nat) -> S (plus n m) = plus n (S m)\nplusReducesS Z m = Refl\nplusReducesS (S k) m = cong S (plusReducesS k m)\n", "meta": {"hexsha": "c5fa68de2bb73337016b4f40fefa9a48c3577532", "size": 678, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/samples/Proofs.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/samples/Proofs.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/samples/Proofs.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": 22.6, "max_line_length": 64, "alphanum_fraction": 0.6238938053, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6722355327034717}} {"text": "module BoundedNat\n\nimport Data.Fin\nimport Data.So\n\n%default total\n\nnamespace MaybeResult\n\n atm : (xs : List a) -> (n : Nat) -> Maybe a\n atm [] _ = Nothing\n atm (x::_) Z = Just x\n atm (_::xs) (S n) = xs `atm` n\n\nnamespace SoLtParam\n\n ats : (xs : List a) -> (n : Nat) -> {auto ok : So (n `lt` length xs)} -> a\n ats (x::_) Z = x\n ats (_::xs) (S k) {ok} = xs `ats` k\n ats [] Z impossible\n ats [] (S k) impossible\n\n x0s : Char\n x0s = ['1', '2', '3'] `ats` 0\n\n x2s : Char\n x2s = ['1', '2', '3'] `ats` 2\n\n --x3s : Char\n --x3s = ['1', '2', '3'] `ats` 3\n\nnamespace SoJustParam\n\n ltlt : So (n < k) -> So (n `lt` k)\n ltlt {n = Z} {k = Z} so = so\n ltlt {n = Z} {k = (S k)} so = so\n ltlt {n = (S j)} {k = Z} so = so\n ltlt {n = (S j)} {k = (S l)} _ with (choose (j < l))\n ltlt _ | Left subso = ltlt subso\n ltlt {n = (S j)} {k = (S l)} _ | Right sso with (compare j l)\n ltlt _ | Right sso | LT = absurd sso\n\n atss : (xs : List a) -> (n : Nat) -> {auto ok : So (n < length xs)} -> a\n atss xs n {ok} = SoLtParam.ats xs n {ok = ltlt ok}\n\n x0ss : Char\n x0ss = ['1', '2', '3'] `atss` 0\n\n x2ss : Char\n x2ss = ['1', '2', '3'] `atss` 2\n\n --x3ss : Char\n --x3ss = ['1', '2', '3'] `atss` 3\n\nnamespace LteParam\n\n atl : (xs : List a) -> (n : Nat) -> {auto ok : LT n (length xs)} -> a\n atl (x::_) Z = x\n atl (_::xs) (S n) {ok = (LTESucc _)} = xs `atl` n\n\n x0l : Char\n x0l = ['1', '2', '3'] `atl` 0\n\n x2l : Char\n x2l = ['1', '2', '3'] `atl` 2\n\n --x3l : Char\n --x3l = ['1', '2', '3'] `atl` 3\n\nnamespace InBoundsParam\n\n ati : (xs : List a) -> (n : Nat) -> {auto ok : InBounds n xs} -> a\n ati (x::_) Z = x\n ati (_::xs) (S k) {ok = InLater _} = xs `ati` k\n\n x0i : Char\n x0i = ['1', '2', '3'] `ati` 0\n\n x2i : Char\n x2i = ['1', '2', '3'] `ati` 2\n\n --x3i : Char\n --x3i = ['1', '2', '3'] `ati` 3\n\nnamespace CumstomWithLte\n\n data BoundedNat : Nat -> Type where\n MkBNat : (n : Nat) -> {auto ok : LT n b} -> BoundedNat b\n\n atb : (xs : List a) -> BoundedNat (length xs) -> a\n atb (x::_) (MkBNat Z) = x\n atb (_::xs) (MkBNat (S n) {ok = (LTESucc _)}) = xs `atb` MkBNat n\n atb [] (MkBNat n) impossible\n\n x0b : Char\n x0b = ['1', '2', '3'] `atb` MkBNat 0\n\n x2b : Char\n x2b = ['1', '2', '3'] `atb` MkBNat 2\n\n --x3b : Char\n --x3b = ['1', '2', '3'] `atb` MkBNat 3\n\nnamespace FinParam\n\n atf : (xs : List a) -> Fin (length xs) -> a\n atf (x::_) FZ = x\n atf (_::xs) (FS n) = xs `atf` n\n\n x0f : Char\n x0f = ['1', '2', '3'] `atf` 0\n\n x2f : Char\n x2f = ['1', '2', '3'] `atf` 2\n\n --x3f : Char\n --x3f = ['1', '2', '3'] `atf` 3\n", "meta": {"hexsha": "2a3ff46031d57e2e071fee5f4e792de87c156f45", "size": 2690, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "2020.01.22-to-bhk-lecture/idris/BoundedNat.idr", "max_stars_repo_name": "buzden/code-in-lectures", "max_stars_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-17T07:01:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T07:01:15.000Z", "max_issues_repo_path": "2020.01.22-to-bhk-lecture/idris/BoundedNat.idr", "max_issues_repo_name": "buzden/code-in-lectures", "max_issues_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "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": "2020.01.22-to-bhk-lecture/idris/BoundedNat.idr", "max_forks_repo_name": "buzden/code-in-lectures", "max_forks_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "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.7966101695, "max_line_length": 76, "alphanum_fraction": 0.4498141264, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6722008369398113}} {"text": "module ConstructedInt\n\nimport MoreNatProofs\nimport NonZeroNat\n\n%access public export\n%default total\n\ndata ConsInt : Type where\n Negative : (n : Nat) -> ConsInt\n Positive : (n : Nat) -> ConsInt\n\n%name ConsInt h, i, j, k, l\n\ngetSign : (i : ConsInt) -> (Nat -> ConsInt)\ngetSign (Negative n) = Negative\ngetSign (Positive n) = Positive\n\ncastIntegerToConsInt : Integer -> ConsInt\ncastIntegerToConsInt x = case x < 0 of\n False => Positive (toNat x)\n True => Negative (toNat (abs x))\n\nnegPlusPos : Nat -> Nat -> ConsInt\nnegPlusPos n k = case isLTE n k of\n (Yes prf) => Positive (k - n)\n (No contra) => Negative ((-) n k {smaller = notLTEFlips contra})\n\naddConsInt : ConsInt -> ConsInt -> ConsInt\naddConsInt (Negative n) (Negative k) = Negative (n + k)\naddConsInt (Negative n) (Positive k) = negPlusPos n k\naddConsInt (Positive n) (Positive k) = Positive (n + k)\naddConsInt (Positive n) (Negative k) = negPlusPos k n\n\n\nmultConsInt : ConsInt -> ConsInt -> ConsInt\nmultConsInt (Negative n) (Negative k) = Positive (n * k)\nmultConsInt (Positive n) (Positive k) = Positive (n * k)\nmultConsInt (Negative n) (Positive k) = Negative (n * k)\nmultConsInt (Positive n) (Negative k) = Negative (n * k)\n\n\nNum ConsInt where\n (+) = addConsInt\n (*) = multConsInt\n\n fromInteger = castIntegerToConsInt\n\nAbs ConsInt where\n abs (Negative n) = Positive n\n abs (Positive n) = Positive n\n\nnegateConsInt : ConsInt -> ConsInt -> ConsInt\nnegateConsInt x (Negative n) = x + (Positive n)\nnegateConsInt x (Positive n) = x + (Negative n)\n\nNeg ConsInt where\n negate x = negateConsInt (fromInteger 0) x\n (-) = negateConsInt\n\nequalConsInt : ConsInt -> ConsInt -> Bool\nequalConsInt (Negative n) (Negative k) = n == k\nequalConsInt (Negative Z) (Positive Z) = True\nequalConsInt (Negative Z) (Positive (S k)) = False\nequalConsInt (Negative (S j)) (Positive Z) = False\nequalConsInt (Negative (S j)) (Positive (S k)) = False\nequalConsInt (Positive Z) (Negative Z) = True\nequalConsInt (Positive Z) (Negative (S k)) = False\nequalConsInt (Positive (S j)) (Negative k) = False\nequalConsInt (Positive n) (Positive k) = n == k\n\nEq ConsInt where\n (==) = equalConsInt\n\nCast Integer ConsInt where\n cast = castIntegerToConsInt\n\ncastConsIntToInteger : (orig : ConsInt) -> Integer\ncastConsIntToInteger (Positive n) = cast n\ncastConsIntToInteger (Negative n) = -(cast n)\n\n\nCast ConsInt Integer where\n cast = castConsIntToInteger\n\ncastNatToConsInt : (orig : Nat) -> ConsInt\ncastNatToConsInt orig = Positive orig\n\nCast Nat ConsInt where\n cast = castNatToConsInt\n\ncastConsIntToString : (orig : ConsInt) -> String\ncastConsIntToString orig = cast (castConsIntToInteger orig)\n\nCast ConsInt String where\n cast = castConsIntToString\n\nShow ConsInt where\n show = castConsIntToString\n\n-- Proofs\nnegSameNumberEq : {m : Nat} -> Negative m = Negative m\nnegSameNumberEq {m = Z} = Refl\nnegSameNumberEq {m = (S k)} = Refl\n\nsameSignSameAbsValueEq : {sign : (Nat -> ConsInt)} -> {auto n : Nat} -> (sign m) = (sign m)\nsameSignSameAbsValueEq {sign = sign} {n = n} = Refl\n\nnegativeZNotEqNegSk : {auto n : Nat} -> ((Negative Z) = (Negative (S n)) -> Void)\nnegativeZNotEqNegSk Refl impossible\n\nnegEqImpliesNegSuccEq : (prf : k = j) -> Negative (S k) = Negative (S j)\nnegEqImpliesNegSuccEq Refl = Refl\n\nnotEqNegativeImpliesNotEq : (contra : (k = j) -> Void) -> (Negative (S k) = Negative (S j)) -> Void\nnotEqNegativeImpliesNotEq contra Refl = contra Refl\n\ndata Eq : (m, n : ConsInt) -> Type where\n EqZeroBothNeg : Eq (Negative Z) (Negative Z)\n EqZeroFirstPos : Eq (Positive Z) (Negative Z)\n EqZeroFirstNeg : Eq (Negative Z) (Positive Z)\n EqZeroBothPos : Eq (Positive Z) (Positive Z)\n EqSuccPos : Eq (Positive (S k)) (Positive (S k))\n EqSuccNeg : Eq (Negative (S l)) (Negative (S l))\n\nNegZeroNotEqSucc : Eq (Negative 0) (Negative (S k)) -> Void\nNegZeroNotEqSucc EqZeroBothNeg impossible\nNegZeroNotEqSucc EqZeroFirstPos impossible\nNegZeroNotEqSucc EqZeroFirstNeg impossible\nNegZeroNotEqSucc EqZeroBothPos impossible\nNegZeroNotEqSucc EqSuccPos impossible\nNegZeroNotEqSucc EqSuccNeg impossible\n\nNegSuccNotEqZero : Eq (Negative (S j)) (Negative 0) -> Void\nNegSuccNotEqZero EqZeroBothNeg impossible\nNegSuccNotEqZero EqZeroFirstPos impossible\nNegSuccNotEqZero EqZeroFirstNeg impossible\nNegSuccNotEqZero EqZeroBothPos impossible\nNegSuccNotEqZero EqSuccPos impossible\nNegSuccNotEqZero EqSuccNeg impossible\n\nNegSuccEq : (prf : j = k) -> Eq (Negative (S j)) (Negative (S k))\nNegSuccEq Refl = EqSuccNeg\n\nNegSuccNotEq : (contra : (j = k) -> Void) -> Eq (Negative (S j)) (Negative (S k)) -> Void\nNegSuccNotEq contra EqSuccNeg = contra Refl\n\nnegZeroNotEqPositiveSucc : Eq (Negative 0) (Positive (S k)) -> Void\nnegZeroNotEqPositiveSucc EqZeroBothNeg impossible\nnegZeroNotEqPositiveSucc EqZeroFirstPos impossible\nnegZeroNotEqPositiveSucc EqZeroFirstNeg impossible\nnegZeroNotEqPositiveSucc EqZeroBothPos impossible\nnegZeroNotEqPositiveSucc EqSuccPos impossible\nnegZeroNotEqPositiveSucc EqSuccNeg impossible\n\nnegSuccNotEqPositiveZero : Eq (Negative (S j)) (Positive 0) -> Void\nnegSuccNotEqPositiveZero EqZeroBothNeg impossible\nnegSuccNotEqPositiveZero EqZeroFirstPos impossible\nnegSuccNotEqPositiveZero EqZeroFirstNeg impossible\nnegSuccNotEqPositiveZero EqZeroBothPos impossible\nnegSuccNotEqPositiveZero EqSuccPos impossible\nnegSuccNotEqPositiveZero EqSuccNeg impossible\n\nnegSuccNotEqPosSucc : Eq (Negative (S j)) (Positive (S k)) -> Void\nnegSuccNotEqPosSucc EqZeroBothNeg impossible\nnegSuccNotEqPosSucc EqZeroFirstPos impossible\nnegSuccNotEqPosSucc EqZeroFirstNeg impossible\nnegSuccNotEqPosSucc EqZeroBothPos impossible\nnegSuccNotEqPosSucc EqSuccPos impossible\nnegSuccNotEqPosSucc EqSuccNeg impossible\n\nposZeroNotEqNegSucc : Eq (Positive 0) (Negative (S k)) -> Void\nposZeroNotEqNegSucc EqZeroBothNeg impossible\nposZeroNotEqNegSucc EqZeroFirstPos impossible\nposZeroNotEqNegSucc EqZeroFirstNeg impossible\nposZeroNotEqNegSucc EqZeroBothPos impossible\nposZeroNotEqNegSucc EqSuccPos impossible\nposZeroNotEqNegSucc EqSuccNeg impossible\n\nposSuccNotEqNegZero : Eq (Positive (S j)) (Negative 0) -> Void\nposSuccNotEqNegZero EqZeroBothNeg impossible\nposSuccNotEqNegZero EqZeroFirstPos impossible\nposSuccNotEqNegZero EqZeroFirstNeg impossible\nposSuccNotEqNegZero EqZeroBothPos impossible\nposSuccNotEqNegZero EqSuccPos impossible\nposSuccNotEqNegZero EqSuccNeg impossible\n\nposSuccNotEqNegSucc : Eq (Positive (S j)) (Negative (S k)) -> Void\nposSuccNotEqNegSucc EqZeroBothNeg impossible\nposSuccNotEqNegSucc EqZeroFirstPos impossible\nposSuccNotEqNegSucc EqZeroFirstNeg impossible\nposSuccNotEqNegSucc EqZeroBothPos impossible\nposSuccNotEqNegSucc EqSuccPos impossible\nposSuccNotEqNegSucc EqSuccNeg impossible\n\nposZeroNotEqSucc : Eq (Positive 0) (Positive (S k)) -> Void\nposZeroNotEqSucc EqZeroBothNeg impossible\nposZeroNotEqSucc EqZeroFirstPos impossible\nposZeroNotEqSucc EqZeroFirstNeg impossible\nposZeroNotEqSucc EqZeroBothPos impossible\nposZeroNotEqSucc EqSuccPos impossible\nposZeroNotEqSucc EqSuccNeg impossible\n\nposSuccNotEqZero : Eq (Positive (S j)) (Positive 0) -> Void\nposSuccNotEqZero EqZeroBothNeg impossible\nposSuccNotEqZero EqZeroFirstPos impossible\nposSuccNotEqZero EqZeroFirstNeg impossible\nposSuccNotEqZero EqZeroBothPos impossible\nposSuccNotEqZero EqSuccPos impossible\nposSuccNotEqZero EqSuccNeg impossible\n\nposSuccEq : (prf : j = k) -> Eq (Positive (S j)) (Positive (S k))\nposSuccEq Refl = EqSuccPos\n\nposSuccNotEq : (contra : (j = k) -> Void) -> Eq (Positive (S j)) (Positive (S k)) -> Void\nposSuccNotEq contra EqSuccPos = contra Refl\n\n-- I really wish I could find a way to make proofs here more concise.\nisEq : (i, j : ConsInt) -> Dec (i `Eq` j)\nisEq (Negative Z) (Negative Z) = Yes EqZeroBothNeg\nisEq (Negative Z) (Negative (S k)) = No NegZeroNotEqSucc\nisEq (Negative (S j)) (Negative Z) = No NegSuccNotEqZero\nisEq (Negative (S j)) (Negative (S k)) = case isEq j k of\n (Yes prf) => Yes (NegSuccEq prf)\n (No contra) => No (NegSuccNotEq contra)\nisEq (Negative Z) (Positive Z) = Yes EqZeroFirstNeg\nisEq (Negative Z) (Positive (S k)) = No negZeroNotEqPositiveSucc\nisEq (Negative (S j)) (Positive Z) = No negSuccNotEqPositiveZero\nisEq (Negative (S j)) (Positive (S k)) = No negSuccNotEqPosSucc\nisEq (Positive Z) (Negative Z) = Yes EqZeroFirstPos\nisEq (Positive Z) (Negative (S k)) = No posZeroNotEqNegSucc\nisEq (Positive (S j)) (Negative Z) = No posSuccNotEqNegZero\nisEq (Positive (S j)) (Negative (S k)) = No posSuccNotEqNegSucc\nisEq (Positive Z) (Positive Z) = Yes EqZeroBothPos\nisEq (Positive Z) (Positive (S k)) = No posZeroNotEqSucc\nisEq (Positive (S j)) (Positive Z) = No posSuccNotEqZero\nisEq (Positive (S j)) (Positive (S k)) = case isEq j k of\n (Yes prf) => Yes (posSuccEq prf)\n (No contra) => No (posSuccNotEq contra)\n\n||| Proofs that `m` is not equal to `n`\n||| @ m the first number\n||| @ n the second number\nNotEq : (m, n : ConsInt) -> Type\nNotEq m n = Not (m `Eq` n)\n\neQImplNotNotEq : (prf : Eq h i) -> (Eq h i -> Void) -> Void\neQImplNotNotEq prf f = f prf\n\nnotEqImplNotEq : (contra : Eq h i -> Void) -> Eq h i -> Void\nnotEqImplNotEq contra x = contra x\n\nisNotEq : (h, i : ConsInt) -> Dec (h `NotEq` i)\nisNotEq h i = case isEq h i of\n (Yes prf) => No (eQImplNotNotEq prf)\n (No contra) => Yes (notEqImplNotEq contra)\n\ndata LTE : (j, k : ConsInt) -> Type where\n ||| -m <= +n\n LTENegPos : LTE (Negative m) (Positive n)\n ||| -(m + 1) <= -0\n LTEBothNegWZero : LTE (Negative (S m)) (Negative Z)\n ||| +0 <= +(n + 1)\n LTEBothPosWZero : LTE (Positive Z) (Positive (S n))\n ||| left >= right -> -left <= -right\n LTEBothNegLTE : LTE right left -> LTE (Negative left) (Negative right)\n ||| left >= right -> +left >= + right\n LTEBothPosLTE : Nat.LTE left right -> LTE (Positive left) (Positive right)\n ||| j = k -> j <= k\n LTEBothEq : Eq j k -> LTE j k\n\n\nnegZeroNotLTENegSucc : LTE (Negative 0) (Negative (S k)) -> Void\nnegZeroNotLTENegSucc (LTEBothEq EqZeroBothNeg) impossible\nnegZeroNotLTENegSucc (LTEBothEq EqZeroFirstPos) impossible\nnegZeroNotLTENegSucc (LTEBothEq EqZeroFirstNeg) impossible\nnegZeroNotLTENegSucc (LTEBothEq EqZeroBothPos) impossible\nnegZeroNotLTENegSucc (LTEBothEq EqSuccPos) impossible\nnegZeroNotLTENegSucc (LTEBothEq EqSuccNeg) impossible\n\n\nposZeroNotLTENegSucc : LTE (Positive 0) (Negative (S k)) -> Void\nposZeroNotLTENegSucc (LTEBothEq EqZeroBothNeg) impossible\nposZeroNotLTENegSucc (LTEBothEq EqZeroFirstPos) impossible\nposZeroNotLTENegSucc (LTEBothEq EqZeroFirstNeg) impossible\nposZeroNotLTENegSucc (LTEBothEq EqZeroBothPos) impossible\nposZeroNotLTENegSucc (LTEBothEq EqSuccPos) impossible\nposZeroNotLTENegSucc (LTEBothEq EqSuccNeg) impossible\n\nposSuccNotLTENeg : LTE (Positive (S j)) (Negative k) -> Void\nposSuccNotLTENeg (LTEBothEq EqZeroBothNeg) impossible\nposSuccNotLTENeg (LTEBothEq EqZeroFirstPos) impossible\nposSuccNotLTENeg (LTEBothEq EqZeroFirstNeg) impossible\nposSuccNotLTENeg (LTEBothEq EqZeroBothPos) impossible\nposSuccNotLTENeg (LTEBothEq EqSuccPos) impossible\nposSuccNotLTENeg (LTEBothEq EqSuccNeg) impossible\n\nposSuccNotLTEZero : LTE (Positive (S j)) (Positive 0) -> Void\nposSuccNotLTEZero (LTEBothPosLTE LTEZero) impossible\nposSuccNotLTEZero (LTEBothPosLTE (LTESucc _)) impossible\nposSuccNotLTEZero (LTEBothEq EqZeroBothNeg) impossible\nposSuccNotLTEZero (LTEBothEq EqZeroFirstPos) impossible\nposSuccNotLTEZero (LTEBothEq EqZeroFirstNeg) impossible\nposSuccNotLTEZero (LTEBothEq EqZeroBothPos) impossible\nposSuccNotLTEZero (LTEBothEq EqSuccPos) impossible\nposSuccNotLTEZero (LTEBothEq EqSuccNeg) impossible\n\nnegSuccNotGTEImposs : (contra : GTE l k -> Void) -> LTE (Negative (S l)) (Negative (S k)) -> Void\nnegSuccNotGTEImposs contra (LTEBothNegLTE (LTESucc x)) = contra x\nnegSuccNotGTEImposs {l = l} {k = l} contra (LTEBothEq EqSuccNeg) = contra lteRefl\n\nposSuccNotLTEImposs : (contra : LTE l k -> Void) -> LTE (Positive (S l)) (Positive (S k)) -> Void\nposSuccNotLTEImposs contra (LTEBothPosLTE (LTESucc x)) = contra x\nposSuccNotLTEImposs {l = l} {k = l} contra (LTEBothEq EqSuccPos) = contra lteRefl\n\nisLTE : (i, j : ConsInt) -> Dec (i `LTE` j)\nisLTE (Negative Z) (Negative Z) = Yes (LTEBothEq EqZeroBothNeg)\nisLTE (Negative Z) (Negative (S k)) = No negZeroNotLTENegSucc\nisLTE (Negative (S j)) (Negative Z) = Yes LTEBothNegWZero\nisLTE (Negative (S l)) (Negative (S k)) = case isGTE l k of\n (Yes prf) => Yes (LTEBothNegLTE (LTESucc prf))\n (No contra) => No (negSuccNotGTEImposs contra)\nisLTE (Negative n) (Positive k) = Yes LTENegPos\nisLTE (Positive Z) (Negative Z) = Yes (LTEBothEq EqZeroFirstPos)\nisLTE (Positive Z) (Negative (S k)) = No posZeroNotLTENegSucc\nisLTE (Positive (S j)) (Negative k) = No posSuccNotLTENeg\nisLTE (Positive Z) (Positive Z) = Yes (LTEBothEq EqZeroBothPos)\nisLTE (Positive Z) (Positive (S k)) = Yes LTEBothPosWZero\nisLTE (Positive (S j)) (Positive Z) = No posSuccNotLTEZero\nisLTE (Positive (S l)) (Positive (S k)) = case isLTE l k of\n (Yes prf) => Yes (LTEBothPosLTE (LTESucc prf))\n (No contra) => No (posSuccNotLTEImposs contra)\n\nGTE : ConsInt -> ConsInt -> Type\nGTE h i = LTE i h\n\nisGTE : (h, i : ConsInt) -> Dec (h `GTE` i)\nisGTE h i = isLTE i h\n\ndata LT : (h, i : ConsInt) -> Type where\n LTPosZeroPosSucc : LT (Positive Z) (Positive (S m))\n LTNegPosSucc : LT (Negative (S m)) (Positive i)\n LTNegLTSwap : Nat.LT m n -> LT (Negative n) (Negative m)\n LTPosLT : Nat.LT m n -> LT (Positive m) (Positive n)\n LTNotEqLTE : ConstructedInt.NotEq h i -> LTE h i -> LT h i\n\n\n\nnotLTEImplNotEq : (contra : ConstructedInt.LTE h i -> Void) -> NotEq h i\nnotLTEImplNotEq {h} {i} contra = case ConstructedInt.isEq h i of\n (Yes prf) => void (contra (LTEBothEq prf))\n (No contra1) => contra1\n\n-- Basically a computer generated proof, with lots of case splits and searches. Hopefully Idris 2 will do this sort of thing better. Alternatively, maybe I can find out what I'm doing wrong.\nisLTAndIsEqImposs : (prf1 : Eq h i) -> (prf : LT h i) -> NotEq h i\nisLTAndIsEqImposs EqZeroBothNeg (LTNegLTSwap LTEZero) impossible\nisLTAndIsEqImposs EqZeroBothNeg (LTNegLTSwap (LTESucc _)) impossible\nisLTAndIsEqImposs EqZeroBothNeg (LTNotEqLTE f (LTEBothNegLTE LTEZero)) = \\__pi_arg => f EqZeroBothNeg\nisLTAndIsEqImposs EqZeroBothNeg (LTNotEqLTE f (LTEBothEq EqZeroBothNeg)) = \\__pi_arg => f EqZeroBothNeg\nisLTAndIsEqImposs EqZeroFirstPos (LTNotEqLTE f (LTEBothEq EqZeroFirstPos)) = \\__pi_arg => f EqZeroFirstPos\nisLTAndIsEqImposs EqZeroFirstNeg (LTNotEqLTE f LTENegPos) = \\__pi_arg => f EqZeroFirstNeg\nisLTAndIsEqImposs EqZeroFirstNeg (LTNotEqLTE f (LTEBothEq EqZeroFirstNeg)) = \\__pi_arg => f EqZeroFirstNeg\nisLTAndIsEqImposs EqZeroBothPos (LTPosLT LTEZero) impossible\nisLTAndIsEqImposs EqZeroBothPos (LTPosLT (LTESucc _)) impossible\nisLTAndIsEqImposs EqZeroBothPos (LTNotEqLTE f (LTEBothPosLTE LTEZero)) = \\__pi_arg => f EqZeroBothPos\nisLTAndIsEqImposs EqZeroBothPos (LTNotEqLTE f (LTEBothEq EqZeroBothPos)) = \\__pi_arg => f EqZeroBothPos\nisLTAndIsEqImposs EqSuccPos (LTPosLT (LTESucc x)) = \\__pi_arg => lTELeftNotSuccOfRight x\nisLTAndIsEqImposs EqSuccPos (LTNotEqLTE f (LTEBothPosLTE (LTESucc x))) = \\__pi_arg => f EqSuccPos\nisLTAndIsEqImposs EqSuccPos (LTNotEqLTE f (LTEBothEq EqSuccPos)) = \\__pi_arg => f EqSuccPos\nisLTAndIsEqImposs EqSuccNeg (LTNegLTSwap (LTESucc x)) = \\__pi_arg => lTELeftNotSuccOfRight x\nisLTAndIsEqImposs EqSuccNeg (LTNotEqLTE f (LTEBothNegLTE x)) = \\__pi_arg => f EqSuccNeg\nisLTAndIsEqImposs EqSuccNeg (LTNotEqLTE f (LTEBothEq EqSuccNeg)) = \\__pi_arg => f EqSuccNeg\n\nlTImplNotEq : (prf : ConstructedInt.LT h i) -> NotEq h i\nlTImplNotEq {h} {i} prf = case isEq h i of\n (Yes prf1) => isLTAndIsEqImposs prf1 prf\n (No contra) => contra\n\n\nlTEAndLTImplNotEq : (prf : ConstructedInt.LTE h i) -> (x : LT h i) -> NotEq h i\nlTEAndLTImplNotEq {h} {i} prf x = case isLTE h i of\n (Yes prf) => lTImplNotEq x\n (No contra) => notLTEImplNotEq contra\n\nmakeNotEq : (contra : NotEq h i -> Void) -> (prf : LTE h i) -> (x : LT h i) -> Eq h i -> Void\nmakeNotEq contra prf x y = contra (lTEAndLTImplNotEq prf x)\n\nlteLtImplNotEq : (prf : ConstructedInt.LTE h i) -> (x : LT h i) -> NotEq h i\nlteLtImplNotEq {h} {i} prf x = case isNotEq h i of\n (Yes prf1) => prf1\n (No contra) => makeNotEq contra prf x\n\nlTNotNotEq : (contra : ConstructedInt.NotEq h i -> Void) -> (prf : LTE h i) -> LT h i -> Void\nlTNotNotEq contra prf x = contra (lteLtImplNotEq prf x)\n\neQImpliesLTE : (h, i : ConsInt) -> (prf : Eq h i) -> LTE h i\neQImpliesLTE (Negative Z) (Negative Z) EqZeroBothNeg = LTEBothNegLTE LTEZero\neQImpliesLTE (Positive Z) (Negative Z) EqZeroFirstPos = LTEBothEq EqZeroFirstPos\neQImpliesLTE (Negative Z) (Positive Z) EqZeroFirstNeg = LTENegPos\neQImpliesLTE (Positive Z) (Positive Z) EqZeroBothPos = LTEBothPosLTE LTEZero\neQImpliesLTE (Positive (S k)) (Positive (S k)) EqSuccPos = LTEBothPosLTE (LTESucc lTEkk)\neQImpliesLTE (Negative (S l)) (Negative (S l)) EqSuccNeg = LTEBothNegLTE (LTESucc lTEkk)\n\nnotEqAndNotLTEImplLT : (h, i : ConsInt) -> (contra1 : Eq h i -> Void) -> (contra : LTE h i -> Void) -> LT h i\nnotEqAndNotLTEImplLT (Negative Z) (Negative Z) contra1 contra = LTNegLTSwap ?notEqAndNotLTEImplLT_rhs_6\nnotEqAndNotLTEImplLT (Negative Z) (Negative (S k)) contra1 contra = ?notEqAndNotLTEImplLT_rhs_7\nnotEqAndNotLTEImplLT (Negative (S j)) (Negative Z) contra1 contra = ?notEqAndNotLTEImplLT_rhs_2\nnotEqAndNotLTEImplLT (Negative (S j)) (Negative (S k)) contra1 contra = ?notEqAndNotLTEImplLT_rhs_8\nnotEqAndNotLTEImplLT (Negative Z) (Positive Z) contra1 contra = ?notEqAndNotLTEImplLT_rhs_4\nnotEqAndNotLTEImplLT (Negative Z) (Positive (S k)) contra1 contra = ?notEqAndNotLTEImplLT_rhs_10\nnotEqAndNotLTEImplLT (Negative (S j)) (Positive k) contra1 contra = ?notEqAndNotLTEImplLT_rhs_9\nnotEqAndNotLTEImplLT (Positive n) (Negative k) contra1 contra = ?notEqAndNotLTEImplLT_rhs_1\nnotEqAndNotLTEImplLT (Positive n) (Positive k) contra1 contra = ?notEqAndNotLTEImplLT_rhs_5\n\nnotLTEImplLT : (contra : ConstructedInt.LTE h i -> Void) -> LT h i\nnotLTEImplLT {h} {i} contra = case isEq h i of\n (Yes prf) => void (contra (eQImpliesLTE h i prf))\n (No contra1) => notEqAndNotLTEImplLT h i contra1 contra\n\nisLT : (h, i : ConsInt) -> Dec (h `LT` i)\nisLT h i = case isLTE h i of\n (Yes prf) => (case isNotEq h i of\n (Yes prf1) => Yes (LTNotEqLTE prf1 prf)\n (No contra) => No (lTNotNotEq contra prf))\n (No contra) => Yes (notLTEImplLT contra)\n\n-- Testing with types\n\n%access private\n\nfourMinusTenIsNegativeSix : Eq ((Positive 4) - (Positive 10)) (Negative 6)\nfourMinusTenIsNegativeSix = EqSuccNeg\n\nfourMinusNegativeTenIsNotNegativeSix : Eq ((Positive 4) - (Negative 10)) (Negative 6) -> Void\nfourMinusNegativeTenIsNotNegativeSix EqZeroBothNeg impossible\nfourMinusNegativeTenIsNotNegativeSix EqZeroFirstPos impossible\nfourMinusNegativeTenIsNotNegativeSix EqZeroFirstNeg impossible\nfourMinusNegativeTenIsNotNegativeSix EqZeroBothPos impossible\nfourMinusNegativeTenIsNotNegativeSix EqSuccPos impossible\nfourMinusNegativeTenIsNotNegativeSix EqSuccNeg impossible\n\nfourMinusTenIsLessThanNegativeTwo : LTE ((Positive 4) - (Positive 10)) (Negative 2)\nfourMinusTenIsLessThanNegativeTwo = LTEBothNegLTE (LTESucc (LTESucc LTEZero))\n\nfourMinusTenIsNotLessThanNegativeFour : LTE ((Positive 4) - (Positive 5)) (Negative 4) -> Void\nfourMinusTenIsNotLessThanNegativeFour (LTEBothNegLTE (LTESucc LTEZero)) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothNegLTE (LTESucc (LTESucc _))) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothEq EqZeroBothNeg) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothEq EqZeroFirstPos) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothEq EqZeroFirstNeg) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothEq EqZeroBothPos) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothEq EqSuccPos) impossible\nfourMinusTenIsNotLessThanNegativeFour (LTEBothEq EqSuccNeg) impossible\n\naNegativeTimesANegativeIsAPositive : LTE (Positive Z) ((Negative n) * (Negative m))\naNegativeTimesANegativeIsAPositive = LTEBothPosLTE LTEZero\n", "meta": {"hexsha": "3379da7be0c73c7d1bd23deb0fb9dd21a11a0c48", "size": 20642, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ConstructedInt.idr", "max_stars_repo_name": "zenntenn/Idris-NumericProofs", "max_stars_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ConstructedInt.idr", "max_issues_repo_name": "zenntenn/Idris-NumericProofs", "max_issues_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ConstructedInt.idr", "max_forks_repo_name": "zenntenn/Idris-NumericProofs", "max_forks_repo_head_hexsha": "96c74cdf9377550affd559966cac79f5ae784465", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.1684901532, "max_line_length": 192, "alphanum_fraction": 0.7275457804, "num_tokens": 6708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6716835590788702}} {"text": "> module Finite.Operations\n\n> import Data.Fin\n> import Data.Vect\n> import Data.Vect.Quantifiers\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Fin.Operations\n> --import Isomorphism.Operations\n> import Sigma.Sigma\n> import Pairs.Operations\n\n\n> %default total\n\n> %access public export\n\n\nFinite types are dependent pairs: an |n : Nat| (the cardinality of the\ntype) and an isomorphism to |Fin n|. Here we extract the cardinality.\n\n> ||| Cardinality of finite types\n> card : {A : Type} -> (fA : Finite A) -> Nat\n> card = getWitness\n\n\nFinite types are dependent pairs: an |n : Nat| (the cardinality of the\ntype) and an isomorphism to |Fin n|. Here we extract the isomorphism.\n\n> ||| Isomorphism of finite types\n> iso : {A : Type} -> (fA : Finite A) -> Iso A (Fin (card fA))\n> iso = getProof\n\n\n> {-\n\nFinite types are dependent pairs: an |n : Nat| (the cardinality of the\ntype) and an isomorphism to |Fin n|. Here we extract the components of\nthe isomorphism.\n\n> ||| For a finite type |A| of cardinality |n|, maps |A|-values to |Fin n|-values\n> toFin : {A : Type} -> (fA : Finite A) -> (A -> Fin (card fA))\n> toFin (Evidence n (MkIso to from toFrom fromTo)) = to\n\n> ||| For a finite type |A| of cardinality |n|, maps |Fin n|-values to |A|-values\n> fromFin : {A : Type} -> (fA : Finite A) -> (Fin (card fA) -> A)\n> fromFin (Evidence n (MkIso to from toFrom fromTo)) = from\n\n> ||| |toFin| is the left inverse of |fromFin|\n> toFinFromFin : {A : Type} -> (fA : Finite A) -> (k : Fin (card fA)) -> toFin fA (fromFin fA k) = k\n> toFinFromFin (Evidence n (MkIso to from toFrom fromTo)) = toFrom\n\n> ||| |fromFin| is the left inverse of |toFin|\n> FromFinToFin : {A : Type} -> (fA : Finite A) -> (a : A) -> fromFin fA (toFin fA a) = a\n> FromFinToFin (Evidence n (MkIso to from toFrom fromTo)) = fromTo\n\n> -}\n\nWe can represent a finite type |A| of cardinality |n| with a vector of\nelements of type |A| of length |n|. This can be done by calling\n|FinOperations.toVect| on the finite function associated (via ||) to |A|.\n\n> ||| Maps a finite type |A| of cardinality |n| to a vector of |A|-values of length |n|\n> toVect : {A : Type} -> (fA : Finite A) -> Vect (card fA) A\n> toVect (MkSigma _ iso) = toVect (from iso)\n> -- toVect fA = toVect (from (iso fA))\n> -- toVect fA = toVect (fromFin fA)\n\n\n> |||\n> CardZ : {A : Type} -> Finite A -> Type\n> CardZ fA = card fA = Z\n\n\n> |||\n> CardNotZ : {A : Type} -> Finite A -> Type\n> CardNotZ = Not . CardZ\n> -- CardNotZ fA = LT Z (card fA)\n", "meta": {"hexsha": "eff2bfacf6779040a055f2935ebc4e697ee746a3", "size": 2476, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Finite/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": "Finite/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": "Finite/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.95, "max_line_length": 100, "alphanum_fraction": 0.6490306947, "num_tokens": 832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6715914919799818}} {"text": "module Data.Nat.Algebra\n\nimport Control.Algebra\nimport Data.Nat\n\n%default total\n\npublic export\nSemigroupV Nat where\n semigroupOpIsAssociative = plusAssociative\n\npublic export\nMonoidV Nat where\n monoidNeutralIsNeutralL = plusZeroRightNeutral\n monoidNeutralIsNeutralR = plusZeroLeftNeutral\n", "meta": {"hexsha": "277fd0251c432df7515bea146001d315f1ee3dcb", "size": 291, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/Nat/Algebra.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/Nat/Algebra.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/Nat/Algebra.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": 18.1875, "max_line_length": 48, "alphanum_fraction": 0.8453608247, "num_tokens": 77, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.671450046700676}} {"text": "import Data.Vect\n\ndata Format = Number Format\n | Str Format\n | Chr Format\n | Dbl 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 (Chr fmt) = (char : Char) -> PrintfType fmt\nPrintfType (Dbl fmt) = (double : 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 (Chr fmt) acc = \\chr => printfFmt fmt (acc ++ (show chr))\nprintfFmt (Dbl fmt) acc = \\dbl => printfFmt fmt (acc ++ (cast dbl))\nprintfFmt (Lit str fmt) acc = printfFmt fmt (acc ++ str)\nprintfFmt End acc = acc\n\ntoFormat : (xs : List Char) -> Format\ntoFormat [] = End\ntoFormat ('%' :: 'd' :: xs) = Number (toFormat xs)\ntoFormat ('%' :: 's' :: xs) = Str (toFormat xs)\ntoFormat ('%' :: 'c' :: xs) = Chr (toFormat xs)\ntoFormat ('%' :: 'f' :: xs) = Dbl (toFormat xs)\ntoFormat ('%' :: xs) = Lit \"%\" (toFormat xs)\ntoFormat (x :: xs) = case toFormat xs of\n Lit lit chars' => Lit (strCons x lit) chars'\n fmt => Lit (strCons x \"\") 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\ntestMatrix : Matrix 2 3\ntestMatrix = [[0, 0, 0], [0, 0, 0]]", "meta": {"hexsha": "47e0de4185c76b85ca98cf33dd28e0b6c5dcdfe0", "size": 1574, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/Printf.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/Printf.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/Printf.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7727272727, "max_line_length": 68, "alphanum_fraction": 0.5933926302, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6713429214581469}} {"text": "module RedBlackSet\n\nimport Set\n\n%default total\n%access private\n\ndata Color = R | B\n\nexport\ndata RedBlackSet a = E | T Color (RedBlackSet a) a (RedBlackSet a)\n\nbalance : Color -> RedBlackSet a -> a -> RedBlackSet a -> RedBlackSet a\nbalance B (T R (T R a x b) y c) z d = T R (T B a x b) y (T B c z d)\nbalance B (T R a x (T R b y c)) z d = T R (T B a x b) y (T B c z d)\nbalance B a x (T R (T R b y c) z d) = T R (T B a x b) y (T B c z d)\nbalance B a x (T R b y (T R c z d)) = T R (T B a x b) y (T B c z d)\nbalance color a x b = T color a x b\n\nexport\nOrd a => Set RedBlackSet a where\n empty = E\n\n member x E = False\n member x (T _ a y b) = case compare x y of\n LT => member x a\n GT => member x b\n EQ => True\n\n insert x s = assert_total $ let T _ a y b = ins s in T B a y b\n where\n ins : Ord a => RedBlackSet a -> RedBlackSet a\n ins E = T R E x E\n ins s'@(T color a y b) = case compare x y of\n LT => balance color (ins a) y b\n GT => balance color a y (ins b)\n EQ => s'\n", "meta": {"hexsha": "50f380a8a3f1bf905be89ccf3843712937fe144e", "size": 1003, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/RedBlackSet.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/RedBlackSet.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/RedBlackSet.idr", "max_forks_repo_name": "ska80/idris-okasaki-pfds", "max_forks_repo_head_hexsha": "8e80feba2fdcebdf90136ac6633275c896177c77", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3947368421, "max_line_length": 71, "alphanum_fraction": 0.5722831505, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6712993567873122}} {"text": "import Data.Fin\nimport Data.Maybe\n\ndata NNat = NZ | NS NNat\n\nzsym : (x : NNat) -> x = NZ -> NZ = x\nzsym NZ Refl = Refl\nzsym (NS _) Refl impossible\n\nzsym' : (x : NNat) -> x = NZ -> NZ = x\nzsym' NZ Refl = Refl\n\nfoo : Nat -> String\nfoo 0 = \"zero\"\nfoo 1 = \"one\"\nfoo x = \"something else\"\n\nbar : Fin (S (S (S Z))) -> String\nbar 0 = \"a\"\nbar 1 = \"b\"\nbar 2 = \"c\"\n", "meta": {"hexsha": "276141128299d228e67a2b465cec71049fbd6ab6", "size": 354, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/coverage005/Cover.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/coverage005/Cover.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/coverage005/Cover.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": 16.0909090909, "max_line_length": 38, "alphanum_fraction": 0.5593220339, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427857178614, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6712193302914529}} {"text": "import Data.Vect\n\nremoveElem : (value : a) -> (xs : Vect (S n) a) -> (prf : Elem value xs) -> Vect n a\nremoveElem value (value :: ys) Here = ys\nremoveElem value {n = Z} (y :: []) (There later) = absurd later\nremoveElem value {n = (S k)} (y :: ys) (There later) = y :: removeElem value ys later\n\noneInVector : Elem 1 [1, 2, 3]\noneInVector = Here\n\nmaryInVector : Elem \"Mary\" [\"Peter\", \"Paul\", \"Mary\"]\nmaryInVector = There (There Here)\n\nremoveElemAuto : (value : a) -> (xs : Vect (S n) a) -> {auto prf : Elem value xs} -> Vect n a\nremoveElemAuto value xs {prf} = removeElem value xs prf\n", "meta": {"hexsha": "e2d1ccdb100cc786c55b7a645089bf15256211f4", "size": 584, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/RemoveElem.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/RemoveElem.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/RemoveElem.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": 36.5, "max_line_length": 93, "alphanum_fraction": 0.6335616438, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869916479465, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.671109999722922}} {"text": "maybeAdd: Num a => Maybe a -> Maybe a -> Maybe a\nmaybeAdd x y = do\n xVal <- x\n yVal <- y\n Just (xVal + yVal)\n \noccurrences: Eq ty => (item: ty) -> (values: List ty) -> Nat\noccurrences item [] = 0\noccurrences item (value :: values) =\n case value == item of\n False => occurrences item values\n True => 1 + occurrences item values\n\ndata Matter = Solid | Liquid | Gas\n\nEq Matter where\n (==) Solid Solid = True\n (==) Liquid Liquid = True\n (==) Gas Gas = True\n (==) _ _ = False\n \ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n\nEq elem => Eq (Tree elem) where\n (==) Empty Empty = True\n (==) (Node left e right) (Node left' e' right') =\n left == left' && e == e' && right == right'\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\nhonkydory: Album\nhonkydory = MkAlbum \"David Bowie\" \"Hunky Dory\" 1971\n\nheroes: Album\nheroes = MkAlbum \"David Bowie\" \"Heroes\" 1977\n\ncollection: List Album\ncollection = [help, rubbersoul, clouds, honkydory, heroes]\n\nEq Album where\n (==) (MkAlbum artist title year) (MkAlbum artist' title' year') =\n artist == artist' && title == title' && year == year'\n\nOrd Album where\n compare (MkAlbum artist title year) (MkAlbum artist' title' year') =\n case compare artist artist' of\n EQ => case compare year year' of\n EQ => compare title title'\n diffYear => diffYear\n diffArtist => diffArtist\n\nShow Album where\n show (MkAlbum artist title year) =\n title ++ \" by \" ++ artist ++ \" (released \" ++ show year ++ \")\"\n\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\nEq Shape where \n (==) (Triangle x z) (Triangle x' z') = x == x' && z == z'\n (==) (Rectangle x z) (Rectangle x' z') = x == x' && z == z'\n (==) (Circle x) (Circle x') = x == x'\n (==) _ _ = False\n\narea: Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\nOrd Shape where\n compare x y = let\n xArea = area x\n yArea = area y\n in\n compare xArea yArea\n\ntestShapes: List Shape\ntestShapes = [Circle 3, Triangle 3 9, Rectangle 2 6, Circle 4, Rectangle 2 7]", "meta": {"hexsha": "5ce6d962a9f2129b126f828b10a82f8ff9facde6", "size": 2462, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Interfaces.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": "Interfaces.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": "Interfaces.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": 26.1914893617, "max_line_length": 77, "alphanum_fraction": 0.6161657189, "num_tokens": 758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6709373235686071}} {"text": "> module SequentialDecisionProblems.applications.AvailableUnavailable\n\n> import Data.Fin\n> import Control.Isomorphism\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Sigma.Sigma\n\n> %default total\n> %auto_implicits off\n> %access public export\n\n\n* Available / Unavailable emissions:\n\n> data AvailableUnavailable = Available | Unavailable \n\n\n* |AvailableUnavailable| is finite and non-empty:\n\n> to : AvailableUnavailable -> Fin 2\n> to Available = FZ\n> to Unavailable = FS FZ\n\n> from : Fin 2 -> AvailableUnavailable\n> from FZ = Available\n> from (FS FZ) = Unavailable\n> from (FS (FS k)) = absurd k\n\n> toFrom : (k : Fin 2) -> to (from k) = k\n> toFrom FZ = Refl\n> toFrom (FS FZ) = Refl\n> toFrom (FS (FS k)) = absurd k\n\n> fromTo : (a : AvailableUnavailable) -> from (to a) = a\n> fromTo Available = Refl\n> fromTo Unavailable = Refl\n\n> ||| \n> finiteAvailableUnavailable : Finite AvailableUnavailable\n> finiteAvailableUnavailable = MkSigma 2 (MkIso to from toFrom fromTo)\n\n> |||\n> cardNotZAvailableUnavailable : CardNotZ finiteAvailableUnavailable\n> cardNotZAvailableUnavailable = cardNotZLemma finiteAvailableUnavailable Available\n\n\n* |AvailableUnavailable| is in |DecEq|:\n\n> availableNotUnavailable : Available = Unavailable -> Void\n> availableNotUnavailable Refl impossible\n\n> implementation [DecEqAvailableUnavailable] DecEq AvailableUnavailable where\n> decEq Available Available = Yes Refl\n> decEq Available Unavailable = No availableNotUnavailable\n> decEq Unavailable Available = No (negEqSym availableNotUnavailable)\n> decEq Unavailable Unavailable = Yes Refl\n\n\n* |AvailableUnavailable| is in |Eq|:\n\n> implementation Eq AvailableUnavailable where\n> (==) Available Available = True\n> (==) Available Unavailable = False\n> (==) Unavailable Available = False\n> (==) Unavailable Unavailable = True\n\n\n> {-\n\n> ---}\n\n\n \n", "meta": {"hexsha": "86dee65e88840bdd712645fb57dcc64390bcf370", "size": 1944, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/applications/AvailableUnavailable.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/AvailableUnavailable.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/AvailableUnavailable.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.2467532468, "max_line_length": 83, "alphanum_fraction": 0.7098765432, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6709219659421368}} {"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\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\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\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", "meta": {"hexsha": "9103c893e84b9e7735f4229dfb7c2789c1e7ce66", "size": 1842, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "_local-site/Code/Ring.Properties.idr", "max_stars_repo_name": "anotherArka/LTS2019", "max_stars_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-01-16T18:03:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T16:28:41.000Z", "max_issues_repo_path": "_local-site/Code/Ring.Properties.idr", "max_issues_repo_name": "anotherArka/LTS2019", "max_issues_repo_head_hexsha": "a3cd249d7ae85301ef8c1bbc363998f74221ca4d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2019-01-08T11:22:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-21T10:26:10.000Z", "max_forks_repo_path": "_local-site/Code/Ring.Properties.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.9268292683, "max_line_length": 147, "alphanum_fraction": 0.5564603692, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6708173012625817}} {"text": "{-\n Copyright 2018 Double-oxygeN\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n-}\n\nmodule Partition\n\n%default total\n%access export\n\n-- define decreasing rule\npublic export\n(>=) : Nat -> Nat -> Type\n(>=) = GTE\n\npublic export\ndata IsDecreasing : List Nat -> Type where\n DecEmpty :\n IsDecreasing Nil\n\n DecSingle :\n (a: Nat) -> a >= 1 ->\n IsDecreasing (a :: Nil)\n\n DecMany :\n (a1: Nat) -> (a2: Nat) -> (ax: List Nat) ->\n a1 >= a2 -> IsDecreasing (a2 :: ax) ->\n IsDecreasing (a1 :: a2 :: ax)\n\n-- some theorems\n\nsuccDec : IsDecreasing (x :: xs) -> IsDecreasing ((S x) :: xs)\nsuccDec (DecSingle x proofXIsPositive) = DecSingle (S x) (lteSuccRight proofXIsPositive)\nsuccDec (DecMany x y ys proofXGteY proofYYsIsDec) = DecMany (S x) y ys (lteSuccRight proofXGteY) proofYYsIsDec\n\n-- define partition\nnamespace Partition\n public export\n data Par : Type where\n MkPar : (ls: List Nat) -> IsDecreasing ls -> Par\n\n ParNil : Par\n ParNil = MkPar Nil DecEmpty\n\n -- partition utility functions\n toList : Par -> List Nat\n toList (MkPar ls _) = ls\n\n index : (n: Nat) -> (l: Par) -> {auto ok: InBounds n (toList l)} -> Nat\n index n l = Prelude.List.index n (Partition.toList l)\n\n length : Par -> Nat\n length l = length $ toList l\n\n multiplicity : Nat -> Par -> Nat\n multiplicity e l = length $ elemIndices e (toList l)\n\n tail : Par -> Par\n tail (MkPar Nil _) = ParNil\n tail (MkPar (x :: Nil) _) = ParNil\n tail (MkPar (x :: y :: ys) (DecMany x y ys _ proofYYsIsDec)) = (MkPar (y :: ys) proofYYsIsDec)\n\n sizePar : Par -> Nat\n sizePar (MkPar Nil _) = Z\n sizePar (MkPar (x :: Nil) (DecSingle _ _)) = x\n sizePar (MkPar (x :: y :: ys) (DecMany x y ys proofXGteY proofYYsIsDec)) =\n x + sizePar (assert_smaller (MkPar (x :: y :: ys) (DecMany x y ys proofXGteY proofYYsIsDec)) (MkPar (y :: ys) proofYYsIsDec))\n\nShow Par where\n show l = \"(\" ++ (join \",\" (toList l)) ++ \")\"\n where\n join : (Show a) => String -> List a -> String\n join _ Nil = \"\"\n join _ (x :: Nil) = show x\n join s (x :: xs) = (show x) ++ s ++ (join s xs)\n\n-- define partition of size N\npublic export\ndata ParN : Nat -> Type where\n MkParN : (l: Par) -> sizePar l = n -> ParN n\n\n-- partition with limit\ndata ParUpper : Nat -> Type where\n MkParUpper : (k: Nat) -> (ls: List Nat) -> IsDecreasing (k :: ls) -> ParUpper k\n\nforgetUpper : ParUpper k -> Par\nforgetUpper (MkParUpper k Nil _) = ParNil\nforgetUpper (MkParUpper k _ (DecMany _ x xs _ proofXXsIsDec)) = MkPar (x :: xs) proofXXsIsDec\n\nparUpperKIsParUpperSuccK : ParUpper k -> ParUpper (S k)\nparUpperKIsParUpperSuccK (MkParUpper k ls proofKLsIsDec) =\n MkParUpper (S k) ls (succDec proofKLsIsDec)\n\nparUpperCons : (k1: Nat) -> k1 >= k2 -> ParUpper k2 -> ParUpper k1\nparUpperCons k1 proofK1GteK2 (MkParUpper k2 ls proofK2LsIsDec) =\n case proofK2LsIsDec of\n DecSingle _ proofK2IsPos => MkParUpper k1 [k1] (DecMany k1 k1 [] lteRefl (DecSingle k1 (lteTransitive proofK2IsPos proofK1GteK2)))\n DecMany _ y ys proofK2GteY proofYYsIsDec => MkParUpper k1 (k1 :: y :: ys) (DecMany k1 k1 (y :: ys) lteRefl (DecMany k1 y ys (lteTransitive proofK2GteY proofK1GteK2) proofYYsIsDec))\n\n-- get all Par(N)\nnaiveAllParNUpper : (k: Nat) -> Nat -> List (ParUpper k)\nnaiveAllParNUpper Z _ = Nil\nnaiveAllParNUpper (S k) Z = (MkParUpper (S k) Nil (DecSingle (S k) (LTESucc LTEZero))) :: Nil\nnaiveAllParNUpper (S k) n with ((S k) <= n)\n | False = parUpperKIsParUpperSuccK <$> naiveAllParNUpper k n\n | True = ((parUpperCons (S k) lteRefl) <$> naiveAllParNUpper (S k) (assert_smaller n (n `minus` (S k)))) ++ (parUpperKIsParUpperSuccK <$> (naiveAllParNUpper k n))\n\nnaiveAllParN : Nat -> List Par\nnaiveAllParN n = forgetUpper <$> naiveAllParNUpper n n\n", "meta": {"hexsha": "b032229b8c182740d3bd738293ffe024dd6c3db2", "size": 4179, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Partition.idr", "max_stars_repo_name": "Double-oxygeN/Partition.idr", "max_stars_repo_head_hexsha": "86c86f637382e41d8526890d88aafa8deeee9d6f", "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": "Partition.idr", "max_issues_repo_name": "Double-oxygeN/Partition.idr", "max_issues_repo_head_hexsha": "86c86f637382e41d8526890d88aafa8deeee9d6f", "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": "Partition.idr", "max_forks_repo_name": "Double-oxygeN/Partition.idr", "max_forks_repo_head_hexsha": "86c86f637382e41d8526890d88aafa8deeee9d6f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5371900826, "max_line_length": 184, "alphanum_fraction": 0.6704953338, "num_tokens": 1429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6705316220035529}} {"text": "module Solutions.Interfaces\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Basics\n--------------------------------------------------------------------------------\n\ninterface Comp a where\n comp : a -> a -> Ordering\n\n-- 1\nanyLarger : Comp a => a -> List a -> Bool\nanyLarger va [] = False\nanyLarger va (x :: xs) = comp va x == GT || anyLarger va xs\n\n-- 2\nallLarger : Comp a => a -> List a -> Bool\nallLarger va [] = True\nallLarger va (x :: xs) = comp va x == GT && allLarger va xs\n\n-- 3\nmaxElem : Comp a => List a -> Maybe a\nmaxElem [] = Nothing\nmaxElem (x :: xs) = case maxElem xs of\n Nothing => Just x\n Just v => if comp x v == GT then Just x else Just v\n\nminElem : Comp a => List a -> Maybe a\nminElem [] = Nothing\nminElem (x :: xs) = case minElem xs of\n Nothing => Just x\n Just v => if comp x v == LT then Just x else Just v\n\n-- 4\ninterface Concat a where\n concat : a -> a -> a\n\nimplementation Concat String where\n concat = (++)\n\nimplementation Concat (List a) where\n concat = (++)\n\n-- 5\nconcatList : Concat a => List a -> Maybe a\nconcatList [] = Nothing\nconcatList (x :: xs) = case concatList xs of\n Nothing => Just x\n Just v => Just (concat x v)\n\n--------------------------------------------------------------------------------\n-- More about Interfaces\n--------------------------------------------------------------------------------\n\n-- 1\ninterface Equals a where\n eq : a -> a -> Bool\n\n neq : a -> a -> Bool\n neq x y = not (eq x y)\n\ninterface Concat a => Empty a where\n empty : a\n\nEquals a => Equals b => Equals (a,b) where\n eq (x1,y1) (x2,y2) = eq x1 x2 && eq y1 y2\n\nComp a => Comp b => Comp (a,b) where\n comp (x1,y1) (x2,y2) = case comp x1 x2 of\n EQ => comp y1 y2\n v => v\n\nConcat a => Concat b => Concat (a,b) where\n concat (x1,y1) (x2,y2) = (concat x1 x2, concat y1 y2)\n\nEmpty a => Empty b => Empty (a,b) where\n empty = (empty, empty)\n\n-- 2\ndata Tree : Type -> Type where\n Leaf : a -> Tree a\n Node : Tree a -> Tree a -> Tree a\n\nEquals a => Equals (Tree a) where\n eq (Leaf x) (Leaf y) = eq x y\n eq (Node l1 r1) (Node l2 r2) = eq l1 l2 && eq r1 r2\n eq _ _ = False\n\nConcat (Tree a) where\n concat = Node\n\n--------------------------------------------------------------------------------\n-- Interfaces in the Prelude\n--------------------------------------------------------------------------------\n\n-- 1\nrecord Complex where\n constructor MkComplex\n rel : Double\n img : Double\n\nEq Complex where\n MkComplex r1 i1 == MkComplex r2 i2 = r1 == r2 && i1 == i2\n\nNum Complex where\n MkComplex r1 i1 + MkComplex r2 i2 = MkComplex (r1 + r2) (i1 + i2)\n MkComplex r1 i1 * MkComplex r2 i2 =\n MkComplex (r1 * r2 - i1 * i2) (r1 * i2 + r2 * i1)\n fromInteger n = MkComplex (fromInteger n) 0.0\n\nNeg Complex where\n negate (MkComplex r i) = MkComplex (negate r) (negate i)\n MkComplex r1 i1 - MkComplex r2 i2 = MkComplex (r1 - r2) (i1 - i2)\n\nFractional Complex where\n MkComplex r1 i1 / MkComplex r2 i2 = case r2 * r2 + i2 * i2 of\n denom => MkComplex ((r1 * r2 + i1 * i2) / denom)\n ((i1 * r2 - r1 * i2) / denom)\n\n-- 2\nShow Complex where\n showPrec p c = showCon p \"MkComplex\" (showArg c.rel ++ showArg c.img)\n\n-- 3\nrecord First a where\n constructor MkFirst\n value : Maybe a\n\npureFirst : a -> First a\npureFirst = MkFirst . Just\n\nmapFirst : (a -> b) -> First a -> First b\nmapFirst f = MkFirst . map f . value\n\nmapFirst2 : (a -> b -> c) -> First a -> First b -> First c\nmapFirst2 f (MkFirst (Just va)) (MkFirst (Just vb)) = pureFirst (f va vb)\nmapFirst2 _ _ _ = MkFirst Nothing\n\nEq a => Eq (First a) where\n (==) = (==) `on` value\n\nOrd a => Ord (First a) where\n compare = compare `on` value\n\nShow a => Show (First a) where\n show = show . value\n\nFromString a => FromString (First a) where\n fromString = pureFirst . fromString\n\nFromDouble a => FromDouble (First a) where\n fromDouble = pureFirst . fromDouble\n\nFromChar a => FromChar (First a) where\n fromChar = pureFirst . fromChar\n\nNum a => Num (First a) where\n (+) = mapFirst2 (+)\n (*) = mapFirst2 (*)\n fromInteger = pureFirst . fromInteger\n\nNeg a => Neg (First a) where\n negate = mapFirst negate\n (-) = mapFirst2 (-)\n\nIntegral a => Integral (First a) where\n mod = mapFirst2 mod\n div = mapFirst2 div\n\nFractional a => Fractional (First a) where\n (/) = mapFirst2 (/)\n recip = mapFirst recip\n\n-- 4\nSemigroup (First a) where\n l@(MkFirst (Just _)) <+> _ = l\n _ <+> r = r\n\nMonoid (First a) where\n neutral = MkFirst Nothing\n\n-- 5\nrecord Last a where\n constructor MkLast\n value : Maybe a\n\npureLast : a -> Last a\npureLast = MkLast . Just\n\nmapLast : (a -> b) -> Last a -> Last b\nmapLast f = MkLast . map f . value\n\nmapLast2 : (a -> b -> c) -> Last a -> Last b -> Last c\nmapLast2 f (MkLast (Just va)) (MkLast (Just vb)) = pureLast (f va vb)\nmapLast2 _ _ _ = MkLast Nothing\n\nEq a => Eq (Last a) where\n (==) = (==) `on` value\n\nOrd a => Ord (Last a) where\n compare = compare `on` value\n\nShow a => Show (Last a) where\n show = show . value\n\nFromString a => FromString (Last a) where\n fromString = pureLast . fromString\n\nFromDouble a => FromDouble (Last a) where\n fromDouble = pureLast . fromDouble\n\nFromChar a => FromChar (Last a) where\n fromChar = pureLast . fromChar\n\nNum a => Num (Last a) where\n (+) = mapLast2 (+)\n (*) = mapLast2 (*)\n fromInteger = pureLast . fromInteger\n\nNeg a => Neg (Last a) where\n negate = mapLast negate\n (-) = mapLast2 (-)\n\nIntegral a => Integral (Last a) where\n mod = mapLast2 mod\n div = mapLast2 div\n\nFractional a => Fractional (Last a) where\n (/) = mapLast2 (/)\n recip = mapLast recip\n\nSemigroup (Last a) where\n _ <+> r@(MkLast (Just _)) = r\n l <+> _ = l\n\nMonoid (Last a) where\n neutral = MkLast Nothing\n\n-- 6\nlast : List a -> Maybe a\nlast = value . foldMap pureLast\n\n-- 7\nrecord Any where\n constructor MkAny\n any : Bool\n\nSemigroup Any where\n MkAny x <+> MkAny y = MkAny (x || y)\n\nMonoid Any where\n neutral = MkAny False\n\nrecord All where\n constructor MkAll\n all : Bool\n\nSemigroup All where\n MkAll x <+> MkAll y = MkAll (x && y)\n\nMonoid All where\n neutral = MkAll True\n\n-- 8\nanyElem : (a -> Bool) -> List a -> Bool\nanyElem f = any . foldMap (MkAny . f)\n\nallElems : (a -> Bool) -> List a -> Bool\nallElems f = all . foldMap (MkAll . f)\n\n-- 9\nrecord Sum a where\n constructor MkSum\n value : a\n\nrecord Product a where\n constructor MkProduct\n value : a\n\nNum a => Semigroup (Sum a) where\n MkSum x <+> MkSum y = MkSum (x + y)\n\nNum a => Monoid (Sum a) where\n neutral = MkSum 0\n\nNum a => Semigroup (Product a) where\n MkProduct x <+> MkProduct y = MkProduct (x * y)\n\nNum a => Monoid (Product a) where\n neutral = MkProduct 1\n\n-- 10\n\nsumList : Num a => List a -> a\nsumList = value . foldMap MkSum\n\nproductList : Num a => List a -> a\nproductList = value . foldMap MkProduct\n", "meta": {"hexsha": "43d6cd227605253027c47f610b3305edcb172986", "size": 6905, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Solutions/Interfaces.idr", "max_stars_repo_name": "gahr/idris2-tutorial", "max_stars_repo_head_hexsha": "e180728abb1440cd4e6994967419117052646236", "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/Solutions/Interfaces.idr", "max_issues_repo_name": "gahr/idris2-tutorial", "max_issues_repo_head_hexsha": "e180728abb1440cd4e6994967419117052646236", "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/Solutions/Interfaces.idr", "max_forks_repo_name": "gahr/idris2-tutorial", "max_forks_repo_head_hexsha": "e180728abb1440cd4e6994967419117052646236", "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.0166666667, "max_line_length": 80, "alphanum_fraction": 0.5687183201, "num_tokens": 2176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.6703238719328735}} {"text": "module Rhone.Canvas.Angle\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Angle\n--------------------------------------------------------------------------------\n\npublic export\ndata Angle : Type where\n Radians : Double -> Angle\n Degree : Double -> Angle\n\nexport %inline\nrad : Double -> Angle\nrad = Radians\n\nexport %inline\ndeg : Double -> Angle\ndeg = Degree\n\nexport\ntoRadians : Angle -> Double\ntoRadians (Radians x) = x\ntoRadians (Degree x) = (x / 180) * pi\n\nexport\ntoDegree : Angle -> Double\ntoDegree (Radians x) = (x / pi) * 180\ntoDegree (Degree x) = x\n\nexport\nShow Angle where\n show = show . toDegree\n", "meta": {"hexsha": "5b9466469acec14175370eb78ee02aeb9c16213a", "size": 669, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Rhone/Canvas/Angle.idr", "max_stars_repo_name": "mattpolzin/idris2-rhone-js", "max_stars_repo_head_hexsha": "8ddde9db0dbd20e4ac8fbf22da990fde96399c25", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-09-30T15:53:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-21T04:39:54.000Z", "max_issues_repo_path": "src/Rhone/Canvas/Angle.idr", "max_issues_repo_name": "mattpolzin/idris2-rhone-js", "max_issues_repo_head_hexsha": "8ddde9db0dbd20e4ac8fbf22da990fde96399c25", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-11-04T04:53:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T03:42:48.000Z", "max_forks_repo_path": "src/Rhone/Canvas/Angle.idr", "max_forks_repo_name": "mattpolzin/idris2-rhone-js", "max_forks_repo_head_hexsha": "8ddde9db0dbd20e4ac8fbf22da990fde96399c25", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-27T01:22:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T01:22:26.000Z", "avg_line_length": 19.1142857143, "max_line_length": 80, "alphanum_fraction": 0.5082212257, "num_tokens": 155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6702785891844425}} {"text": "module Logic.Basic\n\n%access public\n%default total\n\ninfixl 2 <=>\ninfixl 2 <-->\n\ndata (<=>) : (a : Type) -> (b : Type) -> Type where\n (<-->) : (a -> b) -> (b -> a) -> a <=> b\n\n-- 等値の対称性\neq_sym : (a <=> b) -> (b <=> a)\neq_sym (f <--> g) = (g <--> f)\n\n\n-- 等値性から射を導出..ってか取り出してるだけ\n-- TODO:この演算子使い辛くね?\ninfixl 5 ->>\ninfixl 5 <<-\n(->>): (a <=> b) -> a -> b\n(->>) (f <--> _) = f\n\n(<<-) : (a <=> b) -> b -> a\n(<<-) (_ <--> g) = g\n\n\n-- 三段論法\nsyllogism : (a -> b) -> (b -> c) -> a -> c\nsyllogism f g = g . f\n\n-- 三段同値\nsyllogism_eq : a <=> b -> b <=> c -> a <=> c\nsyllogism_eq (f <--> f') (g <--> g') = (g . f) <--> (f' . g')\n\n-- トートロジー同値\ntautology_eq : a <=> a\ntautology_eq = id <--> id\n\n\nnamespace and\n infixl 5 /\\\n (/\\) : Type -> Type -> Type\n (/\\) a b = (a,b)\n\n associative_law : (a /\\ b) /\\ c <=> a /\\ (b /\\ c)\n associative_law = (\\((a,b),c) => (a,(b,c))) <--> (\\(a,(b,c)) => ((a,b),c))\n\n commulative_law : a /\\ b -> b /\\ a\n commulative_law (a, b) = (b, a)\n\n idempotence_and : a /\\ a -> a\n idempotence_and (a,a) = a\n\n -- assoc : (a /\\ b) /\\ c = a /\\ (b /\\ c)\n -- assoc = ?assoc\n\nnamespace or\n infixl 5 \\/\n (\\/) : Type -> Type -> Type\n (\\/) a b = Either a b\n\n associative_law_1 : ((a \\/ b) \\/ c) -> (a \\/ (b \\/ c))\n associative_law_1 (Right c) = Right $ Right c\n associative_law_1 (Left (Left a)) = Left a\n associative_law_1 (Left (Right b)) = Right (Left b)\n\n associative_law_2 : (a \\/ (b \\/ c)) -> ((a \\/ b) \\/ c)\n associative_law_2 (Left a) = Left $ Left a\n associative_law_2 (Right (Left b)) = Left $ Right b\n associative_law_2 (Right (Right c)) = Right c\n\n associative_law : ((a \\/ b) \\/ c) <=> (a \\/ (b \\/ c))\n associative_law = associative_law_1 <--> associative_law_2\n\n commulative_law : a \\/ b -> b \\/ a -- TODO: 片方変換できれば自動的に等値が導けるケース\n commulative_law x = either x Right Left\n\n idempotence_or : a \\/ a -> a\n idempotence_or x = either x id id\n\nabsorption_law_1 : (a /\\ b) \\/ a -> a\nabsorption_law_1 (Left (a,b)) = a\nabsorption_law_1 (Right a) = a\n\nabsorption_law_2 : (a \\/ b) /\\ a -> a\nabsorption_law_2 (_, a) = a\n\npartition_law : a /\\ (b \\/ c) <=> (a /\\ b) \\/ (a /\\ c)\npartition_law = l <--> r\n where\n l (a, (Left b)) = Left (a, b)\n l (a, (Right c)) = Right (a, c)\n r (Left (a,b)) = (a, Left b)\n r (Right (a,c)) = (a, Right c)\n\npartition_law_1 : (b \\/ c) /\\ a <=> (a /\\ b) \\/ (a /\\ c)\n--partition_law_1 = let (f <--> g) = partition_law\n-- in (f . and.commulative_law) <--> (and.commulative_law . g)\n\ndm_nor : Not (a \\/ b) <=> (Not a) /\\ (Not b)\ndm_nand : Not (a /\\ b) <=> (Not a) \\/ (Not b)\n\n\n", "meta": {"hexsha": "852cde00507070c77cd38f8b755ab33f142e41c2", "size": 2558, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Logic/Basic.idr", "max_stars_repo_name": "seagull-kamome/idris-toy", "max_stars_repo_head_hexsha": "5e4b7c5969fab57dedac314d972211affc6e4785", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-06-04T16:11:33.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-04T16:11:33.000Z", "max_issues_repo_path": "Logic/Basic.idr", "max_issues_repo_name": "seagull-kamome/idris-toy", "max_issues_repo_head_hexsha": "5e4b7c5969fab57dedac314d972211affc6e4785", "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": "Logic/Basic.idr", "max_forks_repo_name": "seagull-kamome/idris-toy", "max_forks_repo_head_hexsha": "5e4b7c5969fab57dedac314d972211affc6e4785", "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.3619047619, "max_line_length": 80, "alphanum_fraction": 0.4984362783, "num_tokens": 1086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6702785852660047}} {"text": "module Record.List\n\nimport Data.List\n\n-- All functions must be total\n%default total\n\n-- All definitions and functions are exported\n%access public export\n\n-- *** Properties of equality ***\n\nsymNot : Not (x = y) -> Not (y = x)\nsymNot notEqual Refl = notEqual Refl\n\n\n-- *** Properties of List ***\n\nconsNotEqNil : {xs : List t} -> Not (x :: xs = [])\nconsNotEqNil Refl impossible\n\n\n-- *** Properties of Elem ***\n\nnoEmptyElem : Not (Elem x [])\nnoEmptyElem Here impossible\n\nnoElemInCons : Not (Elem x (y :: ys)) -> Not (Elem x ys)\nnoElemInCons notElemCons elemTail = notElemCons $ There elemTail\n\nifNotElemThenNotEqual : Not (Elem x (y :: ys)) -> Not (x = y)\nifNotElemThenNotEqual notElemCons equal = notElemCons $ rewrite equal in Here\n\nifNotEqualNotElemThenNotInCons : Not (Elem x ys) -> Not (x = y) -> Not (Elem x (y :: ys))\nifNotEqualNotElemThenNotInCons nIsE nEq Here = nEq Refl\nifNotEqualNotElemThenNotInCons nIsE nEq (There th) = nIsE th\n\n\n-- *** Predicates over lists ***\n\n-- Represents that every element of the first list fulfills a predicate over the entire second list\ndata AllOverList : (t -> List u -> Type) -> List t -> List u -> Type where\n AllOverListNil : AllOverList p [] us\n AllOverListCons : (v : t) -> p v us -> AllOverList p ts us -> AllOverList p (v :: ts) us\n\n-- All elements from the first list belong in the second list \nAllInList : List t -> List t -> Type\nAllInList ts us = AllOverList Elem ts us\n\n-- No element from the first list belong in the second list\nAllNotInList : List t -> List t -> Type\nAllNotInList ts us = AllOverList (\\x => \\xs => Not (Elem x xs)) ts us\n\nnothingIsInEmpty : (xs : List t) -> AllNotInList xs []\nnothingIsInEmpty [] = AllOverListNil\nnothingIsInEmpty (x :: xs) = AllOverListCons x noEmptyElem (nothingIsInEmpty xs)\n\nifAllNotInConsThenAllNotInRest : AllNotInList ls (x :: xs) -> AllNotInList ls xs\nifAllNotInConsThenAllNotInRest AllOverListNil = AllOverListNil\nifAllNotInConsThenAllNotInRest {ls = l :: _} (AllOverListCons l nIsE notAllInList) = \n let allNotInRest = ifAllNotInConsThenAllNotInRest notAllInList\n in AllOverListCons l (noElemInCons nIsE) allNotInRest\n\nifAllNotInListAndValueNotInFirstOneThenNotInCons : Not (Elem y xs) -> AllNotInList xs ys -> AllNotInList xs (y :: ys) \nifAllNotInListAndValueNotInFirstOneThenNotInCons nIsE AllOverListNil = AllOverListNil\nifAllNotInListAndValueNotInFirstOneThenNotInCons nIsEY (AllOverListCons x nIsEX allNot) = \n let allNotInRest = ifAllNotInListAndValueNotInFirstOneThenNotInCons (noElemInCons nIsEY) allNot\n nEq = ifNotElemThenNotEqual nIsEY\n nIsEXCons = ifNotEqualNotElemThenNotInCons nIsEX (symNot nEq)\n in AllOverListCons x nIsEXCons allNotInRest\n \nifAllNotInListThenOthersAreNotInFirstOne : AllNotInList xs ys -> AllNotInList ys xs\nifAllNotInListThenOthersAreNotInFirstOne {ys} AllOverListNil = nothingIsInEmpty ys\nifAllNotInListThenOthersAreNotInFirstOne (AllOverListCons _ nIsE allNot) = \n let allNotInXs = ifAllNotInListThenOthersAreNotInFirstOne allNot\n in ifAllNotInListAndValueNotInFirstOneThenNotInCons nIsE allNotInXs\n \n \n-- *** IsSet ***\n\ndata IsSet : List t -> Type where\n IsSetNil : IsSet []\n IsSetCons : Not (Elem x xs) -> IsSet xs -> IsSet (x :: xs)\n \nifSetThenNotElemFirst : IsSet (x :: xs) -> Not (Elem x xs)\nifSetThenNotElemFirst (IsSetCons notXIsInXs _) = notXIsInXs\n \nifSetThenRestIsSet : IsSet (x :: xs) -> IsSet xs\nifSetThenRestIsSet (IsSetCons _ xsIsSet) = xsIsSet\n\nifNotSetHereThenNeitherThere : Not (IsSet xs) -> Not (IsSet (x :: xs))\nifNotSetHereThenNeitherThere notXsIsSet (IsSetCons xIsInXs xsIsSet) = notXsIsSet xsIsSet \n \nifIsElemThenConsIsNotSet : Elem x xs -> Not (IsSet (x :: xs)) \nifIsElemThenConsIsNotSet xIsInXs (IsSetCons notXIsInXs xsIsSet) = notXIsInXs xIsInXs\n\n-- Decidability function for IsSet \nisSet : DecEq t => (xs : List t) -> Dec (IsSet xs)\nisSet [] = Yes IsSetNil\nisSet (x :: xs) with (isSet xs)\n isSet (x :: xs) | No notXsIsSet = No $ ifNotSetHereThenNeitherThere notXsIsSet\n isSet (x :: xs) | Yes xsIsSet with (isElem x xs)\n isSet (x :: xs) | Yes xsIsSet | No notXInXs = Yes $ IsSetCons notXInXs xsIsSet\n isSet (x :: xs) | Yes xsIsSet | Yes xInXs = No $ ifIsElemThenConsIsNotSet xInXs\n \n \n-- *** Functions on List (lty, Type) ***\n\nlabelsOf: List (lty, Type) -> List lty\nlabelsOf = map fst\n\ninfixr 3 ://:\n\n-- Deletes a single element from the list\n(://:) : DecEq lty => lty -> List (lty, Type) -> List (lty, Type)\n(://:) l [] = []\n(://:) l ((l', ty) :: ts) with (decEq l l')\n (://:) l ((l', ty) :: ts) | Yes _ = ts\n (://:) l ((l', ty) :: ts) | No _ = (l', ty) :: (l ://: ts)\n\ninfixr 4 :///:\n \n-- Deletes a list of elements from the list\n(:///:) : DecEq lty => List lty -> List (lty, Type) -> List (lty, Type)\n(:///:) [] ts = ts\n(:///:) (l :: ls) ts = l ://: (ls :///: ts)\n\ninfixr 4 :||:\n\n-- Returns the left union of two lists\n(:||:) : DecEq lty => List (lty, Type) -> List (lty, Type) -> List (lty, Type)\n(:||:) ts us = ts ++ ((labelsOf ts) :///: us)\n\ninfixr 4 :<:\n\n-- Returns left projection of a list\n(:<:) : DecEq lty => List lty -> List (lty, Type) -> List (lty, Type)\n(:<:) _ [] = []\n(:<:) ls ((l, ty) :: ts) with (isElem l ls)\n (:<:) ls ((l, ty) :: ts) | Yes _ = (l, ty) :: (ls :<: ts)\n (:<:) ls ((l, _) :: ts) | No _ = ls :<: ts\n\ninfixr 4 :>:\n\n-- Returns right projection of a lsit\n(:>:) : DecEq lty => List lty -> List (lty, Type) -> List (lty, Type)\n(:>:) _ [] = []\n(:>:) ls ((l, ty) :: ts) with (isElem l ls)\n (:>:) ls ((l, _) :: ts) | Yes _ = ls :>: ts\n (:>:) ls ((l, ty) :: ts) | No _ = (l, ty) :: (ls :>: ts)\n\n\n-- *** Theorems on append ***\n\nifIsInOneThenIsInAppend : DecEq lty => {ts, us : List (lty, Type)} -> {l : lty} ->\n Either (Elem l (labelsOf ts)) (Elem l (labelsOf us)) -> \n Elem l (labelsOf (ts ++ us))\nifIsInOneThenIsInAppend (Left isE) = ifIsElemThenIsInAppendLeft isE\n where\n ifIsElemThenIsInAppendLeft : DecEq lty => {ts, us : List (lty, Type)} -> {l : lty} ->\n Elem l (labelsOf ts) -> Elem l (labelsOf (ts ++ us))\n ifIsElemThenIsInAppendLeft {ts=((_, _) :: _)} Here = Here\n ifIsElemThenIsInAppendLeft {ts=((_, _) :: _)} (There th) = \n let isEApp = ifIsElemThenIsInAppendLeft th\n in There isEApp\nifIsInOneThenIsInAppend (Right isE) = ifIsElemThenIsInAppendRight isE \n where\n ifIsElemThenIsInAppendRight : DecEq lty => {ts, us : List (lty, Type)} -> {l : lty} ->\n Elem l (labelsOf us) -> Elem l (labelsOf (ts ++ us)) \n ifIsElemThenIsInAppendRight {ts=[]} isE' = isE'\n ifIsElemThenIsInAppendRight {ts=((_, _) :: _)} {us=[]} isE' = absurd $ noEmptyElem isE'\n ifIsElemThenIsInAppendRight {ts=((_, _) :: _)} {us=((_, _) :: _)} isE' = \n let isEApp = ifIsElemThenIsInAppendRight isE'\n in There isEApp\n\nifIsInAppendThenIsInOne : DecEq lty => {ts, us : List (lty, Type)} -> {l : lty} ->\n Elem l (labelsOf (ts ++ us)) -> \n Either (Elem l (labelsOf ts)) (Elem l (labelsOf us))\nifIsInAppendThenIsInOne {ts=[]} isE = Right isE\nifIsInAppendThenIsInOne {ts=((_, _) :: _)} Here = Left Here\nifIsInAppendThenIsInOne {ts=((_, _) :: _)} (There th) =\n case (ifIsInAppendThenIsInOne th) of\n Left isE => Left $ There isE\n Right isE => Right isE\n \nifNotInAppendThenNotInNeither : DecEq lty => {ts, us : List (lty, Type)} -> {l : lty} ->\n Not (Elem l (labelsOf (ts ++ us))) -> \n (Not (Elem l (labelsOf ts)), Not (Elem l (labelsOf us)))\nifNotInAppendThenNotInNeither {ts=[]} {us} {l} notInAppend = (nIsE1, nIsE2) \n where\n nIsE1 : Not (Elem l [])\n nIsE1 isE = noEmptyElem isE\n \n nIsE2 : Not (Elem l (labelsOf us))\n nIsE2 isE = notInAppend isE \nifNotInAppendThenNotInNeither {ts=((lt, tyt) :: ts)} {us} {l} nIsEApp = (nIsE1, nIsE2) \n where \n nIsE1 : Not (Elem l (labelsOf ((lt, tyt) :: ts)))\n nIsE1 a with (decEq l lt)\n nIsE1 a | Yes ok \n = case a of \n Here => nIsEApp Here\n There th => nIsEApp (rewrite ok in Here)\n nIsE1 a | No contra\n = case a of \n Here => contra Refl\n There th => let isEApp = ifIsInOneThenIsInAppend (Left th)\n in nIsEApp (There isEApp) \n\n nIsE2 : Not (Elem l (labelsOf us))\n nIsE2 isE =\n let isEApp = ifIsInOneThenIsInAppend (Right isE)\n in nIsEApp (There isEApp)\n\nifNotInNeitherThenNotInAppend : DecEq lty => {ts, us : List (lty, Type)} -> {l : lty} ->\n (Not (Elem l (labelsOf ts)), Not (Elem l (labelsOf us))) -> \n Not (Elem l (labelsOf (ts ++ us)))\nifNotInNeitherThenNotInAppend {ts=[]} (_, nIsE2) isEApp = nIsE2 isEApp\nifNotInNeitherThenNotInAppend {ts=((_, _) :: _)} (nIsE1, _) Here = nIsE1 Here\nifNotInNeitherThenNotInAppend {ts=((_, _) :: _)} (nIsE1, nIsE2) (There th) = \n let nIsEApp = ifNotInNeitherThenNotInAppend ((noElemInCons nIsE1), nIsE2)\n in nIsEApp th\n\nifAppendIsSetThenEachIsSet : DecEq lty => {ts, us : List (lty, Type)} -> \n IsSet (labelsOf (ts ++ us)) -> \n (IsSet (labelsOf ts), IsSet (labelsOf us))\nifAppendIsSetThenEachIsSet {ts=[]} isS = (IsSetNil, isS)\nifAppendIsSetThenEachIsSet {ts=((_, _) :: _)} (IsSetCons nIsE isS) =\n let (isSLeft, isSRight) = ifAppendIsSetThenEachIsSet isS\n nIsELeft = fst $ ifNotInAppendThenNotInNeither nIsE\n in (IsSetCons nIsELeft isSLeft, isSRight)\n\nifEachIsSetThenAppendIsSet : DecEq lty => {ts, us : List (lty, Type)} ->\n (IsSet (labelsOf ts), IsSet (labelsOf us)) -> AllNotInList (labelsOf ts) (labelsOf us) ->\n IsSet (labelsOf (ts ++ us))\nifEachIsSetThenAppendIsSet {ts=[]} (_, isSU) AllOverListNil = isSU\nifEachIsSetThenAppendIsSet {ts=(l, _) :: ts} {us} ((IsSetCons nIsET isST), isSU) (AllOverListCons l nIsEU overList) = \n let isSApp = ifEachIsSetThenAppendIsSet {ts} {us} (isST, isSU) overList\n nIsEApp = ifNotInNeitherThenNotInAppend (nIsET, nIsEU)\n in IsSetCons nIsEApp isSApp\n \n \n-- *** Theorems on delete ***\n\nifDeleteThenIsNotElem : DecEq lty => {ts : List (lty, Type)} -> (l : lty) -> {l' : lty} -> \n Not (Elem l' (labelsOf ts)) -> Not (Elem l' (labelsOf (l ://: ts)))\nifDeleteThenIsNotElem {ts=[]} l {l'} nIsE isEDel = absurd $ noEmptyElem isEDel\nifDeleteThenIsNotElem {ts=(l'', ty)::ts} l {l'} nIsE isEDel with (decEq l l'')\n ifDeleteThenIsNotElem {ts=(l, ty)::ts} l {l'} nIsE isEDel | Yes Refl = (noElemInCons nIsE) isEDel\n ifDeleteThenIsNotElem {ts=(l', ty)::ts} l {l'} nIsE Here | No contra = nIsE Here\n ifDeleteThenIsNotElem {ts=(l'', ty)::ts} l {l'} nIsE (There th)| No _ = \n ifDeleteThenIsNotElem l {l'} {ts} (noElemInCons nIsE) th\n \nifDeleteThenIsSet : DecEq lty => {ts : List (lty, Type)} -> (l : lty) -> IsSet (labelsOf ts) -> IsSet (labelsOf (l ://: ts))\nifDeleteThenIsSet {ts=[]} l isS = IsSetNil\nifDeleteThenIsSet {ts=(l', ty)::ts} l (IsSetCons nIsE isS) with (decEq l l') \n ifDeleteThenIsSet {ts=(l, ty)::ts} l (IsSetCons nIsE isS) | Yes Refl = isS\n ifDeleteThenIsSet {ts=(l', ty)::ts} l (IsSetCons nIsE isS) | No _ = \n let nIsEDel = ifDeleteThenIsNotElem l {l'} nIsE\n isSDel = ifDeleteThenIsSet l isS\n in IsSetCons nIsEDel isSDel\n \n \n-- *** Theorems on delete labels ***\n\nifDeleteLabelsThenIsNotElem : DecEq lty => {ts : List (lty, Type)} -> {l : lty} -> (ls : List lty) -> \n Not (Elem l (labelsOf ts)) -> Not (Elem l (labelsOf (ls :///: ts)))\nifDeleteLabelsThenIsNotElem [] nIsE isEDel = absurd $ nIsE isEDel\nifDeleteLabelsThenIsNotElem {ts} {l} (l' :: ls) nIsE isEDel = \n let nIsEDelLabels = ifDeleteLabelsThenIsNotElem ls {ts} nIsE\n in ifDeleteThenIsNotElem {l'=l} {ts=ls :///: ts} l' nIsEDelLabels isEDel\n\nifDeleteLabelsThenIsSet : DecEq lty => {ts : List (lty, Type)} -> (ls : List lty) -> IsSet (labelsOf ts) -> IsSet (labelsOf (ls :///: ts))\nifDeleteLabelsThenIsSet [] isS = isS\nifDeleteLabelsThenIsSet (l :: ls) isS = \n let isSSub = ifDeleteLabelsThenIsSet ls isS \n in ifDeleteThenIsSet l isSSub\n\nifDeleteThenResultsAreNotInList : DecEq lty => {ts : List (lty, Type)} -> {ls : List lty} -> (l : lty) ->\n AllNotInList ls (labelsOf ts) -> IsSet (labelsOf ts) ->\n AllNotInList (l :: ls) (labelsOf (l ://: ts))\nifDeleteThenResultsAreNotInList {ts=[]} l overList _ = AllOverListCons l noEmptyElem overList\nifDeleteThenResultsAreNotInList {ts=(l', _) :: ts} l overList isS with (decEq l l')\n ifDeleteThenResultsAreNotInList {ts=(l, _) :: ts} l overList (IsSetCons nIsE _) | Yes Refl =\n let allNotInTs = ifAllNotInConsThenAllNotInRest overList\n in AllOverListCons l nIsE allNotInTs\n ifDeleteThenResultsAreNotInList {ts=(l', _) :: ts} l overList (IsSetCons _ isS) | No nEq = \n let overRest = ifAllNotInConsThenAllNotInRest overList\n delAreNotInRest = ifDeleteThenResultsAreNotInList {ts} l overRest isS\n (AllOverListCons _ nIsELSupInLs _) = ifAllNotInListThenOthersAreNotInFirstOne overList\n nIsELSupInCons = ifNotEqualNotElemThenNotInCons nIsELSupInLs (symNot nEq)\n in ifAllNotInListAndValueNotInFirstOneThenNotInCons nIsELSupInCons delAreNotInRest \n\nifDeleteLabelsThenNoneAreInList : DecEq lty => (ls : List lty) -> (ts : List (lty, Type)) ->\n IsSet (labelsOf ts) ->\n AllNotInList ls (labelsOf (ls :///: ts))\nifDeleteLabelsThenNoneAreInList [] _ _ = AllOverListNil\nifDeleteLabelsThenNoneAreInList (l :: ls) ts isS = \n let nInListTs = ifDeleteLabelsThenNoneAreInList ls ts isS\n isSDel = ifDeleteLabelsThenIsSet ls isS\n in ifDeleteThenResultsAreNotInList {ts = ls :///: ts} l nInListTs isSDel\n \n\n-- *** Theorems on left union ***\n\nifLeftUnionThenIsNotElem : DecEq lty => {ts, us : List (lty, Type)} -> (l : lty) ->\n Not (Elem l (labelsOf ts)) -> Not (Elem l (labelsOf us)) ->\n Not (Elem l (labelsOf (ts :||: us)))\nifLeftUnionThenIsNotElem {ts} {us} l nIsET nIsEU = \n let nIsEDelLabels = ifDeleteLabelsThenIsNotElem {ts=us} (labelsOf ts) nIsEU\n nIsEApp = ifNotInNeitherThenNotInAppend (nIsET, nIsEDelLabels)\n in nIsEApp\n \nifLeftUnionThenisSet : DecEq lty => {ts, us : List (lty, Type)} -> \n IsSet (labelsOf ts) -> IsSet (labelsOf us) ->\n IsSet (labelsOf (ts :||: us))\nifLeftUnionThenisSet {ts} {us} isS1 isS2 = \n let isSDel = ifDeleteLabelsThenIsSet {ts=us} (labelsOf ts) isS2\n delLabelsNotInList = ifDeleteLabelsThenNoneAreInList (labelsOf ts) us isS2\n isSApp = ifEachIsSetThenAppendIsSet {ts} {us=(labelsOf ts) :///: us} (isS1, isSDel) delLabelsNotInList\n in isSApp \n \n \n-- *** Theorems on left projection ***\n\nifProjectLeftThenIsNotElem : DecEq lty => {ts : List (lty, Type)} -> (ls : List lty) -> \n Not (Elem l (labelsOf ts)) -> Not (Elem l (labelsOf (ls :<: ts)))\nifProjectLeftThenIsNotElem {ts=[]} ls nIsE isEProj = noEmptyElem isEProj\nifProjectLeftThenIsNotElem {ts=(l', _) :: ts} {l} ls nIsE isEProj with (isElem l' ls)\n ifProjectLeftThenIsNotElem {ts=(l, _) :: ts} {l} _ nIsE Here | Yes _ = nIsE Here\n ifProjectLeftThenIsNotElem {ts=(l', _) :: ts} {l} ls nIsE (There th) | Yes _ = \n ifProjectLeftThenIsNotElem {ts} ls (noElemInCons nIsE) th\n ifProjectLeftThenIsNotElem {ts=(l', _) :: ts} {l} ls nIsE isEProj | No _ = \n ifProjectLeftThenIsNotElem {ts} ls (noElemInCons nIsE) isEProj\n \nifProjectLeftThenIsSet : DecEq lty => {ts : List (lty, Type)} -> (ls : List lty) -> \n IsSet (labelsOf ts) -> IsSet (labelsOf (ls :<: ts))\nifProjectLeftThenIsSet {ts=[]} _ _ = IsSetNil\nifProjectLeftThenIsSet {ts=(l, _) :: ts} ls isS with (isElem l ls)\n ifProjectLeftThenIsSet {ts=(l, _) :: ts} ls (IsSetCons nIsE isS) | Yes _ = \n let nIsEInProj = ifProjectLeftThenIsNotElem {ts} ls nIsE\n isSProj = ifProjectLeftThenIsSet {ts} ls isS\n in IsSetCons nIsEInProj isSProj\n ifProjectLeftThenIsSet {ts=(l, _) :: ts} ls (IsSetCons _ isS) | No _ = \n ifProjectLeftThenIsSet ls isS\n\n\n-- *** Theorems on right projection ***\n\nifProjectRightThenIsNotElem : DecEq lty => {ts : List (lty, Type)} -> (ls : List lty) -> \n Not (Elem l (labelsOf ts)) -> Not (Elem l (labelsOf (ls :>: ts)))\nifProjectRightThenIsNotElem {ts=[]} ls nIsE isEProj = noEmptyElem isEProj\nifProjectRightThenIsNotElem {ts=(l', _) :: ts} {l} ls nIsE isEProj with (isElem l' ls)\n ifProjectRightThenIsNotElem {ts=(l', _) :: ts} {l} ls nIsE isEProj | Yes _ = \n ifProjectRightThenIsNotElem {ts} ls (noElemInCons nIsE) isEProj\n ifProjectRightThenIsNotElem {ts=(l, _) :: ts} {l} _ nIsE Here | No _ = nIsE Here\n ifProjectRightThenIsNotElem {ts=(l', _) :: ts} {l} ls nIsE (There th) | No _ = \n ifProjectRightThenIsNotElem {ts} ls (noElemInCons nIsE) th\n \nifProjectRightThenIsSet : DecEq lty => {ts : List (lty, Type)} -> (ls : List lty) -> \n IsSet (labelsOf ts) -> IsSet (labelsOf (ls :>: ts))\nifProjectRightThenIsSet {ts=[]} _ _ = IsSetNil\nifProjectRightThenIsSet {ts=(l, _) :: ts} ls isS with (isElem l ls)\n ifProjectRightThenIsSet {ts=(l, _) :: ts} ls (IsSetCons _ isS) | Yes _ = \n ifProjectRightThenIsSet ls isS \n ifProjectRightThenIsSet {ts=(l, _) :: ts} ls (IsSetCons nIsE isS) | No _ = \n let nIsEInProj = ifProjectRightThenIsNotElem {ts} ls nIsE\n isSProj = ifProjectRightThenIsSet {ts} ls isS\n in IsSetCons nIsEInProj isSProj\n", "meta": {"hexsha": "d6d29cc1dc28b751d37423a938488bf26523df14", "size": 17623, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/list.idr", "max_stars_repo_name": "gonzaw/extensible-records", "max_stars_repo_head_hexsha": "b4843e8941acb023aa7a0c7ea2de09ba31cfed27", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2017-09-25T08:33:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T14:11:38.000Z", "max_issues_repo_path": "src/list.idr", "max_issues_repo_name": "gonzaw/extensible-records", "max_issues_repo_head_hexsha": "b4843e8941acb023aa7a0c7ea2de09ba31cfed27", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-09-29T12:54:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-13T01:52:45.000Z", "max_forks_repo_path": "src/list.idr", "max_forks_repo_name": "gonzaw/extensible-records", "max_forks_repo_head_hexsha": "b4843e8941acb023aa7a0c7ea2de09ba31cfed27", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-01-19T02:53:40.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T18:10:30.000Z", "avg_line_length": 47.6297297297, "max_line_length": 138, "alphanum_fraction": 0.6356465982, "num_tokens": 6133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.6702752951454733}} {"text": "||| Additional views for Vect\nmodule Data.Vect.Views.Extra\n\nimport Control.WellFounded\nimport Data.Vect\nimport Data.Nat\n\n\n||| View for splitting a vector in half, non-recursively\npublic export\ndata Split : Vect n a -> Type where\n SplitNil : Split []\n SplitOne : Split [x]\n ||| two non-empty parts\n SplitPair : {n : Nat} -> {m : Nat} ->\n (x : a) -> (xs : Vect n a) -> (y : a) -> (ys : Vect m a) ->\n Split (x :: xs ++ y :: ys)\n\ntotal\nsplitHelp : {n : Nat} -> (head : a) -> (zs : Vect n a) ->\n Nat -> Split (head :: zs)\nsplitHelp head [] _ = SplitOne\nsplitHelp head (z :: zs) 0 = SplitPair head [] z zs\nsplitHelp head (z :: zs) 1 = SplitPair head [] z zs\nsplitHelp head (z :: zs) (S (S k))\n = case splitHelp z zs k of\n SplitOne => SplitPair head [] z zs\n SplitPair x xs y ys => SplitPair head (x :: xs) y ys\n\n||| Covering function for the `Split` view\n||| Constructs the view in linear time\nexport total\nsplit : {n : Nat} -> (xs : Vect n a) -> Split xs\nsplit [] = SplitNil\nsplit {n = S k} (x :: xs) = splitHelp x xs k\n\n||| View for splitting a vector in half, recursively\n|||\n||| This allows us to define recursive functions which repeatedly split vectors\n||| in half, with base cases for the empty and singleton lists.\npublic export\ndata SplitRec : Vect k a -> Type where\n SplitRecNil : SplitRec []\n SplitRecOne : SplitRec [x]\n SplitRecPair : {n : Nat} -> {m : Nat} -> {xs : Vect (S n) a} -> {ys : Vect (S m) a} ->\n (lrec : Lazy (SplitRec xs)) -> (rrec : Lazy (SplitRec ys)) -> SplitRec (xs ++ ys)\n\nsmallerPlusL : (m : Nat) -> (k : Nat) -> LTE (S (S m)) (S (m + S k))\nsmallerPlusL m k = rewrite sym (plusSuccRightSucc m k) in LTESucc $ LTESucc $ lteAddRight _\n\nsmallerPlusR : (m : Nat) -> (k : Nat) -> LTE (S (S k)) (S (m + S k))\nsmallerPlusR m k = rewrite sym (plusSuccRightSucc m k) in\n LTESucc $ LTESucc $ rewrite plusCommutative m k in lteAddRight _\n\n||| Covering function for the `SplitRec` view\n||| Constructs the view in O(n lg n)\npublic export total\nsplitRec : {k : Nat} -> (xs : Vect k a) -> SplitRec xs\nsplitRec input with (sizeAccessible k)\n splitRec input | acc with (split input)\n splitRec {k = 0} [] | acc | SplitNil = SplitRecNil\n splitRec {k = 1} [x] | acc | SplitOne = SplitRecOne\n splitRec {k = S nl + S nr} (x :: xs ++ y :: ys) | Access rec | SplitPair x xs y ys =\n SplitRecPair\n (splitRec {k = S nl} (x :: xs) | rec _ $ smallerPlusL nl nr)\n (splitRec {k = S nr} (y :: ys) | rec _ $ smallerPlusR nl nr)\n", "meta": {"hexsha": "c11af9a896dd265ea1cb112550821fc9d026e645", "size": 2545, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Vect/Views/Extra.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/contrib/Data/Vect/Views/Extra.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/contrib/Data/Vect/Views/Extra.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 37.9850746269, "max_line_length": 91, "alphanum_fraction": 0.6015717092, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.6702645542019268}} {"text": "module SimpleLambdaLang\n\nimport Data.Fin\nimport Data.Vect\n\ndata Ty = TyBool | TyFun Ty Ty\n\ntypeOf : Ty -> Type\ntypeOf TyBool = Bool\ntypeOf (TyFun x y) = typeOf x -> typeOf y\n\nusing (n : Nat, ctx : Vect n Ty)\n data Expr : Vect n Ty -> Ty -> Type where\n T : Expr ctx TyBool\n F : Expr ctx TyBool\n IF : Expr ctx TyBool -> Expr ctx t -> Expr ctx t -> Expr ctx t\n Var' : (i : Fin n) -> Expr ctx (index i ctx)\n Lam' : Expr (a :: ctx) b -> Expr ctx (TyFun a b)\n App' : Expr ctx (TyFun a b) -> Expr ctx a -> Expr ctx b\n\ndata Env : Vect n Ty -> Type where\n Nil : Env []\n (::) : typeOf t -> Env ctx -> Env (t::ctx)\n\nlookup : (i : Fin n) -> (env : Env ctx) -> typeOf (index i ctx)\nlookup FZ (x :: xs) = x\nlookup (FS x) (y :: xs) = lookup x xs\n\neval : Env ctx -> Expr ctx t -> typeOf t\neval env (Var' i) = lookup i env\neval env (Lam' body) = \\x => eval (x :: env) body\neval env (App' f x) = eval env f $ eval env x\neval env T = True\neval env F = False\neval env (IF expr expr' expr'') = if eval env expr then eval env expr' else eval env expr''\n\n\nnot'' : Expr ctx (TyFun TyBool TyBool)\nnot'' = Lam' $ IF (Var' 0) F T\n", "meta": {"hexsha": "5493c8373f929ac3aec9334c9587c53a642346ff", "size": 1143, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/TypedLambdaEvaluator.idr", "max_stars_repo_name": "tgrospic/dependently-typed-slides", "max_stars_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/TypedLambdaEvaluator.idr", "max_issues_repo_name": "tgrospic/dependently-typed-slides", "max_issues_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/TypedLambdaEvaluator.idr", "max_forks_repo_name": "tgrospic/dependently-typed-slides", "max_forks_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.575, "max_line_length": 91, "alphanum_fraction": 0.5844269466, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6698829432817008}} {"text": "\ndata Expr = Val Int\n | Mult Expr Expr\n | Add Expr Expr\n | Sub Expr Expr\n%name Expr expr1, expr2\n\nevaluate : Expr -> Int\nevaluate (Val x) = x\nevaluate (Mult expr1 expr2) = evaluate expr1 * evaluate expr2\nevaluate (Add expr1 expr2) = evaluate expr1 + evaluate expr2\nevaluate (Sub expr1 expr2) = evaluate expr1 - evaluate expr2\n", "meta": {"hexsha": "9ca89151dd2cb3468b224554d74db7799fa20aaf", "size": 353, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/myInt.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/myInt.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/myInt.idr", "max_forks_repo_name": "robkorn/idris-type-driven-development-exercises", "max_forks_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-18T12:54:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-18T12:54:05.000Z", "avg_line_length": 27.1538461538, "max_line_length": 61, "alphanum_fraction": 0.6685552408, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6698829362745546}} {"text": "import Data.Vect\n\naddMatrix : Num numType =>\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType) ->\n Vect rows (Vect cols numType)\n\nmultMatrix : Num numType =>\n Vect n (Vect m numType) -> Vect m (Vect p numType) ->\n Vect n (Vect p numType)\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ [] -- \"No such variable n\"\n\ntransposeHelper : (x : Vect n elem) -> (xsTrans : Vect n (Vect len elem)) -> Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n zipWith ((el, v) -> el :: v) x xsTrans\n", "meta": {"hexsha": "83a58d46713cdfccbb443d0198081d3633552e61", "size": 820, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Matrix.idr", "max_stars_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_stars_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matrix.idr", "max_issues_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_issues_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Matrix.idr", "max_forks_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_forks_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.652173913, "max_line_length": 103, "alphanum_fraction": 0.593902439, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6698407713662847}} {"text": "{- Ctrl-Alt-A: Add definition\n Ctrl-Alt-C: Case split\n Ctrl-Alt-D: Documentation\n Ctrl-Alt-L: Lift hole: Lifts a hole to the top level as a new function definition\n Ctrl-Alt-M: Match: Replaces a hole with a case expression that matches on an intermediate result\n Ctrl-Alt-R: Reloads and typechecks the current buffer\n Ctrl-Alt-S: Search\n Ctrl-Alt-T: Type-check: Displays the type under cursor\n Ctrl-Alt-W: Add With View -}\nmodule Main\n\n-- The View\ndata ListLast : List a -> Type where\n Empty : ListLast []\n NonEmpty : (xs : List a) -> (x : a) -> ListLast (xs ++ [x])\n\ndescribeHelper : (input : List Int) -> (form : ListLast input) -> String\ndescribeHelper [] Empty = \"Empty\"\ndescribeHelper (xs ++ [x]) (NonEmpty xs x) = \"Non-empty, initial portion = \" ++ show xs\n\n-- Covering function for the View\ntotal\nlistLast : (xs : List a) -> ListLast xs\nlistLast [] = Empty\nlistLast (x :: xs) = case listLast xs of\n Empty => NonEmpty [] x\n NonEmpty ys y => NonEmpty (x :: ys) y\n\ndescribeListEnd : List Int -> String\ndescribeListEnd xs = describeHelper xs (listLast xs)\n\ndescribeListEndWith : List Int -> String\ndescribeListEndWith input with (listLast input)\n describeListEndWith [] | Empty = \"Empty\"\n describeListEndWith (xs ++ [x]) | (NonEmpty xs x) = \"Non-empty, initial portion = \" ++ show xs\n\nmyReverse : List a -> List a\nmyReverse input with (listLast input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (NonEmpty xs x) = x :: myReverse xs\n\ndata SplitList : List a -> Type where\n SplitNil : SplitList []\n SplitOne : SplitList [x]\n SplitPair : (lefts : List a) -> (rights : List a) -> SplitList (lefts ++ rights)\n\ntotal\nsplitList : (input : List a) -> SplitList input\nsplitList input = splitListHelp input input\n where\n splitListHelp : List a -> (input : List a) -> SplitList input\n splitListHelp _ [] = SplitNil\n splitListHelp _ [x] = SplitOne\n splitListHelp (_ :: _ :: counter) (item :: items) =\n case splitListHelp counter items of\n SplitNil => SplitOne\n SplitOne {x} => SplitPair [item] [x]\n SplitPair lfts rgts => SplitPair (item :: lfts) rgts\n splitListHelp _ items = SplitPair [] items\n\nmergeSort : Ord a => List a -> List a\nmergeSort input with (splitList input)\n mergeSort [] | SplitNil = []\n mergeSort [x] | SplitOne = [x]\n mergeSort (lefts ++ rights) | (SplitPair lefts rights) = merge (mergeSort lefts) (mergeSort rights)\n\nmain : IO ()\nmain = do\n putStrLn $ describeListEnd []\n putStrLn $ describeListEnd [1]\n putStrLn $ describeListEnd [1,2,3]\n putStrLn $ describeListEndWith []\n putStrLn $ show $ myReverse [1,2,3,4,5]\n putStrLn $ show $ merge [1,3,5] [2,4,6]\n printLn $ mergeSort [3,2,1]\n printLn $ mergeSort [5,1,4,3,2,6,8,7,9]\n", "meta": {"hexsha": "eb4d7993cf970e38b6753511718bb9310f309273", "size": 2726, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "test/tdd/chapter10/01_View.idr", "max_stars_repo_name": "pdani/idris-grin", "max_stars_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2019-06-06T10:35:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T08:48:30.000Z", "max_issues_repo_path": "test/tdd/chapter10/01_View.idr", "max_issues_repo_name": "pdani/idris-grin", "max_issues_repo_head_hexsha": "c224b65551b2b2b91f564f858ba08df1d6af00b3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-11-21T20:45:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T12:29:23.000Z", "max_forks_repo_path": "test/tdd/chapter10/01_View.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": 35.4025974026, "max_line_length": 101, "alphanum_fraction": 0.667644901, "num_tokens": 821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971212, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.6698382824164661}} {"text": "module Quotient_Type\n\n%access public export\n%default total\n\nIsRefl : (typ : Type) -> (rel : typ -> typ -> Type) -> Type\nIsRefl typ rel = (a : typ) -> (rel a a)\n\nIsSym : (typ : Type) -> (rel : typ -> typ -> Type) -> Type\nIsSym typ rel = (a, b : typ) -> (rel a b) -> (rel b a)\n\nIsTrans : (typ : Type) -> (rel : typ -> typ -> Type) -> Type\nIsTrans typ rel = (a, b, c : typ) -> (rel a b) -> (rel b c) -> (rel a c)\n\nIsEqRel : (typ : Type) -> (rel : typ -> typ -> Type) -> Type\nIsEqRel typ rel = ( (IsRefl typ rel) , ( (IsSym typ rel), (IsTrans typ rel) ) )\n\ndata Quotient_Type : (typ : Type) -> (rel : typ -> typ -> Type) -> Type where\n Cons_quotient_Type : (IsEqRel typ rel) -> (Quotient_Type typ rel)\n\n||| Type of proof that a function passes through the relations\n\nPasses_Through : (ty1 : Type) -> (rel_1 : ty1 -> ty1 -> Type) ->\n (ty2 : Type) -> (rel_2 : ty2 -> ty2 -> Type) ->\n (f : ty1 -> ty2) -> Type\n\nPasses_Through ty1 rel_1 ty2 rel_2 f =\n (a, b : ty1) -> (rel_1 a b) -> (rel_2 (f a) (f b))\n\n||| Type of function between two quotient types\ndata Quotient_Function : (ty1 : Type) -> (rel_1 : ty1 -> ty1 -> Type) ->\n (ty2 : Type) -> (rel_2 : ty2 -> ty2 -> Type) -> Type where\n\n Cons_quotient_Function : (f : ty1 -> ty2) -> (Passes_Through ty1 rel_1 ty2 rel_2 f)\n -> (Quotient_Function ty1 rel_1 ty2 rel_2)\n\n||| The type of transports of a relation\nTransport_of : (ty : Type) -> (rel : ty -> ty -> Type) -> (P : ty -> Type) -> Type\nTransport_of ty rel P = (a, b : ty) -> (rel a b) -> (P a) -> (P b)\n\n||| Definition of a family of quotient types\ndata Quotient_Family : (ty : Type) -> (rel : ty -> ty -> Type) -> Type where\n Cons_quotient_Family : (P : ty -> Type) -> (Transport_of ty rel P) -> (Quotient_Family ty rel)\n\n||| Given a quotient family gets the underlying family.\nget_Family : (ty : Type) -> (rel : ty -> ty -> Type) -> (P : (Quotient_Family ty rel)) ->\n (ty -> Type)\nget_Family ty rel (Cons_quotient_Family p tr) = p\n\n||| Given a quotient type gets the transport\nget_Transport : (ty : Type) -> (rel : ty -> ty -> Type) -> (P : (Quotient_Family ty rel)) ->\n (Transport_of ty rel (get_Family ty rel P))\nget_Transport ty rel (Cons_quotient_Family P tr) = tr\n\n||| Type of proofs that a dependent function passes through the corresponding relations\nPasses_Through_Dependent : (ty1 : Type) -> (rel_1 : ty1 -> ty1 -> Type) ->\n (P : (Quotient_Family ty1 rel_1)) ->\n (relP : (a : ty1) -> ((get_Family ty1 rel_1 P) a) -> ((get_Family ty1 rel_1 P) a) -> Type) ->\n (f : (a : ty1) -> ((get_Family ty1 rel_1 P) a) ) -> Type\n\nPasses_Through_Dependent ty1 rel_1 P relP f = (a, b : ty1) -> (pt : rel_1 a b) ->\n ( (relP b) ((get_Transport ty1 rel_1 P) a b pt (f a)) (f b))\n\n||| A proof that any equivalence relation factors through equality\nEqRel_factors_through_Eq : (ty : Type) -> (rel : ty -> ty -> Type) -> (IsEqRel ty rel) ->\n (a, b : ty) -> (a = b) -> (rel a b)\n\nEqRel_factors_through_Eq ty rel pfEqRel a a Refl = (fst pfEqRel) a\n\n||| The condition on the function type A -> B to make it the quotient function type (A, relA) -> (B, relB)\nFunction_rel : (ty1 : Type) -> (rel1 : ty1 -> ty1 -> Type) -> (IsEqRel ty1 rel1) ->\n (ty2 : Type) -> (rel2 : ty2 -> ty2 -> Type) -> (IsEqRel ty2 rel2) ->\n (f, g : (ty1 -> ty2)) ->\n (Passes_Through ty1 rel1 ty2 rel2 f) ->\n (Passes_Through ty1 rel1 ty2 rel2 g) -> Type\n\nFunction_rel ty1 rel1 pfEq1 ty2 rel2 pfEq2 f g pf_f pf_g =\n (a, b : ty1) -> (rel1 a b) -> (rel2 (f a) (g b))\n\nIsRefl_Function_rel : (ty1 : Type) -> (rel1 : ty1 -> ty1 -> Type) -> (pf1 : IsEqRel ty1 rel1) ->\n (ty2 : Type) -> (rel2 : ty2 -> ty2 -> Type) -> (pf2 : IsEqRel ty2 rel2) ->\n (f : (ty1 -> ty2)) -> (pf_f : Passes_Through ty1 rel1 ty2 rel2 f) ->\n (Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f f pf_f pf_f)\n\nIsRefl_Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f pf_f = pf_f\n\nIsSym_Function_rel : (ty1 : Type) -> (rel1 : ty1 -> ty1 -> Type) -> (pf1 : IsEqRel ty1 rel1) ->\n (ty2 : Type) -> (rel2 : ty2 -> ty2 -> Type) -> (pf2 : IsEqRel ty2 rel2) ->\n (f : (ty1 -> ty2)) -> (pf_f : Passes_Through ty1 rel1 ty2 rel2 f) ->\n (g : (ty1 -> ty2)) -> (pf_g : Passes_Through ty1 rel1 ty2 rel2 g) ->\n (Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f g pf_f pf_g) ->\n (Function_rel ty1 rel1 pf1 ty2 rel2 pf2 g f pf_g pf_f)\n\nIsSym_Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f pf_f g pf_g pf_rel a b pfab = let\n\n pf_sym_1 : ((a1 : ty1) -> (b1 : ty1) -> (rel1 a1 b1) -> (rel1 b1 a1))\n = (fst (snd pf1))\n\n pf_sym_2 : ((a1 : ty2) -> (b1 : ty2) -> (rel2 a1 b1) -> (rel2 b1 a1))\n = (fst (snd pf2))\n\n pf4 : (rel1 b a)\n = pf_sym_1 a b pfab\n\n pf5 : (rel2 (f b) (g a))\n = pf_rel b a pf4\n\n pf6 : (rel2 (g a) (f b))\n = pf_sym_2 (f b) (g a) pf5\n in\n pf6\n\nIsTrans_Function_rel : (ty1 : Type) -> (rel1 : ty1 -> ty1 -> Type) -> (pf1 : IsEqRel ty1 rel1) ->\n (ty2 : Type) -> (rel2 : ty2 -> ty2 -> Type) -> (pf2 : IsEqRel ty2 rel2) ->\n (f : (ty1 -> ty2)) -> (pf_f : Passes_Through ty1 rel1 ty2 rel2 f) ->\n (g : (ty1 -> ty2)) -> (pf_g : Passes_Through ty1 rel1 ty2 rel2 g) ->\n (h : (ty1 -> ty2)) -> (pf_h : Passes_Through ty1 rel1 ty2 rel2 h) ->\n (Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f g pf_f pf_g) ->\n (Function_rel ty1 rel1 pf1 ty2 rel2 pf2 g h pf_g pf_h) ->\n (Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f h pf_f pf_h)\n \nIsTrans_Function_rel ty1 rel1 pf1 ty2 rel2 pf2 f pf_f g pf_g h pf_h pf_fg pf_gh a b pf_ab = let\n\n pf3 : (rel2 (f a) (g b))\n = pf_fg a b pf_ab\n\n pf_refl_1 : ((a1 : ty1) -> rel1 a1 a1)\n = (fst pf1)\n\n pf_refl_2 : ((a1 : ty2) -> rel2 a1 a1)\n = (fst pf2)\n\n -- pf4 : (rel2 (g b) (g b))\n -- = pf_refl_2 (g b)\n\n pf5 : (rel2 (g b) (h b))\n = pf_gh b b (pf_refl_1 b)\n\n pf_trans_2 : ((a1 : ty2) -> (b1 : ty2) -> (c : ty2) ->\n (rel2 a1 b1) -> (rel2 b1 c) -> (rel2 a1 c))\n = (snd (snd pf2))\n\n pf6 : (rel2 (f a) (h b))\n = pf_trans_2 (f a) (g b) (h b) pf3 pf5\n\n in\n pf6\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n{-\ndata Quotient_Dependent_Function : (ty : Type) -> (rel : ty -> ty -> Type) ->\n (P : (Quotient_Family ty rel)) -> Type where\n quotient_Dependent_Function : (a, b : ty) -> (rel a b) ->\n -}\n", "meta": {"hexsha": "e37390376d703f883578e9e86ca77695f2b2d950", "size": 6753, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Quotient_Type.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/Quotient_Type.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/Quotient_Type.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": 39.261627907, "max_line_length": 120, "alphanum_fraction": 0.5246557086, "num_tokens": 2376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.669559152467744}} {"text": "module InsSort\n\nimport Data.Vect\n\n%default total\n\ninsert : Ord a => a -> Vect n a -> Vect (S n) a\ninsert x [] = [x]\ninsert x (y :: ys) = case compare x y of\n GT => y :: insert x ys\n _ => x :: y :: ys\n\nisort : Ord a => Vect n a -> Vect n a\nisort [] = []\nisort (x :: xs) = insert x (isort xs)", "meta": {"hexsha": "0d6f4def4466fab1fe8621f637110aa4de586b97", "size": 341, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "chapter3/InsSort.idr", "max_stars_repo_name": "timmyjose-study/tdd-with-idris", "max_stars_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter3/InsSort.idr", "max_issues_repo_name": "timmyjose-study/tdd-with-idris", "max_issues_repo_head_hexsha": "be2cd6fc4bbcd58cb4e14ed1e22c9cc99aade4d0", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter3/InsSort.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.7333333333, "max_line_length": 48, "alphanum_fraction": 0.4721407625, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6695124518193387}} {"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\nappend : Vect n elem -> Vect m elem -> Vect (n + m) elem\nappend [] ys = ys\nappend (x :: xs) ys = x :: append xs ys\n\nzip : Vect n a -> Vect n b -> Vect n (a, b)\nzip [] [] = []\nzip (x :: xs) (y :: ys) = (x, y) :: zip xs ys\n", "meta": {"hexsha": "51707412e4fad77f86a18c32b126fe1f2ca0f261", "size": 356, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/Vect.idr", "max_stars_repo_name": "DimaSamoz/idris-book", "max_stars_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter4/Vect.idr", "max_issues_repo_name": "DimaSamoz/idris-book", "max_issues_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter4/Vect.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.4285714286, "max_line_length": 56, "alphanum_fraction": 0.4859550562, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6692449341226357}} {"text": "-- Minimal propositional logic, PHOAS approach, final encoding\n\nmodule Pf.Mp\n\n%default total\n\n\n-- Types\n\ninfixl 2 :&&\ninfixl 1 :||\ninfixr 0 :=>\ndata Ty : Type where\n UNIT : Ty\n (:=>) : Ty -> Ty -> Ty\n (:&&) : Ty -> Ty -> Ty\n (:||) : Ty -> Ty -> Ty\n FALSE : Ty\n\ninfixr 0 :<=>\n(:<=>) : Ty -> Ty -> Ty\n(:<=>) a b = (a :=> b) :&& (b :=> a)\n\nNOT : Ty -> Ty\nNOT a = a :=> FALSE\n\nTRUE : Ty\nTRUE = FALSE :=> FALSE\n\n\n-- Context and truth judgement\n\nCx : Type\nCx = Ty -> Type\n\nisTrue : Ty -> Cx -> Type\nisTrue a tc = tc a\n\n\n-- Terms\n\nTmRepr : Type\nTmRepr = Cx -> Ty -> Type\n\ninfixl 1 :$\nclass ArrMpTm (tr : TmRepr) where\n var : isTrue a tc -> tr tc a\n lam' : (isTrue a tc -> tr tc b) -> tr tc (a :=> b)\n (:$) : tr tc (a :=> b) -> tr tc a -> tr tc b\n\nlam'' : {tr : TmRepr} -> ArrMpTm tr => (tr tc a -> tr tc b) -> tr tc (a :=> b)\nlam'' f = lam' $ \\x => f (var x)\n\nsyntax \"lam\" {a} \":=>\" [b] = lam'' (\\a => b)\n\nclass ArrMpTm tr => MpTm (tr : TmRepr) where\n pair : tr tc a -> tr tc b -> tr tc (a :&& b)\n fst : tr tc (a :&& b) -> tr tc a\n snd : tr tc (a :&& b) -> tr tc b\n left : tr tc a -> tr tc (a :|| b)\n right : tr tc b -> tr tc (a :|| b)\n case' : tr tc (a :|| b) -> (isTrue a tc -> tr tc c) -> (isTrue b tc -> tr tc c) -> tr tc c\n\ncase'' : {tr : TmRepr} -> MpTm tr => tr tc (a :|| b) -> (tr tc a -> tr tc c) -> (tr tc b -> tr tc c) -> tr tc c\ncase'' xy f g = case' xy (\\x => f (var x)) (\\y => g (var y))\n\nsyntax \"[\" [a] \",\" [b] \"]\" = pair a b\nsyntax \"case\" [ab] \"of\" {a} \":=>\" [c1] or {b} \":=>\" [c2] = case'' ab (\\a => c1) (\\b => c2)\n\nThm : Ty -> Type\nThm a = {tr : TmRepr} -> {tc : Cx} -> MpTm tr => tr tc a\n\n\n-- Example theorems\n\nc1 : Thm (a :&& b :<=> b :&& a)\nc1 =\n [ lam xy :=> [ snd xy , fst xy ]\n , lam yx :=> [ snd yx , fst yx ]\n ]\n\nc2 : Thm (a :|| b :<=> b :|| a)\nc2 =\n [ lam xy :=>\n case xy\n of x :=> right x\n or y :=> left y\n , lam yx :=>\n case yx\n of y :=> right y\n or x :=> left x\n ]\n\ni1 : Thm (a :&& a :<=> a)\ni1 =\n [ lam xx :=> fst xx\n , lam x :=> [ x , x ]\n ]\n\ni2 : Thm (a :|| a :<=> a)\ni2 =\n [ lam xx :=>\n case xx\n of x :=> x\n or x :=> x\n , lam x :=> left x\n ]\n\nl3 : Thm ((a :=> a) :<=> TRUE)\nl3 =\n [ lam x :=> lam nt :=> nt\n , lam b :=> lam x :=> x\n ]\n\nl1 : Thm (a :&& (b :&& c) :<=> (a :&& b) :&& c)\nl1 =\n [ lam xyz :=>\n (let yz = snd xyz in\n [ [ fst xyz , fst yz ] , snd yz ])\n , lam xyz :=>\n (let xy = fst xyz in\n [ fst xy , [ snd xy , snd xyz ] ])\n ]\n\nl2 : Thm (a :&& TRUE :<=> a)\nl2 =\n [ lam xt :=> fst xt\n , lam x :=> [ x , lam nt :=> nt ]\n ]\n\nl4 : Thm (a :&& (b :|| c) :<=> (a :&& b) :|| (a :&& c))\nl4 =\n [ lam xyz :=>\n (let x = fst xyz in\n case snd xyz\n of y :=> left [ x , y ]\n or z :=> right [ x , z ])\n , lam xyxz :=>\n case xyxz\n of xy :=> ([ fst xy , left (snd xy) ])\n or xz :=> [ fst xz , right (snd xz) ]\n ]\n\nl6 : Thm (a :|| (b :&& c) :<=> (a :|| b) :&& (a :|| c))\nl6 =\n [ lam xyz :=>\n case xyz\n of x :=> ([ left x , left x ])\n or yz :=> [ right (fst yz) , right (snd yz) ]\n , lam xyxz :=>\n case fst xyxz\n of x :=> left x\n or y :=>\n case snd xyxz\n of x :=> left x\n or z :=> right [ y , z ]\n ]\n\nl7 : Thm (a :|| TRUE :<=> TRUE)\nl7 =\n [ lam xt :=> lam nt :=> nt\n , lam t :=> right t\n ]\n\nl9 : Thm (a :|| (b :|| c) :<=> (a :|| b) :|| c)\nl9 =\n [ lam xyz :=>\n case xyz\n of x :=> left (left x)\n or yz :=>\n case yz\n of y :=> left (right y)\n or z :=> right z\n , lam xyz :=>\n case xyz\n of xy :=>\n case xy\n of x :=> left x\n or y :=> right (left y)\n or z :=> right (right z)\n ]\n\nl11 : Thm ((a :=> (b :&& c)) :<=> (a :=> b) :&& (a :=> c))\nl11 =\n [ lam xyz :=>\n [ lam x :=> fst (xyz :$ x)\n , lam x :=> snd (xyz :$ x)\n ]\n , lam xyxz :=>\n lam x :=> [ fst xyxz :$ x , snd xyxz :$ x ]\n ]\n\nl12 : Thm ((a :=> TRUE) :<=> TRUE)\nl12 =\n [ lam f :=> lam nt :=> nt\n , lam t :=> lam f :=> t\n ]\n\nl13 : Thm ((a :=> (b :=> c)) :<=> ((a :&& b) :=> c))\nl13 =\n [ lam xyz :=>\n lam xy :=> xyz :$ fst xy :$ snd xy\n , lam xyz :=>\n lam x :=>\n lam y :=> xyz :$ [ x , y ]\n ]\n\nl16 : Thm (((a :&& b) :=> c) :<=> (a :=> (b :=> c)))\nl16 =\n [ lam xyz :=>\n lam x :=>\n lam y :=> xyz :$ [ x , y ]\n , lam xyz :=>\n lam xy :=> xyz :$ fst xy :$ snd xy\n ]\n\nl17 : Thm ((TRUE :=> a) :<=> a)\nl17 =\n [ lam tx :=> tx :$ (lam nt :=> nt)\n , lam x :=> lam tx :=> x\n ]\n\nl19 : Thm (((a :|| b) :=> c) :<=> (a :=> c) :&& (b :=> c))\nl19 =\n [ lam xyz :=>\n [ lam x :=> xyz :$ left x\n , lam y :=> xyz :$ right y\n ]\n , lam xzyz :=>\n lam xy :=>\n case xy\n of x :=> fst xzyz :$ x\n or y :=> snd xzyz :$ y\n ]\n", "meta": {"hexsha": "5d8880dcefca9e0cb2d25344a816e6376fb68ad3", "size": 4951, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Pf/Mp.idr", "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": ["X11"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_issues_repo_path": "src/Pf/Mp.idr", "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_licenses": ["X11"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Pf/Mp.idr", "max_forks_repo_name": "mietek/formal-logic", "max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_forks_repo_licenses": ["X11"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0680851064, "max_line_length": 111, "alphanum_fraction": 0.3734599071, "num_tokens": 2001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6692159056416754}} {"text": "module SimpleLang\n\ndata Ty = TyInt | TyBool\n\ninterp : Ty -> Type\ninterp TyInt = Int\ninterp TyBool = Bool\n\ndata Expr : Ty -> Type where\n CInt : Int -> Expr TyInt\n CBool : Bool -> Expr TyBool\n Add : Expr TyInt -> Expr TyInt -> Expr TyInt\n LT : Expr TyInt -> Expr TyInt -> Expr TyBool\n\neval : Expr t -> interp t\neval (CInt x) = x\neval (CBool x) = x\neval (Add x y) = eval x + eval y\neval (LT x y) = eval x < eval y\n", "meta": {"hexsha": "73c034b3a1ccec3bb4660bbb831158ba4228dc76", "size": 422, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/SimpleLang.idr", "max_stars_repo_name": "tgrospic/dependently-typed-slides", "max_stars_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/SimpleLang.idr", "max_issues_repo_name": "tgrospic/dependently-typed-slides", "max_issues_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SimpleLang.idr", "max_forks_repo_name": "tgrospic/dependently-typed-slides", "max_forks_repo_head_hexsha": "c5f15191fbb4b917e61117fb723b508037b02471", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1, "max_line_length": 49, "alphanum_fraction": 0.6232227488, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6691693318377092}} {"text": "module GaloisCh1\r\n\r\n-- > idris -p base\r\nimport Data.Fin\r\n\r\n%default total\r\n-- %auto_implicits off\r\n\r\n{--\r\n/libs/prelude/Prelude/Algebra.idr\r\ninterface Semigroup ty where\r\n (<+>) : ty -> ty -> ty\r\ninterface Semigroup ty => Monoid ty where\r\n neutral : ty\r\n/libs/contrib/Control/Algebra.idr\r\ninterface Monoid a => Group a where\r\n inverse : a -> a\r\n/libs/contrib/Interfaces/Verified.idr\r\ninterface Semigroup a => VerifiedSemigroup a where\r\n semigroupOpIsAssociative : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r\r\ninterface (VerifiedSemigroup a, Monoid a) => VerifiedMonoid a where\r\n monoidNeutralIsNeutralL : (l : a) -> l <+> Algebra.neutral = l\r\n monoidNeutralIsNeutralR : (r : a) -> Algebra.neutral <+> r = r\r\ninterface (VerifiedMonoid a, Group a) => VerifiedGroup a where\r\n groupInverseIsInverseL : (l : a) -> l <+> inverse l = Algebra.neutral\r\n groupInverseIsInverseR : (r : a) -> inverse r <+> r = Algebra.neutrals\r\nVerifiedGroup ZZ using PlusZZMonoidV where\r\n groupInverseIsInverseL k = rewrite sym $ multCommutativeZ (NegS 0) k in\r\n rewrite multNegLeftZ 0 k in\r\n rewrite multOneLeftNeutralZ k in\r\n plusNegateInverseLZ k\r\n groupInverseIsInverseR k = rewrite sym $ multCommutativeZ (NegS 0) k in\r\n rewrite multNegLeftZ 0 k in\r\n rewrite multOneLeftNeutralZ k in\r\n plusNegateInverseRZ k\r\n--}\r\n\r\n-- 群の定義\r\ninfixl 6 <+>\r\ninterface Group a where\r\n (<+>) : a -> a -> a\r\n gUnit : a\r\n gInv : a -> a\r\n vAssoc : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r\r\n vUnit : (c : a) -> (c <+> gUnit = c, gUnit <+> c = c)\r\n vInv : (c : a) -> (c <+> gInv c = gUnit, gInv c <+> c = gUnit)\r\n\r\n-- 準同型\r\nrecord Hom (g : Type)(h : Type)(grp : Group g)(hrp : Group h)(f : g -> h) where\r\n constructor MkHom\r\n -- 左辺の<+>はgrpのもの、右辺の<+>はhrpのもの\r\n hom : (a, b : g) -> f (a <+> b) = f a <+> f b\r\n\r\n-- 単射\r\nrecord Mono (g : Type)(h : Type)(f : g -> h) where\r\n constructor MkMono\r\n mono : (a, b : g) -> f a = f b -> a = b\r\n\r\n-- 全射\r\nrecord Epi (g : Type)(h : Type)(f : g -> h) where\r\n constructor MkEpi\r\n epi : (z : h) -> (a ** f a = z)\r\n\r\n-- gはhの部分群である\r\nrecord Subgroup (g : Type)(h : Type)(grp : Group g)(hrp : Group h)(f : g -> h) where\r\n constructor MkSubgroup\r\n sHom : Hom g h grp hrp f\r\n sMono : Mono g h f\r\n\r\n-- gとhは同型である\r\nrecord Iso (g : Type)(h : Type)(grp : Group g)(hrp : Group h)(f : g -> h) where\r\n constructor MkIso\r\n iSubgroup : Subgroup g h grp hrp f\r\n iEpi : Epi g h f\r\n-- ----------------------------------\r\n\r\n\r\n-- 巡回群\r\nplusModN : (n : Nat) -> Fin n -> Fin n -> Fin n\r\nplusModN Z finZ _ = absurd finZ\r\nplusModN (S k) finX finY =\r\n let n = S k;\r\n x = toNat finX;\r\n y = toNat finY\r\n in fromNat $ modNatNZ (x + y) n SIsNotZ\r\n\r\ninvModN : (n : Nat) -> Fin n -> Fin n\r\ninvModN Z finZ = absurd finZ\r\ninvModN (S k) finX =\r\n let n = S k;\r\n x = toNat finX\r\n in fromNat $ modNatNZ (minus n x) n SIsNotZ\r\n\r\nimplementation [CyN] Group (Fin n) where\r\n (<+>) {n = n} = plusModN n\r\n gUnit {n = Z } = idris_crash \"no constructor!\"\r\n gUnit {n = (S n)} = FZ\r\n gInv {n = n} = invModN n\r\n vAssoc l c r = ?rhs1\r\n vUnit r = ?rhs2\r\n vInv r = ?rhs3\r\n-- ----------------------------------\r\n\r\ncyclicToCyclic : (n, k : Nat) -> Fin (S n) -> Fin (S (mult k (S n) + n))\r\ncyclicToCyclic n Z = id -- idにするところがミソ\r\ncyclicToCyclic n (S k) = \\_ =>\r\n let y = S (mult (S k) (S n) + n) in fromNat y\r\n\r\n-- ◆定理1.5 巡回群の部分群は巡回群である\r\n-- 部分群の位数(S n)が、元の群の位数(S k)*(S n)の約数である事を仮定した\r\n-- S (mult k (S n) + n) = (S k) * (S n)\r\ncyclicSubCyclic : (n : Nat)\r\n -> ((k : Nat) -> Subgroup (Fin (S n)) (Fin (S (mult k (S n) + n))) subGrp CyN (cyclicToCyclic n k))\r\n -> Iso (Fin (S n)) (Fin (S n)) subGrp CyN (cyclicToCyclic n Z)\r\ncyclicSubCyclic n fSubG = MkIso (fSubG Z) (MkEpi (\\z => (z ** Refl)))\r\n\r\n\r\n-- 既約剰余類群\r\n-- 元かどうかは、外からのBool値で判断する\r\ndata FinBool : (n : Nat) -> Type where\r\n Fb : Fin n -> Bool -> FinBool n\r\n\r\nmultModN : (n : Nat) -> Fin n -> Fin n -> Fin n\r\nmultModN Z finZ _ = absurd finZ\r\nmultModN (S k) finX finY =\r\n let n = S k;\r\n x = toNat finX;\r\n y = toNat finY\r\n in fromNat $ modNatNZ (x * y) n SIsNotZ\r\n\r\nmultModNFb : (n : Nat) -> FinBool n -> FinBool n -> FinBool n\r\nmultModNFb Z (Fb finZ _ ) _ = absurd finZ\r\nmultModNFb (S _) (Fb _ False) _ = Fb FZ False\r\nmultModNFb (S _) (Fb _ True ) (Fb _ False) = Fb FZ False\r\nmultModNFb (S k) (Fb finX True ) (Fb finY True ) = Fb (multModN (S k) finX finY) True\r\n\r\ninvModNFb : (n : Nat) -> FinBool n -> FinBool n\r\ninvModNFb Z (Fb finZ _ ) = absurd finZ\r\ninvModNFb (S _) (Fb _ False) = Fb FZ False\r\ninvModNFb (S k) (Fb finX True ) = Fb (invModN (S k) finX) True\r\n\r\nimplementation [Mgm] Group (FinBool n) where\r\n (<+>) {n = n} = multModNFb n\r\n gUnit {n = Z } = idris_crash \"no constructor!\"\r\n gUnit {n = (S n)} = Fb FZ True\r\n gInv {n = n} = invModNFb n\r\n vAssoc l c r = ?rhs4\r\n vUnit c = ?rhs5\r\n vInv c = ?rhs6\r\n-- ----------------------------------\r\n\r\n\r\n-- 群の直積\r\nimplementation [GPr] (Group a, Group b) => Group (a, b) where\r\n (x, y) <+> (z, u) = (x <+> z, y <+> u)\r\n gUnit = (gUnit, gUnit)\r\n gInv (x, y) = (gInv x, gInv y)\r\n vAssoc l c r = ?rhs7\r\n vUnit c = ?rhs8\r\n vInv c = ?rhs9\r\n-- ----------------------------------\r\n\r\n\r\n-- ◆定理1.9 (Z/(p^e)(q^f)Z)* ≡ (Z/(p^e)Z)* × (Z/(q^f)Z)*\r\nfFinBoolToGPr : (p, q, e, f : Nat)\r\n -> (FinBool ((power (S (S p)) (S (S e)))*(power (S (S (S q))) (S f))))\r\n -> (FinBool (power (S (S p)) (S (S e))), FinBool (power (S (S (S q))) (S f)))\r\ntheorem1_9 : (p, q, e, f : Nat)\r\n -> (Group (FinBool (power (S (S p)) (S (S e))))\r\n -> Group (FinBool (power (S (S (S q))) (S f)))\r\n -> Iso\r\n (FinBool ((power (S (S p)) (S (S e)))*(power (S (S (S q))) (S f))))\r\n (FinBool (power (S (S p)) (S (S e))), FinBool (power (S (S (S q))) (S f))) Mgm GPr (fFinBoolToGPr p q e f))\r\n\r\n-- ◆定理1.18 (Z/2^nZ)*は巡回群の直積に同型である\r\n-- (Z/2^nZ)* ≡ (Z/2^(n-2)Z) × (Z/2Z)\r\nfTheorem1_18 : (e : Nat)\r\n -> (FinBool (power 2 (S (S e)))) -> (Fin (power 2 e), Fin 2)\r\ntheorem1_18 : (e : Nat)\r\n -> (Group (Fin (power 2 e))\r\n -> Group (Fin 2)\r\n -> Iso\r\n (FinBool (power 2 (S (S e))))\r\n (Fin (power 2 e), Fin 2) Mgm GPr (fTheorem1_18 e))\r\n\r\n-- ◆定理1.19 (Z/奇素数p^nZ)*は巡回群の直積に同型である\r\n-- (Z/p^nZ)* ≡ (Z/p^(n-1)Z) × (Z/(p-1)Z)\r\nfTheorem1_19 : (q, f : Nat)\r\n -> (FinBool (power (S (S (S q))) (S n))) -> (Fin (power (S (S (S q))) n), Fin p)\r\ntheorem1_19 : (q, f : Nat)\r\n -> (Group (Fin (power (S (S (S q))) f))\r\n -> Group (Fin (S (S q)))\r\n -> Iso\r\n (FinBool (power (S (S (S q))) (S f)))\r\n (Fin (power (S (S (S q))) f), Fin (S (S q))) Mgm GPr (fTheorem1_19 q f))\r\n\r\n-- ◆定理1.20 既約剰余類群は巡回群の直積に同型である\r\nmgmProduct : (p, q, e, f : Nat)\r\n -> Either ((Group (FinBool (power (S (S p)) (S (S e))))\r\n -> Group (FinBool (power (S (S (S q))) (S f)))\r\n -> Iso\r\n (FinBool ((power (S (S p)) (S (S e)))*(power (S (S (S q))) (S f))))\r\n (FinBool (power (S (S p)) (S (S e))), FinBool (power (S (S (S q))) (S f))) Mgm GPr (fFinBoolToGPr p q e f)),\r\n (Group (Fin (power 2 e))\r\n -> Group (Fin 2)\r\n -> Iso\r\n (FinBool (power 2 (S (S e))))\r\n (Fin (power 2 e), Fin 2) Mgm GPr (fTheorem1_18 e)),\r\n (Group (Fin (power (S (S (S q))) f))\r\n -> Group (Fin (S (S q)))\r\n -> Iso\r\n (FinBool (power (S (S (S q))) (S f)))\r\n (Fin (power (S (S (S q))) f), Fin (S (S q))) Mgm GPr (fTheorem1_19 q f))\r\n )\r\n ((Group (FinBool (power (S (S p)) (S (S e))))\r\n -> Group (FinBool (power (S (S (S q))) (S f)))\r\n -> Iso\r\n (FinBool ((power (S (S p)) (S (S e)))*(power (S (S (S q))) (S f))))\r\n (FinBool (power (S (S p)) (S (S e))), FinBool (power (S (S (S q))) (S f))) Mgm GPr (fFinBoolToGPr p q e f)),\r\n (Group (Fin (power (S (S (S p))) e))\r\n -> Group (Fin (S (S p)))\r\n -> Iso\r\n (FinBool (power (S (S (S p))) (S e)))\r\n (Fin (power (S (S (S p))) e), Fin (S (S p))) Mgm GPr (fTheorem1_19 p e)),\r\n (Group (Fin (power (S (S (S q))) f))\r\n -> Group (Fin (S (S q)))\r\n -> Iso\r\n (FinBool (power (S (S (S q))) (S f)))\r\n (Fin (power (S (S (S q))) f), Fin (S (S q))) Mgm GPr (fTheorem1_19 q f))\r\n )\r\nmgmProduct Z q e f = Left ((theorem1_9 Z q e f), (theorem1_18 e), (theorem1_19 q f))\r\nmgmProduct (S p) q e f = Right ((theorem1_9 (S p) q e f), (theorem1_19 (S p) e), (theorem1_19 q f))\r\n\r\n\r\n\r\n", "meta": {"hexsha": "8c9c2db2963e390f064c5f0a8bb894a0a7125f8d", "size": 8703, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/GaloisCh1.idr", "max_stars_repo_name": "righ1113/IshiiSan_Galois_Idris", "max_stars_repo_head_hexsha": "31ca9df13f5438c8860ba0449b0df28f1f1d85fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-12T22:17:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T22:17:37.000Z", "max_issues_repo_path": "src/GaloisCh1.idr", "max_issues_repo_name": "righ1113/IshiiSan_Galois_Idris", "max_issues_repo_head_hexsha": "31ca9df13f5438c8860ba0449b0df28f1f1d85fe", "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/GaloisCh1.idr", "max_forks_repo_name": "righ1113/IshiiSan_Galois_Idris", "max_forks_repo_head_hexsha": "31ca9df13f5438c8860ba0449b0df28f1f1d85fe", "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.8771186441, "max_line_length": 121, "alphanum_fraction": 0.4933930828, "num_tokens": 3484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6691666555581253}} {"text": "module SnocList\n\n-- data SnocList ty = Nil | Snoc (SnocList ty) ty\n\npublic export\ndata SnocList : List a -> Type where\n Empty : SnocList []\n Snoc : (rec : SnocList xs) -> SnocList (xs ++ [x])\n\npublic export\nsnocList : (xs : List a) -> SnocList xs\nsnocList xs = snocListHelp Empty xs\n where\n snocListHelp : SnocList input -> (xs : List a) -> SnocList (input ++ xs)\n snocListHelp {input} snoc [] = rewrite appendNilRightNeutral input in snoc\n snocListHelp {input} snoc (x :: xs)\n = rewrite appendAssociative input [x] xs in\n (snocListHelp (Snoc snoc {x}) xs)\n\nmy_reverse_help' : (input : List a) -> SnocList input -> List a\nmy_reverse_help' [] Empty = []\nmy_reverse_help' (xs ++ [x]) (Snoc rec) = x :: my_reverse_help' xs rec\n\ntotal\nmy_reverse' : List a -> List a\nmy_reverse' xs = my_reverse_help' xs (snocList xs)\n\ntotal\nmy_reverse : List a -> List a\nmy_reverse input with (snocList input)\n my_reverse [] | Empty = []\n my_reverse (xs ++ [x]) | (Snoc rec) = x :: my_reverse xs | rec\n\n-- reverse_snoc : SnocList ty -> List ty\n-- reverse_snoc [] = []\n-- reverse_snoc (Snoc xs x) = x :: reverse_snoc xs\n", "meta": {"hexsha": "9c077fdfc22a363d4d774415ea6e5b9bf1cb3185", "size": 1132, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-10/SnocList.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/SnocList.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/SnocList.idr", "max_forks_repo_name": "tekerson/type-driven-development", "max_forks_repo_head_hexsha": "52f1cf8dddd90c3306e8ded109bc4a3eff03b1b1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5945945946, "max_line_length": 78, "alphanum_fraction": 0.6537102473, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6690458442739792}} {"text": "module BoundedGCD\nimport ZZ\nimport ZZUtils\nimport Divisors\n\n\n%default total\n%access public export\n\nnotLTEimpliesLT : (a: Nat) -> (b: Nat) -> (LTE a b -> Void) -> LTE (S b) a\nnotLTEimpliesLT Z b contra = void (contra (LTEZero))\nnotLTEimpliesLT (S k) Z f = LTESucc (LTEZero)\nnotLTEimpliesLT (S k) (S j) contra =\n LTESucc (notLTEimpliesLT k j previousContra) where\n previousContra = \\evidence : (LTE k j) => contra (LTESucc evidence)\n\nsubWithBound: (n: Nat) -> (m: Nat) -> (LTE m n) -> (k: Nat ** LTE k n)\nsubWithBound n Z LTEZero = (n ** lteRefl)\nsubWithBound (S p) (S q) (LTESucc pf) = case subWithBound p q pf of\n (x ** pf) =>\n (x ** lteSuccRight pf)\n\nboundedGCD : (bnd: Nat) -> (n: Nat) -> (m: Nat) -> (LTE n bnd) -> (LTE (S m) bnd) -> Nat\nboundedGCD (S b) Z m x (LTESucc y) = m\nboundedGCD (S b) (S k) Z x (LTESucc y) = (S k)\nboundedGCD (S b) (S Z) (S j) (LTESucc x) (LTESucc y) = S Z\nboundedGCD (S b) (S k) (S Z) (LTESucc x) (LTESucc y) = S Z\nboundedGCD (S b) (S (S (k))) (S (S (j))) (LTESucc x) (LTESucc y) =\n case isLTE j k of\n (Yes prf) => case subWithBound k j prf of\n (diff ** pf) => boundedGCD b (S (S j)) diff y (lteTransitive (LTESucc pf) x)\n (No contra) =>\n let\n ineq = notLTEimpliesLT j k contra\n in\n boundedGCD b (S (S j)) (S (S k)) y (lteTransitive (LTESucc (LTESucc ineq)) y)\n\ngcdAlgo : Nat -> Nat -> Nat\ngcdAlgo k j = case isLTE (S j) k of\n (Yes prf) => boundedGCD k k j lteRefl prf\n (No contra) =>\n let\n ineq = notLTEimpliesLT (S j) k contra\n in\n boundedGCD (S j) k j (lteSuccLeft ineq) lteRefl\n\n\n\n|||Given a proof that m<=n, returns n-m with proof that k = n-m<=n and\n|||(Pos k)=(Pos n)+(-(Pos m) as integers\nsubWithBoundZ: (n: Nat) -> (m: Nat) -> (LTE m n) -> (k: Nat ** ((LTE k n),((Pos k)=(Pos n)+(-(Pos m)))))\nsubWithBoundZ n Z LTEZero = (n ** (lteRefl,rewrite plusZeroRightNeutralZ (Pos n) in\n Refl))\nsubWithBoundZ (S p) (S q) (LTESucc pf) = case subWithBoundZ p q pf of\n (x ** (pf,subpf)) =>\n (x ** (lteSuccRight pf,\n (subSuccSuccNeutrtalZ subpf)))\n|||Rewrites n = a + (-m) as a = n+ (1*m)\nsimpleRewrite:{n:ZZ}->{a:ZZ}->{m:ZZ}->(n= a+(-m))->(a= n +(1*m))\nsimpleRewrite prf {a}{n}{m} = rewrite sym $ plusZeroLeftNeutralZ a in\n rewrite multOneLeftNeutralZ m in\n rewrite sym $ plusNegateInverseLZ m in\n rewrite plusCommutativeZ n m in\n rewrite sym $ plusAssociativeZ m (-m) a in\n rewrite plusCommutativeZ (-m) a in\n cong (sym prf)\n\n|||If n = a+ (-m), then gcd (m,n) = gcd (a,m)\nhelperboundedGCDZ:{n:ZZ}->{m:ZZ}->GCDZ m n d->\n (n= a+(-m))->GCDZ a m d\nhelperboundedGCDZ x prf = euclidConservesGcdWithProof {quot = (1)} (simpleRewrite prf) x\n\n||| Proves that Pos (k)+ (- (Pos (j)) = minusNatZ k j\nsimplerewrite2:{k:Nat}->{j:Nat}-> Pos (k)+ (- (Pos (j))) = minusNatZ k j\nsimplerewrite2 {k = k}{j = Z}= rewrite plusZeroRightNeutralZ (Pos k) in Refl\nsimplerewrite2 {k = k}{j = (S j)}= Refl\n\n||| Proves that NotBothZero Z m implies (Pos m) is positive\nnotBothZeroZeroNatPos:{m:Nat}->NotBothZero Z m -> (IsPositive (Pos m))\nnotBothZeroZeroNatPos {m = (S k)} RightIsNotZero = Positive\n\n|||A bounded GCD function that given a bound and natural numbers n and m such that\n|||n and m are not both zero, returns gcd((Pos n),(Pos m)) with proof\nboundedGCDZ : (bnd: Nat) -> (n: Nat) -> (m: Nat) -> (LTE n bnd) -> (LTE (S m) bnd)->\n (NotBothZero n m) -> (d:ZZ**GCDZ (Pos n) (Pos m) d)\nboundedGCDZ (S b) Z m x (LTESucc y) nbz = ((Pos m)**(gcdSymZ (gcdOfZeroAndInteger (Pos m) (notBothZeroZeroNatPos nbz)) ))\nboundedGCDZ (S b) (S k) Z x (LTESucc y) nbz = (Pos (S k)**gcdOfZeroAndInteger (Pos (S k)) Positive)\nboundedGCDZ (S b) (S Z) (S j) (LTESucc x) (LTESucc y) nbz = (1 **(gcdSymZ (gcdOfOneAndInteger (Pos (S j)))))\nboundedGCDZ (S b) (S k) (S Z) (LTESucc x) (LTESucc y) nbz = (1 **(gcdOfOneAndInteger (Pos (S k))))\nboundedGCDZ (S b) (S (S (k))) (S (S (j))) (LTESucc x) (LTESucc y) nbz =\n case isLTE j k of\n (Yes prf) => case subWithBoundZ k j prf of\n (diff ** (pf,subpf)) => (case boundedGCDZ b (S (S j)) diff y (lteTransitive (LTESucc pf) x) LeftIsNotZero of\n (d**gcdpf) => (d**(helperboundedGCDZ gcdpf (rewrite sym $simplerewrite2 {k=k}{j=j} in subpf))))\n (No contra) =>\n let\n ineq = notLTEimpliesLT j k contra\n in\n (case boundedGCDZ b (S (S j)) (S (S k)) y (lteTransitive (LTESucc (LTESucc ineq)) y) LeftIsNotZero of\n (d**gcdpf) => (d** (gcdSymZ gcdpf)))\n\n|||A helper for bezReplace which does the rewrite as indicated in its type.\nhelperbezReplace:{v:ZZ}->{u:ZZ}->{j:Nat}->{diff:Nat}->{d:ZZ}->{k:Nat}->\n d = ( u *(Pos (S (S j)))) + ( v*(Pos diff))->(Pos diff) = (Pos k )+(-(Pos j))->\n d=(u*(Pos (S (S j)))) + (v * ((Pos k) + (-(Pos j))))\nhelperbezReplace prf prf1 = rewrite sym $ prf1 in prf\n\n|||A helper function for boundedGCDbez which does the rewrite as indicated in its type.\nbezReplace:{v:ZZ}->{u:ZZ}->{j:Nat}->{diff:Nat}->{d:ZZ}->{k:Nat}->\n d = ( u *(Pos (S (S j)))) + ( v*(Pos diff))->(Pos diff) = (Pos k )+(-(Pos j))->\n d=v*(Pos (S(S k))) +(u+(-v))*(Pos (S (S j)))\nbezReplace {v}{u}{j}{diff}{k} prf prf1 = rewrite plusCommutativeZ (v*(Pos (S(S k)))) ((u+(-v))*(Pos (S (S j)))) in\n rewrite plusCommutativeZ u (-v) in\n rewrite multDistributesOverPlusLeftZ (-v) u (Pos (S (S j))) in\n rewrite multNegateLeftZ v (Pos (S (S j))) in\n rewrite sym $ multNegateRightZ v (Pos (S (S j))) in\n rewrite sym $ plusAssociativeZ (v*(NegS (S j))) (u*(Pos (S (S j)))) (v*(Pos (S (S k)))) in\n rewrite plusCommutativeZ (u*(Pos (S (S j)))) (v*(Pos (S (S k)))) in\n rewrite plusAssociativeZ (v*(NegS (S j))) (v*(Pos (S (S k)))) (u*(Pos (S (S j)))) in\n rewrite sym $multDistributesOverPlusRightZ v (NegS (S j)) (Pos (S (S k))) in\n rewrite plusCommutativeZ (v*(minusNatZ k j)) (u* (Pos (S (S j)))) in\n rewrite sym $ simplerewrite2 {k=k}{j=j}in\n helperbezReplace prf prf1\n\n|||A bounded GCD function that given a bound and natural numbers n and m such that\n|||n and m are not both zero, returns gcd((Pos n),(Pos m)) and bezout coefficients\n|||with proof that it is the gcd and proof that it is a linear combination of\n|||(Pos n) and (Pos m)\nboundedGCDbez : (bnd: Nat) -> (n: Nat) -> (m: Nat) -> (LTE n bnd) -> (LTE (S m) bnd)->\n (NotBothZero n m) -> (d**((GCDZ (Pos n) (Pos m) d),(u:ZZ**v:ZZ**(d=(u*(Pos n))+(v*(Pos m))))))\nboundedGCDbez (S b) Z m x (LTESucc y) nbz = ((Pos m)**((gcdSymZ (gcdOfZeroAndInteger (Pos m) (notBothZeroZeroNatPos nbz))),\n (0**1**(rewrite multOneLeftNeutralZ (Pos m) in Refl))))\nboundedGCDbez (S b) (S k) Z x (LTESucc y) nbz = ((Pos (S k))**((gcdOfZeroAndInteger (Pos (S k)) Positive),(1**0**( rewrite plusZeroRightNeutral k in\n rewrite plusZeroRightNeutral k in\n Refl))))\nboundedGCDbez (S b) (S Z) (S j) (LTESucc x) (LTESucc y) nbz = (1 **((gcdSymZ (gcdOfOneAndInteger (Pos (S j)))),(1**0**Refl)))\nboundedGCDbez (S b) (S k) (S Z) (LTESucc x) (LTESucc y) nbz = (1 **((gcdOfOneAndInteger (Pos (S k))),(0**1**Refl)))\nboundedGCDbez (S b) (S (S (k))) (S (S (j))) (LTESucc x) (LTESucc y) nbz =\n case isLTE j k of\n (Yes prf) => case subWithBoundZ k j prf of\n (diff ** (pf,subpf)) => (case boundedGCDbez b (S (S j)) diff y (lteTransitive (LTESucc pf) x) LeftIsNotZero of\n (d**(gcdpf,(u**v**eqpf))) => (d**((helperboundedGCDZ gcdpf (rewrite sym $simplerewrite2 {k=k}{j=j} in subpf)),\n (v**(u+(-v)**( bezReplace eqpf subpf))))))\n (No contra) =>\n let\n ineq = notLTEimpliesLT j k contra\n in\n (case boundedGCDbez b (S (S j)) (S (S k)) y (lteTransitive (LTESucc (LTESucc ineq)) y) LeftIsNotZero of\n (d**(gcdpf,(u**v**eqpf))) => (d** ((gcdSymZ gcdpf), (v**u**\n rewrite plusCommutativeZ (v*(Pos (S (S k)) )) (u*(Pos (S (S j)) )) in\n eqpf))))\n", "meta": {"hexsha": "b137b0c3f1fdf78bea6055904a585255b98951f5", "size": 9254, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/BoundedGCD.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/BoundedGCD.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/BoundedGCD.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": 60.8815789474, "max_line_length": 150, "alphanum_fraction": 0.5025934731, "num_tokens": 3043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.668914828235693}} {"text": "module GCDZZ\nimport Divisors\nimport ZZ\nimport NatUtils\nimport gcd\nimport ZZUtils\n%default total\n%access public export\n\n|||Converts the expression (a=r+(q*b)) to its integer equivalent\ntotal\nExpNatToZZ:{a:Nat}->{b:Nat}->(a=r+(q*b))->((Pos a)=Pos(r)+((Pos q)*(Pos b)))\nExpNatToZZ Refl = Refl\n\n\n|||Given a nonnegative integer a and positive integer b, it returns quotient and remainder\n|||with proof of (a = rem + (quot * b) and that 0<=rem(b:ZZ)->IsNonNegative a -> IsPositive b ->\n(quot : ZZ ** (rem : ZZ ** ((a = rem + (quot * b)), LTZ rem b,(IsNonNegative rem))))\nQuotRemZ (Pos j) (Pos (S k)) NonNegative Positive =\n case (euclidDivide j (S k) (SIsNotZ {x=(k)})) of\n (q ** (r ** (equality, rlessb))) =>\n ((Pos q)**((Pos r)**((ExpNatToZZ equality),(ltNatToZZ rlessb),NonNegative)))\n\n\n\n\n|||Returns gcd of a and b with proof when a is positive and b is nonnegative\nGCDCalc :(a:ZZ)->(b:ZZ)->(IsPositive a)->(IsNonNegative b)->(d**(GCDZ a b d))\nGCDCalc a (Pos Z) x NonNegative = (a**(gcdOfZeroAndInteger a x))\nGCDCalc (Pos (S j)) (Pos (S k)) Positive NonNegative = assert_total $\n case QuotRemZ (Pos (S j)) (Pos (S k)) NonNegative Positive of\n (quot ** (rem ** (equality, remLessb,remNonNeg))) =>\n (case GCDCalc (Pos (S k)) rem Positive remNonNeg of\n (x ** pf) => (x**(euclidConservesGcdWithProof equality pf)))\n\n|||Returns Bezout coefficients with proof for a Positive integer a and\n|||NonNegative integer b with proofs of GCD and equality\nbez:(a:ZZ)->(b:ZZ)->(IsPositive a)->(IsNonNegative b) ->\n (d**((GCDZ a b d),(m:ZZ**n:ZZ**(d=(m*a)+(n*b)))))\nbez a (Pos Z) x NonNegative = (a**((gcdOfZeroAndInteger a x),(1**0**prf))) where\n prf = rewrite (multOneLeftNeutralZ a) in\n (rewrite (plusZeroRightNeutralZ a) in Refl)\nbez (Pos (S j)) (Pos (S k)) Positive NonNegative = assert_total $\n case QuotRemZ (Pos (S j)) (Pos (S k)) NonNegative Positive of\n (quot ** (rem ** (equality, remLessb,remNonNeg))) =>\n (case bez (Pos (S k)) rem Positive remNonNeg of\n (g**((gcdprf),(m1**n1**lincombproof))) =>\n (g**((euclidConservesGcdWithProof equality gcdprf),\n ((n1)**(m1+(n1*(-quot)))**\n (bezoutReplace equality lincombproof)))))\n\n\n|||Returns gcd of two integers with proof given that not both of them are zero\ngcdZZ:(a:ZZ)->(b:ZZ)->(NotBothZeroZ a b)->(d**(GCDZ a b d))\ngcdZZ (Pos (S k)) (Pos j) LeftPositive =\n GCDCalc (Pos (S k)) (Pos j) Positive NonNegative\ngcdZZ (Pos (S k)) (NegS j) LeftPositive =\n case GCDCalc (Pos (S k)) (-(NegS j)) Positive NonNegative of\n (x ** pf) => (x**(negatingPreservesGcdRight pf))\ngcdZZ (NegS k) (Pos j) LeftNegative =\n case GCDCalc (-(NegS k)) (Pos j) Positive NonNegative of\n (x**pf) =>(x**(negatingPreservesGcdLeft pf))\ngcdZZ (NegS k) (NegS j) LeftNegative =\n case GCDCalc (-(NegS k)) (-(NegS j)) Positive NonNegative of\n (x ** pf) => (x**((negatingPreservesGcdLeft\n (negatingPreservesGcdRight pf))))\ngcdZZ a (Pos (S k)) RightPositive = assert_total $\n case gcdZZ (Pos (S k)) a LeftPositive of\n (x ** pf) => (x** (gcdSymZ pf))\ngcdZZ a (NegS k) RightNegative = assert_total $\n case gcdZZ (NegS k) a LeftNegative of\n (x ** pf) => (x** (gcdSymZ pf))\n\n\n|||Returns Bezout coefficients with proof for two integers a and b such that\n|||not both of them are zero with proofs of GCD and equality\nbezoutCoeffs:(a:ZZ)->(b:ZZ)->NotBothZeroZ a b->\n (d**((GCDZ a b d),(m:ZZ**n:ZZ**(d=(m*a)+(n*b)))))\nbezoutCoeffs (Pos (S k)) (Pos j) LeftPositive =\n bez (Pos (S k)) (Pos j) Positive NonNegative\nbezoutCoeffs (Pos (S k)) (NegS j) LeftPositive =\n case bez (Pos (S k)) (-(NegS j)) Positive NonNegative of\n (x **( pf,(m**n**lproof))) =>\n (x**((negatingPreservesGcdRight pf),(m**(-n)**\n (rewrite multNegNegNeutralZ n (Pos(S j)) in lproof))))\nbezoutCoeffs (NegS k) (Pos j) LeftNegative =\n case bez (-(NegS k)) (Pos j) Positive NonNegative of\n (x**(pf,(m**n**lproof))) =>(x**((negatingPreservesGcdLeft pf),((-m)**n**\n (rewrite multNegNegNeutralZ m (Pos (S k)) in lproof))))\nbezoutCoeffs (NegS k) (NegS j) LeftNegative =\n case bez (-(NegS k)) (-(NegS j)) Positive NonNegative of\n (x**(pf,(m**n**lproof))) => (x**((((negatingPreservesGcdLeft\n (negatingPreservesGcdRight pf)))),((-m)**(-n)**\n (rewrite multNegNegNeutralZ m (Pos (S k)) in\n rewrite multNegNegNeutralZ n (Pos(S j)) in\n lproof))))\nbezoutCoeffs a (Pos (S k)) RightPositive = assert_total $\n case bezoutCoeffs (Pos (S k)) a LeftPositive of\n (x**(pf,(m**n**lproof))) => (x** ((gcdSymZ pf),(n**m**\n (rewrite plusCommutativeZ (n*a) (m*(Pos (S k))) in lproof))))\nbezoutCoeffs a (NegS k) RightNegative = assert_total $\n case bezoutCoeffs (NegS k) a LeftNegative of\n (x**(pf,(m**n**lproof))) => (x** ((gcdSymZ pf),(n**m**\n (rewrite plusCommutativeZ (n*a) (m*(NegS k)) in lproof))))\n\n|||Proof that if d = ja + kb, then md = jma + kmb\nmultOnLeft:{a:ZZ}->(m:ZZ)->(d=(j*a)+(k*b))->((m*d)=j*(m*a)+k*(m*b))\nmultOnLeft {a}{b}{j}{k}{d} m prf =\n rewrite multAssociativeZ j m a in\n rewrite multAssociativeZ k m b in\n rewrite multCommutativeZ j m in\n rewrite multCommutativeZ k m in\n rewrite sym $ multAssociativeZ m j a in\n rewrite sym $ multAssociativeZ m k b in\n rewrite sym $ multDistributesOverPlusRightZ m (j*a) (k*b) in\n cong prf\n\n\n|||A helper function for gcdOfMultiple\ngenfunctionGcdOfMultiple:{a:ZZ}->{b:ZZ}->{d:ZZ}->{k:ZZ}->{j:ZZ}->(d=j*a+k*b)->\n (m:ZZ)->\n ({c:ZZ}->(IsCommonFactorZ (m*a) (m*b) c) -> (IsDivisibleZ (m*d) c))\ngenfunctionGcdOfMultiple{a}{b}{d}{k}{j} prf m commonpf =\n linCombDivLeftWithProof {a=(m*a)}{b=(m*b)}{d=(m*d)} (multOnLeft m prf) commonpf\n\n\n|||The theorem that if m>0 and a and b are not both zero, then gcd(ma,mb) = m *gcd (a,b)\ngcdOfMultiple:(m:ZZ)-> (IsPositive m)->(GCDZ a b d) ->NotBothZeroZ a b->\n (GCDZ (m*a) (m*b) (m*d) )\ngcdOfMultiple{a}{b}{d} m mPos (dPos, (dDiva,dDivb),fd) notzero=\n case bezoutCoeffs a b notzero of\n (g**(gisgcd,(j**k**linpf))) =>\n ((posMultPosIsPos mPos dPos),((multBothSidesOfDiv m dDiva),\n (multBothSidesOfDiv m dDivb)),\n (genfunctionGcdOfMultiple{d=d} (rewrite (gcdIsUnique gisgcd (dPos, (dDiva,dDivb),fd)) in linpf) m ))\n\n|||The proof that if c = (2*c)*n, then 1 = (2*n)\n|||A helper function for gcdZeroZeroContra\nhelping1: {c:ZZ}->{n:ZZ}->(IsPositive c)->(c = (2*c)*n) ->(1= (2*n))\nhelping1{n}{c} cPos prf =\n (multRightCancelZ 1 (2*n) c (posThenNotZero cPos) exp) where\n exp = rewrite multOneLeftNeutralZ c in\n rewrite sym $ multAssociativeZ 2 n c in\n rewrite multCommutativeZ n c in\n rewrite multAssociativeZ 2 c n in\n prf\n|||Proof that 2=1 is impossible\ntwoIsNotOne:Pos (S (S Z))= Pos (S Z)->Void\ntwoIsNotOne Refl impossible\n|||Proof that 2= -1 is impossible\ntwoIsNotMinusOne: (Pos (S (S Z))= (NegS Z))->Void\ntwoIsNotMinusOne Refl impossible\n\n|||Proof that 1 = (2*n) is impossible\noneIsTwoTimesIntContra:{n:ZZ}-> (1= (2*n))->Void\noneIsTwoTimesIntContra{n} prf =\n (case productOneThenNumbersOne 2 n (sym prf) of\n (Left (a,b )) => twoIsNotOne a\n (Right (a,b)) => twoIsNotMinusOne a)\n\n|||Proof that if c is positive, 2c|c is impossible\ntwiceDividesOnceContra:IsPositive c ->(IsDivisibleZ c (2*c) )->Void\ntwiceDividesOnceContra cPos (n ** pf) =oneIsTwoTimesIntContra( helping1 cPos pf)\n|||GCD of 0 and 0 does not exist\ngcdZeroZeroContra:{k:ZZ}->(GCDZ 0 0 k)->Void\ngcdZeroZeroContra {k} (kPos,(kDivZ1,kDivZ2),fk) =\n twiceDividesOnceContra kPos (fk {c=(2*k)} (zzDividesZero (2*k),zzDividesZero (2*k)))\n\n|||The actual definition of GCD as the 'greatest' common divisor\nGCDZr: (a:ZZ) -> (b:ZZ) -> (d:ZZ) -> Type\nGCDZr a b d = ((IsCommonFactorZ a b d),\n ({c:ZZ}->(IsCommonFactorZ a b c)->(LTEZ c d)))\n\n|||GCD of 0 and 0 does not exist even in this definition.\ngcdrZeroZeroContra:{k:ZZ}->(GCDZr 0 0 k)->Void\ngcdrZeroZeroContra{k} ((kDiv1, kDiv2),fk) =\n succNotLteNumZ k (fk((zzDividesZero (1+k)),(zzDividesZero (1+k))))\n\n|||A helper function function for GCDZImpliesGCDZr\nhelperGCDZImpliesGCDZr:({k:ZZ}->(IsCommonFactorZ a b k)->(IsDivisibleZ d k))->(IsPositive d)->\n {c:ZZ}->(IsCommonFactorZ a b c)->(LTEZ c d)\nhelperGCDZImpliesGCDZr {d=(Pos (S k))} f Positive {c = (NegS j)} y = NegLessPositive\nhelperGCDZImpliesGCDZr {d=(Pos (S k))} f Positive {c = (Pos Z)} y = PositiveLTE (LTEZero)\nhelperGCDZImpliesGCDZr {d=(Pos (S k))} f Positive {c = (Pos (S j))} y =\n posDivPosImpliesLte (f y) Positive Positive\n\n|||Proof that (GCDZ a b d) implies (GCDZr a b d)\nGCDZImpliesGCDZr:(GCDZ a b d)->(GCDZr a b d)\nGCDZImpliesGCDZr (dPos,cfab,fd) = (cfab,(helperGCDZImpliesGCDZr fd dPos))\n\n|||Rewrites GCDZr a b e as GCDZr c d e , given a prrof that a=c and b=d\ngcdReplace:{a:ZZ}->{b:ZZ}->(a=c)->(b=d)->GCDZr a b e -> GCDZr c d e\ngcdReplace prf prf1 x = rewrite (sym prf) in\n rewrite (sym prf1) in\n x\n|||Rewrites GCDZ a b e as GCDZ c d e , given a prrof that a=c and b=d\ngcdzReplace:{a:ZZ}->{b:ZZ}->(a=c)->(b=d)->GCDZ a b e -> GCDZ c d e\ngcdzReplace prf prf1 x = rewrite (sym prf) in\n rewrite (sym prf1) in\n x\n|||GCD is unique even in this definition\ngcdrIsUnique:(GCDZr a b c)->(GCDZr a b d)->(c=d)\ngcdrIsUnique (comfactc,fc) (comfactd,fd) =\n lteAndGteImpliesEqualZ (fc (comfactd)) (fd (comfactc))\n\n|||Proof that (GCDZr a b d) implies (GCDZ a b d)\nGCDZrImpliesGCDZ:{a:ZZ}->{b:ZZ}-> (GCDZr a b d)->(GCDZ a b d)\nGCDZrImpliesGCDZ {a}{b}{d} gcdr =\n (case checkNotBothZero a b of\n Left (aZ,bZ) => void (gcdrZeroZeroContra (gcdReplace aZ bZ gcdr))\n Right notZ =>\n (case bezoutCoeffs a b notZ of\n (g**(gisgcd,(j**k**linpf))) =>\n rewrite (gcdrIsUnique gcdr (GCDZImpliesGCDZr gisgcd)) in\n gisgcd))\n|||If d = gcd (a,b) then there exists m and n such that d =ma +nb\ngcdIsLinComb:(GCDZ a b d)->(m:ZZ**n:ZZ**(d=(m*a)+(n*b)))\ngcdIsLinComb {a}{b} gcd =\n (case checkNotBothZero a b of\n Left (aZ,bZ) => void (gcdZeroZeroContra (gcdzReplace aZ bZ gcd))\n (Right notZ) =>\n (case bezoutCoeffs a b notZ of\n (g**(gisgcd,(j**k**linpf))) =>\n (j**k**(rewrite (sym(gcdIsUnique gcd gisgcd)) in linpf))))\n\n|||Theorem that if c|ab and gcd (a,c) =1 , then c|b\ncaCoprimeThencDivb : (IsDivisibleZ (a*b) c)->(GCDZ a c 1)->\n (IsDivisibleZ b c)\ncaCoprimeThencDivb cDivab gcd1{a}{b}{c} =\n (case gcdIsLinComb gcd1 of\n (m**n**linpf) =>\n linCombDivLeftWithProof {a=(a*b)} {b=(c*b)} {d=b} {c=c} {m=m} {n=n}\n ( rewrite multAssociativeZ m a b in\n rewrite multAssociativeZ n c b in\n rewrite sym $ multDistributesOverPlusLeftZ (m*a) (n*c) b in\n rewrite multCommutativeZ ((m*a)+(n*c)) b in\n (rewriteLeftTimesOneAsLeft (cong linpf)))\n (cDivab,(multDiv (selfDivide c) b)))\n\n|||SmallestPosLinComb a b d is a proof that d is the smallest positive\n|||linear combination of a and b\nSmallestPosLinComb: (a:ZZ)->(b:ZZ)->(d:ZZ)->Type\nSmallestPosLinComb a b d = ((IsPositive d),(m**n**(d=(m*a)+(n*b))),\n ({c:ZZ}->{j:ZZ}->{k:ZZ}->(IsPositive c)-> (c=j*a+k*b)->(LTEZ d c)))\n|||The theorem that the smallest positive linear combination is unique\nsmallestPosLinCombIsUnique :(SmallestPosLinComb a b c)->\n (SmallestPosLinComb a b d)->(c=d)\nsmallestPosLinCombIsUnique (cPos,(m**n**prfc),fc) (dPos,(u**v**prfd),fd) =\n lteAndGteImpliesEqualZ (fd cPos prfc) (fc dPos prfd)\n\n|||Proof that j+0=j+(n*0) for any integer n\nhelping2:{j:ZZ}->(n:ZZ)->j+0=j+(n*0)\nhelping2 n = rewrite multZeroRightZeroZ n in Refl\n|||Proof that any linear combination of 0 and 0 is 0\nlinCombZeroZeroIsZero: (m:ZZ**n:ZZ**(k=(m*0)+(n*0)))->(k=0)\nlinCombZeroZeroIsZero (m**n**lprf) =\n rewrite sym $ multZeroRightZeroZ m in\n rewrite sym $ plusZeroRightNeutralZ (m*0) in\n rewrite helping2 {j=(m*0)} n in\n lprf\n\n|||The theorem that smallest positive linear combination of Zero andZero\n|||doesnt exist\nsmallestPosLinCombZeroZeroVoid:{k:ZZ}->(SmallestPosLinComb 0 0 k)->Void\nsmallestPosLinCombZeroZeroVoid (kPos,(m**n**prfk),fk) =\n zeroNotPos (rewrite sym $(linCombZeroZeroIsZero (m**n**prfk)) in kPos)\n\n|||The theorem that gcd(a,b) is less than or equal to any\n|||positive linear combination of a and b\ngcdIsSmallerThanLinComb: (GCDZ a b d)->\n ({c:ZZ}->{j:ZZ}->{k:ZZ}->(IsPositive c)-> (c=j*a+k*b)->(LTEZ d c))\ngcdIsSmallerThanLinComb (dPos,(dDiva,dDivb),fd) cPos prf =\n posDivPosImpliesLte (linCombDivLeftWithProof prf (dDiva,dDivb)) cPos dPos\n\n|||Theorem that gcd(a,b) is the smallest positive linear combination of\n|||a and b\ngcdIsSmallestPosLinComb: (GCDZ a b d)->(SmallestPosLinComb a b d)\ngcdIsSmallestPosLinComb (dPos,(dDiva,dDivb),fd) =\n (case gcdIsLinComb (dPos,(dDiva,dDivb),fd) of\n (m**n**prf) =>\n (dPos,(m**n**prf),\n (gcdIsSmallerThanLinComb (dPos,(dDiva,dDivb),fd))))\n\n|||Rewrites SmallestPosLinComb a b e to SmallestPosLinComb c d e\n|||when given a proof that a=c and b=d\nsmallestPosLinCombReplace:{a:ZZ}->{b:ZZ}->(a=c)->(b=d)->SmallestPosLinComb a b e ->\n SmallestPosLinComb c d e\nsmallestPosLinCombReplace prf prf1 x = rewrite (sym prf) in\n rewrite (sym prf1) in\n x\n|||Theorem that the smallest positive linear combination of a and b is\n|||the gcd of a and b\nsmallestPosLinCombIsGcd:(SmallestPosLinComb a b d)->(GCDZ a b d)\nsmallestPosLinCombIsGcd {a} {b} splc =\n (case checkNotBothZero a b of\n (Left (aZ,bZ)) => void (smallestPosLinCombZeroZeroVoid\n (smallestPosLinCombReplace aZ bZ splc))\n Right notZ =>\n (case bezoutCoeffs a b notZ of\n (g**(gisgcd,(j**k**linpf))) =>\n rewrite (smallestPosLinCombIsUnique splc (gcdIsSmallestPosLinComb gisgcd)) in\n gisgcd))\n", "meta": {"hexsha": "33de7ed44d5a6fd1cc3203ed30ddac8fc44a7af9", "size": 13960, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/GCDZZ.idr", "max_stars_repo_name": "rathivrunda/LTS2019", "max_stars_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Code/GCDZZ.idr", "max_issues_repo_name": "rathivrunda/LTS2019", "max_issues_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Code/GCDZZ.idr", "max_forks_repo_name": "rathivrunda/LTS2019", "max_forks_repo_head_hexsha": "5fbe033ee2274c12cfe7be8dbacbd630a72852cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7704918033, "max_line_length": 121, "alphanum_fraction": 0.631017192, "num_tokens": 5047, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6688036992024796}} {"text": "\nmodule DescribeList\n\ndata ListLast : List a -> Type where\n Empty : ListLast []\n NonEmpty : (xs : List a) -> (x : a) -> ListLast (xs ++ [x])\n\ntotal\nlistLast : (xs : List a) -> ListLast xs\nlistLast [] = Empty\nlistLast (x :: xs) = case listLast xs of\n Empty => NonEmpty [] x\n NonEmpty ys y => NonEmpty (x :: ys) y\n\ndescribeHelper : (input : List Int) -> (form : ListLast input) -> String\ndescribeHelper [] Empty = \"Empty it is.\"\ndescribeHelper (xs ++ [x]) (NonEmpty xs x) = \"Empty it is not, initial: \" ++ show xs\n\ndescribeListEnd : List Int -> String\ndescribeListEnd xs = describeHelper xs (listLast xs)\n\ndescribeListEWith : List Int -> String\ndescribeListEWith xs with (listLast xs)\n describeListEWith [] | Empty = \"Empty it is.\"\n describeListEWith (ys ++ [x]) | (NonEmpty ys x) = \"Empty it is not, initial: \" ++ show ys\n\n\nmyReverse : List a -> List a\nmyReverse xs with (listLast xs)\n myReverse [] | Empty = []\n myReverse (ys ++ [x]) | (NonEmpty ys x) = x :: myReverse ys\n\n", "meta": {"hexsha": "ec293142ab4b844022be3abc3babe9e277f1a7c4", "size": 1036, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter10/DescribeList.idr", "max_stars_repo_name": "robkorn/idris-type-driven-development-exercises", "max_stars_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-18T12:54:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T09:54:21.000Z", "max_issues_repo_path": "Chapter10/DescribeList.idr", "max_issues_repo_name": "robkorn/idris-type-driven-development-exercises", "max_issues_repo_head_hexsha": "d3dcf7e0e0707c991a20c020e671e6e0aa21cf84", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter10/DescribeList.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": 31.3939393939, "max_line_length": 92, "alphanum_fraction": 0.6138996139, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6686988749412418}} {"text": "> module NonNegDouble.LTEProperties\n\n> import NonNegDouble.NonNegDouble\n> import NonNegDouble.Constants\n> import NonNegDouble.Predicates\n> import NonNegDouble.BasicOperations\n> import NonNegDouble.Operations\n> import NonNegDouble.Properties\n> import Double.Predicates\n> import Double.Postulates\n> import Double.Properties\n> import Rel.TotalPreorder \n\n> %default total\n> %access public export\n\n\n* |LTE| is a total preorder:\n\n> ||| LTE is reflexive\n> reflexiveLTE : (x : NonNegDouble) -> x `LTE` x\n> reflexiveLTE x = reflexiveLTE (toDouble x)\n\n\n> ||| LTE is transitive\n> transitiveLTE : (x, y, z : NonNegDouble) -> x `LTE` y -> y `LTE` z -> x `LTE` z\n> transitiveLTE x y z xLTEy yLTEz = transitiveLTE (toDouble x) (toDouble y) (toDouble z) xLTEy yLTEz\n\n\n> ||| LTE is total\n> totalLTE : (x, y : NonNegDouble) -> Either (x `LTE` y) (y `LTE` x) \n> totalLTE x y = totalLTE (toDouble x) (toDouble y)\n\n\n> ||| LTE is a total preorder\n> totalPreorderLTE : TotalPreorder NonNegDouble.Predicates.LTE\n> totalPreorderLTE = MkTotalPreorder LTE reflexiveLTE transitiveLTE totalLTE\n\n\n* Properties of |LTE| and |plus|:\n\n> using implementation NumNonNegDouble\n> ||| LTE is monotone w.r.t. `(+)`\n> monotonePlusLTE : {a, b, c, d : NonNegDouble} -> \n> a `LTE` b -> c `LTE` d -> (a + c) `LTE` (b + d)\n> monotonePlusLTE {a} {b} {c} {d} aLTEb cLTEd = s3 where\n> s1 : (toDouble a) + (toDouble c) `LTE` (toDouble b) + (toDouble d)\n> s1 = monotonePlusLTE {a = toDouble a} {b = toDouble b} {c = toDouble c} {d = toDouble d} aLTEb cLTEd\n> s2 : toDouble (a + c) `LTE` (toDouble b) + (toDouble d)\n> s2 = replace {P = \\ X => X `LTE` (toDouble b) + (toDouble d)} (sym (toDoublePlusLemma a c)) s1\n> s3 : toDouble (a + c) `LTE` toDouble (b + d)\n> s3 = replace {P = \\ X => toDouble (a + c) `LTE` X} (sym (toDoublePlusLemma b d)) s2\n\n\n* Properties of |LTE| and |mult|:\n\n> using implementation NumNonNegDouble\n> ||| LTE is monotone w.r.t. `(*)`\n> monotoneMultLTE : {a, b, c, d : NonNegDouble} -> \n> a `LTE` b -> c `LTE` d -> (a * c) `LTE` (b * d)\n> monotoneMultLTE {a} {b} {c} {d} aLTEb cLTEd = s3 where\n> s1 : (toDouble a) * (toDouble c) `LTE` (toDouble b) * (toDouble d)\n> s1 = monotoneMultLTE {a = toDouble a} {b = toDouble b} {c = toDouble c} {d = toDouble d} aLTEb cLTEd\n> s2 : toDouble (a * c) `LTE` (toDouble b) * (toDouble d)\n> s2 = replace {P = \\ X => X `LTE` (toDouble b) * (toDouble d)} (sym (toDoubleMultLemma a c)) s1\n> s3 : toDouble (a * c) `LTE` toDouble (b * d)\n> s3 = replace {P = \\ X => toDouble (a * c) `LTE` X} (sym (toDoubleMultLemma b d)) s2\n\n\n* Properties of |LTE| and |sum|:\n\n> using implementation NumNonNegDouble\n> ||| |sum| is monotone\n> monotoneSum : {A : Type} ->\n> (f : A -> NonNegDouble) -> (g : A -> NonNegDouble) ->\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\n> ---}\n \n", "meta": {"hexsha": "a8e87d90c7b2a2d6aa6711d6ea3ed14850f57d5e", "size": 3180, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NonNegDouble/LTEProperties.lidr", "max_stars_repo_name": "zenntenn/IdrisLibs", "max_stars_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NonNegDouble/LTEProperties.lidr", "max_issues_repo_name": "zenntenn/IdrisLibs", "max_issues_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NonNegDouble/LTEProperties.lidr", "max_forks_repo_name": "zenntenn/IdrisLibs", "max_forks_repo_head_hexsha": "a81c3674273a4658cd205e9bd1b6f95163cefc3e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.5517241379, "max_line_length": 112, "alphanum_fraction": 0.5946540881, "num_tokens": 1123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6685952189613714}} {"text": "module Control.Algebra.ZZGCDOfVectAlg\n\nimport Control.Algebra\nimport Classes.Verified\nimport Control.Algebra.VectorSpace\n\nimport Data.ZZ\nimport Control.Algebra.NumericInstances\nimport Control.Algebra.ZZVerifiedInstances\n\nimport Data.Matrix\nimport Data.Matrix.Algebraic\nimport Data.Matrix.AlgebraicVerified\nimport Data.Matrix.LinearCombinations -- for (vectVectLScalingCompatibility)\n\nimport Data.Vect.Structural\n\nimport Control.Algebra.ZZDivisors\n\nimport Data.Fin.FinOrdering\nimport Data.Fin.Structural\n\n{-\n(bezQTy) is the only thing actually used from here,\nsomething req.d to potentially generalize to other Bezout domains.\n-}\nimport Control.Algebra.ZZBezoutsIdentity\n\n-- Dependent pattern matching using (do) notation binds improves clarity\nimport Control.Monad.Identity\nimport Syntax.PreorderReasoning\n\nimport Control.Algebra.DiamondInstances\n\n%default total\n\n\n\n{-\nTable of contents:\n* Lemmas about extending a GCD to more than 2 numbers\n* The extension of a GCD of 2 numbers to that of a Vect of numbers\n-}\n\n\n\n{-\nLemmas about extending a GCD to more than 2 numbers\n-}\n\n\n\nvectGCDFnExtension : ( t : Fin n -> ZZ )\n\t-> ( r, r' : ZZ )\n\t-> Fin (S n) -> ZZ\nvectGCDFnExtension _ _ r' FZ = r'\nvectGCDFnExtension t r _ (FS prel) = t prel <.> r\n\nvectGCDExtension' : ( t : Fin n -> ZZ )\n\t-> ( factorizationAtInd : ( j : Fin n )\n\t\t-> t j <.> ( vs <:> xs ) = index j xs )\n\t-> ( factorizationX : r' <.> s = x )\n\t-> ( factorizationWithin : r <.> s = vs <:> xs )\n\t-> ( i : Fin (S n) )\n\t-> vectGCDFnExtension t r r' i <.> s = index i (x :: xs)\nvectGCDExtension' t factorizationAtInd factorizationX factorizationWithin FZ\n\t= factorizationX\nvectGCDExtension' t factorizationAtInd factorizationX factorizationWithin (FS prel)\n\t= trans (sym $ ringOpIsAssociative _ _ _)\n\t$ trans (cong factorizationWithin)\n\t$ factorizationAtInd prel\n\nvectGCDExtension : ( factorizationAtInd : ( j : Fin n )\n\t\t-> index j xs `quotientOverZZ` ( vs <:> xs ) )\n\t-> ( factorizationX : x `quotientOverZZ` s )\n\t-> ( factorizationWithin : (vs <:> xs) `quotientOverZZ` s )\n\t-> ( i : Fin (S n) )\n\t-> index i (x :: xs) `quotientOverZZ` s\nvectGCDExtension factorizationAtInd (factnXDiv ** factnXPr) (factnWinDiv ** factnWinPr) i\n\t= let vectGCDOldFn = \\j => getWitness $ factorizationAtInd j\n\tin let vectGCDOldPr = \\j => getProof $ factorizationAtInd j\n\tin ( vectGCDFnExtension vectGCDOldFn factnWinDiv factnXDiv i\n\t\t** vectGCDExtension' vectGCDOldFn vectGCDOldPr factnXPr factnWinPr i )\n\nbezoutDotRewrite : {a : ZZ}\n\t-> (a :: (b <#> vs)) <:> (x :: xs) = a<.>x <+> b<.>(vs <:> xs)\nbezoutDotRewrite {a} {b} {x} {xs} {vs} = (\n\t(a :: (b <#> vs)) <:> (x :: xs)\n\t) ={ monoidrec1D }= (\n\ta<.>x <+> ( (b <#> vs)<:>xs )\n\t) ={ cong vectVectLScalingCompatibility }= (\n\ta<.>x <+> b<.>(vs <:> xs)\n\t) QED\n\n\n\n{-\nThe extension of a GCD of 2 numbers to that of a Vect of numbers\n-}\n\n\n\n{- (gcdToVectGCD) parameters -}\nparameters (\n\tgcdAlg : (c, d : ZZ)\n\t\t-> ( zpar : (ZZ, ZZ) ** uncurry (bezQTy c d) zpar )\n\t) {\n\ngcdToVectGCD :\n\t(k : Nat)\n\t-> (x : Vect k ZZ)\n\t-> ( v : Vect k ZZ **\n\t\t( i : Fin k )\n\t\t-> (index i x) `quotientOverZZ` (v <:> x) )\ngcdToVectGCD Z [] = ( [] ** \\i => FinZElim i )\ngcdToVectGCD (S predk) (x::xs) with (gcdToVectGCD predk xs)\n\t| (vs ** recQFn) = runIdentity $ do {\n\t\t\t( (a, b) ** (gcdivA, gcdivB) )\n\t\t\t\t<- Id $ gcdAlg x (vs <:> xs)\n\t\t\tlet vectGCDExtensionFn = vectGCDExtension\n\t\t\t\t{s=a<.>x <+> b<.>(vs <:> xs)}\n\t\t\t\t{xs=xs}\n\t\t\t\t{vs=vs}\n\t\t\t\t{x=x}\n\t\t\t\trecQFn gcdivA gcdivB\n\t\t\treturn $ ( a::(b<#>vs) **\n\t\t\t\t\\i => let apAtI = vectGCDExtensionFn i\n\t\t\t\tin (getWitness apAtI\n\t\t\t\t\t** trans (cong bezoutDotRewrite) $ getProof apAtI)\n\t\t\t\t)\n\t\t}\n\n} {- (gcdToVectGCD) parameters -}\n", "meta": {"hexsha": "390797ff345c99d02109bf340d4dd124a0ff219c", "size": 3628, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Control/Algebra/ZZGCDOfVectAlg.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": "Control/Algebra/ZZGCDOfVectAlg.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": "Control/Algebra/ZZGCDOfVectAlg.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": 27.0746268657, "max_line_length": 89, "alphanum_fraction": 0.6595920617, "num_tokens": 1264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6685764675436642}} {"text": "%default total\n\nidentity_fn_applied_twice : (f : Bool -> Bool) -> ((x : Bool) -> f x = x) -> (b : Bool) -> f (f b) = b\nidentity_fn_applied_twice f g b = rewrite g b in g b\n\nnegation_fn_applied_twice : (f : Bool -> Bool) -> ((x : Bool) -> f x = not x) -> (b : Bool) -> f (f b) = b\nnegation_fn_applied_twice f g False = rewrite g (f False) in rewrite g False in Refl\nnegation_fn_applied_twice f g True = rewrite g (f True) in rewrite g True in Refl\n\nandb_eq_orb : (b, c : Bool) -> (b && c = b || c) -> b = c\nandb_eq_orb False False prf = Refl\nandb_eq_orb False True Refl impossible\nandb_eq_orb True False Refl impossible\nandb_eq_orb True True prf = Refl\n\ndata Bin : Type where\n Z : Bin\n Odd : Bin -> Bin\n Even : Bin -> Bin\n\nincr : Bin -> Bin\nincr Z = Odd Z\nincr (Odd x) = Even x\nincr b@(Even x) = Odd b\n\nbinToNat : Bin -> Nat\nbinToNat Z = Z\nbinToNat (Odd x) = S (binToNat x)\nbinToNat (Even x) = S (S (binToNat x))\n\nbin_to_nat_pres_incr : (b : Bin) -> binToNat $ incr b = S (binToNat b)\nbin_to_nat_pres_incr Z = Refl\nbin_to_nat_pres_incr (Odd x) = Refl\nbin_to_nat_pres_incr (Even x) = Refl\n\nnatToBin : (n : Nat) -> Bin\nnatToBin Z = Z\nnatToBin (S k) = incr $ natToBin k\n\nbin_to_nat_reverse_eq : (n : Nat) -> binToNat $ natToBin n = n\nbin_to_nat_reverse_eq Z = Refl\nbin_to_nat_reverse_eq (S k) =\n rewrite bin_to_nat_pres_incr (natToBin k) in\n rewrite bin_to_nat_reverse_eq k in\n Refl\n\nnat_to_bin_reverse_eq : (b : Bin) -> natToBin $ binToNat b = b\nnat_to_bin_reverse_eq Z = Refl\nnat_to_bin_reverse_eq k = rewrite nat_to_bin_reverse_eq k in Refl\n", "meta": {"hexsha": "6da0ed8f65608eabc7ececfca6dd8dacca36ede1", "size": 1570, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/SF11.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/SF11.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/SF11.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": 31.4, "max_line_length": 106, "alphanum_fraction": 0.6732484076, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.6684280332084239}} {"text": "doit3times : (f : x -> x) -> (n : x) -> x\ndoit3times f = f . f . f\n\ntest_doit3times1 : doit3times (\\n => n + 2) 3 = 9\ntest_doit3times1 = Refl\n\ntest_doit3times2 : doit3times (\\b => not b) True = False\ntest_doit3times2 = Refl\n\nfltr : (test : a -> Bool) -> (l : List a) -> List a\nfltr test [] = []\nfltr test (x :: xs) =\n if test x\n then x :: fltr test xs\n else fltr test xs\n\nevenb : (n : Nat) -> Bool\nevenb Z = True\nevenb (S (S k)) = evenb k\nevenb k = False\n\ntest_filter1 : fltr Main.evenb [1, 2, 3, 4] = [2, 4]\ntest_filter1 = Refl\n\ntest_filter2 : fltr (\\l => length l == 1) [[1, 2], [3], [4], [5, 6, 7], [], [8]] = [[3], [4], [8]]\ntest_filter2 = Refl\n\noddb : (n : Nat) -> Bool\noddb Z = False\noddb (S Z) = True\noddb (S (S k)) = oddb k\n\ncount_oddmembers : (l : List Nat) -> Nat\ncount_oddmembers l = length $ fltr oddb l\n\ntest_count_oddmembers1 : count_oddmembers [1, 0, 3, 1, 4, 5] = 4\ntest_count_oddmembers1 = Refl\n\ntest_count_oddmembers2 : count_oddmembers [0, 2, 4] = 0\ntest_count_oddmembers2 = Refl\n\ntest_count_oddmembers3 : count_oddmembers [] = 0\ntest_count_oddmembers3 = Refl\n\ntest_anon_fn : doit3times (\\n => mult n n) 2 = 256\ntest_anon_fn = Refl\n\nfilter_even_gt7 : (l : List Nat) -> List Nat\nfilter_even_gt7 = filter evenb . filter (\\n => n > 7)\n\ntest_filter_even_gt7_1 : filter_even_gt7 [1, 2, 6, 9, 10, 3, 12, 8] = [10, 12, 8]\ntest_filter_even_gt7_1 = Refl\n\ntest_filter_even_gt7_2 : filter_even_gt7 [5, 2, 6, 19, 129] = []\ntest_filter_even_gt7_2 = Refl\n\npartn : (test : a -> Bool) -> (l : List a) -> (List a, List a)\npartn test [] = ([], [])\npartn test (x :: xs) =\n let\n (ts, fs) = partn test xs\n in\n if test x\n then (x :: ts, fs)\n else (ts, x :: fs)\n\ntest_partition1 : partn Main.oddb [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4])\ntest_partition1 = Refl\n\ntest_partition2 : partn (\\x => False) [5, 9, 0] = ([], [5, 9, 0])\ntest_partition2 = Refl\n\ntest_map1 : map (\\x => 3 + x) [2, 0, 2] = [5, 3, 5]\ntest_map1 = Refl\n\ntest_map2 : map Main.oddb [2, 1, 2, 5] = [False, True, False, True]\ntest_map2 = Refl\n\ntest_map3 : map (\\n => [evenb n, oddb n]) [2, 1, 2, 5] = [[True, False], [False, True], [True, False], [False, True]]\ntest_map3 = Refl\n", "meta": {"hexsha": "a6e68477dd2777f832969490f440becf4c926cfe", "size": 2195, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/SF52.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/SF52.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/SF52.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.0987654321, "max_line_length": 117, "alphanum_fraction": 0.5954441913, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6683306822294253}} {"text": "module Ch03.Relations\n\n%default total\n%access public export\n\n||| Type representing the reflexive transitive closure of a relation\n|||\n||| Given a relational type `rel : ty -> ty -> Type`, `ReflSymmClos rel` is its reflexive and\n||| transitive closure.\ndata ReflSymmClos : (rel : ty -> ty -> Type) -> ty -> ty -> Type where\n Refl : ReflSymmClos rel x x\n --Snoc : ReflSymmClos rel t t' -> (rel t' t'') -> ReflSymmClos rel t t''\n Cons : (rel t t') -> ReflSymmClos rel t' t'' -> ReflSymmClos rel t t''\n\n||| Appends two (appendable) elements of the reflexive-transitive closure of `rel` together,\n||| thus realizing the transitivity of said closure\n(++) : ReflSymmClos rel t t' ->\n ReflSymmClos rel t' t'' ->\n ReflSymmClos rel t t''\n(++) Refl y = y\n(++) (Cons x z) y = Cons x (z ++ y)\n\n||| Given `rel t1 t2`, returns the associated relation in the reflexive transitive closure,\n||| thus realizing the \"closure part\" of said closure\nweaken : rel t1 t2 -> ReflSymmClos rel t1 t2\nweaken x = Cons x Refl\n\n||| Dual version of the `Cons` constructor for convenience.\nsnoc : ReflSymmClos rel t t' -> (rel t' t'') -> ReflSymmClos rel t t''\nsnoc p p' = p ++ (weaken p')\n\n||| Given a function `f` defined on relations of type `rel`, applies that to a relation in the\n||| reflexive-transitive closure of `rel`\nmap : {func : ty -> ty} -> (f : {t1 : ty} -> {t2 : ty} -> rel t1 t2 -> rel (func t1) (func t2)) ->\n (ReflSymmClos rel t1 t2) ->\n (ReflSymmClos rel (func t1) (func t2))\nmap {func} f Refl = Refl\nmap {func} f (Cons x y) = Cons (f x) (map f y)\n", "meta": {"hexsha": "12aaa1ac1362a531d57ca3732ba6c690bffb9177", "size": 1559, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Ch03/Relations.idr", "max_stars_repo_name": "mr-infty/tapl", "max_stars_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-02-27T13:52:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:38:28.000Z", "max_issues_repo_path": "Ch03/Relations.idr", "max_issues_repo_name": "mr-infty/tapl", "max_issues_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch03/Relations.idr", "max_forks_repo_name": "mr-infty/tapl", "max_forks_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T04:56:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T07:08:45.000Z", "avg_line_length": 39.9743589744, "max_line_length": 98, "alphanum_fraction": 0.6452854394, "num_tokens": 537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.668208996668679}} {"text": "> module Double.Predicates\n\n> import Data.So\n\n> %default total\n> %access public export\n> %auto_implicits on\n\n* EQ\n\n> |||\n> data EQ : Double -> Double -> Type where\n> MkEQ : {x : Double} -> {y : Double} -> So (x == y) -> EQ x y\n\n\n* LT\n\n> |||\n> data LT : Double -> Double -> Type where\n> MkLT : {x : Double} -> {y : Double} -> So (x < y) -> LT x y\n\n\n* LTE\n\n> |||\n> data LTE : Double -> Double -> Type where\n> MkLTE : {x : Double} -> {y : Double} -> So (x <= y) -> LTE x y\n\n\n* Non-negative, positive\n\n> -- |||\n> -- data NonNegative : Double -> Type where\n> -- MkNonNegative : {x : Double} -> So (0.0 <= x) -> NonNegative x\n\n> -- |||\n> -- data Positive : Double -> Type where\n> -- MkPositive : {x : Double} -> So (0.0 < x) -> Positive x\n\n> |||\n> NonNegative : (x : Double) -> Type\n> NonNegative x = 0.0 `LTE` x\n\n> |||\n> Positive : (x : Double) -> Type\n> Positive x = 0.0 `LT` x\n\n\n\n", "meta": {"hexsha": "5d40cba40cc48b6e0609d73c471c3c4b24829016", "size": 887, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Double/Predicates.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/Predicates.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/Predicates.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.74, "max_line_length": 69, "alphanum_fraction": 0.5253664036, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6678577879937614}} {"text": "module Python.Telescope\n\nimport public Data.Erased\n\n%default total\n%access public export\n\ndata Binder : (argTy : Type) -> (depTy : Type) -> (argTy -> depTy) -> Type where\n ||| Relevant, mandatory, positional argument.\n Pi : (a : Type) -> Binder a a Basics.id\n\n ||| Erased, mandatory, positional argument.\n Forall : (a : Type) -> Binder (Erased a) (Erased a) Basics.id\n\n ||| An argument with a default value.\n Default : (a : Type) -> (d : a) -> Binder (Maybe a) a (fromMaybe d)\n\n||| Type of sequences where the value of any element may affect\n||| the type of the following elements.\n|||\n||| In other words, a dependent pair generalised to multiple elements.\ndata Telescope : Type -> Type where\n\n ||| Empty telescope.\n Return : Type -> Telescope Unit\n\n ||| Value on which subsequent types may depend.\n Bind :\n (bnd : Binder argTy depTy fromArg)\n -> {b : depTy -> Type}\n -> (tf : (x : depTy) -> Telescope (b x))\n -> Telescope (DPair argTy (b . fromArg))\n\nterm syntax \"pi\" {x} \":\" [t] \".\" [rhs]\n = Bind (Pi t) (\\x : t => rhs);\n\nterm syntax \"forall\" {x} \":\" [t] \".\" [rhs]\n = Bind (Forall t) (\\ex : Erased t => let x = unerase ex in rhs);\n\nterm syntax \"default\" {x} \":\" [t] \"=\" [dflt] \".\" [rhs]\n = Bind (Default t dflt) (\\x : t => rhs);\n\nnamespace DPairSugar\n Nil : Type\n Nil = Unit\n\n (::) : Type -> Type -> Type\n (::) a b = DPair a (const b)\n\nnamespace TupleSugar\n ||| Alternative name for `MkUnit`, useful for the [list, syntax, sugar].\n Nil : Unit\n Nil = ()\n\n ||| Infix name for `MkDPair`, useful for the [list, syntax, sugar].\n (::) : (x : a) -> (y : b x) -> DPair a b\n (::) = MkDPair\n\n||| Convert a list of types to the corresponding tuple type.\ntoTuple : (xs : List Type) -> Type\ntoTuple [] = Unit\ntoTuple (x :: xs) = DPair x (const $ toTuple xs)\n\n||| Convert a list of types to the corresponding simple telescope.\nsimple : (xs : List Type) -> (ret : Type) -> Telescope (toTuple xs)\nsimple [] ret = Return ret\nsimple (a :: as) ret = Bind (Pi a) (\\x => simple as ret)\n\nretTy : (t : Telescope a) -> (args : a) -> Type\nretTy (Return x) () = x\nretTy (Bind {fromArg = fromArg} bnd tf) (MkDPair x xs) = retTy (tf $ fromArg x) xs\n", "meta": {"hexsha": "6b0de89ce7c3b44dc6d264ca32c0431cacb9497b", "size": 2165, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "lib/Python/Telescope.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": "lib/Python/Telescope.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": "lib/Python/Telescope.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": 30.0694444444, "max_line_length": 82, "alphanum_fraction": 0.6069284065, "num_tokens": 681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6675785723833625}} {"text": "module Lambdapants.Term.Nats\n\nimport Lambdapants.Term\n\n%default total\n\n||| Return the Church encoded term corresponding to the provided number.\nexport\nencoded : Nat -> Term\nencoded n = Lam \"f\" (Lam \"x\" nat) where\n nat : Term\n nat = foldr apply (Var \"x\") (replicate n (Term.App (Var \"f\")))\n\napps : String -> String -> Term -> Maybe Nat\napps f x = count 1 where\n count : Nat -> Term -> Maybe Nat\n count n (App (Var g) (Var v)) = if g == f && v == x then Just n else Nothing\n count n (App (Var g) e) = if g == f then count (succ n) e else Nothing\n count _ _ = Nothing\n\n||| Return the natural number interpretation of the term, if it corresponds to\n||| a valid Church encoding.\nexport\ndecoded : Term -> Maybe Nat\ndecoded (Lam f (Lam x term)) =\n case term of\n Var v => if v == x then Just 0 else Nothing\n App _ _ => apps f x term\n Lam _ _ => Nothing\ndecoded _ = Nothing\n", "meta": {"hexsha": "223c086313a065d459779ef3352b0579a893a628", "size": 918, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Lambdapants/Term/Nats.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/Nats.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/Nats.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": 29.6129032258, "max_line_length": 78, "alphanum_fraction": 0.628540305, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.667578566529383}} {"text": "module ArithExample\n\nimport Fix\nimport ALaCarte\n\n%access public export\n\n-- DSL for arithmetic expressions\n\ndata Val k = V Int\ndata Add k = A k k\ndata Mul k = M k k\n\nExpr : Type\nExpr = Fix (Sig [Val, Add, Mul])\n\nFunctor Val where\n map func (V x) = V x\n\nFunctor Add where\n map func (A x y) = A (func x) (func y)\n\nFunctor Mul where\n map func (M x y) = M (func x) (func y)\n\n-- Smart constructors\n\nval : {auto prf : Elem Val fs} -> Int -> Fix (Sig fs)\nval x = inject (V x)\n\n(+) : {auto prf : Elem Add fs} -> Fix (Sig fs) -> Fix (Sig fs) -> Fix (Sig fs)\nx + y = inject (A x y)\n\n(*) : {auto prf : Elem Mul fs} -> Fix (Sig fs) -> Fix (Sig fs) -> Fix (Sig fs)\nx * y = inject (M x y)\n\n-- Evaluation\n\nAlg Val Int where\n alg (V x) = x\n\nAlg Add Int where\n alg (A x y) = x + y\n\nAlg Mul Int where\n alg (M x y) = x * y\n\ncalc : Expr -> Int\ncalc = eval\n\n-- Pretty Printing\n\nAlg Val String where\n alg (V x) = show x\n\nAlg Add String where\n alg (A x y) = \"(\" ++ x ++ \" + \" ++ y ++ \")\"\n\nAlg Mul String where\n alg (M x y) = \"(\" ++ x ++ \" * \" ++ y ++ \")\"\n\npretty : Expr -> String\npretty = eval\n\n-- Examples\n\nex1 : Expr\nex1 = (val 1 + val 2) * val 3\n\nrunEx : Expr -> IO ()\nrunEx e = do\n putStrLn (pretty e)\n putStrLn (show (calc e))\n", "meta": {"hexsha": "5e1085cf5f1e07adaf29cb60bd9f1867b86bced4", "size": 1241, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ArithExample.idr", "max_stars_repo_name": "BakerSmithA/alacarte-idris", "max_stars_repo_head_hexsha": "885a1a9ca3bdc1ff3ef64339cbbd740fdcec15ca", "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/ArithExample.idr", "max_issues_repo_name": "BakerSmithA/alacarte-idris", "max_issues_repo_head_hexsha": "885a1a9ca3bdc1ff3ef64339cbbd740fdcec15ca", "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/ArithExample.idr", "max_forks_repo_name": "BakerSmithA/alacarte-idris", "max_forks_repo_head_hexsha": "885a1a9ca3bdc1ff3ef64339cbbd740fdcec15ca", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7702702703, "max_line_length": 78, "alphanum_fraction": 0.5616438356, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6670341442625676}} {"text": "module Examples.TwoPointLattice\n\nimport public DepSec.Lattice\n\n%access public export\n\ndata TwoPoint = H | L\n\nimplementation JoinSemilattice TwoPoint where\n join L L = L\n join L H = H\n join H L = H\n join H H = H\n\n associative L L L = Refl\n associative L L H = Refl\n associative L H L = Refl\n associative L H H = Refl\n associative H L L = Refl\n associative H H L = Refl\n associative H L H = Refl\n associative H H H = Refl\n\n commutative L L = Refl\n commutative L H = Refl\n commutative H L = Refl\n commutative H H = Refl\n\n idempotent L = Refl\n idempotent H = Refl\n\nimplementation BoundedJoinSemilattice TwoPoint where\n Bottom = L\n unitary H = Refl\n unitary L = Refl\n", "meta": {"hexsha": "c3a4314f9bbb3a21d304b124434a1aa0c4ef85bb", "size": 683, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Examples/TwoPointLattice.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/TwoPointLattice.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/TwoPointLattice.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": 18.9722222222, "max_line_length": 52, "alphanum_fraction": 0.6998535871, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6669053051279603}} {"text": "module Poker\n\nimport Control.ST\nimport Control.ST.Random\nimport Data.Fin\n-- import Data.Fin.Extra\nimport Data.Vect\nimport Data.Vect.Views\n\nimport Poker.Deck\n\n%default total\n\nHand : Type\nHand = Vect 7 Card\n\nsort : Ord t => Vect n t -> Vect n t\nsort xs with (splitRec xs)\n sort [] | SplitRecNil = []\n sort [x] | SplitRecOne = [x]\n sort (ys ++ zs) | (SplitRecPair lrec rrec) =\n merge (sort ys | lrec) (sort zs | rrec)\n\ndata SuitCount : Suit -> Vect n Card -> Nat -> Type where\n SuitEmpty : (h : Vect Z Card) -> SuitCount s h Z\n SuitMatch : (rec : SuitCount s h n) -> SuitCount s ((MkCard s r) :: h) (S n)\n SuitMiss : (rec : SuitCount s h n) ->\n (contra: Not (s = s')) ->\n SuitCount s ((MkCard s' r) :: h) (S n)\n\nsuitCount : (s : Suit) -> (h : Vect m Card) -> (n ** SuitCount s h n)\nsuitCount s [] = (0 ** SuitEmpty [])\nsuitCount s ((MkCard s' r) :: xs) =\n let (_ ** rec) = suitCount s xs\n in case decEq s s' of\n Yes Refl => (_ ** SuitMatch rec)\n No contra => (_ ** SuitMiss rec contra)\n\ndata Run : (b : Nat) -> (xs : Vect m Nat) -> (n : Nat) -> Type where\n EmptyRun : (xs : Vect m Nat) -> Run b xs Z\n Step : Elem (n + b) xs -> (rec : Run b xs n) -> Run b xs (S n)\n\ndata RankCount : Rank -> Vect n Card -> Nat -> Type where\n RankEmpty : (h : Vect Z Card) -> RankCount s h Z\n RankMatch : (rec : RankCount r h n) -> RankCount r ((MkCard s r) :: h) (S n)\n RankMiss : (rec : RankCount r h n) ->\n (contra: Not (r = r')) ->\n RankCount r ((MkCard s r') :: h) (S n)\n\nrankCount : (r : Rank) -> (h : Vect m Card) -> (n ** RankCount r h n)\nrankCount r [] = (0 ** RankEmpty [])\nrankCount r ((MkCard s r') :: xs) =\n let (_ ** rec) = rankCount r xs\n in case decEq r r' of\n Yes Refl => (_ ** RankMatch rec)\n No contra => (_ ** RankMiss rec contra)\n\ndata Ranks : Vect 5 Rank -> Type where\n MkRanks : (rs : Vect 5 Rank) -> Ranks rs\n\ndata StraightRun : Hand -> Type where\n HighStraight : Run b (map (finToNat . Poker.Deck.Card.rank) h) 5 ->\n StraightRun h\n LowStright : Elem Poker.Deck.ace (map Poker.Deck.Card.rank h) ->\n Run 0 (map (finToNat . Poker.Deck.Card.rank) h) 4 ->\n StraightRun h\n\ndata FlushRun : Hand -> Type where\n MkFlush : SuitCount s h n -> LTE 5 n -> FlushRun h\n\ndata Score : Hand -> Type where\n HighCard : Ranks (take 5 . reverse . Poker.sort $ map (Poker.Deck.Card.rank) h) ->\n Score h\n Pair : RankCount r h 2 -> Score h\n TwoPair : RankCount r h 2 -> RankCount s h 2 -> Not (r = s) -> Score h\n Trip : RankCount r h 3 -> Score h\n Straight : StraightRun h -> Score h\n Flush : FlushRun h -> Score h\n FullHouse : RankCount r h 3 -> RankCount s h 2 -> Score h\n FullHouse' : RankCount r h 3 -> RankCount s h 3 -> Not (r = s) -> Score h\n Quad : RankCount r h 4 -> Score h\n StraightFlush : StraightRun h -> FlushRun h -> Score h\n\nisFlushHelp : (h : Hand) -> (s : Suit) -> Maybe (FlushRun h)\nisFlushHelp h s with (suitCount s h)\n isFlushHelp h s | (n ** ss) with (isLTE 5 n)\n isFlushHelp h s | (n ** ss) | (Yes lte) = Just (MkFlush ss lte)\n isFlushHelp h s | (n ** ss) | (No contra) = Nothing\n\nisFlush : (h : Hand) -> Maybe (FlushRun h)\nisFlush h = foldr (<+>) Nothing (map (isFlushHelp h) suits)\n\ncheckRun : (b : Nat) -> (xs : Vect m Nat) -> (n : Nat) -> Maybe (Run b xs n)\ncheckRun b xs Z = Just (EmptyRun xs)\ncheckRun b xs (S n) =\n case isElem (n + b) xs of\n (Yes prf) => Step prf <$> checkRun b xs n\n (No contra) => Nothing\n\nisStraightHelp : (h : Hand) -> (b : Nat) -> Maybe (StraightRun h)\nisStraightHelp h b =\n HighStraight <$> checkRun b (map (finToNat . rank) h) 5\n\nisLowStraight : (h : Hand) -> Maybe (StraightRun h)\nisLowStraight h with (isElem ace (map rank h))\n isLowStraight h | (Yes prf) =\n (LowStright prf <$> checkRun 0 (map (finToNat . rank) h) 4)\n isLowStraight h | (No contra) = Nothing\n\nisStraight : (h : Hand) -> Maybe (StraightRun h)\nisStraight h =\n foldr (<+>) Nothing (map (isStraightHelp h . finToNat) ranks) <+>\n isLowStraight h\n\ncountRanks : (h : Hand) -> Vect 13 (r ** n ** RankCount r h n)\ncountRanks h = map (\\r => (r ** rankCount r h)) (reverse ranks)\n\nfindReps : (c : Nat) ->\n Vect o (r ** n ** RankCount r h n) ->\n List (r' ** RankCount r' h c)\nfindReps c [] = []\nfindReps c (x :: xs) with (x)\n findReps c (x :: xs) | (r'' ** n' ** rc) =\n case decEq c n' of\n (Yes Refl) => (r'' ** rc) :: findReps c xs\n (No contra) => findReps c xs\n\nfindQuad : Vect o (r ** n ** RankCount r h n) ->\n Maybe (Score h)\nfindQuad rs with (findReps 4 rs)\n findQuad rs | [] = Nothing\n findQuad rs | ((r' ** rc) :: _) = Just (Quad rc)\n\nfindTrip : Vect o (r ** n ** RankCount r h n) ->\n Maybe (Score h)\nfindTrip rs with (findReps 3 rs)\n findTrip rs | [] = Nothing\n findTrip rs | ((r' ** rc) :: _) = Just (Trip rc)\n\nfindPairs : Vect o (r ** n ** RankCount r h n) ->\n Maybe (Score h)\nfindPairs rs with (findReps 2 rs)\n findPairs rs | ((r1 ** rc1) :: (r2 ** rc2) :: xs) =\n case decEq r1 r2 of\n (Yes prf) =>\n -- this should never happen, but handle it\n assert_total $ findPairs rs | ((r1 ** rc1) :: xs)\n (No contra) => Just (TwoPair rc1 rc2 contra)\n findPairs rs | ((r' ** rc) :: []) = Just (Pair rc)\n findPairs rs | [] = Nothing\n\nfindFH : Vect o (r ** n ** RankCount r h n) ->\n Maybe (Score h)\nfindFH rs with (findReps 3 rs)\n findFH rs | [] = Nothing\n findFH rs | (x :: []) with (findReps 2 rs)\n findFH rs | (x :: []) | [] = Nothing\n findFH rs | ((r1 ** rc1) :: []) | ((r2 ** rc2) :: _) = Just (FullHouse rc1 rc2)\n findFH rs | ((r1 ** rc1) :: (r2 ** rc2) :: ys) with (decEq r1 r2)\n findFH rs | ((r1 ** rc1) :: (r2 ** rc2) :: ys) | (Yes prf) =\n -- this should never happen, but handle it\n assert_total $ findFH rs | ((r1 ** rc1) :: ys)\n findFH rs | ((r1 ** rc1) :: (r2 ** rc2) :: _) | (No contra) with (findReps 2 rs)\n findFH rs | ((r1 ** rc1) :: (r2 ** rc2) :: _) | (No contra) | [] =\n Just (FullHouse' rc1 rc2 contra)\n findFH rs | ((r1 ** rc1) :: (r2 ** rc2) :: _) | (No contra) | ((r3 ** rc3) :: _) =\n if (r2 > r3)\n then Just (FullHouse' rc1 rc2 contra)\n else Just (FullHouse rc1 rc3)\n\nscore : (h : Hand) -> Score h\nscore h =\n let f = isFlush h\n s = isStraight h\n rs = countRanks h\n m = (StraightFlush <$> s <*> f) <+>\n (findQuad rs) <+>\n (findFH rs) <+>\n (Flush <$> f) <+>\n (Straight <$> s) <+>\n (findTrip rs) <+>\n (findPairs rs)\n hc = HighCard $ MkRanks (take 5 . reverse . sort $ map rank h)\n in maybe hc id m\n\n-- Local Variables:\n-- idris-load-packages: (\"contrib\")\n-- End:\n", "meta": {"hexsha": "54406693c2aa66e9bbde9654ffecd791c1d88667", "size": 6688, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Poker.idr", "max_stars_repo_name": "farrellm/idris-poker", "max_stars_repo_head_hexsha": "3a729383be701834497e65fe48156e38d7f866d5", "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/Poker.idr", "max_issues_repo_name": "farrellm/idris-poker", "max_issues_repo_head_hexsha": "3a729383be701834497e65fe48156e38d7f866d5", "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/Poker.idr", "max_forks_repo_name": "farrellm/idris-poker", "max_forks_repo_head_hexsha": "3a729383be701834497e65fe48156e38d7f866d5", "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.3862433862, "max_line_length": 88, "alphanum_fraction": 0.5578648325, "num_tokens": 2279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6665490611464101}} {"text": "module Logic\n\ndisjNot : Either (a -> Void) (b -> Void) -> (a, b) -> Void\ndisjNot (Left l) (a, _) = l a\ndisjNot (Right r) (_, b) = r b\n\nnotEx : {p : a -> Type} -> ((x : a ** p x) -> Void) -> (y : a) -> p y -> Void\nnotEx ne y py = ne (y ** py)\n\nnnnEl : (((a -> Void) -> Void) -> Void) -> (a -> Void)\nnnnEl f x = f (\\p => absurd $ p x)\n\nnnnLe : (a -> Void) -> (((a -> Void) -> Void) -> Void)\nnnnLe f g = g f\n\ndepCurr : {p : a -> Type} -> ((x : a ** p x) -> b) -> ((y : a) -> p y -> b)\ndepCurr f y x = f (y ** x)\n\ndepUncurr : {p : a -> Type} -> ((y : a) -> p y -> b) -> ((x : a ** p x) -> b)\ndepUncurr f (z ** q) = f z q\n", "meta": {"hexsha": "ce834d355ecc820d56f73196bcf2bc545bf0f07c", "size": 618, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "2020.01.22-to-bhk-lecture/idris/Logic.idr", "max_stars_repo_name": "buzden/code-in-lectures", "max_stars_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-17T07:01:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T07:01:15.000Z", "max_issues_repo_path": "2020.01.22-to-bhk-lecture/idris/Logic.idr", "max_issues_repo_name": "buzden/code-in-lectures", "max_issues_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "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": "2020.01.22-to-bhk-lecture/idris/Logic.idr", "max_forks_repo_name": "buzden/code-in-lectures", "max_forks_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "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.4285714286, "max_line_length": 77, "alphanum_fraction": 0.425566343, "num_tokens": 264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6661679614193541}} {"text": "module Primes\n\nimport NatUtils\nimport gcd\nimport Data.Fin\nimport NatOrder\nimport SriramAssRecRule\n\n%access public export\n%default total\n\n\n--isDivisible a b can be constucted if b divides a\nisDivisible : Nat -> Nat -> Type\nisDivisible a b = (n : Nat ** (GT n 0, a = b * n))\n\n--1 divides everything\noneDiv : (a : Nat) -> {auto x : GT a 0} -> isDivisible a 1\noneDiv a {x=pf} = (a ** (pf , rewrite plusZeroRightNeutral a in Refl))\n\n--If 1|a => 1*c | a*c\nmulDiv : (a, c : Nat) -> {auto pf1 : GT a 0} -> {auto pf2 : GT c 0} ->\n isDivisible a 1 -> isDivisible (a * c) c\nmulDiv a c {pf1=p} x = (a ** (p ,rewrite multCommutative a c in Refl))\n\n--Either(a=b)(_) <=> Either (S a = S b)(_)\nhelp1 : {a : Nat} -> {b : Nat} ->\n Either (a = b) (Either (LT (S a) (S b)) (LT (S b) (S a))) ->\n Either (S a = S b) (Either (LT (S a) (S b)) (LT (S b) (S a)))\nhelp1 {a} {b} (Left l) = Left (eqSucc a b l)\nhelp1 (Right r) = Right r\n\n--Either(_)(Either(Sa Either (_)(Either(a {b : Nat} ->\n Either (a = b) (Either (LT a b) (LT (S b) (S a))) ->\n Either (a = b) (Either (LT (S a) (S b)) (LT (S b) (S a)))\nhelp2 (Left l) = Left l\nhelp2 {a} {b} (Right (Left l)) = Right(Left (LTESucc l))\nhelp2 (Right (Right r)) = Right (Right r)\n\n--Either(_)(Either(_)(Sb Either (_)(Either(_)(b {b : Nat} ->\n Either (a = b) (Either (LT a b) (LT b a)) ->\n Either (a = b) (Either (LT a b) (LT (S b) (S a)))\nhelp3 (Left l) = Left l\nhelp3 (Right (Left l)) = Right(Left l)\nhelp3 {a} {b} (Right (Right r)) = Right (Right (LTESucc r))\n\n|||Either a = b, a < b, or a > b\ntotOrdNat : (a : Nat) -> (b : Nat) ->\n Either (a = b) (Either (LT a b) (LT b a))\ntotOrdNat Z Z = Left Refl\ntotOrdNat Z (S k) = Right (Left (LTESucc LTEZero))\ntotOrdNat (S k) Z = Right (Right (LTESucc LTEZero))\ntotOrdNat (S k) (S j) = help1 (help2 (help3 (totOrdNat k j)))\n\n--LTE a b => LTE a*n b*n\nmultRightLTE : (a,b : Nat) -> (n : Nat) -> GT n 0 ->\n LTE a b -> LTE (a*n) (b*n)\nmultRightLTE a b (S Z) (LTESucc LTEZero) lteab =\n rewrite multOneRightNeutral a in\n rewrite multOneRightNeutral b in\n lteab\nmultRightLTE a b (S (S k)) (LTESucc LTEZero{right=(S k)}) lteab =\n rewrite multRightSuccPlus a (S k) in\n rewrite multRightSuccPlus b (S k) in\n ltePlusIsLTE lteab\n (multRightLTE a b (S k) (LTESucc LTEZero{right=k}) lteab)\n\n--If a = b*n, b <= a\naEqProdImpAGtB : (a,b,n : Nat) -> GT n 0 -> (a = b*n) -> LTE b a\naEqProdImpAGtB _ _ Z LTEZero _ impossible\naEqProdImpAGtB _ _ Z (LTESucc _) _ impossible\naEqProdImpAGtB (b * (S k)) b (S k) x Refl = case b of\n Z => LTEZero\n (S m) =>\n rewrite sym (multOneLeftNeutral (S m)) in\n rewrite multCommutative (S m) (S k) in\n rewrite multDistributesOverPlusRight k (S Z) m in\n rewrite plusCommutative (k*1) (k*m) in\n rewrite plusAssociative m (k*m) (k*1) in\n rewrite plusCommutative (m + k*m) (k*1) in\n rewrite sym (multDistributesOverPlusRight (S k) 1 m) in\n multRightLTE 1 (S k) (S m) (LTESucc (LTEZero)) x\n\n--If b | a => b <= a\nbDivAImpAGtB : (a,b,n : Nat) -> isDivisible a b -> LTE b a\nbDivAImpAGtB a b n (x ** pf) = case (fst pf) of\n (LTESucc LTEZero{right=k}) => aEqProdImpAGtB a b (S k) (fst pf) (snd pf)\n\n--GT implies Not LTE\ngtImpliesNotLTE : GT a b -> Not (LTE a b)\ngtImpliesNotLTE {a=Z} {b=_} LTEZero impossible\ngtImpliesNotLTE {a=Z} {b=_} (LTESucc _) impossible\ngtImpliesNotLTE {a=(S k)} {b=Z} x = case isLTE (S k) Z of\n (Yes prf) => absurd\n (No contra) => contra\ngtImpliesNotLTE {a=(S k)} {b=(S j)} x = case isLTE (S k) (S j) of\n (Yes prf) => void\n (gtImpliesNotLTE (fromLteSucc x) (fromLteSucc prf))\n (No contra) => contra\n\n--If b > a => b does not divide a\nbGtAImpNotbDivA : (a,b,n : Nat) -> GT b a -> (isDivisible a b -> Void)\nbGtAImpNotbDivA a b n x = impliesContrapositive\n (isDivisible a b)\n (LTE b a)\n (bDivAImpAGtB a b n)\n (gtImpliesNotLTE x)\n\n--(S (S k)) = 0 is not possible\nzNotEqSS : (k : Nat) -> ((S (S k)) = 0 -> Void)\nzNotEqSS Z = absurd\nzNotEqSS (S k) = absurd\n\n--isDivisible p 0 => (S (S k)) = 0\nhelp4 : (p : Nat) -> LTE 2 p -> isDivisible p 0 -> p = 0\nhelp4 Z LTEZero _ impossible\nhelp4 Z (LTESucc _) _ impossible\nhelp4 (S Z) (LTESucc LTEZero) _ impossible\nhelp4 (S Z) (LTESucc (LTESucc _)) _ impossible\nhelp4 (S (S k)) (LTESucc (LTESucc LTEZero)) x = snd (snd x)\n\n\n--If x = 0, and p >= 2, x cannot divide p\nzNotDivp : (p : Nat) -> LTE 2 p -> ((isDivisible p 0) -> Void)\nzNotDivp Z LTEZero impossible\nzNotDivp Z (LTESucc _) impossible\nzNotDivp (S Z) (LTESucc LTEZero) impossible\nzNotDivp (S Z) (LTESucc (LTESucc _)) impossible\nzNotDivp (S (S k)) (LTESucc (LTESucc LTEZero)) =\n impliesContrapositive\n (isDivisible (S (S k)) 0)\n ((S (S k)) = 0)\n (help4 (S (S k)) (LTESucc (LTESucc LTEZero)))\n (zNotEqSS k)\n\n-- Helping out metaHelp\nmetaMetaHelp5 : (j : Nat) -> (S (j+0)) = (S j)\nmetaMetaHelp5 Z = Refl\nmetaMetaHelp5 (S k) = rewrite plusZeroRightNeutral k in Refl\n\n--Helping out help5\nmetaHelp5 : (S (S k)) = (S (j+0)) -> (S (S k)) = (S (j))\nmetaHelp5 {j} prf = rewrite sym (metaMetaHelp5 j) in prf\n\n\n-- Helping out the absurd case\nhelp5: (S (S k)) = (S (j+0)) -> LT (S j) (S (S k)) -> LTE (S Z) 0\nhelp5 {k} {j} prf x = lteMinusConstantRight {c=(S j)}\n (rewrite sym (metaMetaHelp5 j) in\n rewrite sym prf in\n rewrite eqSucc (S (S k)) (S j) (metaHelp5 prf) in\n x)\n\n--If a divides b => b=a*n\nbDivAImpBEqAN : (a,b : Nat) -> isDivisible b a -> (k : Nat ** b = a * k)\nbDivAImpBEqAN a b (p ** (proofGT, proofEq)) = (p ** proofEq)\n\n--To help out help6\nmetaHelp6 : (p : Nat) -> (x : Nat) -> (c : Nat) ->\n (p = x*c) -> q = c -> (p = q*x)\nmetaHelp6 p x c prf prf1 = rewrite prf1 in\n rewrite multCommutative c x in prf\n\n--To help out a case in notDivIfRem\nhelp6 : (p : Nat) -> (x : Nat) -> (c : Nat) ->\n (p = q*x) -> (p = (S r) + q*x) ->\n (Z = (S r))\nhelp6 p x c {q} {r} p1 p2 = plusRightCancel Z (S r) (q*x) (trans (sym p1) p2)\n\n--To help out another case of notDivIfRem\nhelp7 : (p : Nat) -> (x : Nat) -> (c : Nat) -> (k : Nat) -> (r : Nat) ->\n c + k = q -> p = x*c -> p = (S r) + q*x ->\n Z = (S r) + k*x\nhelp7 p x c k r pfSum pfMul pfRem =\n plusRightCancel Z ((S r)+k*x) (c*x)\n (rewrite sym (plusAssociative (S r) (k*x) (c*x)) in\n rewrite plusCommutative (k*x) (c*x) in\n rewrite sym (multDistributesOverPlusLeft c k x) in\n rewrite pfSum in\n rewrite sym (multCommutative x c) in\n rewrite sym (pfMul) in pfRem)\n\n--Helper for help8\nmetahelp8 : (x : Nat) -> (S q) + k = c -> x +(q+k)*x = c*x\nmetahelp8 x prf = rewrite sym prf in Refl\n\n--Last case!\nhelp8 : (p : Nat) -> (x : Nat) -> (c : Nat) -> (k : Nat) ->\n (m : Nat) -> (r : Nat) -> (q : Nat) ->\n (S q) + k = c -> (S (S r)) + m = x -> p = x*c -> p = (S r) + q*x ->\n Z = k*(S r) + (S k)*(S m)\nhelp8 p x c k m r q qLtc srLtx pfMul pfRem =\n plusLeftCancel (S r) Z (k*(S r) + (S k)*(S m))\n (rewrite plusAssociative (S r) (k*(S r)) ((S k)*(S m)) in\n rewrite sym (multDistributesOverPlusRight (S k) (S r) (S m)) in\n rewrite plusAssociative r (S Z) m in\n rewrite plusCommutative r (S Z) in\n rewrite srLtx in\n rewrite sym (plusCommutative (k*x) ((S (S r)) + m)) in\n rewrite srLtx in\n rewrite plusCommutative (k*x) x in\n rewrite plusZeroRightNeutral r in\n plusLeftCancel (q*x) (S r) (x + k*x)\n (rewrite plusAssociative (q*x) x (k*x) in\n rewrite plusCommutative (q*x) x in\n rewrite sym (multDistributesOverPlusLeft (S q) k x) in\n rewrite metahelp8 {q=q} {k=k} {c=c} x qLtc in\n rewrite (multCommutative c x) in\n rewrite sym pfMul in\n rewrite plusCommutative (q*x) (S r) in\n (sym pfRem)))\n\nhelp9 : (k,r,m : Nat) ->\n Z = k*(S r) + (S k)*(S m) -> Z = (S k)*(S m) + k*(S r)\nhelp9 k r m prf = rewrite plusCommutative ((S k)*(S m)) (k*(S r)) in prf\n\n--To help out the last case, by creating a term of an uninhabited type\nnotDivIfRem : (p : Nat) -> (x : Nat) -> (r : Nat) -> {q : Nat} ->\n (p = (S r) + q*x) -> LT (S r) x ->\n (c : Nat ** p = x * c) -> Void\nnotDivIfRem p x r {q=q} prfRem prfLt (c ** prfDiv) =\n case decEq q c of\n (Yes prf) => absurd $\n (help6 p x c (metaHelp6 p x c prfDiv prf) prfRem)\n (No contra) => case totOrdNat q c of\n (Left l) => void (contra l)\n (Right (Left qLtc)) => case (lteToLEQ qLtc) of\n (k ** pf1) => case (lteToLEQ prfLt) of\n (m ** pf2) => absurd $\n help9 k r m\n (help8 p x c k m r q pf1 pf2 prfDiv prfRem)\n (Right (Right qGtc)) => case (lteToLEQ (lteSuccLeft qGtc)) of\n (k ** pf) => absurd $\n (help7 p x c k r pf prfDiv prfRem)\n\n--The usual case for divisibility\nusual : (p : Nat) -> LTE 2 p -> (x : Nat) -> (LT 0 x) -> (LT x p) ->\n (euc : (q : Nat ** (r : Nat ** ((p = r + (q * x)), LT r x)))) ->\n Dec (isDivisible p x)\nusual Z LTEZero _ _ _ _ impossible\nusual Z (LTESucc _) _ _ _ _ impossible\nusual (S Z) (LTESucc LTEZero) _ _ _ _ impossible\nusual (S Z) (LTESucc (LTESucc _)) _ _ _ _ impossible\nusual (S (S _)) (LTESucc (LTESucc LTEZero)) Z LTEZero _ _ impossible\nusual (S (S _)) (LTESucc (LTESucc LTEZero)) Z (LTESucc _) _ _ impossible\nusual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc with (euc)\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | (Z ** (Z ** (pf,_))) = absurd $ pf\n\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | ((S Z) ** (Z ** (pf,_))) = absurd $\n (help5 pf xLtp)\n\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | ((S (S b)) ** (Z ** (pf,_))) =\n Yes ((S (S b)) ** ((LTESucc LTEZero),\n (rewrite multCommutative (S j) (S (S b)) in pf)))\n\n usual (S (S k)) (LTESucc (LTESucc LTEZero))\n (S j) (LTESucc LTEZero)\n xLtp euc | (_ ** ((S a) ** (pf1,pf2))) = No\n (impliesContrapositive\n (isDivisible (S (S k)) (S j))\n (c : Nat ** (S (S k)) = (S j) * c)\n (bDivAImpBEqAN (S j) (S (S k)))\n (notDivIfRem (S (S k)) (S j) a pf1 pf2))\n\n\n--Decidability for divisibility\ndecDiv : (p : Nat) -> LTE 2 p -> (x : Nat) ->\n {euc : (q : Nat ** (r : Nat ** ((p = r + (q * x)), LT r x)))} ->\n Dec (isDivisible p x)\ndecDiv Z LTEZero _ impossible\ndecDiv Z (LTESucc _) _ impossible\ndecDiv (S Z) (LTESucc LTEZero) _ impossible\ndecDiv (S Z) (LTESucc (LTESucc _)) _ impossible\ndecDiv (S (S k)) (LTESucc (LTESucc LTEZero)) x {euc=big} =\n case totOrdNat (S (S k)) x of\n (Left l) => Yes (1 ** ((LTESucc LTEZero),\n rewrite l in\n rewrite sym (multOneRightNeutral x) in\n Refl))\n (Right (Left l)) => No (bGtAImpNotbDivA\n (S (S k)) x\n (divNatNZ x (S (S k)) SIsNotZ)\n l)\n (Right (Right r)) => case x of\n Z => No (zNotDivp (S (S k)) (LTESucc (LTESucc LTEZero)))\n (S m) => usual (S (S k)) (LTESucc (LTESucc LTEZero)) (S m)\n (LTESucc LTEZero) r big\n", "meta": {"hexsha": "d42b0d98a96483e10707fb9e7d372b965e572949", "size": 12237, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Code/Primes.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/Primes.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/Primes.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": 41.0637583893, "max_line_length": 89, "alphanum_fraction": 0.5079676391, "num_tokens": 4346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6657578339414736}} {"text": "module Problem01\n-- Find the last element of a list.\n\nmyLastV : Vect (S n) a -> a\nmyLastV [x] = x\nmyLastV (_::x::xs) = myLastV (x::xs)\n\nmyIsCons : List a -> Bool\nmyIsCons [] = False\nmyIsCons (x::xs) = True\n\nmyLastL : (l : List a) -> (ok : isCons l = True) -> a\nmyLastL [x] _ = x\nmyLastL (y::x::xs) _ = myLastL (x::xs) Refl\n\n\n", "meta": {"hexsha": "530b7b6537786231fd96c376d19f7c7d1d91f1a0", "size": 325, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris99Problems/Problem01.idr", "max_stars_repo_name": "jesyspa/jesyspa-s-toy-projects", "max_stars_repo_head_hexsha": "f0fc452438cb997dd8dd8c259ed4084b29a8dc1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:14:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-20T18:28:15.000Z", "max_issues_repo_path": "Idris99Problems/Problem01.idr", "max_issues_repo_name": "jesyspa/jesyspa-s-toy-projects", "max_issues_repo_head_hexsha": "f0fc452438cb997dd8dd8c259ed4084b29a8dc1e", "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": "Idris99Problems/Problem01.idr", "max_forks_repo_name": "jesyspa/jesyspa-s-toy-projects", "max_forks_repo_head_hexsha": "f0fc452438cb997dd8dd8c259ed4084b29a8dc1e", "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.1176470588, "max_line_length": 53, "alphanum_fraction": 0.5938461538, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6652405387609573}} {"text": "data Tree elem = ||| A (sub-)tree with no data.\n Empty\n | ||| A node with a left subtree, a value, and a right subtree.\n Node (Tree elem) elem (Tree elem)\n\n%name Tree tree, tree1, tree2\n\ninsert : Ord elem => elem -> Tree elem -> Tree elem\ninsert x Empty = Node Empty x Empty\ninsert x (Node left val right)\n = case compare x val of\n LT => Node (insert x left) val right\n EQ => Node left val right\n GT => Node left val (insert x right)\n", "meta": {"hexsha": "8b8f76c17748cb59c93cd9cc79d24d61eb95178e", "size": 496, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter04/Tree.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TypeDrivenDevelopment/Chapter04/Tree.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypeDrivenDevelopment/Chapter04/Tree.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": 33.0666666667, "max_line_length": 78, "alphanum_fraction": 0.5887096774, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6651340718947449}} {"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\ncurry : ((a, b) -> c) -> a -> b -> c\ncurry f x y = ?curry_rhs\n\nuncurry : (a -> b -> c) -> (a, b) -> c\nuncurry f x = ?uncurry_rhs\n\nappend : Vect n a -> Vect m a -> Vect (n + m) a\nappend [] ys = ?append_rhs_1\nappend (x :: xs) ys = ?append_rhs_2\n\nzipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c\nzipWith f [] [] = ?zipWith_rhs_1\nzipWith f (x :: xs) (y :: ys) = ?zipWith_rhs_2\n", "meta": {"hexsha": "4783a0e1d571fc4356ca7d30102968c425761712", "size": 508, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive004/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/interactive004/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/interactive004/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": 25.4, "max_line_length": 59, "alphanum_fraction": 0.5236220472, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6649726750988042}} {"text": "module Printf\n\ndata Format = Number Format\n | Str Format\n | Lit Char Format -- do we really need String literals?\n | Chr Format -- from exercise 2\n | Dbl Format\n | End\n\ntotal PrintfType : Format -> Type\nPrintfType (Number fmt) = Int -> PrintfType fmt -- NOTE: it would be nice if\n -- we could specify\n -- Num a => a -> PrintfType fmt\nPrintfType (Str fmt) = String -> PrintfType fmt\nPrintfType (Lit lit fmt) = PrintfType fmt\nPrintfType End = String -- teeechnically it should be IO ().\n -- sprintf would have type ... -> String\nPrintfType (Chr fmt) = Char -> PrintfType fmt\nPrintfType (Dbl fmt) = Double -> PrintfType fmt\n\nprintfFmt : (fmt : Format) -> (acc : String) -> PrintfType fmt\nprintfFmt (Number fmt) acc = \\i => printfFmt fmt (acc ++ show i)\nprintfFmt (Str fmt) acc = \\s => printfFmt fmt (acc ++ s)\nprintfFmt (Lit lit fmt) acc = printfFmt fmt (acc ++ cast lit)\nprintfFmt End acc = acc\nprintfFmt (Chr fmt) acc = \\c => printfFmt fmt (acc ++ cast c)\nprintfFmt (Dbl fmt) acc = \\d => printfFmt fmt (acc ++ show d)\n\ntoFormat : List Char -> Format\ntoFormat [] = End\ntoFormat ('%' :: 'd' :: cs) = Number (toFormat cs)\ntoFormat ('%' :: 's' :: cs) = Str (toFormat cs)\ntoFormat ('%' :: 'c' :: cs) = Chr (toFormat cs)\ntoFormat ('%' :: 'f' :: cs) = Dbl (toFormat cs)\ntoFormat (c :: cs) = Lit c (toFormat cs) -- sorry, I'm lazy\n\nprintf : (fmt : String) -> PrintfType (toFormat (unpack fmt))\nprintf fmt = printfFmt _ \"\"\n\nprintfExample : String\nprintfExample = printf \"%d %d %%%%%%s\" 10 2 \"foo\"\n\n-- NOTEs:\n-- Using Lit Char instead of Lit String made things easier when building\n-- literals. I'm curious about the efficiency though...\n\n-- There's still a bit of dependency between format (PrintfType) and\n-- toFormat. For example there is no guarantee that toFormat\n-- will produce a case for all possible Formats.\n-- I wonder if there are languages where we can specify that a function\n-- must be surjective.\n\n-- Let's go back to Chapter6.idr\n", "meta": {"hexsha": "3338dc642cbb41de148fc3abf12847f9f9d673e8", "size": 2128, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Printf.idr", "max_stars_repo_name": "neduard/type-driven-development", "max_stars_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Printf.idr", "max_issues_repo_name": "neduard/type-driven-development", "max_issues_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Printf.idr", "max_forks_repo_name": "neduard/type-driven-development", "max_forks_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4074074074, "max_line_length": 80, "alphanum_fraction": 0.6123120301, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.664946972849635}} {"text": "> module Nat.Coprime\n\n\n> import Nat.GCD\n> import Nat.GCDAlgorithm\n> import Unique.Predicates\n> import Equality.Properties\n> import Nat.GCDEuclid\n> import Pairs.Operations\n> import Sigma.Sigma\n\n\n> %default total\n\n> %access public export\n\n\n> ||| \n> data Coprime : (m : Nat) -> (n : Nat) -> Type where\n> MkCoprime : {m, n : Nat} -> gcdAlg m n = S Z -> Coprime m n\n\n\n> |||\n> CoprimeUnique : {m, n : Nat} -> Unique (Coprime m n)\n> CoprimeUnique {m} {n} (MkCoprime p) (MkCoprime q) = cong (uniqueEq (gcdAlg m n) (S Z) p q)\n", "meta": {"hexsha": "a28d9204468184d598d5b109950680cb9b19af0b", "size": 519, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Nat/Coprime.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/Coprime.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/Coprime.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": 19.9615384615, "max_line_length": 92, "alphanum_fraction": 0.6416184971, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6648650660623634}} {"text": "module Chapter3\n\nimport TypesAndFunctions\nimport Category\nimport Isomorphism\nimport Universality\nimport Naturality\n\n%default total\n\nExercise_3_1_1 : {cat : Category} -> {a, b, c : Object cat} ->\n Isomorphic {cat} a b -> Bijection (Morphism cat a c) (Morphism cat b c)\nExercise_3_1_1 {cat}\n (abIsomorphism ** (baIsomorphism ** ((isLeftInverse, isRightInverse)))) =\n ((\\f : Morphism cat a c => f .* baIsomorphism) **\n ((\\g : Morphism cat b c => g .* abIsomorphism) **\n ((\\f' : Morphism cat a c =>\n let\n assoc = Associativity cat f' baIsomorphism abIsomorphism\n rightId = RightIdentity cat f'\n in\n replace {p=(\\f'' => f'' = f')} (sym assoc)\n (replace {p=(\\z => f' .* z = f')} (sym isLeftInverse) rightId),\n \\g' : Morphism cat b c =>\n let\n assoc = Associativity cat g' abIsomorphism baIsomorphism\n rightId = RightIdentity cat g'\n in\n replace {p=(\\g'' => g'' = g')} (sym assoc)\n (replace {p=(\\z => g' .* z = g')} (sym isRightInverse) rightId)))))\n\nExercise_3_1_2 : {cat : Category} -> (a : Object cat) -> Isomorphic {cat} a a\nExercise_3_1_2 a =\n (catId a ** (catId a ** (LeftIdentity _ _, LeftIdentity _ _)))\n\nExercise_3_1_3 : {cat : Category} -> {a, b : Object cat} ->\n IsTerminal {cat} a -> IsTerminal {cat} b -> Isomorphic {cat} a b\nExercise_3_1_3 aIsTerminal bIsTerminal =\n (fst (bIsTerminal a) ** (fst (aIsTerminal b) **\n (IdOnlyTerminalEndomorphism aIsTerminal\n (fst (aIsTerminal b) .* fst (bIsTerminal a)),\n (IdOnlyTerminalEndomorphism bIsTerminal\n (fst (bIsTerminal a) .* fst (aIsTerminal b))))))\n\nExercise_3_1_4 : {cat : Category} -> {a, b : Object cat} ->\n (aIsTerminal : IsTerminal {cat} a) -> (bIsTerminal : IsTerminal {cat} b) ->\n IsUnique {cat} {a} {b}\n (IsIsomorphism {cat} {a} {b})\n (fst (Exercise_3_1_3 {cat} {a} {b} aIsTerminal bIsTerminal))\nExercise_3_1_4 {cat} {a} {b} aIsTerminal bIsTerminal =\n ((fst (aIsTerminal b) **\n (IdOnlyTerminalEndomorphism aIsTerminal _,\n IdOnlyTerminalEndomorphism bIsTerminal _)),\n \\g : Morphism cat a b,\n g' : DPair (Morphism cat b a) (IsInverse {cat} g) =>\n snd (snd (bIsTerminal a)) g ())\n\nExercise_3_2_1_left : {cat : Category} -> {a, b, x, y : Object cat} ->\n (fInv : Morphism cat b a) -> (g : Morphism cat x y) ->\n (h : Morphism cat a x) ->\n ((preCompose {cat} {a=b} {b=a} {c=y} fInv) .\n (postCompose {cat} {a} {b=x} {c=y} g)) h =\n After cat {a=b} {b=x} {c=y} g (After cat {a=b} {b=a} {c=x} h fInv)\nExercise_3_2_1_left fInv g h = Associativity cat g h fInv\n\nExercise_3_2_1_right : {cat : Category} -> {a, b, x, y : Object cat} ->\n (fInv : Morphism cat b a) -> (g : Morphism cat x y) ->\n (h : Morphism cat a x) ->\n ((postCompose {cat} {a=b} {b=x} {c=y} g) .\n (preCompose {cat} {a=b} {b=a} {c=x} fInv)) h =\n After cat {a=b} {b=x} {c=y} g (After cat {a=b} {b=a} {c=x} h fInv)\nExercise_3_2_1_right fInv g h = Refl\n\nExercise_3_3_1 : {cat : Category} ->\n {observerA, observerB : Object cat} ->\n (beta : ObserverChange {cat} observerA observerB) ->\n Morphism cat observerB observerA\nExercise_3_3_1 = ObserverChangeInducedMorphism\n\nExercise_3_3_2 : {cat : Category} ->\n {observerA, observerB : Object cat} ->\n (beta : ObserverChange {cat} observerA observerB) ->\n (natural : ObserverChangeIsNatural {cat} {observerA} {observerB} beta) ->\n (y : Object cat) -> (g : Morphism cat observerA y) ->\n beta y g =\n After cat {a=observerB} {b=observerA} {c=y}\n g (Exercise_3_3_1 {cat} {observerA} {observerB} beta)\nExercise_3_3_2 beta natural y g =\n appEq {x=g} (ObserverChangeIsPreComposition beta natural y)\n", "meta": {"hexsha": "d1031c27bf9c79617f66cc467fa0ff89113a1a64", "size": 3618, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Chapter3.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/Chapter3.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/Chapter3.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": 40.2, "max_line_length": 77, "alphanum_fraction": 0.6257600884, "num_tokens": 1271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6648581958987414}} {"text": "-- Adder.idr\n\n-- Demonstrate functions with variable number of arguments by an\n-- adder function\n\nAdderType : (numargs : Nat) -> Type -> Type\nAdderType Z numType = numType\nAdderType (S k) numType = (next : numType) -> AdderType k numType\n\n\n||| An adder function for variable number of arguments\nadder : Num numType => (numargs : Nat) -> (acc : numType) -> AdderType numargs numType\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (next + acc)\n\n", "meta": {"hexsha": "35f96d65dc233b4ab944f4a72c9dac4091601c91", "size": 449, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_6/Adder.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_6/Adder.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_6/Adder.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": 28.0625, "max_line_length": 86, "alphanum_fraction": 0.6926503341, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6644039759058558}} {"text": "module Game\n\nimport Quantities\nimport Quantities.Screen\n\nScreenSpeed : Quantity\nScreenSpeed = ScreenLength Time\n\nPxs : Unit ScreenSpeed\nPxs = Pixel Second\n\nrecord PlayerState where\n constructor MkPlayerState\n xSpeed : F Pxs\n ySpeed : F Pxs\n xPos : F Px\n yPos : F Px\n\ngravity : Quantities.Core.F (Pxs Second)\ngravity = -800 =| (Pxs Second)\n\n-- Update player position and speed after a given duration\nupdatePlayerState : F Second -> PlayerState -> PlayerState\nupdatePlayerState dt (MkPlayerState xs ys xp yp) =\n let newYPos = yp <+> ys |*| dt\n in if newYPos <= (0 =| Px)\n then MkPlayerState (0 =| Pxs) (0 =| Pxs) xp (0 =| Px)\n else MkPlayerState xs (ys <+> gravity |*| dt)\n (xp <+> xs |*| dt) newYPos\n", "meta": {"hexsha": "7a2f2187ae9397fe38305cf78fef4b6e8295ec1c", "size": 766, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples/Game.idr", "max_stars_repo_name": "timjb/quantities", "max_stars_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 112, "max_stars_repo_stars_event_min_datetime": "2015-01-18T13:52:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T14:15:46.000Z", "max_issues_repo_path": "examples/Game.idr", "max_issues_repo_name": "timjb/quantities", "max_issues_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-04T08:51:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-17T09:52:29.000Z", "max_forks_repo_path": "examples/Game.idr", "max_forks_repo_name": "timjb/quantities", "max_forks_repo_head_hexsha": "140357c3ec06e5b29b5d369cb59f1f5925f000a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-04-28T23:49:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T17:28:34.000Z", "avg_line_length": 25.5333333333, "max_line_length": 60, "alphanum_fraction": 0.6422976501, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9546474233166328, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6643948277491248}} {"text": "data BSTree : Type -> Type where\n Empty : Ord elem => BSTree elem\n Node : Ord elem => (left : BSTree elem) \n -> (val : elem)\n -> (right: BSTree elem) \n -> BSTree elem\n\ninsert : elem -> BSTree elem -> BSTree elem\ninsert x Empty = Node Empty x Empty\ninsert x orig@(Node left val right) = case compare x val of\n LT => Node (insert x left) val right\n EQ => orig\n GT => Node left val (insert x right)\n", "meta": {"hexsha": "d5c61a48184e7e8a04f82e3ba10abc6ce67bbd9f", "size": 603, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch4/BSTree.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/ch4/BSTree.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/ch4/BSTree.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": 43.0714285714, "max_line_length": 79, "alphanum_fraction": 0.4295190713, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6642832517749788}} {"text": "module Data.LeftistHeap\n\nimport Decidable.Order\n\n%default total\n\nmutual\n export\n data Heap : .(constraint : Ordered a rel) -> .(count : Nat) -> Type where\n Empty : Heap _ Z\n Node : (n : Nat)\n -> (value : a)\n -> {countLeft : Nat}\n -> (left : Heap constraint countLeft)\n -> {countRight : Nat}\n -> (right : Heap constraint countRight)\n -> .{auto fitsLeft : Fits value left}\n -> .{auto fitsRight : Fits value right}\n -> .{auto leftistPrf : LTE (rank right) (rank left)}\n -> .{auto rankPrf : n = S $ rank right}\n -> Heap constraint (S $ countLeft + countRight)\n\n Fits : {constraint : Ordered a rel} -> a -> Heap constraint cnt -> Type\n Fits {cnt = Z} _ _ = ()\n Fits {cnt = S _} x h = rel x (findMin h)\n\n rank : Heap _ _ -> Nat\n rank Empty = Z\n rank (Node _ _ _ right) = S $ rank right\n\n export\n findMin : .{constraint : Ordered a _} -> Heap constraint (S _) -> a\n findMin (Node _ value _ _) = value\n\nexport\nempty : Heap _ Z\nempty = Empty\n\nmakeFit : .{constraint : Ordered a rel}\n -> .(fitsValue : a)\n -> (value : a)\n -> {count1 : Nat}\n -> {count2 : Nat}\n -> (h1 : Heap constraint count1)\n -> (h2 : Heap constraint count2)\n -> .{auto fits1 : Fits value h1}\n -> .{auto fits2 : Fits value h2}\n -> .{auto relPrf : rel fitsValue value}\n -> Subset (Heap constraint (S $ count1 + count2)) (Fits fitsValue)\nmakeFit {count1} {count2} {relPrf} fitsValue value h1 h2 with (order {to = LTE} (rank h1) (rank h2))\n | (Left _) = rewrite plusCommutative count1 count2 in\n Element (Node _ value h2 h1) relPrf\n | (Right _) = Element (Node _ value h1 h2) relPrf\n\ncovering\nmergeHelper : .{constraint : Ordered a rel}\n -> .{value : a}\n -> {count1 : Nat}\n -> {count2 : Nat}\n -> (h1 : Heap constraint count1)\n -> (h2 : Heap constraint count2)\n -> .{auto fits1 : Fits value h1}\n -> .{auto fits2 : Fits value h2}\n -> Subset (Heap constraint (count1 + count2)) (Fits value)\nmergeHelper Empty Empty = Element Empty ()\nmergeHelper {fits1} h@(Node {countLeft} {countRight} n _ _ _) Empty = rewrite plusZeroRightNeutral (countLeft + countRight) in Element h fits1\nmergeHelper {fits2} Empty h@(Node {countLeft} {countRight} n _ _ _) = Element h fits2\nmergeHelper {value} {rel}\n (Node {countLeft = countLeft1} {countRight = countRight1} _ value1 left1 right1)\n (Node {countLeft = countLeft2} {countRight = countRight2} _ value2 left2 right2)\n = case order {to = rel} value1 value2 of\n Left orderPrf => rewrite sym $ plusAssociative countLeft1 countRight1 (S $ countLeft2 + countRight2) in\n let (Element mergedHeap fitsMergedHeap) = mergeHelper {value = value1} right1 (Node _ value2 left2 right2) in\n makeFit value value1 left1 mergedHeap\n Right orderPrf => rewrite sym $ plusSuccRightSucc (countLeft1 + countRight1) (countLeft2 + countRight2) in\n rewrite plusCommutative countLeft2 countRight2 in\n rewrite plusAssociative (countLeft1 + countRight1) countRight2 countLeft2 in\n let (Element mergedHeap fitsMergedHeap) = mergeHelper {value = value2} (Node _ value1 left1 right1) right2 in\n makeFit value value2 mergedHeap left2\n\nexport\nmerge : .{constraint : Ordered a rel}\n -> {count1 : Nat} -> {count2 : Nat}\n -> (h1 : Heap constraint count1) -> (h2 : Heap constraint count2)\n -> Heap constraint (count1 + count2)\nmerge Empty Empty = Empty\nmerge {count1} h Empty = rewrite plusZeroRightNeutral count1 in h\nmerge Empty h = h\nmerge h1@(Node _ _ _ _) h2@(Node _ _ _ _)\n = assert_total $ case order {to = rel} (findMin h1) (findMin h2) of\n Left orderPrf => case mergeHelper {value = (findMin h1)} h1 h2 {fits1 = reflexive (findMin h1)} of\n Element h _ => h\n Right orderPrf => case mergeHelper {value = (findMin h2)} h1 h2 {fits2 = reflexive (findMin h2)} of\n Element h _ => h\n\nexport\ninsert : .{constraint : Ordered a _} -> .{n : Nat} -> a -> Heap constraint n -> Heap constraint (S n)\ninsert value heap = merge (Node 1 value Empty Empty) heap\n\nexport\ndeleteMin : .{constraint : Ordered a _} -> {n : Nat} -> Heap constraint (S n) -> Heap constraint n\ndeleteMin (Node _ _ left right) = merge left right\n\nnamespace OrderedLeftistHeap\n export\n data CountedHeap : .(constraint : Ordered a rel) -> Type where\n MkCountedHeap : (n : Nat) -> (Heap constraint n) -> CountedHeap constraint\n\n export\n empty : CountedHeap _\n empty = MkCountedHeap Z empty\n\n export\n count : CountedHeap _ -> Nat\n count (MkCountedHeap n _) = n\n\n export\n findMin : .{constraint : Ordered ty _} -> CountedHeap constraint -> Maybe ty\n findMin (MkCountedHeap Z _) = Nothing\n findMin (MkCountedHeap (S _) h) = Just $ findMin h\n\n export\n merge : .{constraint : Ordered _ _} -> CountedHeap constraint -> CountedHeap constraint -> CountedHeap constraint\n merge (MkCountedHeap count1 h1) (MkCountedHeap count2 h2) = MkCountedHeap (count1 + count2) (merge h1 h2)\n\n export\n insert : .{constraint : Ordered ty _} -> ty -> CountedHeap constraint -> CountedHeap constraint\n insert a (MkCountedHeap n h) = MkCountedHeap (S n) (insert a h)\n\n export\n deleteMin : .{constraint : Ordered ty _} -> CountedHeap constraint -> CountedHeap constraint\n deleteMin orig@(MkCountedHeap Z h) = orig\n deleteMin (MkCountedHeap (S n) h) = MkCountedHeap n (deleteMin h)\n", "meta": {"hexsha": "b8106715118eed03de540c727e221362fabd766b", "size": 5585, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Data/LeftistHeap.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/LeftistHeap.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/LeftistHeap.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": 41.6791044776, "max_line_length": 142, "alphanum_fraction": 0.6293643688, "num_tokens": 1626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6642832452593829}} {"text": "\nimport Data.Vect\n\n\nallLengths : Vect l String -> Vect l Nat\nallLengths [] = []\nallLengths (x :: xs) = length x :: allLengths xs\n\n\ninsert : Ord elem => (x : elem) -> (xsSorted : Vect len elem) -> Vect (S len) elem\ninsert x [] = [x]\ninsert x (y :: xs) = case x < y of\n False => y :: insert x xs\n True => x :: y :: xs\n\n\ninsSort : Ord elem => Vect n elem -> Vect n elem\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insert x xsSorted\n\n\nmyLength : List a -> Nat\nmyLength [] = 0\nmyLength (x :: xs) = 1 + myLength xs\n\nmyRev : List a -> List a\nmyRev [] = []\nmyRev (x :: xs) = myRev xs ++ [x]\n\nmyMap : (a -> b) -> List a -> List b\nmyMap f [] = []\nmyMap f (x :: xs) = f x :: map f xs\n\nvecMap : (a -> b) -> Vect n a -> Vect n b\nvecMap f [] = []\nvecMap f (x :: xs) = f x :: vecMap f xs\n", "meta": {"hexsha": "b3b522ed813967cc8dcd15a83c6a06803ea964dc", "size": 868, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter3/WordLengthvec.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": "Chapter3/WordLengthvec.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": "Chapter3/WordLengthvec.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": 22.8421052632, "max_line_length": 82, "alphanum_fraction": 0.5069124424, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6636810704491741}} {"text": "> module InfiniteHorizonSequentialDecisionProblems.Theory\n\n> import Data.Vect\n\n> import Finite.Predicates\n> import Finite.Operations\n> import Finite.Properties\n> import Vect.Operations\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Sequential decision processes\n\n> State : Type\n> Ctrl : (x : State) -> Type\n> M : Type -> Type\n> nexts : (x : State) -> (y : Ctrl x) -> M State\n> fmap : {A, B : Type} -> (A -> B) -> M A -> M B\n\n\n* Sequential decision problems\n\n> Val : Type\n> reward : (x : State) -> (y : Ctrl x) -> (x' : State) -> Val\n> plus : Val -> Val -> Val\n> LTE : Val -> Val -> Type\n> meas : M Val -> Val\n\n\n* Policies\n\n> Policy : Type\n> Policy = (x : State) -> Ctrl x\n\n\n* The value of policies\n\n> ||| A value function ...\n> val : State -> Policy -> Val\n\n> ||| ... that fulfils the specification\n> valSpec : Type\n> valSpec = (x : State) -> (p : Policy) -> \n> val x p \n> = \n> meas (fmap (\\ x' => reward x (p x) x' `plus` val x' p) (nexts x (p x)))\n\n\n* Optimality of policies\n\n> |||\n> Opt : Policy -> Type\n> Opt p = (x : State) -> (p' : Policy) -> val x p' `LTE` val x p\n\n\n* Optimal policies\n\n> ||| \n> cval : (x : State) -> Ctrl x -> (p : Policy) -> Val\n> cval x y p = meas (fmap (\\ x' => reward x y x' `plus` val x' p) (nexts x y))\n\n> cvalargmax : (x : State) -> (p : Policy) -> Ctrl x\n\n> ||| A policy ...\n> opt : Policy\n\n> ||| ... that fulfils Bellman's equation\n> optSpec : Type\n> optSpec = (x : State) -> opt x = cvalargmax x opt \n\n\n* Optimality of |opt|\n\n** Additional assumptions\n\n> reflexiveLTE : (a : Val) -> a `LTE` a\n> transitiveLTE : {a, b, c : Val} -> a `LTE` b -> b `LTE` c -> a `LTE` c\n> monotonePlusLTE : {a, b, c, d : Val} -> a `LTE` b -> c `LTE` d -> (a `plus` c) `LTE` (b `plus` d)\n> measMon : {A : Type} ->\n> (f : A -> Val) -> (g : A -> Val) ->\n> ((a : A) -> (f a) `LTE` (g a)) ->\n> (ma : M A) -> meas (fmap f ma) `LTE` meas (fmap g ma)\n\n> cvalmax : (x : State) -> (p : Policy) -> Val\n> cvalargmaxSpec : (x : State) -> (p : Policy) -> cvalmax x p = cval x (cvalargmax x p) p\n> cvalmaxSpec : (x : State) -> (y : Ctrl x) -> (p : Policy) -> (cval x y p) `LTE` (cvalmax x p)\n\n\n** |opt| is optimal\n\n> mutual\n\n> ||| ... is an optimal policy\n> optLemma1 : (vs : valSpec) -> (os : optSpec) ->\n> (x : State) -> (y : Ctrl x) -> (p : Policy) -> \n> cval x y p `LTE` cval x y opt\n> optLemma1 vs os x y p = s9 where\n> f' : State -> Val\n> f' = \\ x' => reward x y x' `plus` val x' p \n> f : State -> Val\n> f = \\ x' => reward x y x' `plus` val x' opt\n> s1 : (x' : State) -> val x' p `LTE` val x' opt\n> s1 x' = assert_total (optLemma2 vs os) x' p\n> s2 : (x' : State) -> (f' x') `LTE` (f x')\n> s2 x' = monotonePlusLTE (reflexiveLTE (reward x y x')) (s1 x')\n> s3 : meas (fmap f' (nexts x y)) `LTE` meas (fmap f (nexts x y))\n> s3 = measMon f' f s2 (nexts x y)\n> s9 : cval x y p `LTE` cval x y opt\n> s9 = s3\n\n> ||| ... is an optimal policy\n> optLemma2 : (vs : valSpec) -> (os : optSpec) -> Opt opt\n> optLemma2 vs os x p' = s9 where\n> s1 : val x p' = cval x (p' x) p'\n> s1 = vs x p'\n> s2 : cval x (p' x) p' `LTE` cval x (p' x) opt\n> s2 = assert_total optLemma1 vs os x (p' x) p'\n> s3 : cval x (p' x) opt `LTE` cvalmax x opt\n> s3 = cvalmaxSpec x (p' x) opt\n> s4 : cvalmax x opt = cval x (cvalargmax x opt) opt\n> s4 = cvalargmaxSpec x opt\n> s5 : cval x (cvalargmax x opt) opt = cval x (opt x) opt\n> s5 = replace {P = \\ U => cval x U opt = cval x (opt x) opt} (os x) Refl\n> s6 : cval x (opt x) opt = val x opt\n> s6 = sym (vs x opt)\n> s7 : cval x (p' x) p' `LTE` cvalmax x opt\n> s7 = transitiveLTE s2 s3\n> s8 : val x p' `LTE` cvalmax x opt\n> s8 = replace {P = \\ W => W `LTE` cvalmax x opt} (sym s1) s7\n> s9 : val x p' `LTE` val x opt\n> s9 = replace {P = \\ W => val x p' `LTE` W} (trans (trans s4 s5) s6) s8\n\n\n* Can one compute optimal policies?\n\nIf |State| is finite\n\n> finiteState : Finite State\n\nwe can compute the number of values of type |State| and collect them in\na vector\n\n> cardState : Nat\n> cardState = card finiteState\n\n> vectState : Vect cardState State\n> vectState = toVect finiteState\n\nFor a fixed policy |p|, we can represent the value of |p| by a value table\n\n> vt : Policy -> Vect cardState Val\n\n> val x p = index k (vt p) where\n> k : Fin cardState\n> k = lookup x vectState (toVectComplete finiteState x)\n\nIn this case, the specification of |val| \n\n< valSpec = (x : State) -> (p : Policy) -> \n< val x p \n< = \n< meas (fmap (\\ x' => reward x (p x) x' `plus` val x' p) (nexts x (p x)))\n\ndefines a linear, implicit problem for the components |vt p|. Let\n\n\n\n\n\n> {-\n\n> ---}\n\n\n", "meta": {"hexsha": "2774f829ebb306aaf91dd5a531c976a13a87a3f5", "size": 4958, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "InfiniteHorizonSequentialDecisionProblems/Theory.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": "InfiniteHorizonSequentialDecisionProblems/Theory.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": "InfiniteHorizonSequentialDecisionProblems/Theory.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.8539325843, "max_line_length": 101, "alphanum_fraction": 0.5149253731, "num_tokens": 1823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6635516024346779}} {"text": "{-------------------------------------------------------------\n Equivlance relation rules mod n.\n-------------------------------------------------------------}\n\n|||\n||| ModEq n x y is (aweful) prefix notation for a type x == y (mod n).\n|||\n||| This is a singleton dependent type, and it is inhabited solely\n||| by its constructor. So you can pattern match on tye constructor\n||| by there are no values.\n|||\ndata ModEq : (n:Nat) -> (x:Nat) -> (y:Nat) -> Type where\n {- 3 constructors, we mostly think of n, x, y as implicit.\n reflexive: x==x (mod n), \n left-induct: x == y (mod n) => x+n == y (mod n)\n right-induct: x == y (mod n) => x == (y+n) (mod n)\n -}\n Reflex : (x:Nat) -> ModEq n x x --- Needs syntatic sugar, for now prefix\n LInd : (ModEq n x y) -> ModEq n (x+n) y\n RInd : (ModEq n x y) -> ModEq n x (y+n)\n\n{- Proof of reflexive property. -}\ntotal\nisRefl : (x:Nat) -> ModEq n x x\nisRefl x = Reflex x\n\n{----- Proof of symmetric property. -----}\ntotal\nisSym : (ModEq n x y) -> ModEq n y x\n{- x=x => x=x -}\nisSym (Reflex x) = Reflex x\n{- \n (LInd (x=y=>(x+n)=y) \n & u={x=y}) \n -------------------\n u={x=y}\n ------------------\n y=x (induct on u) \n ------------------\n RInd y=x = y=(x+n) \n -}\nisSym (LInd u) = RInd (isSym u) \n{- x=(y+n) => u={x=y} => y=x (induct) => (y+n)=x -}\nisSym (RInd u) = LInd (isSym u) \n\n{----- Proof of transitive property. -----}\ntotal isTrans : (ModEq n x y) -> (ModEq n y z) -> (ModEq n x z)\n--isTrans (RInd _) (LInd _) = ?isTrans_rhs_1\n{- x=x & x=y => x=y -}\nisTrans (Reflex x) v = v\nisTrans u (Reflex y) = u\n{- ((x=y=>(x+n)=y) & y=z) => x=y & y=z => x=z (induct) => (x+n)=z -}\nisTrans (LInd u) v = LInd (isTrans u v)\nisTrans u (RInd v) = RInd (isTrans u v)\n{- (x=y=>x=(y+n)) & (y=z=>(y+n)=z) => x=y & y=z => x=z (induct) -}\nisTrans (RInd u) (LInd v) {n} {x} {y=x+n} = isTrans u v -- Note: need to expose implicit y=x+n\n\n{----- Proof of congruence property. -----}\ntotal isCong : (ModEq n x y) -> (ModEq n a b) -> (ModEq n (x+a) (y+b))\nisCong (Reflex x) (Reflex a) = Reflex (x+a)\nisCong {n} (LInd {x} u) (Reflex a) = \n {-\n (x+n) == y (mod n) because u={x == y (mod n)}\n a == a (mod n)\n ---------------------------------------------\n x+a == y+a (mod n) (induct)\n ---------------------------------------------\n (x+a)+n == y+a (mod n) (LInd)\n ---------------------------------------------\n x+(a+n) == y+a (mod n) (Associative)\n ---------------------------------------------\n x+(n+a) == y+a (mod n) (Commutative)\n ---------------------------------------------\n (x+n)+a == y+a (mod n) (Associative)\n -}\n let w = (x+a)+n in LInd (isCong u (Reflex a))\n rewrite plusCommutative n x in \n rewrite plusAssociative n x a in \n rewrite plusAssociative (x+a) n in w\n \nisCong {n} (RInd {y} u) (Reflex a) = \n-- rewrite plusAssociative y n a in \n rewrite plusCommutative a n in \n rewrite plusAssociative y a n in\n RInd (isCong u (Reflex a))\nisCong {n} {x} u (LInd {x=a} v) = -- imiplicitly need n, x, a in scope.\n {- \n u={x == y (mod n) }\n (a+n) == b only if, v={a==b}\n ----------------------\n x+a == y+b by induction on u, v\n ----------------------\n (x+a)+n == y+b by LInd\n x+(a+n) == y+b by associativity\n -}\n rewrite plusAssociative x a n in LInd (isCong u v)\nisCong {n} {y} u (RInd {y=b} v) = -- imiplicitly need n, x, a in scope.\n {- \n u={x == y (mod n) }\n a == (b+n) only if, v={a==b}\n ----------------------\n x+a == y+b by induction on u, v\n ----------------------\n x+a == (y+b)+n by RInd\n x+a == y+(b+n) by associativity\n -}\n rewrite plusAssociative y b n in RInd (isCong u v)\n", "meta": {"hexsha": "b068d0b3b05be059f3a6425621b59daffff4a809", "size": 3886, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/modular.idr", "max_stars_repo_name": "algeboy/BlackBoxType", "max_stars_repo_head_hexsha": "f8a7163086185953ef1dcc9216ee7a189f44b7ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/modular.idr", "max_issues_repo_name": "algeboy/BlackBoxType", "max_issues_repo_head_hexsha": "f8a7163086185953ef1dcc9216ee7a189f44b7ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/modular.idr", "max_forks_repo_name": "algeboy/BlackBoxType", "max_forks_repo_head_hexsha": "f8a7163086185953ef1dcc9216ee7a189f44b7ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-30T23:33:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-30T23:33:41.000Z", "avg_line_length": 35.9814814815, "max_line_length": 95, "alphanum_fraction": 0.4302624807, "num_tokens": 1297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6635515929682297}} {"text": "module LeftistHeap\n\nimport Heap\n\n%default total\n%access private\n\nexport\ndata LeftistHeap a = E | T Int a (LeftistHeap a) (LeftistHeap a)\n\nrank : LeftistHeap a -> Int\nrank E = 0\nrank (T r _ _ _) = r\n\nmakeT : a -> LeftistHeap a -> LeftistHeap a -> LeftistHeap a\nmakeT x a b = if rank a >= rank b then T (rank b + 1) x a b\n else T (rank a + 1) x b a\n\nexport\nHeap LeftistHeap where\n empty = E\n isEmpty E = True\n isEmpty _ = False\n\n insert x h = merge (T 1 x E E) h\n\n merge h E = h\n merge E h = h\n merge h1@(T _ x a1 b1) h2@(T _ y a2 b2) =\n if x <= y then makeT x a1 (merge b1 h2)\n else makeT y a2 (merge h1 b2)\n\n findMin E = idris_crash \"empty heap\"\n findMin (T _ x a b) = x\n\n deleteMin E = idris_crash \"empty heap\"\n deleteMin (T _ x a b) = merge a b\n", "meta": {"hexsha": "873a356718e8a29df8971a9a41a20675b94b84fa", "size": 791, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/LeftistHeap.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/LeftistHeap.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/LeftistHeap.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": 20.8157894737, "max_line_length": 64, "alphanum_fraction": 0.6093552465, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6633822719086562}} {"text": "module Cic\n\nimport Bits\nimport Synchronous\nimport Unsigned\n\nimport Data.Bits\n\n%access export\n%default total\n\n-- See Hogenauer's 1981 paper \"An Economical Class of Digital Filters for\n-- Decimation and Interpolation\". All the equations are referenced against this\n-- paper\n\n--------------------------------------------------------------------------------\n-- CIC subcircuits\n--------------------------------------------------------------------------------\n\n||| Prune an `Unsigned n` down to a smaller `Unsigned m`\nprune : Unsigned n -> Unsigned m\nprune {n} {m} x = saturate . cast $\n shiftR (cast . cast {to=Double} $ cast x {to=Integer}) -- Horrible!\n (cast $ n `minus` m)\n\n||| Extend an `Unsigned n` up to a larger `Unsigned m`\nextend : Unsigned n -> Unsigned m\nextend = saturate . cast\n\n||| Integrator circuit\npartial\nintegrate : Stream (Unsigned n) -> Stream (Unsigned n)\nintegrate xs = liftA2 (addWrap) xs (delay 0 $ integrate xs)\n\n||| Boolean true every Rth cycle, starting at first cycle\neveryR : (r: Nat) -> Stream Bool\neveryR Z = pure False\neveryR (S j) = map (\\a=>modNatNZ a (S j) SIsNotZ == 0) $ counterFrom 0\n\n||| Downsampler circuit\ndownsample : (r: Nat) -> Stream a -> Stream (Maybe a)\ndownsample r = zipWith (\\e, x=>if e then Just x else Nothing) (everyR r)\n\n||| Comb filter circuit\ncomb : (m : Nat) -> Stream (Maybe (Unsigned n)) -> Stream (Maybe (Unsigned n))\ncomb _ xs = map (\\(a,b)=>map (`minusWrap` b) a) $\n zip xs (regMaybe 0 xs) -- TODO Delay by m... and get\n\n--------------------------------------------------------------------------------\n-- Wordlength calculations\n--------------------------------------------------------------------------------\n\n||| Recursive definition of a binomial coefficient\nnChooseK : (n: Nat) -> (k: Nat) -> Nat\nnChooseK n Z = 1\nnChooseK Z (S k) = 0\nnChooseK (S n) (S k) = if k>n then 0 else\n nChooseK n k + nChooseK n (S k)\n\n||| Helper to divide two `Nat`s safely, returning zero for division by zero\n||| (fight me, mathematicians)\ndivNatOrZero : Nat -> Nat -> Nat\ndivNatOrZero k Z = Z\ndivNatOrZero k (S j) = divNatNZ k (S j) SIsNotZ\n\nparameters (r, n, m : Nat)\n\n ||| Partial system function, $h_j(k)$ (Eq. 9b)\n hjk : (j, k : Nat) -> Integer\n hjk j k = case j <= n of\n True => sum $ map (\\l => pow (-1) l * cast (\n (nChooseK n l) *\n (nChooseK ((n `minus` j)+(k `minus` r*m*l)) (k `minus` r*m*l)))\n ) [0..(divNatOrZero k (r*m))]\n False => pow (-1) k * cast (nChooseK (minus (2*n+1) j) k)\n\n ||| Variance error gain for stage j, $F(j)$ (Eq. 16b)\n fj : (j : Nat) -> Double\n fj j = case j == (2*n+1) of\n True => 1.0\n False => sqrt . cast . sum $ map (\\k=>pow (hjk j k) 2) [0..((r*m `minus` 1) * n + j `minus` 1)]\n\n ||| Max unpruned wordlength, $B_{max}$ (Eq 12)\n bmax : (bin : Nat) -> Nat\n bmax bin = bin + clog2 (pow (r*m) n)\n\n ||| Error at output due to final rounding/truncation, $E_{2N+1}$ (Eq. 12)\n eT2n1 : (bin, bout : Nat) -> Integer\n eT2n1 bin bout = pow 2 $ bmax bin `minus` bout\n\n ||| Variance at output due to final rounding/truncation, $\\sigma_T_{2N+1}$ (Eq. 14)\n sigmaT2n1 : (bin, bout : Nat) -> Double\n sigmaT2n1 bin bout = sqrt $ cast (pow (eT2n1 bin bout) 2) / 12.0\n\n ||| Bits to prune at stage j, $B_j$ (Eq. 21).\n ||| We use log laws to avoid errors with an integer implementation of log2\n bj : (bin, bout, j : Nat) -> Nat\n bj bin bout j = flog2Approx $ (sigmaT2n1 bin bout) * (sqrt $ 6.0 / (cast n)) / fj j\n\n ||| Bits to keep at stage j\n cicAccPruned : (bin, bout, j : Nat) -> Nat\n cicAccPruned bin bout j = if j==0 then bmax bin else\n if j>=(2*n+1) then bout else\n bmax bin `minus` bj bin bout j\n\n--------------------------------------------------------------------------------\n-- CIC decimator\n--------------------------------------------------------------------------------\n\n ||| Recursive integrator chain\n partial --Because of integrate\n cicDecimateRecI : (bin, bout, j : Nat)\n -> Stream (Unsigned (cicAccPruned bin bout 0))\n -> Stream (Unsigned (cicAccPruned bin bout j))\n cicDecimateRecI bin bout Z = id\n cicDecimateRecI bin bout (S j) = map prune . integrate .\n cicDecimateRecI bin bout j\n\n ||| Recursive comb filter chain\n cicDecimateRecC : (bin, bout, j : Nat)\n -> Stream (Maybe (Unsigned (cicAccPruned bin bout n)))\n -> Stream (Maybe (Unsigned (cicAccPruned bin bout (j+n))))\n cicDecimateRecC bin bout Z = id\n cicDecimateRecC bin bout (S j) = map (map prune) . comb m .\n cicDecimateRecC bin bout j\n ||| CIC decimator circuit\n partial --Because of integrate\n cicDecimate : Stream (Unsigned bin) -> Stream (Maybe (Unsigned bout))\n cicDecimate {bin} {bout} =\n map (map prune) . -- Final truncation, after\n cicDecimateRecC bin bout n . -- Recursive comb steps, after\n downsample r . -- Downsample, after\n cicDecimateRecI bin bout n . -- Recursive integrate steps, after\n map (extend {m=cicAccPruned bin bout 0}) -- Input extend\n\n-- TODO Is it worth proving that cicAccPruned bin bout (2*n+1)) == bout?\n\n||| Example of calculating pruning for Hogenauer's design example (Section IV. D)\nmainBj : IO ()\nmainBj = print $ map (bj 25 4 1 16 16) [1..8]\n\n||| Example of simulating `cicDecimate`\npartial\nmainSim : IO ()\nmainSim = do let dut = cicDecimate {bin=8} {bout=8} 3 3 1\n let inp = map (\\t=> saturate {n=8} . cast $\n sin (t*2*pi/10.0) * 127 + 127 )\n $ counterFrom 0 {ty=Double}\n let out = take 40 $ simulate dut inp\n putStrLn . show $ zip (take 40 inp) out\n", "meta": {"hexsha": "771c36222122b06bc2e8a4f77dc8a0431609df83", "size": 5841, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Cic.idr", "max_stars_repo_name": "cramsay/idris_dsp_circuits", "max_stars_repo_head_hexsha": "d706aec31874ab57b24dd63e37076d3774922b3f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-03T15:50:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-03T15:50:57.000Z", "max_issues_repo_path": "src/Cic.idr", "max_issues_repo_name": "cramsay/idris_dsp_circuits", "max_issues_repo_head_hexsha": "d706aec31874ab57b24dd63e37076d3774922b3f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-06-03T16:46:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-03T16:46:47.000Z", "max_forks_repo_path": "src/Cic.idr", "max_forks_repo_name": "cramsay/idris_dsp_circuits", "max_forks_repo_head_hexsha": "d706aec31874ab57b24dd63e37076d3774922b3f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-03T16:00:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-03T16:00:33.000Z", "avg_line_length": 38.6821192053, "max_line_length": 101, "alphanum_fraction": 0.5435713063, "num_tokens": 1721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.663316467319021}} {"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\ntranspose : {m : Nat} -> Vect n (Vect m a) -> Vect m (Vect n a)\ntranspose [] = ?empties\ntranspose (x :: xs) = let xs_trans = transpose xs in\n ?transposeHelper\n", "meta": {"hexsha": "d3eb4aad7bee6b2a51f24ad40649f41562c6678b", "size": 308, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/interactive006/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/interactive006/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/interactive006/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.0, "max_line_length": 63, "alphanum_fraction": 0.5292207792, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6629714780866246}} {"text": "module Coinduction\n\ncorecord Stream a where\n head : a\n tail : Stream a\n \ntotal causal \nzeros : Stream Nat\n&head zeros = Z\n&tail zeros = zeros\n\ntotal causal \nrepeat : a -> Stream a\n&head repeat n = n\n&tail repeat n = repeat n\n\ntotal causal \nmap : (a -> b) -> Stream a -> Stream b\n&head map f s = f (head s)\n&tail map f s = map f (tail s)\n\ntotal causal \nnats : Stream Nat\n&head nats = Z\n&tail nats = map S nats\n\ntotal causal \nzipWith : (a -> b -> c) -> Stream a -> Stream b -> Stream c\n&head zipWith f s t = f (head s) (head t)\n&tail zipWith f s t = zipWith f (tail s) (tail t)\n\ntotal causal \nfib : Stream Nat\n&head fib = Z\n&head &tail fib = S Z\n&tail &tail fib = zipWith (+) fib (tail fib)\n\ntotal causal \nunfold : (s -> (a, s)) -> s -> Stream a\n&head unfold step x = fst (step x)\n&tail unfold step x = unfold step (snd (step x))\n\ntotal causal \ninterleave : Stream a -> Stream a -> Stream a\n&head interleave s t = head s\n&tail interleave s t = interleave t (tail s)\n\ntotal causal \ntoggle : Stream Nat\n&head toggle = Z\n&head &tail toggle = S Z\n&tail &tail toggle = toggle\n\ntotal causal \npaperfold : Stream Nat\n&head paperfold = Z\n&tail paperfold = interleave paperfold toggle\n\ntotal causal \npaperfold' : Stream Nat\npaperfold' = interleave toggle paperfold'\n\ntotal causal \ncycle : Nat -> Stream Nat\ncycle n = cycle' n n\n where\n total causal \n cycle' : Nat -> Nat -> Stream Nat\n &head cycle' Z m = Z\n &head cycle' (S n) m = (S n)\n &tail cycle' Z m = cycle' m m\n &tail cycle' (S n) m = cycle' n m\n \ntotal causal \nfac : Stream Nat\n&head fac = (S Z)\n&tail fac = (zipWith (*) (map S nats) fac)\n\ntotal causal \nmergef : (Nat -> Nat -> Stream Nat -> Stream Nat) -> \n Stream Nat -> Stream Nat -> Stream Nat\nmergef f s t = f (head s) (head t) (mergef f (tail s) (tail t))\n\ntotal causal\nprepend : List a -> Stream a -> Stream \nprepend [] s = s\nprepend (x ::xs) s = x :: (prepend xs s)\n\ncorecord Tree : Type -> Type where\n value : Tree a -> a\n left : Tree a -> Tree a\n right : Tree a -> Tree a\n \ntotal causal \ntmap : (a -> b) -> Tree a -> Tree b\n&value tmap f t = f (value t)\n&left tmap f t = tmap f (left t)\n&right tmap f t = tmap f (right t)\n\ntotal causal \ntzip : (a -> b -> c) -> Tree a -> Tree b -> Tree c\n&value tzip f t r = f (value t) (value r)\n&left tzip f t r = tzip f (left t) (left r)\n&right tzip f t r = tzip f (right t) (right r)\n\ntotal causal \ntrepeat : a -> Tree a\n&value trepeat n = n\n&left trepeat n = trepeat n\n&right trepeat n = trepeat n\n\ntotal causal \ncarry : Tree Nat\n&value carry = S Z\n&left carry = trepeat Z\n&right carry = tmap S carry\n\ntotal causal unfoldTree : (s -> (a, s, s)) -> s -> Tree a\n&value unfoldTree step x = fst' (step x)\n&left unfoldTree step x = unfoldTree step (snd' (step x))\n&right unfoldTree step x = unfoldTree step (trd' (step x))\n\n\n\n\ntotal causal \ncalculateWilfully : Tree (Nat, Nat)\ncalculateWilfully = grow((S Z), (S Z))\n where\n total causal \n grow : (Nat, Nat) -> Tree(Nat, Nat)\n grow (n, d) = MkTree (n, d) (grow(n, n + d)) (grow(n + d, d))\n\ncorecord Partiality : Type -> Type where\n p : Partiality a -> Either a (Partiality a)\n constructor P\n \ntotal causal \nnever : Partiality a\nnever = P (Right never)\n\ntotal causal \nbind : Partiality a -> (a -> Partiality b) -> Partiality b\nbind (P (Left x)) f = f x\nbind (P (Right x)) f = P (Right (bind x f))\n\ncorecord FunMachine : Type -> Type where\n skip : FunMachine a -> FunMachine a\n calc : FunMachine a -> (a, FunMachine a)\n fun : FunMachine a -> (a -> a)\n \ntotal causal \nmultmachine : Stream Nat -> FunMachine Nat\n&skip multmachine s = multmachine (tail s)\n&calc multmachine s = \n (fun (multmachine $ tail s) (head s) , \n multmachine $ tail s)\n&fun multmachine s = (*) (head s)\n\ndata Response = OK | BadRequest\n\ntotal\nreject : a -> Response\nreject _ = BadRequest\n\ntotal causal \npingserver : FunMachine Response\n&skip pingserver = pingserver\n&calc pingserver = (OK, pingserver)\n&fun pingserver = reject\n\n\ncorecord Idler : Type -> Type where\n idle : Idler a -> Idler a\n stop : Idler a -> a\n \ntotal causal \npingserver' : Idler Response\n&idle pingserver' = pingserver'\n&stop pingserver' = OK\n\nping' : Response\nping' = stop (idle (idle pingserver'))\n\ntotal causal \nimap : (a -> b) -> Idler a -> Idler b\n&idle imap f i = imap f (idle i)\n&stop imap f i = f (stop i)\n\ntotal causal \ncounter : Nat -> Idler Nat\n&idle counter n = imap S (counter n) \n&stop counter n = n\n", "meta": {"hexsha": "56e87f34dd3373ea589bc4e8fc3ec86c029a7ac3", "size": 4455, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples/CoinductionExamplesReport.idr", "max_stars_repo_name": "sualitu/thesis", "max_stars_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/CoinductionExamplesReport.idr", "max_issues_repo_name": "sualitu/thesis", "max_issues_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "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/CoinductionExamplesReport.idr", "max_forks_repo_name": "sualitu/thesis", "max_forks_repo_head_hexsha": "22d2cb4f21dc7c2dab011da5bb560c003650a2bc", "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.9639175258, "max_line_length": 65, "alphanum_fraction": 0.6307519641, "num_tokens": 1422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6629280752746725}} {"text": "module Utils\n\nimport Data.Vect\n\ncycle : (xs : Vect (S n) a) -> Stream a\ncycle (x :: xs) = x :: cycle' xs\n where cycle' : Vect n a -> Stream a\n cycle' [] = x :: cycle' xs\n cycle' (y :: ys) = y :: cycle' ys\n\ntake' : (n : Nat) -> (xs : Stream a) -> Vect n a\ntake' Z _ = []\ntake' (S n) (x :: xs) = x :: (take' n xs)\n\nexport\nshift : Nat -> Vect n a -> Vect n a\nshift Z xs = xs\nshift (S k) [] = []\nshift {n = S m} (S k) (x :: xs) = take' (S m) $ drop (S k) $ cycle (x :: xs)\n\nexport\nmax' : Ord a => Vect (S n) a -> a\nmax' (x :: xs) = foldl max x xs\n\nexport\nmin' : Ord a => Vect (S n) a -> a\nmin' (x :: xs) = foldl min x xs\n\nexport\nallPairs : Vect (S n) a -> Vect (S n) (Vect n (a, a))\nallPairs {n} xs = g xs n where\n f : Vect (S n) a -> Vect n (a, a)\n f (x :: xs) = map (MkPair x) xs\n\n g : Vect (S n) a -> (m : Nat) -> Vect (S m) (Vect n (a, a))\n g xs Z = [f xs]\n g xs (S k) = (f $ shift (S k) xs) :: g xs k\n", "meta": {"hexsha": "88f2affbc6177303c64d51e9e9ac7af420dc89bd", "size": 929, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Utils.idr", "max_stars_repo_name": "tscholak/AoC2017", "max_stars_repo_head_hexsha": "983eda0e6260e9cb22577e5f055ba1442f1e36ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-04T13:14:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-04T13:14:53.000Z", "max_issues_repo_path": "Utils.idr", "max_issues_repo_name": "tscholak/AoC2017", "max_issues_repo_head_hexsha": "983eda0e6260e9cb22577e5f055ba1442f1e36ee", "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": "Utils.idr", "max_forks_repo_name": "tscholak/AoC2017", "max_forks_repo_head_hexsha": "983eda0e6260e9cb22577e5f055ba1442f1e36ee", "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.4473684211, "max_line_length": 76, "alphanum_fraction": 0.4822389666, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6629280708211625}} {"text": "module Algebra.Solver.Ring.Expr\n\nimport public Data.List.Elem\nimport public Algebra.Ring\nimport Syntax.PreorderReasoning\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Natural Numbers\n--------------------------------------------------------------------------------\n\n||| Multiplies a value `n` times with itself. In case of `n`\n||| being zero, this returns `1`.\npublic export\npow : Ring a => a -> Nat -> a\npow x 0 = 1\npow x (S k) = x * pow x k\n\n--------------------------------------------------------------------------------\n-- Expression\n--------------------------------------------------------------------------------\n\n||| Data type representing expressions in a commutative ring.\n|||\n||| This is used to at compile time compare different forms of\n||| the same expression and proof that they evaluate to\n||| the same result.\n|||\n||| An example:\n|||\n||| ```idris example\n||| 0 binom1 : {x,y : Bits8} -> (x + y) * (x + y) === x * x + 2 * x * y + y * y\n||| binom1 = solve [x,y]\n||| ((x .+. y) * (x .+. y))\n||| (x .*. x + 2 *. x *. y + y .*. y)\n||| ```\n|||\n||| @ a the type used in the arithmetic expression\n||| @ as list of variables which don't reduce at compile time\n|||\n||| In the example above, `x` and `y` are variables, while `2`\n||| is a literal known at compile time. To make working with\n||| variables more convenient (the have to be wrapped in data\n||| constructor `Var`, by using function `var` for instance),\n||| additional operators for addition, multiplication, and\n||| subtraction are provided.\n|||\n||| In order to proof that two expressions evaluate to the\n||| same results, the following steps are taken at compile\n||| time:\n|||\n||| 1. Both expressions are converted to a normal form via\n||| `Algebra.Solver.Ring.Sum.normalize`.\n||| 2. The normal forms are compared for being identical.\n||| 3. Since in `Algebra.Solver.Ring.Sum` there is a proof that\n||| converting an expression to its normal form does not\n||| affect the result when evaluating it, if the normal\n||| forms are identical, the two expressions must evaluate\n||| to the same result.\n|||\n||| You can find several examples of making use of this\n||| in `Data.Prim.Integer.Extra`.\npublic export\ndata Expr : (a : Type) -> (as : List a) -> Type where\n ||| A literal. This should be a value known at compile time\n ||| so that it reduces during normalization.\n Lit : (v : a) -> Expr a as\n\n ||| A variabl. This is is for values not known at compile\n ||| time. In order to compare and merge variables, we need an\n ||| `Elem x as` proof.\n Var : (x : a) -> Elem x as -> Expr a as\n\n ||| Negates and expression.\n Neg : Expr a as -> Expr a as\n\n ||| Addition of two expressions.\n Plus : (x,y : Expr a as) -> Expr a as\n\n ||| Multiplication of two expressions.\n Mult : (x,y : Expr a as) -> Expr a as\n\n ||| Subtraction of two expressions.\n Minus : (x,y : Expr a as) -> Expr a as\n\n||| While this allows you to use the usual operators\n||| for addition and multiplication, it is often convenient\n||| to use related operators `.*.`, `.+.`, and similar when\n||| working with variables.\npublic export\nNum a => Num (Expr a as) where\n (+) = Plus\n (*) = Mult\n fromInteger = Lit . fromInteger\n\npublic export\nNeg a => Neg (Expr a as) where\n negate = Neg\n (-) = Minus\n\n||| Like `Var` but takes the `Elem x as` as an auto implicit\n||| argument.\npublic export\nvar : {0 as : List a} -> (x : a) -> Elem x as => Expr a as\nvar x = Var x %search\n\n--------------------------------------------------------------------------------\n-- Syntax\n--------------------------------------------------------------------------------\n\ninfixl 8 .+., .+, +.\n\ninfixl 8 .-., .-, -.\n\ninfixl 9 .*., .*, *.\n\n||| Addition of variables. This is an alias for\n||| `var x + var y`.\npublic export\n(.+.) : {0 as : List a}\n -> (x,y : a)\n -> Elem x as\n => Elem y as\n => Expr a as\n(.+.) x y = Plus (var x) (var y)\n\n||| Addition of variables. This is an alias for\n||| `x + var y`.\npublic export\n(+.) : {0 as : List a}\n -> (x : Expr a as)\n -> (y : a)\n -> Elem y as\n => Expr a as\n(+.) x y = Plus x (var y)\n\n||| Addition of variables. This is an alias for\n||| `var x + y`.\npublic export\n(.+) : {0 as : List a}\n -> (x : a)\n -> (y : Expr a as)\n -> Elem x as\n => Expr a as\n(.+) x y = Plus (var x) y\n\n||| Subtraction of variables. This is an alias for\n||| `var x - var y`.\npublic export\n(.-.) : {0 as : List a}\n -> (x,y : a)\n -> Elem x as\n => Elem y as\n => Expr a as\n(.-.) x y = Minus (var x) (var y)\n\n||| Subtraction of variables. This is an alias for\n||| `x - var y`.\npublic export\n(-.) : {0 as : List a}\n -> (x : Expr a as)\n -> (y : a)\n -> Elem y as\n => Expr a as\n(-.) x y = Minus x (var y)\n\n||| Subtraction of variables. This is an alias for\n||| `var x - y`.\npublic export\n(.-) : {0 as : List a}\n -> (x : a)\n -> (y : Expr a as)\n -> Elem x as\n => Expr a as\n(.-) x y = Minus (var x) y\n\n||| Multiplication of variables. This is an alias for\n||| `var x * var y`.\npublic export\n(.*.) : {0 as : List a}\n -> (x,y : a)\n -> Elem x as\n => Elem y as\n => Expr a as\n(.*.) x y = Mult (var x) (var y)\n\n||| Multiplication of variables. This is an alias for\n||| `var x * y`.\npublic export\n(*.) : {0 as : List a}\n -> (x : Expr a as)\n -> (y : a)\n -> Elem y as\n => Expr a as\n(*.) x y = Mult x (var y)\n\n||| Multiplication of variables. This is an alias for\n||| `x * var y`.\npublic export\n(.*) : {0 as : List a}\n -> (x : a)\n -> (y : Expr a as)\n -> Elem x as\n => Expr a as\n(.*) x y = Mult (var x) y\n\n--------------------------------------------------------------------------------\n-- Evaluation\n--------------------------------------------------------------------------------\n\n||| Evaluation of expressions. This keeps the exact\n||| structure of the expression tree. For instance\n||| `eval $ x .*. (y .+. z)` evaluates to `x * (y + z)`.\npublic export\neval : Ring a => Expr a as -> a\neval (Lit v) = v\neval (Var x y) = x\neval (Neg v) = neg $ eval v\neval (Plus x y) = eval x + eval y\neval (Mult x y) = eval x * eval y\neval (Minus x y) = eval x - eval y\n\n--------------------------------------------------------------------------------\n-- Proofs\n--------------------------------------------------------------------------------\n\n||| Proof that addition of exponents is equivalent to multiplcation\n||| of the two terms.\nexport\n0 ppow : Ring a\n => (m,n : Nat)\n -> (x : a)\n -> pow x (m + n) === pow x m * pow x n\nppow 0 n x = sym multOneLeftNeutral\nppow (S k) n x = Calc $\n |~ x * pow x (plus k n)\n ~~ x * (pow x k * pow x n) ... cong (x*) (ppow k n x)\n ~~ (x * pow x k) * pow x n ... multAssociative\n", "meta": {"hexsha": "fc6fbf26b734f63ea0dd6730ea5a2daf0e427fe4", "size": 6861, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Solver/Ring/Expr.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/Ring/Expr.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/Ring/Expr.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": 28.5875, "max_line_length": 80, "alphanum_fraction": 0.4981781081, "num_tokens": 1966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6629068700807853}} {"text": "import Decidable.Equality\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\n-- the equalities below (i.e (x = y) -> Void ) get constrained \n-- to be the same value (i.e (x = x) -> Void )\n\nheadUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} ->\n (contra : (x = y) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\nheadUnequal contra Refl = contra Refl\n\ntailUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} ->\n (contra : (xs = ys) -> Void) -> ((x :: xs) = (y :: ys)) -> Void\ntailUnequal contra Refl = contra Refl\n\nDecEq a => DecEq (Vect n a) where\n decEq [] [] = Yes Refl\n decEq (x :: xs) (y :: ys) = \n case decEq x y of\n Yes Refl => case decEq xs ys of\n Yes Refl => Yes Refl\n No contra => No (tailUnequal contra)\n No contra => No (headUnequal contra)\n", "meta": {"hexsha": "8c00d14862a8b636052d8ee361e6e6b87cc82455", "size": 989, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch8/ex_8_3.idr", "max_stars_repo_name": "trevarj/tdd_idris_examples", "max_stars_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ch8/ex_8_3.idr", "max_issues_repo_name": "trevarj/tdd_idris_examples", "max_issues_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ch8/ex_8_3.idr", "max_forks_repo_name": "trevarj/tdd_idris_examples", "max_forks_repo_head_hexsha": "63a7128a797b64cb0ba54562778cdf9712b4d9f5", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6296296296, "max_line_length": 72, "alphanum_fraction": 0.4782608696, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6627946604558455}} {"text": "||| Properties of the reverse function.\nmodule Data.List.Reverse\n\nimport Data.Nat\nimport Data.List\nimport Data.List.Equalities\n\n%default total\n\nexport\nreverseOntoAcc : (xs, ys, zs : List a) ->\n reverseOnto (ys ++ zs) xs = (reverseOnto ys xs) ++ zs\nreverseOntoAcc [] _ _ = Refl\nreverseOntoAcc (x :: xs) (ys) (zs) = reverseOntoAcc xs (x :: ys) zs\n\n||| Serves as a specification for reverseOnto.\nexport\nreverseOntoSpec : (xs, ys : List a) -> reverseOnto xs ys = reverse ys ++ xs\nreverseOntoSpec xs ys = reverseOntoAcc ys [] xs\n\n||| The reverse of an empty list is an empty list. Together with reverseCons,\n||| serves as a specification for reverse.\nexport\nreverseNil : reverse [] = []\nreverseNil = Refl\n\n||| The reverse of a cons is the reverse of the tail followed by the head.\n||| Together with reverseNil serves as a specification for reverse.\nexport\nreverseCons : (x : a) -> (xs : List a) -> reverse (x::xs) = reverse xs `snoc` x\nreverseCons x xs = reverseOntoSpec [x] xs\n\n||| Reversing an append is appending reversals backwards.\nexport\nreverseAppend : (xs, ys : List a) ->\n reverse (xs ++ ys) = reverse ys ++ reverse xs\nreverseAppend [] ys = sym (appendNilRightNeutral (reverse ys))\nreverseAppend (x :: xs) ys =\n rewrite reverseCons x (xs ++ ys) in\n rewrite reverseAppend xs ys in\n rewrite reverseCons x xs in\n sym $ appendAssociative (reverse ys) (reverse xs) [x]\n\n||| A slow recursive definition of reverse.\npublic export\n0 slowReverse : List a -> List a\nslowReverse [] = []\nslowReverse (x :: xs) = slowReverse xs `snoc` x\n\n||| The iterative and recursive defintions of reverse are the same.\nexport\nreverseEquiv : (xs : List a) -> slowReverse xs = reverse xs\nreverseEquiv [] = Refl\nreverseEquiv (x :: xs) =\n rewrite reverseEquiv xs in\n rewrite reverseAppend [x] xs in\n Refl\n\n||| Reversing a singleton list is a no-op.\nexport\nreverseSingletonId : (x : a) -> reverse [x] = [x]\nreverseSingletonId _ = Refl\n\n||| Reversing a reverse gives the original.\nexport\nreverseReverseId : (xs : List a) -> reverse (reverse xs) = xs\nreverseReverseId [] = Refl\nreverseReverseId (x :: xs) =\n rewrite reverseCons x xs in\n rewrite reverseAppend (reverse xs) [x] in\n rewrite reverseReverseId xs in\n Refl\n\n||| Reversing onto preserves list length.\nexport\nreverseOntoLength : (xs, acc : List a) ->\n length (reverseOnto acc xs) = length acc + length xs\nreverseOntoLength [] acc = rewrite plusZeroRightNeutral (length acc) in Refl\nreverseOntoLength (x :: xs) acc =\n rewrite reverseOntoLength xs (x :: acc) in\n plusSuccRightSucc (length acc) (length xs)\n\n||| Reversing preserves list length.\nexport\nreverseLength : (xs : List a) -> length (reverse xs) = length xs\nreverseLength xs = reverseOntoLength xs []\n\n||| Equal reversed lists are equal.\nexport\nreverseEqual : (xs, ys : List a) -> reverse xs = reverse ys -> xs = ys\nreverseEqual xs ys prf =\n rewrite sym $ reverseReverseId xs in\n rewrite prf in\n reverseReverseId ys\n", "meta": {"hexsha": "a3479b939d201e9e31d97770918a8841cb8f874f", "size": 2959, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/List/Reverse.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/libs/contrib/Data/List/Reverse.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/libs/contrib/Data/List/Reverse.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.1473684211, "max_line_length": 79, "alphanum_fraction": 0.7019263265, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.662626871023388}} {"text": "-- Tree.idr\n--\n-- Demonstates generic data types\n\nmodule Tree\n\n||| A binary tree\npublic export\ndata Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n\n%name Tree tree, tree1\n\n||| Inserts a new element into a binary search tree\nexport\ninsert : Ord elem => elem -> Tree elem -> Tree elem\ninsert x Empty = Node Empty x Empty\ninsert x (Node left val right) = case compare x val of\n LT => Node (insert x left) val right\n EQ => Node left val right\n GT => Node left val (insert x right)\n\n\n\n", "meta": {"hexsha": "f626d07d24f091b88c2aa4c17aec906b8a652be5", "size": 613, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Idris/TDD/Chapter_4/Tree.idr", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Idris/TDD/Chapter_4/Tree.idr", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Idris/TDD/Chapter_4/Tree.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.52, "max_line_length": 74, "alphanum_fraction": 0.5513866232, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6625920057947896}} {"text": "module RationalSetoid\nimport Rational\nimport SignedInt\nimport Setoid\nimport SignedSetoid\nimport NatExtension\n\n%default total\n%access public export\n\nrationalReflx : Reflx RationalEq\nrationalReflx (MkRat a b) = RationalRefl (signedReflx (a $* (S b)))\n\nrationalSymm : Symm RationalEq\nrationalSymm (MkRat a1 b1) (MkRat a2 b2) (RationalRefl rr) = RationalRefl (signedSymm (a1 $* (S b2)) (a2 $* (S b1)) rr)\n\nrationalTrans : Trans RationalEq\nrationalTrans (MkRat (SInt p1 n1) b1) (MkRat (SInt p2 n2) b2) (MkRat (SInt p3 n3) b3)\n (RationalRefl (SignedRefl sr12)) (RationalRefl (SignedRefl sr23)) = RationalRefl (SignedRefl sr13)\n where\n _1 : (p1 * S b2) * S b3 + (n2 * S b1) * S b3 = (p2 * S b1) * S b3 + (n1 * S b2) * S b3\n _1 = trans (trans l_tr (cong {f = (* S b3)} sr12)) r_tr\n where\n l_tr : (p1 * S b2) * S b3 + (n2 * S b1) * S b3 = ((p1 * S b2) + (n2 * S b1)) * S b3\n l_tr = sym (multDistributesOverPlusLeft (p1 * S b2) (n2 * S b1) (S b3))\n\n r_tr : ((p2 * S b1) + (n1 * S b2)) * S b3 = (p2 * S b1) * S b3 + (n1 * S b2) * S b3\n r_tr = multDistributesOverPlusLeft (p2 * S b1) (n1 * S b2) (S b3)\n\n _2 : (p2 * S b3) * S b1 + (n3 * S b2) * S b1 = (p3 * S b2) * S b1 + (n2 * S b3) * S b1\n _2 = trans (trans l_tr (cong {f = (* S b1)} sr23)) r_tr\n where\n l_tr : (p2 * S b3) * S b1 + (n3 * S b2) * S b1 = ((p2 * S b3) + (n3 * S b2)) * S b1\n l_tr = sym (multDistributesOverPlusLeft (p2 * S b3) (n3 * S b2) (S b1))\n\n r_tr : ((p3 * S b2) + (n2 * S b3)) * S b1 = (p3 * S b2) * S b1 + (n2 * S b3) * S b1\n r_tr = multDistributesOverPlusLeft (p3 * S b2) (n2 * S b3) (S b1)\n\n _3 : ((p1 * S b2) * S b3 + (n2 * S b1) * S b3) + ((p2 * S b3) * S b1 + (n3 * S b2) * S b1) =\n ((p2 * S b1) * S b3 + (n1 * S b2) * S b3) + ((p3 * S b2) * S b1 + (n2 * S b3) * S b1)\n _3 = rewrite _1 in rewrite _2 in Refl\n\n _4 : (p1 * S b2) * S b3 + (n3 * S b2) * S b1 = (n1 * S b2) * S b3 + (p3 * S b2) * S b1\n _4 = rewrite plusCommutative (p1 * S b2 * S b3) (n3 * S b2 * S b1) in _47\n where\n _41 : ((p1 * S b2) * S b3 + (n2 * S b1) * S b3) + ((p2 * S b3) * S b1 + (n3 * S b2) * S b1) =\n ((p2 * S b3) * S b1 + (n3 * S b2) * S b1) + ((p1 * S b2) * S b3 + (n2 * S b3) * S b1)\n _41 =\n rewrite sym $ multAssociative n2 (S b3) (S b1) in\n rewrite sym $ multAssociative n2 (S b1) (S b3) in\n rewrite sym $ multCommutative (S b3) (S b1) in\n rewrite plusCommutative ((p1 * S b2) * S b3 + n2 * (S (b1 + b3 * S b1))) ((p2 * S b3) * S b1 + (n3 * S b2) * S b1) in\n Refl\n\n _42 : ((p2 * S b3) * S b1 + (n3 * S b2) * S b1) + (p1 * S b2) * S b3 + (n2 * S b3) * S b1 =\n ((p2 * S b1) * S b3 + (n1 * S b2) * S b3) + (p3 * S b2) * S b1 + (n2 * S b3) * S b1\n _42 =\n rewrite sym $ plusAssociative ((p2 * S b3) * S b1 + (n3 * S b2) * S b1) ((p1 * S b2) * S b3) ((n2 * S b3) * S b1) in\n rewrite sym $ plusAssociative ((p2 * S b1) * S b3 + (n1 * S b2) * S b3) ((p3 * S b2) * S b1) ((n2 * S b3) * S b1) in\n rewrite sym _41 in\n _3\n\n _43 : (p2 * S b3) * S b1 + (n3 * S b2) * S b1 + (p1 * S b2) * S b3 =\n (p2 * S b1) * S b3 + (n1 * S b2) * S b3 + (p3 * S b2) * S b1\n _43 = plusRightCancel _ _ (n2 * S b3 * S b1) _42\n\n _44 : (p2 * S b3) * S b1 + ((n3 * S b2) * S b1 + (p1 * S b2) * S b3) =\n (p2 * S b1) * S b3 + ((n1 * S b2) * S b3 + (p3 * S b2) * S b1)\n _44 =\n rewrite plusAssociative ((p2 * S b3) * S b1) ((n3 * S b2) * S b1) ((p1 * S b2) * S b3) in\n rewrite plusAssociative ((p2 * S b1) * S b3) ((n1 * S b2) * S b3) ((p3 * S b2) * S b1) in\n _43\n\n _45 : (p2 * S b1) * S b3 + ((n3 * S b2) * S b1 + (p1 * S b2) * S b3) =\n (p2 * S b3) * S b1 + ((n3 * S b2) * S b1 + (p1 * S b2) * S b3)\n _45 =\n rewrite sym $ multAssociative p2 (S b1) (S b3) in\n rewrite multCommutative (S b1) (S b3) in\n rewrite multAssociative p2 (S b3) (S b1) in\n Refl\n\n _46 : (p2 * S b1) * S b3 + ((n3 * S b2) * S b1 + (p1 * S b2) * S b3) =\n (p2 * S b1) * S b3 + ((n1 * S b2) * S b3 + (p3 * S b2) * S b1)\n _46 = rewrite _45 in _44\n\n _47 : (n3 * S b2) * S b1 + (p1 * S b2) * S b3 =\n (n1 * S b2) * S b3 + (p3 * S b2) * S b1\n _47 = plusLeftCancel (p2 * S b1 * S b3) _ _ _46\n\n _5 : S b2 * (p1 * S b3 + n3 * S b1) = S b2 * (n1 * S b3 + p3 * S b1)\n _5 =\n rewrite multDistributesOverPlusRight (S b2) (p1 * S b3) (n3 * S b1) in\n rewrite multDistributesOverPlusRight (S b2) (n1 * S b3) (p3 * S b1) in\n rewrite takeY (S b2) p1 (S b3) in\n rewrite takeY (S b2) n1 (S b3) in\n rewrite takeY (S b2) p3 (S b1) in\n rewrite takeY (S b2) n3 (S b1) in\n _4\n\n sr13 : p1 * S b3 + n3 * S b1 = p3 * S b1 + n1 * S b3\n sr13 =\n rewrite plusCommutative (p3 * S b1) (n1 * S b3) in\n multLeftCancel _ _ _ _5\n\n\nRationalSetoid : Setoid\nRationalSetoid = MkSetoid Rational RationalEq (EqProof RationalEq rationalReflx rationalSymm rationalTrans)\n", "meta": {"hexsha": "fd2690f65939a11840afd441a60a04aeb9622229", "size": 5175, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "hw6/RationalSetoid.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/RationalSetoid.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/RationalSetoid.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": 47.9166666667, "max_line_length": 129, "alphanum_fraction": 0.4807729469, "num_tokens": 2378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6623899665187541}} {"text": "module UnivalenceFromScratch\n\n-- Based on http://www.cs.bham.ac.uk/~mhe/agda-new/UnivalenceFromScratch.html\n\ndata Sigma : (x : Type) -> (y : x -> Type) -> Type where\n Pair : (a : x) -> y a -> Sigma x y\n\n-- We need something like --without-K\ndata Id : {x : Type} -> x -> x -> Type where\n Refl : (a : x) -> Id a a\n\nJ : {x : Type} ->\n (alpha : (a, b : x) -> Id a b -> Type) ->\n ((a : x) -> alpha a a (Refl a)) ->\n (a, b : x) -> (p : Id a b) -> alpha a b p\nJ alpha f b b (Refl b) = f b\n\nisSingleton : Type -> Type\nisSingleton x = Sigma x (\\a => (b : x) -> Id a b)\n\nfiber : {x, y : Type} -> (x -> y) -> y -> Type\nfiber {x} f b = Sigma x (\\a => Id (f a) b)\n\nisEquiv : {x, y : Type} -> (x -> y) -> Type\nisEquiv {y} f = (b : y) -> isSingleton (fiber f b)\n\nEq : Type -> Type -> Type\nEq x y = Sigma (x -> y) (\\f => isEquiv f)\n\nsingletonType : {x : Type} -> x -> Type\nsingletonType {x} a = Sigma x (\\b => Id b a)\n\neta : {x : Type} -> (a : x) -> singletonType a\neta a = Pair a (Refl a)\n\nsingletonTypesAreSingletons : {x : Type} -> (a : x) -> isSingleton (singletonType a)\nsingletonTypesAreSingletons = h\n where\n alpha : (b, a : x) -> Id b a -> Type\n alpha b a p = Id (eta a) (Pair b p)\n f : (a : x) -> alpha a a (Refl a)\n f a = Refl (eta a)\n phi : (b, a : x) -> (p : Id b a) -> Id (eta a) (Pair b p)\n phi = J alpha f\n g : (a : x) -> (sigma : singletonType a) -> Id (eta a) sigma\n g a (Pair b p) = phi b a p\n h : (a : x) -> Sigma (singletonType a) (\\b => (sigma : singletonType a) -> Id b sigma)\n h a = Pair (eta a) (g a)\n\nid : (x : Type) -> x -> x\nid x a = a\n\nidIsEquiv : (x : Type) -> isEquiv (id x)\nidIsEquiv x = g\n where\n g : (a : x) -> isSingleton (fiber (id x) a)\n g = singletonTypesAreSingletons\n\nIdToEq : (x, y : Type) -> Id x y -> Eq x y\nIdToEq = J alpha f\n where\n alpha : (x, y : Type) -> Id x y -> Type\n alpha x y p = Eq x y\n f : (x : Type) -> alpha x x (Refl x)\n f x = Pair (id x) (idIsEquiv x)\n\nisUnivalent : Type\nisUnivalent = (x, y : Type) -> isEquiv (IdToEq x y)\n", "meta": {"hexsha": "d00e3203dd8df829bbbf9803a90a171a50a0c9a8", "size": 2023, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/UnivalenceFromScratch.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/UnivalenceFromScratch.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/UnivalenceFromScratch.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": 29.3188405797, "max_line_length": 90, "alphanum_fraction": 0.524468611, "num_tokens": 781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6623899575917748}} {"text": "module Data.List.Predicates.Unique\n\nimport public Data.List.NotElem\n\n%default total\n%access public export\n\ndata Unique : (prfSame : a -> a -> Type)\n -> (ns : List a)\n -> Type\n where\n Empty : Unique p Nil\n Extend : (node : a)\n -> (prfNotElem : NotElem p node ns)\n -> (rest : Unique p ns)\n -> Unique p (node :: ns)\n\nnodeIsFoundLater : (contra : NotElem prfSame x xs -> Void)\n -> Unique prfSame (x :: xs)\n -> Void\nnodeIsFoundLater contra (Extend x prfNotElem rest) = contra prfNotElem\n\nrestNotUnique : (contra : Unique prfSame xs -> Void)\n -> (prfX : NotElem prfSame x xs)\n -> Unique prfSame (x :: xs)\n -> Void\nrestNotUnique contra prfX (Extend x prfNotElem rest) = contra rest\n\nunique : (decEq : (x,y : a) -> Dec (prfSame x y))\n -> (xs : List a)\n -> Dec (Unique prfSame xs)\nunique decEq [] = Yes Empty\nunique decEq (x :: xs) with (notElem decEq x xs)\n unique decEq (x :: xs) | (Yes prfX) with (unique decEq xs)\n unique decEq (x :: xs) | (Yes prfX) | (Yes prfXS) = Yes (Extend x prfX prfXS)\n unique decEq (x :: xs) | (Yes prfX) | (No contra) = No (restNotUnique contra prfX)\n\n unique decEq (x :: xs) | (No contra) = No (nodeIsFoundLater contra)\n\ntoList : {ns : List a} -> Unique prfSame ns -> List a\ntoList Empty = []\ntoList (Extend node prfNotElem rest) = node :: toList rest\n\n-- --------------------------------------------------------------------- [ EOF ]\n", "meta": {"hexsha": "b445d3db06898873115fe968fef67ecde922f887", "size": 1497, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/List/Predicates/Unique.idr", "max_stars_repo_name": "witt3rd/idris-containers", "max_stars_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 99, "max_stars_repo_stars_event_min_datetime": "2015-03-01T20:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:17:39.000Z", "max_issues_repo_path": "Data/List/Predicates/Unique.idr", "max_issues_repo_name": "witt3rd/idris-containers", "max_issues_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2015-03-23T19:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T13:05:44.000Z", "max_forks_repo_path": "Data/List/Predicates/Unique.idr", "max_forks_repo_name": "witt3rd/idris-containers", "max_forks_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-06-02T17:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T14:51:07.000Z", "avg_line_length": 33.2666666667, "max_line_length": 86, "alphanum_fraction": 0.5591182365, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6623708090575303}} {"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 _) impossible \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 First 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)) First 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\ncoTransStepValueIrreducible : CoTransStep e1 e2 -> Value e1 -> e1 = e2\ncoTransStepValueIrreducible (CoTStRefl e1) v = Refl\ncoTransStepValueIrreducible (CoTStTrans st ctst) v = absurd $ valueIrreducible _ v st\n\n-- End: VALUE <=> IRREDUCIBLE\n-----------------------------\n\n\n\n", "meta": {"hexsha": "1e9c42296623cabc269274c90540a01eaff7996c", "size": 3970, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codata/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": "codata/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": "codata/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": 34.5217391304, "max_line_length": 85, "alphanum_fraction": 0.5496221662, "num_tokens": 1057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6623002087966027}} {"text": "module Instances.TrustInteger\n\nimport Common.Util\nimport Common.Interfaces\nimport Specifications.DiscreteOrderedGroup\nimport Specifications.OrderedRing\nimport Instances.Notation\n\n%default total\n%access public export\n\ndata IntegerLeq : Integer -> Integer -> Type where\n CheckIntegerLeq : So (intToBool (prim__slteBigInt a b)) -> IntegerLeq a b\n\nsoIntegerLeq : IntegerLeq a b -> So (intToBool (prim__slteBigInt a b))\nsoIntegerLeq (CheckIntegerLeq so) = so\n\ndecideLeq : (a,b : Integer) -> Dec (IntegerLeq a b)\ndecideLeq a b = case isItSo (intToBool (prim__slteBigInt a b)) of\n Yes oh => Yes (CheckIntegerLeq oh)\n No contra => No (contra . soIntegerLeq)\n\n\nimplementation Ringops Integer where Ng = negate\n\nimplementation Decidable [Integer, Integer] IntegerLeq where\n decide = decideLeq\n\npostulate integerDiscreteOrderedRing :\n specifyDiscreteOrderedRing {leq = IntegerLeq}\n\nintegerDiscreteOrderedGroup : specifyDiscreteOrderedGroup {leq = IntegerLeq}\nintegerDiscreteOrderedGroup = discreteOrderedGroup integerDiscreteOrderedRing\n\nintegerPartiallyOrderedGroup : specifyPartiallyOrderedGroup {leq = IntegerLeq}\nintegerPartiallyOrderedGroup = partiallyOrderedGroup integerDiscreteOrderedGroup\n", "meta": {"hexsha": "49ced1fcf1d78c258ae90e9184b393622372e81e", "size": 1192, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Instances/TrustInteger.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/TrustInteger.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/TrustInteger.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": 32.2162162162, "max_line_length": 80, "alphanum_fraction": 0.8129194631, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.662296966428057}} {"text": "module Main\n\nimport Data.String\nimport Data.List\n\nmaxByThird : Ord c => List (a, b, c) -> (a, b, c)\nmaxByThird = foldr1 (\\(ax, ay, av), (x, y, v) => if v > av then (x, y, v) else (ax, ay, av))\n\ncell : Integer -> Integer -> Integer -> Integer\ncell x y serial = (mod (div ((((x + 10) * y) + serial) * (x + 10)) 100) 10) - 5\n\ngrid : Integer -> List (List Integer)\ngrid serial = [[cell x y serial | y <- [1..300]] | x <- [1..300]]\n\nsquareCell : Integer -> Integer -> Integer -> List (List Integer) -> Integer\nsquareCell size x y g = if (x + size - 1) > 300 || (y + size - 1) > 300 then 0 else\n sum\n . map (\n sum\n . List.take (fromIntegerNat size)\n . List.drop (fromIntegerNat (y - 1)) \n )\n . List.take (fromIntegerNat size)\n . List.drop (fromIntegerNat (x - 1))\n $ g\n\nsquare : Integer -> List (List Integer) -> (Integer, Integer, Integer)\nsquare size g = maxByThird [(x, y, squareCell size x y g) | x <- [1..300 - (size - 2)], y <- [1..300 - (size - 2)]]\n\npart1 : List (List Integer) -> (Integer, Integer, Integer)\npart1 = square 3\n\npart2 : List (List Integer) -> (Integer, Integer, Integer)\npart2 g = maxByThird [square size g | size <- [1..10]]\n\nmain : IO()\nmain = do\n (Right str) <- readFile \"11.in\"\n let (Just serial) = String.parseInteger str\n let g = grid serial\n putStrLn \"(x, (y, power)\"\n printLn $ square 1 g\n printLn $ square 2 g\n putStrLn \"Solution for part 1:\"\n printLn $ square 3 g\n printLn $ square 4 g\n printLn $ square 5 g\n printLn $ square 6 g\n printLn $ square 7 g\n printLn $ square 8 g\n printLn $ square 9 g\n printLn $ square 10 g\n printLn $ square 11 g\n printLn $ square 12 g\n printLn $ square 13 g\n printLn $ square 14 g\n printLn $ square 15 g\n printLn $ square 16 g\n printLn $ square 17 g\n printLn $ square 18 g\n printLn $ square 19 g\n printLn $ square 20 g\n printLn $ square 21 g\n printLn $ square 22 g\n printLn $ square 23 g\n printLn $ square 24 g\n printLn $ square 25 g\n printLn $ square 26 g\n printLn $ square 27 g\n printLn $ square 28 g\n printLn $ square 29 g\n \n -- I do not want to optimize this right now, so... it works so it's good.\n -- You just take the biggest power, seems to be between 13 and 20 all the time.\n -- Starts at one, the size is the line number, not counting the info lines.\n\n-- Solution part 1: 235,87\n-- Solution part 2: 234,272,18\n", "meta": {"hexsha": "98e7329f7248f2de44ca4786b2dc89f8c5191b31", "size": 2434, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "2018/Day11.idr", "max_stars_repo_name": "vypxl/aoc", "max_stars_repo_head_hexsha": "4187837ecd8bf7464efa4953588b8c53d5675cfb", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-08T23:39:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T23:39:52.000Z", "max_issues_repo_path": "2018/Day11.idr", "max_issues_repo_name": "vypxl/aoc", "max_issues_repo_head_hexsha": "4187837ecd8bf7464efa4953588b8c53d5675cfb", "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": "2018/Day11.idr", "max_forks_repo_name": "vypxl/aoc", "max_forks_repo_head_hexsha": "4187837ecd8bf7464efa4953588b8c53d5675cfb", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-12-19T16:44:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-19T19:00:55.000Z", "avg_line_length": 30.8101265823, "max_line_length": 115, "alphanum_fraction": 0.6006573541, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7248702821204019, "lm_q1q2_score": 0.6622969575898466}} {"text": "data ListLast : List a -> Type where\n Empty : ListLast []\n NonEmpty : (xs : List a) -> (x : a) -> ListLast (xs ++ [x])\n\ndescribeHelper : Show a => (input : List a) -> (form : ListLast input) -> String\ndescribeHelper [] Empty = \"Empty\"\ndescribeHelper (xs ++ [x]) (NonEmpty xs x) =\n \"Non-empty, initial portion = \" ++ show xs\n\ntotal\nlistLast : (xs : List a) -> ListLast xs\nlistLast [] = Empty\nlistLast (x :: xs) =\n case listLast xs of\n Empty => NonEmpty [] x\n NonEmpty ys y => NonEmpty (x :: ys) y\n\ndescibeListEnd : Show a => List a -> String\ndescibeListEnd xs = describeHelper xs (listLast xs)\n\ndescibeListEndWith : Show a => List a -> String\ndescibeListEndWith input with (listLast input)\n descibeListEndWith [] | Empty = \"Empty\"\n descibeListEndWith (xs ++ [x]) | (NonEmpty xs x) =\n \"Non-empty, initial portion = \" ++ show xs\n\nmyReverse : List a -> List a\nmyReverse input with (listLast input)\n myReverse [] | Empty = []\n myReverse (xs ++ [x]) | (NonEmpty xs x) = x :: myReverse xs\n", "meta": {"hexsha": "87889a20b3f3e773a9009e9bcb661e62f2a2a2a3", "size": 1015, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/DescribeList.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/DescribeList.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/DescribeList.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": 32.7419354839, "max_line_length": 80, "alphanum_fraction": 0.6295566502, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6622227947221975}} {"text": "import Aoc\nimport Data.Nat\nimport Data.Strings\n\nPoint : Type\nPoint = (Integer, Integer)\n\n||| Add two points.\n(+~) : Point -> Point -> Point\n(+~) (x,y) (x',y') = (x+x',y+y')\ninfixl 5 +~\n\n||| Scale a point.\n(*~) : Integer -> Point -> Point\n(*~) n (x,y) = (n*x,n*y)\ninfixl 6 *~\n\n||| Turn a vector 90° to the left. (+x is >, +y is ^)\nturnLeft : Point -> Point\nturnLeft (x,y) = (-y,x)\n\n||| Turn a vector 90° to the right. (+x is >, +y is ^)\nturnRight : Point -> Point\nturnRight (x,y) = (y,-x)\n\nmanhattanNorm : Point -> Integer\nmanhattanNorm (x,y) = abs x + abs y\n\nrecord Ship where\n constructor MkShip\n position : Point\n direction : Point\n\ndata Instruction\n = North Integer\n | South Integer\n | East Integer\n | West Integer\n | Left90 Nat\n | Right90 Nat\n | Forward Integer\n\n||| Move a ship's position.\nmove : Point -> Ship -> Ship\nmove d s = record { position $= (+~ d) } s\n\n||| Move a ship's waypoint (direction vector).\nmoveWaypoint : Point -> Ship -> Ship\nmoveWaypoint d s = record { direction $= (+~ d) } s\n\n||| Follow an instruction, * style.\nstep1 : Ship -> Instruction -> Ship\nstep1 s (North n) = move (0, n) s\nstep1 s (South n) = move (0, -n) s\nstep1 s (East n) = move (n, 0) s\nstep1 s (West n) = move (-n, 0) s\nstep1 s (Left90 n) = record { direction $= times n turnLeft } s\nstep1 s (Right90 n) = record { direction $= times n turnRight } s\nstep1 s (Forward n) = move (n *~ s.direction) s\n\n||| Follow an instruction, ** style.\nstep2 : Ship -> Instruction -> Ship\nstep2 s (North n) = moveWaypoint (0, n) s\nstep2 s (South n) = moveWaypoint (0, -n) s\nstep2 s (East n) = moveWaypoint (n, 0) s\nstep2 s (West n) = moveWaypoint (-n, 0) s\nstep2 s (Left90 n) = record { direction $= times n turnLeft } s\nstep2 s (Right90 n) = record { direction $= times n turnRight } s\nstep2 s (Forward n) = move (n *~ s.direction) s\n\n||| Try to divide a natural number by 90.\ndiv90 : Nat -> Maybe Nat\ndiv90 n =\n case divmodNatNZ n 90 SIsNotZ of\n (k, 0) => Just k\n _ => Nothing\n\n||| Try to parse an instruciton.\nparseInstruction : String -> Maybe Instruction\nparseInstruction s =\n case break isDigit s of\n (\"N\", n) => North <$> parsePositive n\n (\"S\", n) => South <$> parsePositive n\n (\"E\", n) => East <$> parsePositive n\n (\"W\", n) => West <$> parsePositive n\n (\"L\", n) => Left90 <$> (parsePositive n >>= div90)\n (\"R\", n) => Right90 <$> (parsePositive n >>= div90)\n (\"F\", n) => Forward <$> parsePositive n\n _ => Nothing\n\nmain : IO ()\nmain = do\n xs <- parseLines parseInstruction\n let ship1 = foldl step1 (MkShip (0, 0) (1, 0)) xs\n putStr \"* \"; printLn (manhattanNorm ship1.position)\n let ship2 = foldl step2 (MkShip (0, 0) (10, 1)) xs\n putStr \"** \"; printLn (manhattanNorm ship2.position)\n", "meta": {"hexsha": "f1ff068e554baa41fe43a035ebf52a78d73d79a2", "size": 2715, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "day-12.idr", "max_stars_repo_name": "lynn/aoc-2020", "max_stars_repo_head_hexsha": "a66b9cac109f9c3b51f18f5fb2d54ebdf395bb10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-12-01T13:40:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-22T13:23:21.000Z", "max_issues_repo_path": "day-12.idr", "max_issues_repo_name": "lynn/aoc-2020", "max_issues_repo_head_hexsha": "a66b9cac109f9c3b51f18f5fb2d54ebdf395bb10", "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": "day-12.idr", "max_forks_repo_name": "lynn/aoc-2020", "max_forks_repo_head_hexsha": "a66b9cac109f9c3b51f18f5fb2d54ebdf395bb10", "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.7040816327, "max_line_length": 65, "alphanum_fraction": 0.6136279926, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6622225119431676}} {"text": "module Data.AVL.Core.Quantifiers\n\nimport public Data.Tree\nimport public Data.AVL.Core\nimport public Data.AVL.Core.API\n\n%default total\n%access export\n\nnamespace AVL\n namespace Keys\n\n public export\n data 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\n keyNotInAVlTree : (contra : IsKeyIn key tree -> Void)\n -> HasKey key (Element tree prf)\n -> Void\n keyNotInAVlTree contra (IsKey x) = contra x\n\n isKey : DecEq typeKey\n => (key : typeKey)\n -> (tree : AVLTree h typeKey typeValue)\n -> Dec (HasKey key tree)\n isKey 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\n public export\n data All : (predicate : typeKey -> Type)\n -> (tree : AVLTree h typeKey typeValue)\n -> Type\n where\n MkProof : (prf : Tree.Keys.All p (Subset.getWitness avl))\n -> All p avl\n\n namespace Values\n\n\n public export\n data 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\n valueNotInAVLTree : (contra : IsValueIn value tree -> Void)\n -> HasValue value (Element tree prf)\n -> Void\n valueNotInAVLTree contra (IsValue prf) = contra prf\n\n isValue : DecEq typeValue\n => (value : typeValue)\n -> (tree : AVLTree h typeKey typeValue)\n -> Dec (HasValue value tree)\n isValue 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\n public export\n data All : (predicate : typeValue -> Type)\n -> (tree : AVLTree h typeKey typeValue)\n -> Type\n where\n MkProof : (prf : Tree.Values.All p (Subset.getWitness avl))\n -> AVL.Values.All p avl\n\n namespace KVPairs\n\n\n public export\n data All : (predicate : typeKey -> typeValue -> Type)\n -> (tree : AVLTree k typeKey typeValue)\n -> Type\n where\n MkProof : (prf : Tree.KVPairs.All p (Subset.getWitness avl))\n -> All p avl\n", "meta": {"hexsha": "a6dd483ac6770f991d346e55585a0af19e8b7898", "size": 2571, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/AVL/Core/Quantifiers.idr", "max_stars_repo_name": "witt3rd/idris-containers", "max_stars_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 99, "max_stars_repo_stars_event_min_datetime": "2015-03-01T20:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-01T02:17:39.000Z", "max_issues_repo_path": "Data/AVL/Core/Quantifiers.idr", "max_issues_repo_name": "witt3rd/idris-containers", "max_issues_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 30, "max_issues_repo_issues_event_min_datetime": "2015-03-23T19:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-01T13:05:44.000Z", "max_forks_repo_path": "Data/AVL/Core/Quantifiers.idr", "max_forks_repo_name": "witt3rd/idris-containers", "max_forks_repo_head_hexsha": "6f4e06a0e85ee6336e493cee800fff42215da2ac", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-06-02T17:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T14:51:07.000Z", "avg_line_length": 30.2470588235, "max_line_length": 84, "alphanum_fraction": 0.5717619603, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6621639870804492}} {"text": "module Sub01Apply18x3\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\nimport ProofColDivSeqPostuProof\n\n%default total\n-- %language ElabReflection\n\n\n-- 3(6x+1) --B[1,-2]--> 3x\nexport\napply18x3 : (Not . P) (S (plus (plus (plus k k) (plus k k)) (plus k k)))\n -> (m : Nat **\n (LTE (S m) (S (plus (plus (plus k k) (plus k k)) (plus k k))), (Not . P) m))\napply18x3 {k} col = (k ** (lte18x3 k, b18x3To3x k col)) where\n lte18x3 : (k:Nat) -> LTE (S k) (S (plus (plus (plus k k) (plus k k)) (plus k k)))\n lte18x3 Z = LTESucc LTEZero\n lte18x3 (S k) = rewrite (sym (plusSuccRightSucc k k)) in\n rewrite (sym (plusSuccRightSucc (plus k k) (S (plus k k)))) in\n rewrite (sym (plusSuccRightSucc (plus k k) (plus k k))) in\n rewrite (sym (plusSuccRightSucc (plus (plus k k) (plus k k)) (S (plus k k)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus k k) (plus k k)) (plus k k))) in\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc) (lte18x3 k)\n\n\n\n", "meta": {"hexsha": "c6851acd9508ef0713650359fbe65a03be7d19bd", "size": 1002, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program2/Sub01Apply18x3.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/Sub01Apply18x3.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/Sub01Apply18x3.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": 35.7857142857, "max_line_length": 102, "alphanum_fraction": 0.6377245509, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.662056975286877}} {"text": "\nmodule BigStep\n\n-- Relation 'BigStep' for fully reducing terms\n-- in the simply-typed lambda calculus to values.\n \n\nimport Term\nimport Subst\n\n\n%default total\n%access public export\n\n\n-----------------------------------------------------------------------\n-- Begin: BIG-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n\n-- The relation 'BigStep' defines evaluation of terms in the lambda\n-- calculus following big-step semantics.\n--\n-- Big-step semantics fully evaluates terms to values.\n-- (A proof of this statement appears below.)\ndata BigStep : Term [] t -> (y: Term [] t) -> Type where\n BStValue : (v : Value e) -> BigStep e e\n --\n BStApp : BigStep e1 (TAbs e1') ->\n BigStep e2 e2' ->\n BigStep (subst e2' First e1') e ->\n BigStep (TApp e1 e2) e\n -- \n BStFix : BigStep e (TAbs e') ->\n BigStep (subst (TFix (TAbs e')) First e') e'' ->\n BigStep (TFix e) e''\n -- \n BStSucc : BigStep e e' ->\n BigStep (TSucc e) (TSucc e')\n -- \n BStPredZero : BigStep e TZero ->\n BigStep (TPred e) TZero\n -- \n BStPredSucc : BigStep e (TSucc e') ->\n BigStep (TPred e) e'\n -- \n BStIfzZero : BigStep e1 TZero ->\n BigStep e2 e ->\n BigStep (TIfz e1 e2 _) e\n -- \n BStIfzSucc : BigStep e1 (TSucc _) ->\n BigStep e3 e ->\n BigStep (TIfz e1 _ e3) e\n\n\nbigStepFst : {e : Term [] t} -> BigStep e _ -> Term [] t\nbigStepFst {e = e} _ = e\n\n\nbigStepSnd : {e : Term [] t} -> BigStep _ e -> Term [] t\nbigStepSnd {e = e} _ = e\n\n\nbigStepValue : BigStep _ e -> Value e\nbigStepValue (BStValue v) = v\nbigStepValue (BStApp _ _ z) = bigStepValue z\nbigStepValue (BStFix _ z) = bigStepValue z\nbigStepValue (BStSucc z) = VSucc (bigStepValue z)\nbigStepValue (BStPredZero _) = VZero\nbigStepValue (BStPredSucc z) = case bigStepValue z of\n VZero impossible\n VSucc v => v\nbigStepValue (BStIfzZero _ z) = bigStepValue z\nbigStepValue (BStIfzSucc _ z) = bigStepValue z\n\n \nbigStepValueIrreducible : BigStep e1 e2 -> Value e1 -> e1 = e2\nbigStepValueIrreducible (BStValue VZero) VZero = Refl\nbigStepValueIrreducible (BStValue v1) (VSucc v2) = Refl\nbigStepValueIrreducible (BStSucc bst) (VSucc v) = \n cong $ bigStepValueIrreducible bst v\nbigStepValueIrreducible (BStValue v) VAbs = Refl\n\n\nbigStepTransitive : BigStep e1 e2 -> BigStep e2 e3 -> BigStep e1 e3\nbigStepTransitive (BStValue v) bst = bst\nbigStepTransitive (BStApp x w t) y = BStApp x w $ bigStepTransitive t y\nbigStepTransitive (BStFix x w) y = BStFix x $ bigStepTransitive w y\nbigStepTransitive (BStSucc x) (BStValue v) = BStSucc x\nbigStepTransitive (BStSucc x) (BStSucc y) = BStSucc $ bigStepTransitive x y\nbigStepTransitive (BStPredZero x) (BStValue v) = BStPredZero x\nbigStepTransitive (BStPredSucc x) y = let bst1 = BStSucc y\n bst2 = bigStepTransitive x bst1\n in BStPredSucc bst2\nbigStepTransitive (BStIfzZero w s) y = BStIfzZero w (bigStepTransitive s y)\nbigStepTransitive (BStIfzSucc w s) y = BStIfzSucc w (bigStepTransitive s y)\n\n-- End: BIG-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n---------------------------------------------------------------------\n\n\n\n-------------------------------------------------------\n-- Begin: CO-INDUCTIVE RELATION FOR BIG-STEP EVALUATION\n\ncodata CoBigStep : Term [] t -> (y: Term [] t) -> Type where\n CoBStValue : (v : Value e) -> CoBigStep e e\n --\n CoBStApp : CoBigStep e1 (TAbs e1') ->\n CoBigStep e2 e2' ->\n CoBigStep (subst e2' First e1') e ->\n CoBigStep (TApp e1 e2) e\n -- \n CoBStFix : CoBigStep e (TAbs e') ->\n CoBigStep (subst (TFix (TAbs e')) First e') e'' ->\n CoBigStep (TFix e) e''\n -- \n CoBStSucc : CoBigStep e e' ->\n CoBigStep (TSucc e) (TSucc e')\n -- \n CoBStPredZero : CoBigStep e TZero ->\n CoBigStep (TPred e) TZero\n -- \n CoBStPredSucc : CoBigStep e (TSucc e') ->\n CoBigStep (TPred e) e'\n -- \n CoBStIfzZero : CoBigStep e1 TZero ->\n CoBigStep e2 e ->\n CoBigStep (TIfz e1 e2 _) e\n -- \n CoBStIfzSucc : CoBigStep e1 (TSucc _) ->\n CoBigStep e3 e ->\n CoBigStep (TIfz e1 _ e3) e\n\n\ncoBigStepValueIrreducible : CoBigStep e1 e2 -> Value e1 -> e1 = e2\ncoBigStepValueIrreducible (CoBStValue VZero) VZero = Refl\ncoBigStepValueIrreducible (CoBStValue v1) (VSucc v2) = Refl\ncoBigStepValueIrreducible (CoBStSucc cbst) (VSucc v) = \n cong $ coBigStepValueIrreducible cbst v\ncoBigStepValueIrreducible (CoBStValue v) VAbs = Refl\n\n\ncoBigStepTransitive : CoBigStep e1 e2 -> CoBigStep e2 e3 -> CoBigStep e1 e3\ncoBigStepTransitive (CoBStValue v) y = y\ncoBigStepTransitive (CoBStApp x z w) y = CoBStApp x z $ coBigStepTransitive w y \ncoBigStepTransitive (CoBStFix x z) y = CoBStFix x $ coBigStepTransitive z y\ncoBigStepTransitive (CoBStSucc x) (CoBStValue v) = CoBStSucc x\ncoBigStepTransitive (CoBStSucc x) (CoBStSucc y) = CoBStSucc $ coBigStepTransitive x y\ncoBigStepTransitive (CoBStPredZero x) (CoBStValue v) = CoBStPredZero x\ncoBigStepTransitive (CoBStPredSucc x) y = let cbst1 = CoBStSucc y\n in CoBStPredSucc $ coBigStepTransitive x cbst1\ncoBigStepTransitive (CoBStIfzZero z w) y = CoBStIfzZero z $ coBigStepTransitive w y\ncoBigStepTransitive (CoBStIfzSucc w s) y = CoBStIfzSucc w $ coBigStepTransitive s y\n\n\nbigStepToCoBigStep : BigStep e1 e2 -> CoBigStep e1 e2\nbigStepToCoBigStep (BStValue v) = CoBStValue v\nbigStepToCoBigStep (BStApp bst1 bst2 bst3) = CoBStApp (bigStepToCoBigStep bst1)\n (bigStepToCoBigStep bst2)\n (bigStepToCoBigStep bst3)\nbigStepToCoBigStep (BStFix bst1 bst2) = CoBStFix (bigStepToCoBigStep bst1)\n (bigStepToCoBigStep bst2)\nbigStepToCoBigStep (BStSucc bst) = CoBStSucc $ bigStepToCoBigStep bst\nbigStepToCoBigStep (BStPredZero bst) = CoBStPredZero $ bigStepToCoBigStep bst\nbigStepToCoBigStep (BStPredSucc bst) = CoBStPredSucc $ bigStepToCoBigStep bst\nbigStepToCoBigStep (BStIfzZero bst1 bst2) = CoBStIfzZero (bigStepToCoBigStep bst1)\n (bigStepToCoBigStep bst2)\nbigStepToCoBigStep (BStIfzSucc bst1 bst2) = CoBStIfzSucc (bigStepToCoBigStep bst1)\n (bigStepToCoBigStep bst2)\n \n-- End: CO-INDUCTIVE RELATION FOR BIG-STEP EVALUATION\n-----------------------------------------------------\n\n\n\n\n\n\n\n", "meta": {"hexsha": "8566d8276e0fd7013829e69468081e362a0b1951", "size": 7047, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codata/src/BigStep.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codata/src/BigStep.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codata/src/BigStep.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.3687150838, "max_line_length": 88, "alphanum_fraction": 0.5818078615, "num_tokens": 2213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6619779377177749}} {"text": "import Syntax.PreorderReasoning\n\n-------- some notation ----------\ninfixr 6 .+.,:+:\ninfixr 7 .*.,:*:\n\ninterface Additive a where\n constructor MkAdditive\n (.+.) : a -> a -> a\n O : a\n\ninterface Additive2 a where\n constructor MkAdditive2\n (:+:) : a -> a -> a\n O2 : a\n\ninterface Multiplicative a where\n constructor MkMultiplicative\n (.*.) : a -> a -> a\n I : a\n\nrecord MonoidOver U where\n constructor WithStruct\n Unit : U\n Mult : U -> U -> U\n lftUnit : (x : U) -> Unit `Mult` x = x\n rgtUnit : (x : U) -> x `Mult` Unit = x\n assoc : (x,y,z : U)\n -> x `Mult` (y `Mult` z) = (x `Mult` y) `Mult` z\n\nrecord Monoid where\n constructor MkMonoid\n U : Type\n Struct : MonoidOver U\n\nAdditiveStruct : (m : MonoidOver a) -> Additive a\nAdditiveStruct m = MkAdditive (Mult $ m)\n (Unit $ m)\nAdditiveStruct2 : (m : MonoidOver a) -> Additive2 a\nAdditiveStruct2 m = MkAdditive2 (Mult $ m)\n (Unit $ m)\nAdditiveStructs : (ma : MonoidOver a) -> (mb : MonoidOver b)\n -> (Additive a, Additive2 b)\nAdditiveStructs ma mb = (AdditiveStruct ma, AdditiveStruct2 mb)\n\ngetAdditive : (m : Monoid) -> Additive (U m)\ngetAdditive m = AdditiveStruct (Struct m)\n\nMultiplicativeStruct : (m : Monoid) -> Multiplicative (U m)\nMultiplicativeStruct m = MkMultiplicative (Mult $ Struct m)\n (Unit $ Struct m)\n-----------------------------------------------------\n\n0 Commutative : MonoidOver a -> Type\nCommutative m = (x,y : a) -> let _ = AdditiveStruct m in\n x .+. y = y .+. x\n\n0 Commute : (Additive a, Additive2 a) => Type\nCommute =\n (x11,x12,x21,x22 : a) ->\n ((x11 :+: x12) .+. (x21 :+: x22))\n =\n ((x11 .+. x21) :+: (x12 .+. x22))\n\nproduct : (ma, mb : Monoid) -> Monoid\nproduct ma mb =\n let\n %hint aStruct : Additive (U ma)\n aStruct = getAdditive ma\n %hint bStruct : Additive (U mb)\n bStruct = getAdditive mb\n\n in MkMonoid (U ma, U mb) $ WithStruct\n (O, O)\n (\\(x1,y1), (x2, y2) => (x1 .+. x2, y1 .+. y2))\n (\\(x,y) => rewrite lftUnit (Struct ma) x in\n rewrite lftUnit (Struct mb) y in\n Refl)\n (\\(x,y) => rewrite rgtUnit (Struct ma) x in\n rewrite rgtUnit (Struct mb) y in\n Refl)\n (\\(x1,y1),(x2,y2),(x3,y3) =>\n rewrite assoc (Struct ma) x1 x2 x3 in\n rewrite assoc (Struct mb) y1 y2 y3 in\n Refl)\n\nEckmannHilton : forall a . (ma,mb : MonoidOver a)\n -> let ops = AdditiveStructs ma mb in\n Commute @{ops}\n -> (Commutative ma, (x,y : a) -> x .+. y = x :+: y)\nEckmannHilton ma mb prf =\n let %hint first : Additive a\n first = AdditiveStruct ma\n %hint second : Additive2 a\n second = AdditiveStruct2 mb in\n let SameUnits : (the a O === O2)\n SameUnits = Calc $\n |~ O\n ~~ O .+. O ...(sym $ lftUnit ma O)\n ~~ (O :+: O2) .+. (O2 :+: O) ...(sym $ cong2 (.+.)\n (rgtUnit mb O)\n (lftUnit mb O))\n ~~ (O .+. O2) :+: (O2 .+. O) ...(prf O O2 O2 O)\n ~~ O2 :+: O2 ...(cong2 (:+:)\n (lftUnit ma O2)\n (rgtUnit ma O2))\n ~~ O2 ...(lftUnit mb O2)\n\n SameMults : (x,y : a) -> (x .+. y) === (x :+: y)\n SameMults x y = Calc $\n |~ x .+. y\n ~~ (x :+: O2) .+. (O2 :+: y) ...(sym $ cong2 (.+.)\n (rgtUnit mb x)\n (lftUnit mb y))\n ~~ (x .+. O2) :+: (O2 .+. y) ...(prf x O2 O2 y)\n ~~ (x .+. O ) :+: (O .+. y) ...(cong (\\u =>\n (x .+. u) :+: (u .+. y))\n (sym SameUnits))\n ~~ x :+: y ...(cong2 (:+:)\n (rgtUnit ma x)\n (lftUnit ma y))\n\n Commutativity : Commutative ma\n Commutativity x y = Calc $\n |~ x .+. y\n ~~ (O2 :+: x) .+. (y :+: O2) ...(sym $ cong2 (.+.)\n (lftUnit mb x)\n (rgtUnit mb y))\n ~~ (O2 .+. y) :+: (x .+. O2) ...(prf O2 x y O2)\n ~~ (O .+. y) :+: (x .+. O ) ...(cong (\\u =>\n (u .+. y) :+: (x .+. u))\n (sym SameUnits))\n ~~ y :+: x ...(cong2 (:+:)\n (lftUnit ma y)\n (rgtUnit ma x))\n ~~ y .+. x ...(sym $ SameMults y x)\n in (Commutativity, SameMults)\n", "meta": {"hexsha": "a03b2f94cc0cffc7cf8abc1d60d22312bf7a35ea", "size": 4960, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/interface024/EH.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/interface024/EH.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/interface024/EH.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": 35.9420289855, "max_line_length": 70, "alphanum_fraction": 0.3973790323, "num_tokens": 1440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6619317229602064}} {"text": "import Effects\nimport Effect.Exception\nimport Effect.StdIO\nimport Effect.Random\nimport Effect.System\nimport Data.Vect\n\n%default total\n\n--------------------------------------------------------------------------------\n-- Operations on individual rows\n--------------------------------------------------------------------------------\n\n||| Fills in an array\nfillIn : LTE n m -> a -> Vect n a -> Vect m a\nfillIn LTEZero c [] = replicate _ c\nfillIn (LTESucc w) c (x :: xs) = x :: (fillIn w c xs)\n\n||| Filters out the Nothings from a vector of maybes.\n|||\n||| Takes a vector of length n with elements of type Maybe a\n||| and returns the dependent pair (m ** (Vect m a, LTE m n)) where\n||| m is the new length, Vect m a is the filtered list, and LTE m n\n||| is a prove that m <= n, that is, that the new list has length\n||| less than or equal to the original list.\nfilterMaybes : Vect n (Maybe a) -> (m ** (Vect m a, LTE m n))\nfilterMaybes [] = (Z ** ([], LTEZero))\nfilterMaybes (Just x :: xs) = let (_ ** (ys, w)) = filterMaybes xs in\n (_ ** ((x :: ys), LTESucc w))\nfilterMaybes (Nothing :: xs) = let (_ ** (ys, w)) = filterMaybes xs in\n (_ ** (ys, lteSuccRight w))\n\n||| The collapsing of pairs operation of the 2048 game.\n|||\n||| Takes a vector of elements of type a, and performs the \"collapsing\"\n||| operation of the 2048 game. This takes adjacent pairs, and if they\n||| are equal, combines them into a single element with double the value.\n||| Returns a vector of length m and proof that m <= n.\ncollapsePairs : (Num a, Eq a) => Vect n a -> (m ** (Vect m a, LTE m n))\ncollapsePairs (x::x'::xs) =\n if x == x' then\n let (_ ** (ys, w)) = collapsePairs xs in (_ ** ((2 * x) :: ys, lteSuccRight (LTESucc w)))\n else\n let (_ ** (ys, w)) = collapsePairs (x' :: xs) in (_ ** (x :: ys, LTESucc w))\ncollapsePairs (x::[]) = (_ ** ([x], LTESucc LTEZero))\ncollapsePairs [] = (_ ** ([], LTEZero))\n\n||| The basic row operation of the 2048 game.\n|||\n||| Combines the operations of filterMaybes and collapsePairs,\n||| and combines their proofs, and transitivity of <=, to\n||| prove that the result of applying both operations is\n||| a shorter vector than the original. This proof is used\n||| to apply the fillIn function.\nbasicRowOperation : (Eq a, Num a) => Vect n (Maybe a) -> Vect n (Maybe a)\nbasicRowOperation xs = let (m ** (ys, w)) = filterMaybes xs in let\n (l ** (zs, wPrime)) = collapsePairs ys in\n (fillIn (lteTransitive wPrime w) Nothing (map Just zs))\n\n--------------------------------------------------------------------------------\n-- Operations on the game board\n--------------------------------------------------------------------------------\n\n||| Takes the transpose of a rectangular array\ntransposeArray : Vect n (Vect m a) -> Vect m (Vect n a)\ntransposeArray [] = replicate _ []\ntransposeArray (x::xs) = zipWith (::) x (transposeArray xs)\n\n||| Flattens a rectangular array\nflattenArray : Vect n (Vect m a) -> Vect (n * m) a\nflattenArray Nil = Nil\nflattenArray (x::xs) = x ++ (flattenArray xs)\n\n||| Splits an array\nsplit' : Vect (plus n m) a -> (Vect n a, Vect m a)\nsplit' {n=Z} xs = ([], xs)\nsplit' {n=(S k)}{m=l} (x::xs) = let (ys, zs) = split' {n=k}{m=l} xs in\n (x::ys, zs)\n\n||| Unflattens an array\nunFlattenArray : Vect (n * m) a -> Vect n (Vect m a)\nunFlattenArray {n=Z} Nil = Nil\nunFlattenArray {n=(S k)}{m=l} xs = let (ys, zs) = split' {n=l}{m=k*l} xs in\n (ys :: (unFlattenArray zs))\n\n||| Find the indices of all elements of a vector that satisfy some test\nfindIndicesFin : (a -> Bool) -> Vect n a -> List (Fin n)\nfindIndicesFin f [] = []\nfindIndicesFin f (x::xs) = let tail = (map FS (findIndicesFin f xs)) in\n if f x then (FZ :: tail) else tail\n\n--------------------------------------------------------------------------------\n-- Display functions\n--------------------------------------------------------------------------------\n\nshowValue : Show a => Maybe a -> String\nshowValue Nothing = \"....\"\nshowValue (Just x) = pack (List.take 4 (unpack ((show x) ++ \"....\")))\n\nshowRow : Show a => Vect n (Maybe a) -> String\nshowRow [] = \"\"\nshowRow (x::xs) = (showValue x) ++ \" \" ++ (showRow xs)\n\nshowBoard : Show a => Vect m (Vect n (Maybe a)) -> String\nshowBoard [] = \"\"\nshowBoard (x::xs) = (showRow x) ++ \"\\n\" ++ (showBoard xs)\n\n--------------------------------------------------------------------------------\n-- High level game logic\n--------------------------------------------------------------------------------\n\nBoard : Type\nBoard = Vect 4 (Vect 4 (Maybe Int))\n\ndata Direction = Left | Right | Up | Down\n\npartial\nmove : (Eq a, Num a) => Direction -> Vect m (Vect n (Maybe a)) -> Vect m (Vect n (Maybe a))\nmove Left xs = map basicRowOperation xs\nmove Right xs = map (reverse . basicRowOperation . reverse) xs\nmove Up xs = (transposeArray . (move Left) . transposeArray) xs\nmove Down xs = (transposeArray . (move Right) . transposeArray) xs\n\n\n-- myIndex : List (Fin 16) -> Maybe Nat\n-- myIndex lst =\naddRandomPiece : Board -> {[RND, EXCEPTION String]} Eff Board\naddRandomPiece arr = \n case integerToFin 3 16 of\n Nothing => raise \"Game Over\"\n Just idx => pure (unFlattenArray (replaceAt idx (Just 2) flattened))\n where\n flattened : Vect 16 (Maybe Int)\n flattened = flattenArray arr\n indices : List (Fin 16)\n indices = findIndicesFin isNothing flattened\n\ndata UserAction = Quit | Invalid | Move Direction\n\ngetAction : Char -> UserAction\ngetAction 'a' = Move Left\ngetAction 'd' = Move Right\ngetAction 'w' = Move Up\ngetAction 's' = Move Down\ngetAction 'x' = Quit\ngetAction _ = Invalid\n\npartial\nmainLoop : Board -> {[RND, STDIO, EXCEPTION String]} Eff (Board)\nmainLoop b = do putStrLn (showBoard b)\n c <- getChar\n performAction (getAction c)\n where\n partial\n performAction : UserAction -> {[RND, STDIO, EXCEPTION String]} Eff (Board)\n performAction Quit = raise \"You have quit\"\n performAction Invalid = mainLoop b\n performAction (Move dir) = let b' = move dir b in\n if b == b' then\n mainLoop b'\n else\n do\n b'' <- addRandomPiece b'\n mainLoop b''\n\npartial\nstartGame : { [RND, STDIO, SYSTEM, EXCEPTION String] } Eff ()\nstartGame = do\n srand !time\n initialBoard <- addRandomPiece (replicate _ (replicate _ Nothing))\n mainLoop initialBoard\n pure ()\n\npartial\nmain : IO ()\nmain = run startGame\n", "meta": {"hexsha": "b79338f81dd80ef04de31c1267e078f32dcb5fa2", "size": 6432, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "game.idr", "max_stars_repo_name": "bmwant/idris2048", "max_stars_repo_head_hexsha": "f0ff57af5dabb6d3909f9bec014045d971ec7519", "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": "game.idr", "max_issues_repo_name": "bmwant/idris2048", "max_issues_repo_head_hexsha": "f0ff57af5dabb6d3909f9bec014045d971ec7519", "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": "game.idr", "max_forks_repo_name": "bmwant/idris2048", "max_forks_repo_head_hexsha": "f0ff57af5dabb6d3909f9bec014045d971ec7519", "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.3389830508, "max_line_length": 93, "alphanum_fraction": 0.567630597, "num_tokens": 1764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6605831429047935}} {"text": "data IsS : (Nat -> Nat) -> Type where\n Indeed : (s : Nat -> Nat) -> s === S -> IsS s\n\n------------------------------------------------------------------------\n-- 1.\n-- the S pattern is forced by the fact the parameter is instantiated\n-- so everything is fine\n\n-- either left implicit\nindeed : IsS S -> S === S\nindeed (Indeed _ eq) = eq\n\n-- or made explicit\nindeed2 : IsS S -> S === S\nindeed2 (Indeed S eq) = eq\n\n------------------------------------------------------------------------\n-- 2. The S pattern is not forced by the parameter (a generic variable)\n\n-- either don't match on it\nindeed3 : IsS s -> s === S\nindeed3 (Indeed s eq) = eq\n\n-- or match on the proof that forces it\nindeed4 : IsS s -> s === S\nindeed4 (Indeed S Refl) = Refl\n-- ^ forced by Refl\n\n-- If you don't: too bad!\nfail : IsS s -> s === S\nfail (Indeed S eq) = eq\n-- ^ not Refl, S not forced! OUCH\n", "meta": {"hexsha": "0bef42ccd6fa7a5f2966cc80e8bbe822ae9d7c44", "size": 894, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/casetree001/IsS.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/casetree001/IsS.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/casetree001/IsS.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 27.0909090909, "max_line_length": 72, "alphanum_fraction": 0.4988814318, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6605324487612773}} {"text": "module Backprop.Math\n\nimport Backprop.CanBack\nimport Backprop.Node\nimport Control.Optics\nimport public Data.Floating\nimport public Data.Num\n\nexport\nview : {a, b : _} -> CanBack a => Simple Lens a b -> Node i a -> Node i b\nview l = op1 $ \\[x] => (x ^. l, \\d => [set l d zero])\n\ninfixl 0 ^.\nexport\n(^.) : {a, b : _} -> CanBack a => Node i a -> Simple Lens a b -> Node i b\nx ^. l = view l x\n\nexport\nsum : {a : _} -> (CanBack a, NodeFunctor f, Num a, Foldable f) => Node i (f a) -> Node i a\nsum x = Prelude.sum $ Node.sequence x\n\nexport\nmax, min : {a : _} -> (CanBack a, Num a, Ord a) => Node i a -> Node i a -> Node i a\nmax = op2 $ \\[x, y] => (max x y, \\d => [d * if x > y then 1 else 0, d * if y > x then 1 else 0])\nmin = op2 $ \\[x, y] => (min x y, \\d => [d * if x < y then 1 else 0, d * if y < x then 1 else 0])\n\n-- machine learning specific\n\nexport\nrelu : {a : _} -> (CanBack a, Num a, Ord a) => Node i a -> Node i a\nrelu x = max 0 x\n", "meta": {"hexsha": "f349cd4bbc48a4201611e45194d63d1a7485aaf8", "size": 934, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Backprop/Math.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/Backprop/Math.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/Backprop/Math.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": 29.1875, "max_line_length": 96, "alphanum_fraction": 0.5717344754, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.7122321781307375, "lm_q1q2_score": 0.6604979814067674}} {"text": "{-\n Calulator parser\n\n number ::= [ \"-\" ] digit { digit }.\n digit ::= \"0\" | \"1\" | ... | \"8\" | \"9\".\n expr ::= term { addop term }.\n term ::= factor { mulop factor }.\n factor ::= \"(\" expr \")\" | number.\n addop ::= \"+\" | \"-\".\n mulop ::= \"*\".\n\n-}\nmodule Test.Calculator\n\nimport NanoParsec.Parser\nimport NanoParsec.Combinators\n\n\ndata Expr = Add Expr Expr\n | Mul Expr Expr\n | Sub Expr Expr\n | Lit Int\n deriving Show\n\neval :: Expr -> Int\neval ex = case ex of\n Add a b -> eval a + eval b\n Mul a b -> eval a * eval b\n Sub a b -> eval a - eval b\n Lit n -> n\n\nint :: Parser Expr\nint = number >>= \\n -> return (Lit n)\n\nexpr :: Parser Expr\nexpr = term `chainl1` addop\n\nterm :: Parser Expr\nterm = factor `chainl1` mulop\n\nfactor :: Parser Expr\nfactor = int <|> parens expr\n\ninfixOp :: String -> (a -> a -> a) -> Parser (a -> a -> a)\ninfixOp x f = reserved x >>= \\_ => return f\n\naddop :: Parser (Expr -> Expr -> Expr)\naddop = (infixOp \"+\" Add) <|> (infixOp \"-\" Sub)\n\nmulop :: Parser (Expr -> Expr -> Expr)\nmulop = infixOp \"*\" Mul\n", "meta": {"hexsha": "93f7cddf11a2f2d3394061dc3c8db61e6a0d1936", "size": 1078, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Test/Calculator.idr", "max_stars_repo_name": "stallmanifold/idris-nanoparsec", "max_stars_repo_head_hexsha": "adf74d4ad4f1e8df918f3616b1cc8ee89db1c315", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-11-21T13:36:37.000Z", "max_stars_repo_stars_event_max_datetime": "2017-02-21T05:56:30.000Z", "max_issues_repo_path": "Test/Calculator.idr", "max_issues_repo_name": "lambdaxymox/idris-nanoparsec", "max_issues_repo_head_hexsha": "adf74d4ad4f1e8df918f3616b1cc8ee89db1c315", "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": "Test/Calculator.idr", "max_forks_repo_name": "lambdaxymox/idris-nanoparsec", "max_forks_repo_head_hexsha": "adf74d4ad4f1e8df918f3616b1cc8ee89db1c315", "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": 20.7307692308, "max_line_length": 58, "alphanum_fraction": 0.5398886827, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6604870901326065}} {"text": "module Nat\n\npublic export\ndata Nat = Z | S Nat\n\npublic export\nplus : Nat -> Nat -> Nat\nplus Z y = y\nplus (S k) y = S (plus k y)\n\n", "meta": {"hexsha": "80a05def9a287bf10e80b1e44e1f4005c6677619", "size": 129, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/import002/Nat.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/import002/Nat.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/import002/Nat.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": 11.7272727273, "max_line_length": 27, "alphanum_fraction": 0.6124031008, "num_tokens": 44, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.660487082797959}} {"text": "-- Exercise 1\ntotal\nsame_cons : {xs : List a}\n -> {ys : List a}\n -> xs = ys\n -> x :: xs = x :: ys\nsame_cons Refl = Refl\n\n-- Exercise 2\nsame_list : {xs : List a}\n -> {ys : List a}\n -> x = y\n -> xs = ys\n -> x :: xs = y :: ys\nsame_list Refl Refl = Refl\n\n-- Exercise 3\ndata ThreeEq : a -> b -> c -> Type where\n AllSame : ThreeEq x x x\n\n-- Exercise 4\nallSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)\nallSameS x x x AllSame = AllSame\n", "meta": {"hexsha": "3fe4058e6e10fd56dd2671fceadacd0770b03cff", "size": 518, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TypeDrivenDevelopment/Chapter08/Exercises/ex_8_1.idr", "max_stars_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_stars_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TypeDrivenDevelopment/Chapter08/Exercises/ex_8_1.idr", "max_issues_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_issues_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TypeDrivenDevelopment/Chapter08/Exercises/ex_8_1.idr", "max_forks_repo_name": "lambdaxymox/type-driven-development-with-idris", "max_forks_repo_head_hexsha": "e5e55715cd7418f3e6fab8e5658d7518da3fdce7", "max_forks_repo_licenses": ["Apache-2.0", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5833333333, "max_line_length": 72, "alphanum_fraction": 0.4806949807, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6604850433651845}} {"text": "> module Main\n\n> import Data.Fin\n> import Data.Vect\n> import Data.Matrix\n> import Data.Matrix.Numeric\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n\n* Preliminaries\n\nThis is a re-implementation of\n\n https://gist.github.com/mrkgnao/a45059869590d59f05100f4120595623 \n\nwhich, in turn, is an Idris implementation of\n\n https://blog.jle.im/entry/practical-dependent-types-in-haskell-1.html\n\n\n* Layers\n\nA layer of type |A| with |n| inputs and |m| outputs is a vector of |m|\nelements of type |A| (the biases) and a |m| x |n| matrix of elements of\ntype |A| (the weights):\n\n> data Layer : Nat -> Nat -> Type -> Type where\n> MkLayer : {m, n : Nat} -> {A : Type} -> \n> (biases : Vect m A) -> (weights : Matrix m n A) -> Layer n m A\n\n\n* Sequential neural networks\n\nA sequential neural network of type |A| with |n| inputs, |m| outputs and\na sequence of intermediate layers is a sequence of layers of type\n|A|. It can consist of either a single (Output) layer or of a layer with\n|n| inputs and |k| outputs together with a network with |k| inputs and\n|m| outputs:\n\n> infixr 5 :>:\n\n> data Network : Nat -> List Nat -> Nat -> Type -> Type where\n> Output : {n, m : Nat} -> {A : Type} -> \n> Layer n m A -> Network n [] m A\n> (:>:) : {n, k, m : Nat} -> {ks : List Nat} -> {A : Type} -> \n> Layer n k A -> Network k ks m A -> Network n (k :: ks) m A\n\n\n\n* Feed-forward\n\nThe idea is that, given a sequential neural network of type |A| with |n|\ninputs and |m| outputs and a vector of |n| inputs of matching type, one\ncan compute a vector of |n| outputs.\n\nThe computation is called feed-forward. It requires |A| to implement\naddition and multiplication and depends on an \"activation\" function |s :\nA -> A|:\n\n> feedForward : {n, m : Nat} -> {ks : List Nat} -> {A : Type} -> Num A => \n> (A -> A) -> Vect n A -> Network n ks m A -> Vect m A\n\nThe idea is to feed the input into the first layer and pass its output\n(activated through |s|) as input for the next layer. With\n\n> evalLayer : {n, m : Nat} -> {t : Type} -> Num t => \n> Vect n t -> Layer n m t -> Vect m t\n> evalLayer {n} {m} {t} input (MkLayer biases weights) = output where\n> output : Vect m t\n> output = biases + (weights input)\n\nthe implementation of |feedForward| is trivial:\n\n> feedForward s input (Output l) = map s (evalLayer input l)\n> feedForward s input (l :>: ls) = feedForward s (map s (evalLayer input l)) ls\n\n\n* Error\n\nGiven a training pair |(x, y)|, the error is simply the difference\nbetween |y| and the output of the network when fed with the input |x|:\n\n> error : {n, m : Nat} -> {ks : List Nat} -> {t : Type} -> Num t => Neg t =>\n> (t -> t) -> Vect n t -> Vect m t -> Network n ks m t -> Vect m t\n> error {m} {t} s input target network = target - output where\n> output : Vect m t\n> output = (feedForward s input network)\n\n\n* Back propagation\n\n> backPropagation : {n, m : Nat} -> {ks : List Nat} -> {t : Type} -> \n> Num t => Neg t =>\n> (s : t -> t) ->\n> (s' : t -> t) ->\n> (eta : t) ->\n> (input : Vect n t) ->\n> (target : Vect m t) ->\n> Network n ks m t -> Network n ks m t\n\n> backPropagation {t} s s' eta input target net = fst (go input target net)\n> \n> where go : {n, m : Nat} -> {ks : List Nat} ->\n> Vect n t -> Vect m t -> Network n ks m t -> (Network n ks m t, Vect n t)\n> \n> go input target ((MkLayer bias weights) :>: rest) =\n> let y = evalLayer input (MkLayer bias weights)\n> output = map s y\n> (rest', dWs') = go output target rest\n> dEdy = (map s' y) * dWs'\n> bias' = bias - (eta <# dEdy)\n> weights' = weights - (eta <#> (dEdy >< input))\n> layer' = (MkLayer bias' weights')\n> dWs = (transpose weights) dEdy\n> in (layer' :>: rest', dWs)\n>\n> go input target (Output (MkLayer bias weights)) =\n> let y = evalLayer input (MkLayer bias weights)\n> output = map s y\n> dEdy = (map s' y) * (output - target)\n> bias' = bias - (eta <# dEdy)\n> weights' = weights - (eta <#> (dEdy >< input))\n> layer' = (MkLayer bias' weights')\n> dWs = (transpose weights) dEdy\n> in (Output layer', dWs)\n\n\n* Example\n\n> initial : Network 2 [2] 2 Double\n> initial = first :>: second\n> where first = MkLayer [0.35, 0.35]\n> [ [0.15, 0.20],\n> [0.25, 0.30]\n> ]\n> second = Output\n> $ MkLayer [0.60, 0.60]\n> [ [0.40, 0.45],\n> [0.50, 0.55]\n> ]\n\n> input : Vect 2 Double\n> input = [0.05,0.10]\n\n> target : Vect 2 Double\n> target = [0.01,0.99]\n\n> s : Double -> Double\n> s x = 1 / (1 + exp (-x))\n\n> s' : Double -> Double\n> s' x = (s x) * (1 - s x)\n\n> main : IO ()\n> main = let step = backPropagation s s' 0.5 input target\n> errorF = error s input target\n> states = iterate step initial\n> in putStrLn . unlines $ map (show . errorF) (take 100 states)\n\n\n> {-\n\n> ---}\n\n", "meta": {"hexsha": "8baa5247424c6dddd64b1c5d5b62271dd4a4b1bb", "size": 5382, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "NeuralNetworks/CoreTheory.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": "NeuralNetworks/CoreTheory.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": "NeuralNetworks/CoreTheory.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.0357142857, "max_line_length": 88, "alphanum_fraction": 0.5261984392, "num_tokens": 1607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6603643626471285}} {"text": "module Data.OrderedSet\n\nimport public Data.DistinctElements\n\n%access public export\n%default total\n\ndata OrderedSet : Nat -> Type -> Type where\n FromVect : (xs : Vect n a) -> {auto p : DistinctElements xs} -> OrderedSet n a\n\nElem : a -> OrderedSet n a -> Type\nElem x (FromVect xs) = Elem x xs\n\nNil : OrderedSet Z a\nNil = FromVect []\n\n(::) : (x : a) -> (xs : OrderedSet n a) -> {default absurd p : Not (Elem x xs)} -> OrderedSet (S n) a\n(::) x (FromVect xs {p = ps}) {p = p} = FromVect (x::xs) {p = (p,ps)}\n\ntail : OrderedSet (S n) a -> OrderedSet n a\ntail (FromVect (_ :: xs) {p = (_, ps)}) = FromVect xs\n\nisElem : DecEq a => (x : a) -> (xs : OrderedSet n a) -> Dec (Elem x xs)\nisElem x (FromVect xs) = isElem x xs\n\ntoVect : OrderedSet n a -> Vect n a\ntoVect (FromVect xs) = xs\n\nmap : {f : a -> b} -> Injective f -> OrderedSet n a -> OrderedSet n b\nmap inj (FromVect xs {p}) {f} = FromVect (map f xs) {p = mapInjectiveFunction inj p}\n", "meta": {"hexsha": "26fc13694984cd00debe7d924374a3fc45f55880", "size": 936, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/OrderedSet.idr", "max_stars_repo_name": "mat8913/l2idris", "max_stars_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data/OrderedSet.idr", "max_issues_repo_name": "mat8913/l2idris", "max_issues_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Data/OrderedSet.idr", "max_forks_repo_name": "mat8913/l2idris", "max_forks_repo_head_hexsha": "d193e85daf5a38ec86459b814f38b4269c10f61c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1935483871, "max_line_length": 101, "alphanum_fraction": 0.6164529915, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6597938256262558}} {"text": "import Data.Vect\n\ntryIndex : {n : _} -> 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", "meta": {"hexsha": "4224f47d4ef65988e9fb4df5fcf976e19c41b1d8", "size": 217, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/typedd-book/chapter04/TryIndex.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "idris2/tests/typedd-book/chapter04/TryIndex.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "idris2/tests/typedd-book/chapter04/TryIndex.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": 31.0, "max_line_length": 56, "alphanum_fraction": 0.5069124424, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6596925122100962}} {"text": "module Hardware\n\nimport Data.Vect\n\nGate : Type\nGate = Bool -> Bool -> Bool\n\nnand : Gate\nnand True True = False\nnand a b = True\n\nand : Gate\nand a b = nand (nand a b) (nand a b)\n\nor : Gate\nor a b = nand (nand a a) (nand b b)\n\nnot : Bool -> Bool\nnot a = nand a a\n\nnor : Gate\nnor a b = nand q q\n where \n q = nand (nand a a) (nand b b)\n\nxor : Gate\nxor a b = nand d e\n where\n c : Bool\n c = nand a b\n d = nand c a\n e = nand c b\n\nhalfAdder : Bool -> Bool -> (Bool, Bool)\nhalfAdder a b = (xor a b, and a b)\n\nfullAdder : Bool -> Bool -> Bool -> (Bool, Bool)\nfullAdder a b c = (xor a (xor b c), or (and a b) (and c (xor a b)))\n\nWord : Nat -> Type\nWord n = Vect n Bool\n\nByte : Type\nByte = Word 8\n\nrippleCarry : Word n -> Word n -> Word n\nrippleCarry x y = go False x y\n where\n go : Bool -> Vect n Bool -> Vect n Bool -> Vect n Bool\n go carry [] [] = Data.Vect.Nil\n go carry (a :: as) (b :: bs) =\n let (s, c) = fullAdder a b carry\n in s :: go c as bs\n\nzero' : Byte\nzero' = replicate 8 False\n\nzero : Word n\nzero {n} = replicate n False\n\none : Word (S n)\none {n} = True :: replicate n False\n\ntwo : Byte\ntwo = rippleCarry one one\n\nthree : Byte\nthree = rippleCarry one two\n\nfour : Byte\nfour = rippleCarry one three\n", "meta": {"hexsha": "ff84ce6a654001a2972b4253564cdb85f98f9726", "size": 1242, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Hardware.idr", "max_stars_repo_name": "parsonsmatt/hardware", "max_stars_repo_head_hexsha": "ecf05b56176b608519806ecacaf50332a386fe5c", "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/Hardware.idr", "max_issues_repo_name": "parsonsmatt/hardware", "max_issues_repo_head_hexsha": "ecf05b56176b608519806ecacaf50332a386fe5c", "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/Hardware.idr", "max_forks_repo_name": "parsonsmatt/hardware", "max_forks_repo_head_hexsha": "ecf05b56176b608519806ecacaf50332a386fe5c", "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.25, "max_line_length": 67, "alphanum_fraction": 0.5877616747, "num_tokens": 446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6596013494684129}} {"text": "||| Convert binary string to an integer\nmodule BinToDec\n\nimport Data.Nat.Exponentiation\n\ndata BinChar : Char -> Type where\n O : BinChar '0'\n I : BinChar '1'\n\ndata Every : (a -> Type) -> List a -> Type where\n Nil : {P : a -> Type} -> Every P []\n (::) : {P : a -> Type} -> P x -> Every P xs -> Every P (x :: xs)\n \nfromBinChars : Every BinChar xs -> Nat -> Nat\nfromBinChars [] _ = 0\nfromBinChars (_ :: ys) Z = 1 \nfromBinChars (O :: ys) (S k) = fromBinChars ys k\nfromBinChars (I :: ys) (S k) = lpow 2 k + fromBinChars ys k\n\nb : (s : String) -> {auto p : Every BinChar (unpack s)} -> Nat\nb {p} s = fromBinChars p (length s) ", "meta": {"hexsha": "637f452f07b53ba4ff5595c6d4a16496e310121c", "size": 624, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/BinToDec.idr", "max_stars_repo_name": "DejanMilicic/IdrisPlayground", "max_stars_repo_head_hexsha": "2d35ab2d2e2b6d5ba1bbae6d00b2d5d63e50cbc9", "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/BinToDec.idr", "max_issues_repo_name": "DejanMilicic/IdrisPlayground", "max_issues_repo_head_hexsha": "2d35ab2d2e2b6d5ba1bbae6d00b2d5d63e50cbc9", "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/BinToDec.idr", "max_forks_repo_name": "DejanMilicic/IdrisPlayground", "max_forks_repo_head_hexsha": "2d35ab2d2e2b6d5ba1bbae6d00b2d5d63e50cbc9", "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": 29.7142857143, "max_line_length": 66, "alphanum_fraction": 0.5961538462, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6594821190084414}} {"text": "import Data.Vect\n\ninsert : Ord elem =>\n (x : elem) -> (xsSorted : Vect len elem) -> Vect (S len) elem\ninsert x [] = [x]\ninsert x (y :: xs) = case x < y of\n False => y :: insert x xs\n True => x :: y :: xs\n\ninsSort : Ord elem => Vect n elem -> Vect n elem\ninsSort [] = []\ninsSort (x :: xs) = let xsSorted = insSort xs in\n insert x xsSorted\n", "meta": {"hexsha": "fc92f48db22b307109736ddaf8d32589cebfd8f8", "size": 419, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter3/VecSort.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/VecSort.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/VecSort.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": 29.9285714286, "max_line_length": 70, "alphanum_fraction": 0.4725536993, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6593568449602809}} {"text": "plus' : Nat -> Nat -> Nat\nplus' Z y = y\nplus' (S k) y = S (plus' k y)\n\nmult' : Nat -> Nat -> Nat\nmult' Z y = Z\nmult' (S k) y = plus' y (mult' k y)\n", "meta": {"hexsha": "95d29a6b71586e39cff259ad2cf612baa2870cb8", "size": 155, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/functions.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/functions.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/functions.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": 19.375, "max_line_length": 35, "alphanum_fraction": 0.464516129, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6590156379204224}} {"text": "module Data.Fin.Extra\n\nimport Data.Fin\nimport Data.Nat\n\nimport Syntax.WithProof\nimport Syntax.PreorderReasoning\n\n%default total\n\n-------------------------------\n--- `finToNat`'s properties ---\n-------------------------------\n\n||| A Fin's underlying natural number is smaller than the bound\nexport\nelemSmallerThanBound : (n : Fin m) -> LT (finToNat n) m\nelemSmallerThanBound FZ = LTESucc LTEZero\nelemSmallerThanBound (FS x) = LTESucc (elemSmallerThanBound x)\n\n||| Last's underlying natural number is the bound's predecessor\nexport\nfinToNatLastIsBound : {n : Nat} -> finToNat (Fin.last {n}) = n\nfinToNatLastIsBound {n=Z} = Refl\nfinToNatLastIsBound {n=S k} = cong S finToNatLastIsBound\n\n||| Weaken does not modify the underlying natural number\nexport\nfinToNatWeakenNeutral : {n : Fin m} -> finToNat (weaken n) = finToNat n\nfinToNatWeakenNeutral = finToNatQuotient (weakenNeutral n)\n\n||| WeakenN does not modify the underlying natural number\nexport\nfinToNatWeakenNNeutral : (0 m : Nat) -> (k : Fin n) ->\n finToNat (weakenN m k) = finToNat k\nfinToNatWeakenNNeutral m k = finToNatQuotient (weakenNNeutral m k)\n\n||| `Shift k` shifts the underlying natural number by `k`.\nexport\nfinToNatShift : (k : Nat) -> (a : Fin n) -> finToNat (shift k a) = k + finToNat a\nfinToNatShift Z a = Refl\nfinToNatShift (S k) a = cong S (finToNatShift k a)\n\n-------------------------------------------------\n--- Inversion function and related properties ---\n-------------------------------------------------\n\n||| Compute the Fin such that `k + invFin k = n - 1`\npublic export\ninvFin : {n : Nat} -> Fin n -> Fin n\ninvFin FZ = last\ninvFin (FS k) = weaken (invFin k)\n\nexport\ninvFinSpec : {n : _} -> (i : Fin n) -> 1 + finToNat i + finToNat (invFin i) = n\ninvFinSpec {n = S k} FZ = cong S finToNatLastIsBound\ninvFinSpec (FS k) = let H = invFinSpec k in\n let h = finToNatWeakenNeutral {n = invFin k} in\n cong S (rewrite h in H)\n\n||| The inverse of a weakened element is the successor of its inverse\nexport\ninvFinWeakenIsFS : {n : Nat} -> (m : Fin n) -> invFin (weaken m) = FS (invFin m)\ninvFinWeakenIsFS FZ = Refl\ninvFinWeakenIsFS (FS k) = cong weaken (invFinWeakenIsFS k)\n\nexport\ninvFinLastIsFZ : {n : Nat} -> invFin (last {n}) = FZ\ninvFinLastIsFZ {n = Z} = Refl\ninvFinLastIsFZ {n = S n} = cong weaken (invFinLastIsFZ {n})\n\n||| `invFin` is involutive (i.e. applied twice it is the identity)\nexport\ninvFinInvolutive : {n : Nat} -> (m : Fin n) -> invFin (invFin m) = m\ninvFinInvolutive FZ = invFinLastIsFZ\ninvFinInvolutive (FS k) = Calc $\n |~ invFin (invFin (FS k))\n ~~ invFin (weaken (invFin k)) ...( Refl )\n ~~ FS (invFin (invFin k)) ...( invFinWeakenIsFS (invFin k) )\n ~~ FS k ...( cong FS (invFinInvolutive k) )\n\n--------------------------------\n--- Strengthening properties ---\n--------------------------------\n\n||| It's possible to strengthen a weakened element of Fin **m**.\nexport\nstrengthenWeakenIsRight : (n : Fin m) -> strengthen (weaken n) = Just n\nstrengthenWeakenIsRight FZ = Refl\nstrengthenWeakenIsRight (FS k) = rewrite strengthenWeakenIsRight k in Refl\n\n||| It's not possible to strengthen the last element of Fin **n**.\nexport\nstrengthenLastIsLeft : {n : Nat} -> strengthen (Fin.last {n}) = Nothing\nstrengthenLastIsLeft {n=Z} = Refl\nstrengthenLastIsLeft {n=S k} = rewrite strengthenLastIsLeft {n=k} in Refl\n\n||| It's possible to strengthen the inverse of a succesor\nexport\nstrengthenNotLastIsRight : {n : Nat} -> (m : Fin n) -> strengthen (invFin (FS m)) = Just (invFin m)\nstrengthenNotLastIsRight m = strengthenWeakenIsRight (invFin m)\n\n||| Either tightens the bound on a Fin or proves that it's the last.\nexport\nstrengthen' : {n : Nat} -> (m : Fin (S n)) ->\n Either (m = Fin.last) (m' : Fin n ** finToNat m = finToNat m')\nstrengthen' {n = Z} FZ = Left Refl\nstrengthen' {n = S k} FZ = Right (FZ ** Refl)\nstrengthen' {n = S k} (FS m) = case strengthen' m of\n Left eq => Left $ cong FS eq\n Right (m' ** eq) => Right (FS m' ** cong S eq)\n\n----------------------------\n--- Weakening properties ---\n----------------------------\n\nexport\nweakenNZeroIdentity : (k : Fin n) -> weakenN 0 k ~~~ k\nweakenNZeroIdentity FZ = FZ\nweakenNZeroIdentity (FS k) = FS (weakenNZeroIdentity k)\n\nexport\nshiftFSLinear : (m : Nat) -> (f : Fin n) -> shift m (FS f) ~~~ FS (shift m f)\nshiftFSLinear Z f = reflexive\nshiftFSLinear (S m) f = FS (shiftFSLinear m f)\n\nexport\nshiftLastIsLast : (m : Nat) -> {n : Nat} ->\n shift m (Fin.last {n}) ~~~ Fin.last {n=m+n}\nshiftLastIsLast Z = reflexive\nshiftLastIsLast (S m) = FS (shiftLastIsLast m)\n\n-----------------------------------\n--- Division-related properties ---\n-----------------------------------\n\n||| A view of Nat as a quotient of some number and a finite remainder.\npublic export\ndata FractionView : (n : Nat) -> (d : Nat) -> Type where\n Fraction : (n : Nat) -> (d : Nat) -> {auto ok: GT d Z} ->\n (q : Nat) -> (r : Fin d) ->\n q * d + finToNat r = n -> FractionView n d\n\n||| Converts Nat to the fractional view with a non-zero divisor.\nexport\ndivMod : (n, d : Nat) -> {auto ok: GT d Z} -> FractionView n d\ndivMod Z (S d) = Fraction Z (S d) Z FZ Refl\ndivMod {ok=_} (S n) (S d) =\n let Fraction {ok=ok} n (S d) q r eq = divMod n (S d) in\n case strengthen' r of\n Left eq' => Fraction {ok=ok} (S n) (S d) (S q) FZ $\n rewrite sym eq in\n rewrite trans (cong finToNat eq') finToNatLastIsBound in\n cong S $ trans\n (plusZeroRightNeutral (d + q * S d))\n (plusCommutative d (q * S d))\n Right (r' ** eq') => Fraction {ok=ok} (S n) (S d) q (FS r') $\n rewrite sym $ plusSuccRightSucc (q * S d) (finToNat r') in\n cong S $ trans (sym $ cong (plus (q * S d)) eq') eq\n\n-------------------\n--- Conversions ---\n-------------------\n\n||| Total function to convert a nat to a Fin, given a proof\n||| that it is less than the bound.\npublic export\nnatToFinLTE : (n : Nat) -> (0 _ : LT n m) -> Fin m\nnatToFinLTE Z (LTESucc _) = FZ\nnatToFinLTE (S k) (LTESucc l) = FS $ natToFinLTE k l\n\n||| Converting from a Nat to a Fin and back is the identity.\npublic export\nnatToFinToNat :\n (n : Nat)\n -> (lte : LT n m)\n -> finToNat (natToFinLTE n lte) = n\nnatToFinToNat 0 (LTESucc lte) = Refl\nnatToFinToNat (S k) (LTESucc lte) = cong S (natToFinToNat k lte)\n\n----------------------------------------\n--- Result-type changing arithmetics ---\n----------------------------------------\n\n||| Addition of `Fin`s as bounded naturals.\n||| The resulting type has the smallest possible bound\n||| as illustated by the relations with the `last` function.\npublic export\n(+) : {m, n : Nat} -> Fin m -> Fin (S n) -> Fin (m + n)\n(+) FZ y = coerce (cong S $ plusCommutative n (pred m)) (weakenN (pred m) y)\n(+) (FS x) y = FS (x + y)\n\n||| Multiplication of `Fin`s as bounded naturals.\n||| The resulting type has the smallest possible bound\n||| as illustated by the relations with the `last` function.\npublic export\n(*) : {m, n : Nat} -> Fin (S m) -> Fin (S n) -> Fin (S (m * n))\n(*) FZ _ = FZ\n(*) {m = S _} (FS x) y = y + x * y\n\n--- Properties ---\n\n-- Relation between `+` and `*` and their counterparts on `Nat`\n\nexport\nfinToNatPlusHomo : {m, n : Nat} -> (x : Fin m) -> (y : Fin (S n)) ->\n finToNat (x + y) = finToNat x + finToNat y\nfinToNatPlusHomo FZ _\n = finToNatQuotient $ transitive\n (coerceEq _)\n (weakenNNeutral _ _)\nfinToNatPlusHomo (FS x) y = cong S (finToNatPlusHomo x y)\n\nexport\nfinToNatMultHomo : {m, n : Nat} -> (x : Fin (S m)) -> (y : Fin (S n)) ->\n finToNat (x * y) = finToNat x * finToNat y\nfinToNatMultHomo FZ _ = Refl\nfinToNatMultHomo {m = S _} (FS x) y = Calc $\n |~ finToNat (FS x * y)\n ~~ finToNat (y + x * y) ...( Refl )\n ~~ finToNat y + finToNat (x * y) ...( finToNatPlusHomo y (x * y) )\n ~~ finToNat y + finToNat x * finToNat y ...( cong (finToNat y +) (finToNatMultHomo x y) )\n ~~ finToNat (FS x) * finToNat y ...( Refl )\n\n-- Relations to `Fin`'s `last`\n\nexport\nplusPreservesLast : (m, n : Nat) -> Fin.last {n=m} + Fin.last {n} = Fin.last\nplusPreservesLast Z n\n = homoPointwiseIsEqual $ transitive\n (coerceEq _)\n (weakenNNeutral _ _)\nplusPreservesLast (S m) n = cong FS (plusPreservesLast m n)\n\nexport\nmultPreservesLast : (m, n : Nat) -> Fin.last {n=m} * Fin.last {n} = Fin.last\nmultPreservesLast Z n = Refl\nmultPreservesLast (S m) n = Calc $\n |~ last + (last * last)\n ~~ last + last ...( cong (last +) (multPreservesLast m n) )\n ~~ last ...( plusPreservesLast n (m * n) )\n\n-- General addition properties\n\nexport\nplusSuccRightSucc : {m, n : Nat} -> (left : Fin m) -> (right : Fin (S n)) ->\n FS (left + right) ~~~ left + FS right\nplusSuccRightSucc FZ right = FS $ congCoerce reflexive\nplusSuccRightSucc (FS left) right = FS $ plusSuccRightSucc left right\n\n-- Relations to `Fin`-specific `shift` and `weaken`\n\nexport\nshiftAsPlus : {m, n : Nat} -> (k : Fin (S m)) ->\n shift n k ~~~ last {n} + k\nshiftAsPlus {n=Z} k =\n symmetric $ transitive (coerceEq _) (weakenNNeutral _ _)\nshiftAsPlus {n=S n} k = FS (shiftAsPlus k)\n\nexport\nweakenNAsPlusFZ : {m, n : Nat} -> (k : Fin n) ->\n weakenN m k = k + the (Fin (S m)) FZ\nweakenNAsPlusFZ FZ = Refl\nweakenNAsPlusFZ (FS k) = cong FS (weakenNAsPlusFZ k)\n\nexport\nweakenNPlusHomo : {0 m, n : Nat} -> (k : Fin p) ->\n weakenN n (weakenN m k) ~~~ weakenN (m + n) k\nweakenNPlusHomo FZ = FZ\nweakenNPlusHomo (FS k) = FS (weakenNPlusHomo k)\n\nexport\nweakenNOfPlus :\n {m, n : Nat} -> (k : Fin m) -> (l : Fin (S n)) ->\n weakenN w (k + l) ~~~ weakenN w k + l\nweakenNOfPlus FZ l\n = transitive (congWeakenN (coerceEq _))\n $ transitive (weakenNPlusHomo l)\n $ symmetric (coerceEq _)\nweakenNOfPlus (FS k) l = FS (weakenNOfPlus k l)\n-- General addition properties (continued)\n\nexport\nplusZeroLeftNeutral : (k : Fin (S n)) -> FZ + k ~~~ k\nplusZeroLeftNeutral k = transitive (coerceEq _) (weakenNNeutral _ k)\n\nexport\ncongPlusLeft : {m, n, p : Nat} -> {k : Fin m} -> {l : Fin n} ->\n (c : Fin (S p)) -> k ~~~ l -> k + c ~~~ l + c\ncongPlusLeft c FZ\n = transitive (plusZeroLeftNeutral c)\n (symmetric $ plusZeroLeftNeutral c)\ncongPlusLeft c (FS prf) = FS (congPlusLeft c prf)\n\nexport\nplusZeroRightNeutral : (k : Fin m) -> k + FZ ~~~ k\nplusZeroRightNeutral FZ = FZ\nplusZeroRightNeutral (FS k) = FS (plusZeroRightNeutral k)\n\nexport\ncongPlusRight : {m, n, p : Nat} -> {k : Fin (S n)} -> {l : Fin (S p)} ->\n (c : Fin m) -> k ~~~ l -> c + k ~~~ c + l\ncongPlusRight c FZ\n = transitive (plusZeroRightNeutral c)\n (symmetric $ plusZeroRightNeutral c)\ncongPlusRight {n = S _} {p = S _} c (FS prf)\n = transitive (symmetric $ plusSuccRightSucc c _)\n $ transitive (FS $ congPlusRight c prf)\n (plusSuccRightSucc c _)\ncongPlusRight {p = Z} c (FS prf) impossible\n\nexport\nplusCommutative : {m, n : Nat} -> (left : Fin (S m)) -> (right : Fin (S n)) ->\n left + right ~~~ right + left\nplusCommutative FZ right\n = transitive (plusZeroLeftNeutral right)\n (symmetric $ plusZeroRightNeutral right)\nplusCommutative {m = S _} (FS left) right\n = transitive (FS (plusCommutative left right))\n (plusSuccRightSucc right left)\n\nexport\nplusAssociative :\n {m, n, p : Nat} ->\n (left : Fin m) -> (centre : Fin (S n)) -> (right : Fin (S p)) ->\n left + (centre + right) ~~~ (left + centre) + right\nplusAssociative FZ centre right\n = transitive (plusZeroLeftNeutral (centre + right))\n (congPlusLeft right (symmetric $ plusZeroLeftNeutral centre))\nplusAssociative (FS left) centre right = FS (plusAssociative left centre right)\n\n-------------------------------------------------\n--- Splitting operations and their properties ---\n-------------------------------------------------\n\n||| Converts `Fin`s that are used as indexes of parts to an index of a sum.\n|||\n||| For example, if you have a `Vect` that is a concatenation of two `Vect`s and\n||| you have an index either in the first or the second of the original `Vect`s,\n||| using this function you can get an index in the concatenated one.\npublic export\nindexSum : {m : Nat} -> Either (Fin m) (Fin n) -> Fin (m + n)\nindexSum (Left l) = weakenN n l\nindexSum (Right r) = shift m r\n\n||| Extracts an index of the first or the second part from the index of a sum.\n|||\n||| For example, if you have a `Vect` that is a concatenation of the `Vect`s and\n||| you have an index of this `Vect`, you have get an index of either left or right\n||| original `Vect` using this function.\npublic export\nsplitSum : {m : Nat} -> Fin (m + n) -> Either (Fin m) (Fin n)\nsplitSum {m=Z} k = Right k\nsplitSum {m=S m} FZ = Left FZ\nsplitSum {m=S m} (FS k) = mapFst FS $ splitSum k\n\n||| Calculates the index of a square matrix of size `a * b` by indices of each side.\npublic export\nindexProd : {n : Nat} -> Fin m -> Fin n -> Fin (m * n)\nindexProd FZ = weakenN $ mult (pred m) n\nindexProd (FS k) = shift n . indexProd k\n\n||| Splits the index of a square matrix of size `a * b` to indices of each side.\npublic export\nsplitProd : {m, n : Nat} -> Fin (m * n) -> (Fin m, Fin n)\nsplitProd {m=S _} p = case splitSum p of\n Left k => (FZ, k)\n Right l => mapFst FS $ splitProd l\n\n--- Properties ---\n\nexport\nindexSumPreservesLast :\n (m, n : Nat) -> indexSum {m} (Right $ Fin.last {n}) ~~~ Fin.last {n=m+n}\nindexSumPreservesLast Z n = reflexive\nindexSumPreservesLast (S m) n = FS (shiftLastIsLast m)\n\nexport\nindexProdPreservesLast : (m, n : Nat) ->\n indexProd (Fin.last {n=m}) (Fin.last {n}) = Fin.last\nindexProdPreservesLast Z n = homoPointwiseIsEqual\n $ transitive (weakenNZeroIdentity last)\n (congLast (sym $ plusZeroRightNeutral n))\nindexProdPreservesLast (S m) n = Calc $\n |~ indexProd (last {n=S m}) (last {n})\n ~~ FS (shift n (indexProd last last)) ...( Refl )\n ~~ FS (shift n last) ...( cong (FS . shift n) (indexProdPreservesLast m n ) )\n ~~ last ...( homoPointwiseIsEqual prf )\n\n where\n\n prf : shift (S n) (Fin.last {n = n + m * S n}) ~~~ Fin.last {n = n + S (n + m * S n)}\n prf = transitive (shiftLastIsLast (S n))\n (congLast (plusSuccRightSucc n (n + m * S n)))\n\nexport\nsplitSumOfWeakenN : (k : Fin m) -> splitSum {m} {n} (weakenN n k) = Left k\nsplitSumOfWeakenN FZ = Refl\nsplitSumOfWeakenN (FS k) = cong (mapFst FS) $ splitSumOfWeakenN k\n\nexport\nsplitSumOfShift : {m : Nat} -> (k : Fin n) -> splitSum {m} {n} (shift m k) = Right k\nsplitSumOfShift {m=Z} k = Refl\nsplitSumOfShift {m=S m} k = cong (mapFst FS) $ splitSumOfShift k\n\nexport\nsplitOfIndexSumInverse : {m : Nat} -> (e : Either (Fin m) (Fin n)) -> splitSum (indexSum e) = e\nsplitOfIndexSumInverse (Left l) = splitSumOfWeakenN l\nsplitOfIndexSumInverse (Right r) = splitSumOfShift r\n\nexport\nindexOfSplitSumInverse : {m, n : Nat} -> (f : Fin (m + n)) -> indexSum (splitSum {m} {n} f) = f\nindexOfSplitSumInverse {m=Z} f = Refl\nindexOfSplitSumInverse {m=S _} FZ = Refl\nindexOfSplitSumInverse {m=S _} (FS f) with (indexOfSplitSumInverse f)\n indexOfSplitSumInverse {m=S _} (FS f) | eq with (splitSum f)\n indexOfSplitSumInverse {m=S _} (FS _) | eq | Left _ = cong FS eq\n indexOfSplitSumInverse {m=S _} (FS _) | eq | Right _ = cong FS eq\n\n\nexport\nsplitOfIndexProdInverse : {m : Nat} -> (k : Fin m) -> (l : Fin n) ->\n splitProd (indexProd k l) = (k, l)\nsplitOfIndexProdInverse FZ l\n = rewrite splitSumOfWeakenN {n = mult (pred m) n} l in Refl\nsplitOfIndexProdInverse (FS k) l\n = rewrite splitSumOfShift {m=n} $ indexProd k l in\n cong (mapFst FS) $ splitOfIndexProdInverse k l\n\nexport\nindexOfSplitProdInverse : {m, n : Nat} -> (f : Fin (m * n)) ->\n uncurry (indexProd {m} {n}) (splitProd {m} {n} f) = f\nindexOfSplitProdInverse {m = S _} f with (@@ splitSum f)\n indexOfSplitProdInverse {m = S _} f | (Left l ** eq) = rewrite eq in Calc $\n |~ indexSum (Left l)\n ~~ indexSum (splitSum f) ...( cong indexSum (sym eq) )\n ~~ f ...( indexOfSplitSumInverse f )\n indexOfSplitProdInverse f | (Right r ** eq) with (@@ splitProd r)\n indexOfSplitProdInverse f | (Right r ** eq) | ((p, q) ** eq2)\n = rewrite eq in rewrite eq2 in Calc $\n |~ indexProd (FS p) q\n ~~ shift n (indexProd p q) ...( Refl )\n ~~ shift n (uncurry indexProd (splitProd r)) ...( cong (shift n . uncurry indexProd) (sym eq2) )\n ~~ shift n r ...( cong (shift n) (indexOfSplitProdInverse r) )\n ~~ indexSum (splitSum f) ...( sym (cong indexSum eq) )\n ~~ f ...( indexOfSplitSumInverse f )\n", "meta": {"hexsha": "0444e33866ba437c81832b0a7ace6b8d95e9f635", "size": 16876, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "libs/contrib/Data/Fin/Extra.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 128, "max_stars_repo_stars_event_min_datetime": "2020-06-09T21:25:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:50:24.000Z", "max_issues_repo_path": "libs/contrib/Data/Fin/Extra.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-08-26T03:38:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-23T21:32:49.000Z", "max_forks_repo_path": "libs/contrib/Data/Fin/Extra.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-28T04:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T12:47:16.000Z", "avg_line_length": 37.7539149888, "max_line_length": 104, "alphanum_fraction": 0.5970609149, "num_tokens": 5453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893519999, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6587626423002026}} {"text": "import Data.Vect\n\nread_vect_len : (len : Nat) -> IO (Vect len String)\nread_vect_len Z = pure []\nread_vect_len (S k) = do\n x <- getLine\n xs <- read_vect_len k\n pure (x :: xs)\n\nread_vect : IO (n ** Vect n String)\nread_vect = do\n x <- getLine\n if (x == \"\")\n then pure (_ ** [])\n else do (_ ** xs) <- read_vect\n pure (_ ** (x :: xs))\n\nzipInputs : IO ()\nzipInputs = do\n putStrLn \"1:\"\n (len1 ** vec1) <- read_vect\n putStrLn \"2:\"\n (len2 ** vec2) <- read_vect\n case exactLength len1 vec2 of\n Nothing => putStrLn \"Input lengths must be equal\"\n Just vec2' => printLn (zip vec1 vec2')\n", "meta": {"hexsha": "b0435e8fd3a954097d686604554c4a89db095645", "size": 607, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-05/read_vect.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-05/read_vect.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-05/read_vect.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.4814814815, "max_line_length": 53, "alphanum_fraction": 0.5881383855, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6587548727174654}} {"text": "\ndata Elem : a -> List a -> Type where\n Here : Elem x (x :: xs)\n There : Elem x xs -> Elem x (y :: xs)\n\ndata Last : List a -> a -> Type where\n LastOne : Last [value] value\n LastCons : (prf : Last xs value) -> Last (x :: xs) value\n\nnot_in_nil : Last [] value -> Void\nnot_in_nil LastOne impossible\nnot_in_nil (LastCons _) impossible\n\nnot_last_one : (contra : (value = x) -> Void) -> Last [x] value -> Void\nnot_last_one contra LastOne = contra Refl\nnot_last_one _ (LastCons LastOne) impossible\nnot_last_one _ (LastCons (LastCons _)) impossible\n\nnot_last_cons : (contra : Last (x :: xs) value -> Void) ->\n Last (y :: (x :: xs)) value -> Void\nnot_last_cons contra (LastCons prf) = contra prf\n\nisLast : DecEq a => (xs : List a) -> (value : a) -> Dec (Last xs value)\nisLast [] value = No not_in_nil\nisLast [x] value = case decEq value x of\n (Yes Refl) => Yes LastOne\n (No contra) => No (not_last_one contra)\nisLast (y :: (x :: xs)) value = case isLast (x :: xs) value of\n (Yes prf) => Yes (LastCons prf)\n (No contra) => No (not_last_cons contra)\n", "meta": {"hexsha": "4b44f1f6e923e20c7b0aebe6d5b2ea861a9e21e8", "size": 1179, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-09/list.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-09/list.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-09/list.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": 38.0322580645, "max_line_length": 77, "alphanum_fraction": 0.5750636132, "num_tokens": 336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.658630102282177}} {"text": "module CommutativityOfAddition\n\n%default total\n\n\nsym_eq : x = y -> y = x\nsym_eq Refl = Refl\n\ntr_eq : x = y -> y = z -> x = z\ntr_eq Refl Refl = Refl\n\ncongr : (P : a -> b) -> x = y -> P x = P y\ncongr f Refl = Refl\n\n\n-- x = x + 0\nsym_plus_z : {m : Nat} -> m = m + 0\nsym_plus_z {m=Z} = Refl\n-- sym_plus_z {m=(S k)} = congr S (sym_plus_z{m=k})\nsym_plus_z {m=(S k)} = rewrite sym_plus_z{m=k} in Refl\n\n-- S x = 1 + x\nsym_plus_one_left : {m : Nat} -> S m = 1 + m\nsym_plus_one_left = Refl\n\n-- S x = x + 1\nsym_plus_one_right : {m : Nat} -> S m = m + 1\nsym_plus_one_right {m=Z} = Refl\nsym_plus_one_right {m=(S k)} =\n rewrite sym_plus_one_right{m=k} in Refl\n\nproof11 : {m : Nat} -> S m + m = S (m + m)\nproof11 {m = Z} = Refl\nproof11 {m = (S k)} = Refl\n\nproof12 : {m : Nat} -> {a : Nat} -> a + (S m) = S (a + m)\n-- 0 + (S m) = S (0 + m)\nproof12 {m=m} {a=Z} = Refl\nproof12 {m=m} {a=(S k)} = rewrite proof12{m=m}{a=k} in Refl\n\n-- S x + S x = S (S (x + x))\nexport\n-- S (S x) + S (S x) = S (S (S S (x + x)))\nsumSucc : {m : Nat} -> S m + S m = S (S (m + m))\n-- -- S 0 + S 0 = S (S (0 + 0))\nsumSucc {m=Z} = Refl\n-- S (S k) + S (S k) = S (S ((S k) + (S k)))\nsumSucc {m=m} = let rec = proof12{m=m}{a=m} -- (S m) + (S m) = S ((S m) + m)\n in rewrite rec\n in Refl\n\nproof2 : {x: Nat} -> {y: Nat} -> S x + S y = S (S (x + y))\nproof2 {x=Z} {y=Z} = Refl\nproof2 {x=Z} {y=(S k)} = Refl\nproof2 {x=(S k)} {y=Z} = rewrite proof2{x=k}{y=Z} in Refl\nproof2 {x=(S kx)} {y=(S ky)} = rewrite proof2{x=kx}{y=(S ky)} in Refl\n\n\nproof3 : {x, y: Nat} -> {y: Nat} -> S (x + y) = x + (S y)\nproof3 {x=Z}{y=y} = Refl\nproof3 {x=(S k)}{y=y} = -- S (S k + y) = S k + (S y)\n let p = proof3{x=k}{y=y} -- S (k + y) = k + (S y)\n in congr S p\n -- rewrite proof3{x=k}{y=y} -- S (k + y) = k + (S y)\n -- in Refl -- (k + (S y) = k + (S y)\n -- S (S k + y) = S (k + (S y))\n -- replace{P=\\w => S (S k + y) = S w} (proof3{x=k}{y=y}) Refl{x=(S k + y)}\n\n\nsym_plus : {x,y:Nat} -> x + y = y + x\nsym_plus {x=Z}{y=Z} = Refl\nsym_plus {x=Z}{y=(S k)} = sym_plus_z\nsym_plus {x=(S k)}{y=Z} = sym_eq sym_plus_z\n-- sym_plus_z = 0 + x = x + 0\nsym_plus {x=(S kx)}{y=(S ky)} = -- S kx + y = y + S kx\n let p1 = sym_plus{x=kx}{y=(S ky)} -- kx + y = y + kx\n p2 = proof3{x=(S ky)}{y=kx} -- S (y + kx) = y + (S kx)\n in tr_eq (congr S p1) p2\n-- proof3 : S (x + y) = x + (S y)\n\n\n", "meta": {"hexsha": "558740ef2cdcf3bf9e260a90a5f348fd9398a989", "size": 2465, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "proofs/CommutativityOfAddition.idr", "max_stars_repo_name": "GoPavel/idris-proof", "max_stars_repo_head_hexsha": "36f30dc0133d7d968548c50b6aa76f6d6b382c59", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "proofs/CommutativityOfAddition.idr", "max_issues_repo_name": "GoPavel/idris-proof", "max_issues_repo_head_hexsha": "36f30dc0133d7d968548c50b6aa76f6d6b382c59", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proofs/CommutativityOfAddition.idr", "max_forks_repo_name": "GoPavel/idris-proof", "max_forks_repo_head_hexsha": "36f30dc0133d7d968548c50b6aa76f6d6b382c59", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0609756098, "max_line_length": 78, "alphanum_fraction": 0.4547667343, "num_tokens": 1117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.658413820507849}} {"text": "module Algebra.Semiring\n\nimport Data.Nat\nimport Syntax.PreorderReasoning\n\n%default total\n\n||| This interface is a witness that for a\n||| numeric type `a` the axioms of a commutative semiring hold:\n|||\n||| 1. `a` is a commutative monoid under addition:\n||| 1. `+` is associative: `k + (m + n) = (k + m) + n` for all `k,m,n : a`.\n||| 2. `+` is commutative: `m + n = n + m` for all `m,n : a`.\n||| 3. 0 is the additive identity: `n + 0 = n` for all `n : a`.\n|||\n||| 2. `a` is a commutative monoid under multiplication:\n||| 1. `*` is associative: `k * (m * n) = (k * m) * n` for all `k,m,n : a`.\n||| 2. `*` is commutative: `m * n = n * m` for all `m,n : a`.\n||| 3. 1 is the multiplicative identity: `n * 1 = n` for all `n : a`.\n|||\n||| 3. Multiplication is distributive with respect to addition:\n||| `k * (m + n) = (k * m) + (k * n)` for all `k,m,n : a`.\n|||\npublic export\ninterface Num a => Semiring a where\n ||| Addition is associative.\n 0 plusAssociative : {k,m,n : a} -> k + (m + n) === (k + m) + n\n\n ||| Addition is commutative.\n 0 plusCommutative : {m,n : a} -> m + n === n + m\n\n ||| 0 is the additive identity.\n 0 plusZeroLeftNeutral : {n : a} -> 0 + n === n\n\n ||| Multiplication is associative.\n 0 multAssociative : {k,m,n : a} -> k * (m * n) === (k * m) * n\n\n ||| Multiplication is commutative.\n 0 multCommutative : {m,n : a} -> m * n === n * m\n\n ||| 1 is the multiplicative identity.\n 0 multOneLeftNeutral : {n : a} -> 1 * n === n\n\n ||| Multiplication is distributive with respect to addition.\n 0 leftDistributive : {k,m,n : a} -> k * (m + n) === (k * m) + (k * n)\n\n ||| Zero is an absorbing element of multiplication.\n 0 multZeroLeftAbsorbs : {n : a} -> 0 * n === 0\n\n--------------------------------------------------------------------------------\n-- Proofs on Addition\n--------------------------------------------------------------------------------\n\n||| `n + 0 === n` for all `n : a`.\nexport\n0 plusZeroRightNeutral : Semiring a => {n : a} -> n + 0 === n\nplusZeroRightNeutral =\n Calc $\n |~ n + 0\n ~~ 0 + n ... plusCommutative\n ~~ n ... plusZeroLeftNeutral\n\n--------------------------------------------------------------------------------\n-- Proofs on Multiplication\n--------------------------------------------------------------------------------\n\n||| `n * 1 === n` for all `n : a`.\nexport\n0 multOneRightNeutral : Semiring a => {n : a} -> n * 1 === n\nmultOneRightNeutral =\n Calc $\n |~ n * 1\n ~~ 1 * n ... multCommutative\n ~~ n ... multOneLeftNeutral\n\n||| Zero is an absorbing element of multiplication.\nexport\n0 multZeroRightAbsorbs : Semiring a => {n : a} -> n * 0 === 0\nmultZeroRightAbsorbs =\n Calc $\n |~ n * 0\n ~~ 0 * n ... multCommutative\n ~~ 0 ... multZeroLeftAbsorbs\n\n||| Zero is an absorbing element of multiplication.\nexport\nmultZeroAbsorbs : Semiring a\n => (m,n : a)\n -> Either (m === 0) (n === 0)\n -> m * n === 0\nmultZeroAbsorbs m n (Left rfl) =\n Calc $\n |~ m * n\n ~~ 0 * n ... cong (*n) rfl\n ~~ 0 ... multZeroLeftAbsorbs\n\nmultZeroAbsorbs m n (Right rfl) =\n Calc $\n |~ m * n\n ~~ m * 0 ... cong (m*) rfl\n ~~ 0 ... multZeroRightAbsorbs\n\n||| Multiplication is distributive with respect to addition.\nexport\n0 rightDistributive : Semiring a\n => {k,m,n : a}\n -> (m + n) * k === m * k + n * k\nrightDistributive =\n Calc $\n |~ (m + n) * k\n ~~ k * (m + n) ... multCommutative\n ~~ (k * m) + (k * n) ... leftDistributive\n ~~ m * k + k * n ... cong (+ k * n) multCommutative\n ~~ m * k + n * k ... cong (m * k +) multCommutative\n\n--------------------------------------------------------------------------------\n-- Implementations\n--------------------------------------------------------------------------------\n\nexport\nSemiring Nat where\n plusAssociative = Nat.plusAssociative _ _ _\n plusCommutative = Nat.plusCommutative _ _\n plusZeroLeftNeutral = Nat.plusZeroLeftNeutral _\n multAssociative = Nat.multAssociative _ _ _\n multCommutative = Nat.multCommutative _ _\n multOneLeftNeutral = Nat.multOneLeftNeutral _\n leftDistributive = multDistributesOverPlusRight _ _ _\n multZeroLeftAbsorbs = Refl\n", "meta": {"hexsha": "2ec987f7f3058425a4419cd5ad914f4479a60010", "size": 4249, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Algebra/Semiring.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/Semiring.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/Semiring.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.6846153846, "max_line_length": 80, "alphanum_fraction": 0.4968227818, "num_tokens": 1321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6583920552985774}} {"text": "data Tree elem = Empty\n | Node (Tree elem) elem (Tree elem)\n\nFunctor Tree where\n map func Empty = Empty\n map func (Node left e right)\n = Node (map func left)\n (func e)\n (map func right)\n\nFoldable Tree where\n foldr func acc Empty = acc \n foldr func acc (Node left e right)\n = let leftfold = foldr func acc left\n rightfold = foldr func leftfold right in\n func e rightfold\n", "meta": {"hexsha": "d7014ab95ee211b9299d199c61b3708eee8affba", "size": 432, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp7/Tree.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/chp7/Tree.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/chp7/Tree.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": 25.4117647059, "max_line_length": 50, "alphanum_fraction": 0.6111111111, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.658133261939558}} {"text": "module Data.List.Views.Extra\n\nimport Data.List\nimport Data.List.Reverse\nimport Data.List.Views\nimport Data.Nat\nimport Data.List.Equalities\n\n%default total\n\n||| Proof that two numbers differ by at most one\npublic export\ndata Balanced : Nat -> Nat -> Type where\n BalancedZ : Balanced Z Z\n BalancedL : Balanced (S Z) Z\n BalancedRec : Balanced n m -> Balanced (S n) (S m)\n\n%name Balanced bal, b\n\nUninhabited (Balanced Z (S k)) where\n uninhabited BalancedZ impossible\n uninhabited BalancedL impossible\n uninhabited (BalancedRec rec) impossible\n\nexport\nbalancedPred : Balanced (S x) (S y) -> Balanced x y\nbalancedPred (BalancedRec pred) = pred\n\nexport\nmkBalancedEq : {n, m : Nat} -> n = m -> Balanced n m\nmkBalancedEq {n = 0} Refl = BalancedZ\nmkBalancedEq {n = (S k)} Refl = BalancedRec $ mkBalancedEq {n = k} Refl\n\nexport\nmkBalancedL : {n, m : Nat} -> n = S m -> Balanced n m\nmkBalancedL {m = 0} Refl = BalancedL\nmkBalancedL {m = S k} Refl = BalancedRec (mkBalancedL Refl)\n\n||| View of a list split into two halves\n|||\n||| The lengths of the lists are guaranteed to differ by at most one\npublic export\ndata SplitBalanced : List a -> Type where\n MkSplitBal\n : {xs, ys : List a}\n -> Balanced (length xs) (length ys)\n -> SplitBalanced (xs ++ ys)\n\nprivate\nsplitBalancedHelper\n : (revLs : List a)\n -> (rs : List a)\n -> (doubleSkip : List a)\n -> (length rs = length revLs + length doubleSkip)\n -> SplitBalanced (reverse revLs ++ rs)\nsplitBalancedHelper revLs rs [] prf = MkSplitBal balancedLeftsAndRights\n where\n lengthsEqual : length rs = length revLs\n lengthsEqual =\n rewrite sym (plusZeroRightNeutral (length revLs)) in prf\n balancedLeftsAndRights : Balanced (length (reverse revLs)) (length rs)\n balancedLeftsAndRights =\n rewrite reverseLength revLs in\n rewrite lengthsEqual in\n mkBalancedEq Refl\nsplitBalancedHelper revLs [] (x :: xs) prf =\n absurd $\n the (0 = S (plus (length revLs) (length xs)))\n rewrite plusSuccRightSucc (length revLs) (length xs) in\n prf\nsplitBalancedHelper revLs (x :: rs) [lastItem] prf =\n rewrite appendAssociative (reverse revLs) [x] rs in\n rewrite sym (reverseCons x revLs) in\n MkSplitBal $\n the (Balanced (length (reverseOnto [x] revLs)) (length rs)) $\n rewrite reverseCons x revLs in\n rewrite lengthSnoc x (reverse revLs) in\n rewrite reverseLength revLs in\n rewrite lengthsEqual in\n mkBalancedL Refl\n where\n lengthsEqual : length rs = length revLs\n lengthsEqual =\n cong pred $\n the (S (length rs) = S (length revLs)) $\n rewrite plusCommutative 1 (length revLs) in prf\nsplitBalancedHelper revLs (x :: oneFurther) (_ :: (_ :: twoFurther)) prf =\n rewrite appendAssociative (reverse revLs) [x] oneFurther in\n rewrite sym (reverseCons x revLs) in\n splitBalancedHelper (x :: revLs) oneFurther twoFurther $\n cong pred $\n the (S (length oneFurther) = S (S (plus (length revLs) (length twoFurther)))) $\n rewrite plusSuccRightSucc (length revLs) (length twoFurther) in\n rewrite plusSuccRightSucc (length revLs) (S (length twoFurther)) in\n prf\n\n||| Covering function for the `SplitBalanced`\n|||\n||| Constructs the view in linear time\nexport\nsplitBalanced : (input : List a) -> SplitBalanced input\nsplitBalanced input = splitBalancedHelper [] input input Refl\n\n||| The `VList` view allows us to recurse on the middle of a list,\n||| inspecting the front and back elements simultaneously.\npublic export\ndata VList : List a -> Type where\n VNil : VList []\n VOne : VList [x]\n VCons : {x, y : a} -> {xs : List a} -> (rec : Lazy (VList xs)) -> VList (x :: xs ++ [y])\n\nprivate\ntoVList\n : (xs : List a)\n -> SnocList ys\n -> Balanced (length xs) (length ys)\n -> VList (xs ++ ys)\ntoVList [] Empty BalancedZ = VNil\ntoVList [x] Empty BalancedL = VOne\ntoVList [] (Snoc x zs rec) prf =\n absurd $\n the (Balanced 0 (S (length zs))) $\n rewrite sym (lengthSnoc x zs) in prf\ntoVList (x :: xs) (Snoc y ys srec) prf =\n rewrite appendAssociative xs ys [y] in\n VCons $\n toVList xs srec $\n balancedPred $\n rewrite sym (lengthSnoc y ys) in prf\n\n||| Covering function for `VList`\n||| Constructs the view in linear time.\nexport\nvList : (xs : List a) -> VList xs\nvList xs with (splitBalanced xs)\n vList (ys ++ zs) | (MkSplitBal prf) = toVList ys (snocList zs) prf\n\n||| Lazy filtering of a list based on a predicate.\npublic export\ndata LazyFilterRec : List a -> Type where\n Exhausted : (skip : List a) -> LazyFilterRec skip\n Found : (skip : List a) -- initial non-matching elements\n -> (head : a) -- first match\n -> Lazy (LazyFilterRec rest)\n -> LazyFilterRec (skip ++ (head :: rest))\n\n||| Covering function for the LazyFilterRec view.\n||| Constructs the view lazily in linear time.\ntotal export\nlazyFilterRec : (pred : (a -> Bool)) -> (xs : List a) -> LazyFilterRec xs\nlazyFilterRec pred [] = Exhausted []\nlazyFilterRec pred (x :: xs) with (pred x)\n lazyFilterRec pred (x :: xs) | True = Found [] x (lazyFilterRec pred xs)\n lazyFilterRec pred (x :: []) | False = Exhausted [x]\n lazyFilterRec pred (x :: rest@(_ :: xs)) | False = filterHelper [x] rest\n where\n filterHelper\n : (reverseOfSkipped : List a)\n -> {auto prf1 : NonEmpty reverseOfSkipped}\n -> (rest : List a)\n -> {auto prf2 : NonEmpty rest}\n -> LazyFilterRec (reverse reverseOfSkipped ++ rest)\n filterHelper revSkipped (y :: xs) with (pred y)\n filterHelper revSkipped (y :: xs) | True =\n Found (reverse revSkipped) y (lazyFilterRec pred xs)\n filterHelper revSkipped (y :: []) | False =\n rewrite sym (reverseOntoSpec [y] revSkipped) in\n Exhausted $ reverse (y :: revSkipped)\n filterHelper revSkipped (y :: (z :: zs)) | False =\n rewrite appendAssociative (reverse revSkipped) [y] (z :: zs) in\n rewrite sym (reverseOntoSpec [y] revSkipped) in\n filterHelper (y :: revSkipped) (z :: zs)\n\n", "meta": {"hexsha": "daac8a95a1459d6e1199d1869f5b3eb3bcc7a129", "size": 6071, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Data/List/Views/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/List/Views/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/List/Views/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": 34.8908045977, "max_line_length": 90, "alphanum_fraction": 0.6526107725, "num_tokens": 1808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6576377743524404}} {"text": "module Equal\n\n-- Equality type\n\ndata Equal : x -> y -> Type where\n Reflexive : Equal a a\n\n-- Simple examples\n\nbool : Equal Bool Bool\nbool = Reflexive\n\ntrue : Equal True True\ntrue = Reflexive\n\ntwo : Equal 2 (1 + 1)\ntwo = Reflexive\n\n-- Helpers\n\ntransitive : Equal a b -> Equal b c -> Equal a c\ntransitive Reflexive Reflexive = Reflexive\n\nsymmetric : Equal a b -> Equal b a\nsymmetric Reflexive = Reflexive\n\ncongruent : (f : t -> x) -> Equal a b -> Equal (f a) (f b)\ncongruent f Reflexive = Reflexive\n\n-- Stepping it up\n\nplusZero : (n : Nat) -> Equal (plus n Z) n\nplusZero Z = the (Equal Z Z) Reflexive\nplusZero (S k) =\n let induction = plusZero k\n in congruent S induction\n\n-- Built-in equality\n\nplusZero' : (n : Nat) -> plus n Z = n\nplusZero' Z = Refl\nplusZero' (S k) =\n let induction = plusZero' k\n in ?plusZero'_2\n\n---------- Proofs ----------\n\nEqual.plusZero'_2 = proof\n intros\n rewrite induction\n trivial\n\n", "meta": {"hexsha": "f5595c1f55e68eaaa45d37e35a8883d351e06c87", "size": 916, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "speakers/puffnfresh/Equal.idr", "max_stars_repo_name": "nuttycom/lambdaconf-2015-upstream", "max_stars_repo_head_hexsha": "1c768a5d0d86b7391635c54ff5c951dd786113ad", "max_stars_repo_licenses": ["Artistic-2.0"], "max_stars_count": 100, "max_stars_repo_stars_event_min_datetime": "2015-05-19T21:02:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T01:30:39.000Z", "max_issues_repo_path": "speakers/puffnfresh/Equal.idr", "max_issues_repo_name": "rtfeldman/lambdaconf-2015", "max_issues_repo_head_hexsha": "62396a8656df5e1e11a92c0fcfbb9398a10fd956", "max_issues_repo_licenses": ["Artistic-2.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2015-05-12T00:22:15.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-31T00:51:49.000Z", "max_forks_repo_path": "speakers/puffnfresh/Equal.idr", "max_forks_repo_name": "rtfeldman/lambdaconf-2015", "max_forks_repo_head_hexsha": "62396a8656df5e1e11a92c0fcfbb9398a10fd956", "max_forks_repo_licenses": ["Artistic-2.0"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2015-05-06T23:17:26.000Z", "max_forks_repo_forks_event_max_datetime": "2017-04-09T06:48:05.000Z", "avg_line_length": 17.2830188679, "max_line_length": 58, "alphanum_fraction": 0.6528384279, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6575760071600258}} {"text": "import Data.Vect\n\ncreateEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntransposeHelper : (x : Vect n elem) ->\n (xsTrans : Vect n (Vect len elem)) ->\n Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntransposeMat : Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) = let xsTrans = transposeMat xs in\n transposeHelper x xsTrans\n", "meta": {"hexsha": "e709a4279f0e3300af494fbcd1d9dde80742a0f7", "size": 526, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "type_driven_book/chp3/matrices.idr", "max_stars_repo_name": "Ryxai/idris_book_notes", "max_stars_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "type_driven_book/chp3/matrices.idr", "max_issues_repo_name": "Ryxai/idris_book_notes", "max_issues_repo_head_hexsha": "3927f9d72eafe8b8ef8b08280dafe5592084eb18", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "type_driven_book/chp3/matrices.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.875, "max_line_length": 71, "alphanum_fraction": 0.5988593156, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6575509330436963}} {"text": "module Sub05Apply9x6\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\nimport ProofColDivSeqPostuProof\n\n%default total\n-- %language ElabReflection\n\n\n-- 3(3x+2) --C[4,-4]--> 3x\nexport\napply9x6 : (Not . P) (S (S (plus (plus j j) j)))\n -> (m : Nat ** (LTE (S m) (S (S (plus (plus j j) j))), (Not . P) m))\napply9x6 {j} col = (j ** (lte9x6 j, c9x6To3x j col)) where\n lte9x6 : (j:Nat) -> LTE (S j) (S (S (plus (plus j j) j)))\n lte9x6 Z = (lteSuccRight . LTESucc) LTEZero\n lte9x6 (S j) = let lemma = lte9x6 j in\n rewrite (sym (plusSuccRightSucc j j)) in\n rewrite (sym (plusSuccRightSucc (plus j j) j)) in\n (lteSuccRight . lteSuccRight . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "939ab9a10861108f97d85064b443875ccb855ac4", "size": 671, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program2/Sub05Apply9x6.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/Sub05Apply9x6.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/Sub05Apply9x6.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": 26.84, "max_line_length": 70, "alphanum_fraction": 0.6393442623, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.6575183163134501}} {"text": "-- see: http://docs.idris-lang.org/en/latest/tutorial/interp.html\n-- module Interp\n\nimport Data.Vect\nimport Data.Fin\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) -- the context\n -- `HasType i G T` is a proof that variable `i` in context `G` has type `T`\n data HasType : (i : Fin n) -> Vect n Ty -> Ty -> Type where\n -- proof that the most recently defined variable is well-typed:\n Stop : HasType FZ (t :: G) t -- de-Brujin index 0\n Pop : HasType k G t -> HasType (FS k) (u :: G) t -- Pop Stop is index 1, ...\n\n data Expr : Vect n Ty -> Ty -> Type where\n Var : HasType i G t \n -> Expr G t\n Val : (x : Int)\n -> Expr G TyInt\n Lam : Expr (a :: G) t\n -> Expr G (TyFun a t)\n App : Expr G (TyFun a t)\n -> Expr G a\n -> Expr G t\n Op : (interpTy a -> interpTy b -> interpTy c) ->\n Expr G a -> Expr G b\n -> Expr G c\n If : Expr G TyBool -> Lazy (Expr G a) -> Lazy (Expr G a)\n -> 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 -- given a proof that a variable if defined in the context,\n -- we can produce a value from the environment:\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 cnd thn els)\n = if interp env cnd\n then interp env thn\n else interp env els\n\n succ : Expr G (TyFun TyInt TyInt)\n succ = Lam (Op (+) (Var Stop) (Val 1))\n\n add : Expr G (TyFun TyInt (TyFun TyInt TyInt)) -- \\x.\\y.y + x\n add = Lam (Lam (Op (+) (Var Stop) (Var (Pop Stop))))\n -- `interp [] (App (App add (Val 2)) (Val 2))` gives `4 : Int`\n\n iszero : Expr G (TyFun TyInt TyBool)\n iszero = Lam (Op (==) (Var Stop) (Val 0))\n\n -- `interp [] (App fact (Val 4))` gives `24 : Int`\n fact : Expr G (TyFun TyInt TyInt)\n fact = Lam (If (App iszero (Var Stop))\n (Val 1)\n (Op (*) (Var Stop)\n (App fact (Op (-) (Var Stop) (Val 1)))))\n\nmain : IO ()\nmain = do\n putStr \"Enter a number: \"\n n <- getLine\n printLn (interp [] fact (cast n))\n", "meta": {"hexsha": "fa794e24a2985cb19d64cb3407fae24f760b8394", "size": 2659, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "fp/interp.idr", "max_stars_repo_name": "EarlGray/language-snippets", "max_stars_repo_head_hexsha": "31e4cd1cd32a444752e47484ff528a50bb6e14f6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2016-02-21T11:13:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T00:10:51.000Z", "max_issues_repo_path": "fp/interp.idr", "max_issues_repo_name": "EarlGray/language-incubator", "max_issues_repo_head_hexsha": "c875b0427daa5744fd0547eba5434ac4aa000a43", "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": "fp/interp.idr", "max_forks_repo_name": "EarlGray/language-incubator", "max_forks_repo_head_hexsha": "c875b0427daa5744fd0547eba5434ac4aa000a43", "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.2375, "max_line_length": 82, "alphanum_fraction": 0.526513727, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6574057904576589}} {"text": "module AOC.Day.Three\n\nimport AOC.Solution\nimport Data.Vect\nimport Data.String\nimport Data.Nat\n\n%default total\n\n----------------------------------------------------------------------------\n-- Types -------------------------------------------------------------------\n----------------------------------------------------------------------------\n\ndata Bit : Type where\n Low : Bit\n High : Bit\n\nBinary : (n : Nat) -> Type\nBinary n = Vect n Bit\n\nInputType : Type\nInputType = (m ** List (Binary m))\n\n\n----------------------------------------------------------------------------\n-- Interfaces --------------------------------------------------------------\n----------------------------------------------------------------------------\n\nShow Bit where\n show Low = \"0\"\n show High = \"1\"\n\n-- Could be more efficient with fold and cons but eh.\n[BinaryShow] Show (Binary n) where\n show [] = \"\"\n show (x :: xs) = show x ++ show @{BinaryShow} xs\n\nCast Bit Nat where\n cast Low = 0\n cast High = 1\n\nCast Bit Integer where\n cast x = the Integer (cast (the Nat (cast x)))\n\nCast Nat (Maybe Bit) where\n cast 0 = Just Low\n cast 1 = Just High\n cast _ = Nothing\n\nCast Bool Bit where\n cast False = Low\n cast True = High\n\nCast (Binary n) Nat where\n cast = foldl (\\acc, x => acc * 2 + x) 0 . map cast\n\nCast (Binary n) Integer where\n cast x = the Integer (cast (the Nat (cast x)))\n\n----------------------------------------------------------------------------\n-- Helper Functions --------------------------------------------------------\n----------------------------------------------------------------------------\n\ncountBit : Bit -> Integer -> Integer\ncountBit Low x = x - 1\ncountBit High x = x + 1\n\nmoreOf : {n : Nat} -> List (Binary n) -> Vect n Integer\nmoreOf {n} list = foldr (\\x, acc => zipWith countBit x acc) (replicate n 0) list\n\nmostCommon : Vect n Integer -> Binary n\nmostCommon = map (cast . (> 0))\n\nleastCommon : Vect n Integer -> Binary n\nleastCommon = map (cast . (< 0))\n\n\n----------------------------------------------------------------------------\n-- Solutions ---------------------------------------------------------------\n----------------------------------------------------------------------------\n\npart1 : InputType -> String\npart1 (m ** list) = show $ (cast . mostCommon $ mf) * (cast . leastCommon $ mf)\n where\n mf : Vect m Integer\n mf = moreOf list\n\n\n----------------------------------------------------------------------------\n-- Parsing Helper Functions ------------------------------------------------\n----------------------------------------------------------------------------\n\ntoBinaryDep' : (s : List Char) -> Maybe (n ** Binary n)\ntoBinaryDep' [] = Just (0 ** [])\ntoBinaryDep' ('0' :: str) = (toBinaryDep' str) >>= (\\(n ** bin) => Just $ (S n ** Low :: bin))\ntoBinaryDep' ('1' :: str) = (toBinaryDep' str) >>= (\\(n ** bin) => Just $ (S n ** High :: bin))\ntoBinaryDep' _ = Nothing\n\ntoBinaryDep : (s : String) -> Maybe (n ** Binary n)\ntoBinaryDep s = toBinaryDep' (unpack s)\n\n-- Stolen from https://github.com/jumper149/AoC2021/blob/main/03/src/Main.idr\nexactLengths : (len : Nat) -> Traversable t => t (n ** Binary n) -> Maybe (t (Binary len))\nexactLengths len xs = traverse (\\ x => exactLength len x.snd) xs\n\n-- I thought one could define validateBinaryList recursively without\n-- exactLengths, but while that compiles, it results in returning Nothing\n-- always. Not precisely sure which Nothing either (from the recursive call or\n-- from the call to exactLength).\nvalidateBinaryList : List (n ** Binary n) -> Maybe (InputType)\nvalidateBinaryList [] = Just (0 ** [])\nvalidateBinaryList ((len ** bin) :: ys) = do\n list <- exactLengths len ys\n pure (len ** bin :: list)\n\n\n----------------------------------------------------------------------------\n-- Interface for input/output ----------------------------------------------\n----------------------------------------------------------------------------\n\nparser : String -> Maybe (InputType)\nparser = join . map validateBinaryList . sequence . map toBinaryDep . lines\n\nexport\nday3 : (inputType ** AOCSolution inputType)\nday3 = solutionToDP (MkAOCSolution {\n day = 3\n , parser = parser\n , part1 = part1\n , part2 = \\x => \"part2\"\n })\n", "meta": {"hexsha": "430e7f0b9caee621cfccec831cb0f0634b65a36b", "size": 4209, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/AOC/Day/Three.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/Three.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/Three.idr", "max_forks_repo_name": "ryanorendorff/aoc2021", "max_forks_repo_head_hexsha": "47a4d406ee8b70a73bcf6e4b168b02af83201ae7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8863636364, "max_line_length": 95, "alphanum_fraction": 0.4526015681, "num_tokens": 925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7549149813536516, "lm_q1q2_score": 0.6572269105086499}} {"text": "module FirSigned\n\nimport ClosedInt\nimport Synchronous\n\nimport Data.Vect\nimport Data.ZZ\nimport Data.Bits\n\n%access export\n%default total\n\n-- The Vect implementation of Foldable breaks a proof here...\n-- Let's redefine sum for now without using fold\n%hide sum\nsum : Num a => Vect n a -> a\nsum [] = 0\nsum (x::xs) = x + sum xs\n\n||| Combinatorial dot product over `ClosedInt`s\ndotProd : (ws : Vect j ZZ)\n -> Vect j (ClosedInt n m)\n -> ClosedInt (sum $ map (multLo n m) ws)\n (sum $ map (multHi n m) ws)\ndotProd [] [] = zeros\ndotProd (w :: ws) (x :: xs) = add (multConst x w) (dotProd ws xs)\n\n||| Synchronous FIR over `ClosedInt`s\nfir : (ws : Vect j ZZ)\n -> Stream (ClosedInt n m)\n -> Stream (ClosedInt (sum $ map (multLo n m) ws)\n (sum $ map (multHi n m) ws))\nfir {j} ws x = liftA (dotProd ws) (window j zeros x)\n\n-- TODO Consider a wrapper for this with Signed\n\n||| Example of simulating `fir`\nmain : IO ()\nmain = do let dut = fir [1,-1,2]\n let inp = map (saturate {n=0} {m=6}) $ counterFrom 0 {ty=ZZ}\n let out = take 5 $ simulate dut inp\n putStrLn $ show out\n\n-- Local Variables:\n-- idris-load-packages: (\"contrib\")\n-- End:\n", "meta": {"hexsha": "d49e6e3ae83fa0d090180038bb764112c65a4b7f", "size": 1222, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/FirSigned.idr", "max_stars_repo_name": "cramsay/idris_dsp_circuits", "max_stars_repo_head_hexsha": "d706aec31874ab57b24dd63e37076d3774922b3f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-03T15:50:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-03T15:50:57.000Z", "max_issues_repo_path": "src/FirSigned.idr", "max_issues_repo_name": "cramsay/idris_dsp_circuits", "max_issues_repo_head_hexsha": "d706aec31874ab57b24dd63e37076d3774922b3f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-06-03T16:46:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-03T16:46:47.000Z", "max_forks_repo_path": "src/FirSigned.idr", "max_forks_repo_name": "cramsay/idris_dsp_circuits", "max_forks_repo_head_hexsha": "d706aec31874ab57b24dd63e37076d3774922b3f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-03T16:00:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-03T16:00:33.000Z", "avg_line_length": 26.0, "max_line_length": 70, "alphanum_fraction": 0.5981996727, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6571028054450905}} {"text": "module Solutions.Eq\n\nimport Data.HList\nimport Data.Vect\nimport Decidable.Equality\n\n%default total\n\ndata ColType = I64 | Str | Boolean | Float\n\nSchema : Type\nSchema = List ColType\n\nIdrisType : ColType -> Type\nIdrisType I64 = Int64\nIdrisType Str = String\nIdrisType Boolean = Bool\nIdrisType Float = Double\n\nRow : Schema -> Type\nRow = HList . map IdrisType\n\nrecord Table where\n constructor MkTable\n schema : Schema\n size : Nat\n rows : Vect size (Row schema)\n\ndata SameColType : (c1, c2 : ColType) -> Type where\n SameCT : SameColType c1 c1\n\n--------------------------------------------------------------------------------\n-- Equality as a Type\n--------------------------------------------------------------------------------\n\n-- 1\n\nsctReflexive : SameColType c1 c1\nsctReflexive = SameCT\n\n-- 2\n\nsctSymmetric : SameColType c1 c2 -> SameColType c2 c1\nsctSymmetric SameCT = SameCT\n\n-- 3\n\nsctTransitive : SameColType c1 c2 -> SameColType c2 c3 -> SameColType c1 c3\nsctTransitive SameCT SameCT = SameCT\n\n-- 4\n\nsctCong : (f : ColType -> a) -> SameColType c1 c2 -> f c1 = f c2\nsctCong f SameCT = Refl\n\n-- 5\n\nnatEq : (n1,n2 : Nat) -> Maybe (n1 = n2)\nnatEq 0 0 = Just Refl\nnatEq (S k) (S j) = cong S <$> natEq k j\nnatEq (S k) 0 = Nothing\nnatEq 0 (S _) = Nothing\n\n-- 6\n\nappRows : {ts1 : _} -> Row ts1 -> Row ts2 -> Row (ts1 ++ ts2)\nappRows {ts1 = []} Nil y = y\nappRows {ts1 = _ :: _} (h :: t) y = h :: appRows t y\n\nzip : Table -> Table -> Maybe Table\nzip (MkTable s1 m rs1) (MkTable s2 n rs2) = case natEq m n of\n Just Refl => Just $ MkTable _ _ (zipWith appRows rs1 rs2)\n Nothing => Nothing\n\n--------------------------------------------------------------------------------\n-- Programs as Proofs\n--------------------------------------------------------------------------------\n\n-- 1\n\nmapIdEither : (ea : Either e a) -> map Prelude.id ea = ea\nmapIdEither (Left ve) = Refl\nmapIdEither (Right va) = Refl\n\n-- 2\n\nmapIdList : (as : List a) -> map Prelude.id as = as\nmapIdList [] = Refl\nmapIdList (x :: xs) = cong (x ::) $ mapIdList xs\n\n-- 3\n\ndata BaseType = DNABase | RNABase\n\ndata Nucleobase : BaseType -> Type where\n Adenine : Nucleobase b\n Cytosine : Nucleobase b\n Guanine : Nucleobase b\n Thymine : Nucleobase DNABase\n Uracile : Nucleobase RNABase\n\nNucleicAcid : BaseType -> Type\nNucleicAcid = List . Nucleobase\n\ncomplementBase : (b : BaseType) -> Nucleobase b -> Nucleobase b\ncomplementBase DNABase Adenine = Thymine\ncomplementBase RNABase Adenine = Uracile\ncomplementBase _ Cytosine = Guanine\ncomplementBase _ Guanine = Cytosine\ncomplementBase _ Thymine = Adenine\ncomplementBase _ Uracile = Adenine\n\ncomplement : (b : BaseType) -> NucleicAcid b -> NucleicAcid b\ncomplement b = map (complementBase b)\n\ncomplementBaseId : (b : BaseType)\n -> (nb : Nucleobase b)\n -> complementBase b (complementBase b nb) = nb\ncomplementBaseId DNABase Adenine = Refl\ncomplementBaseId RNABase Adenine = Refl\ncomplementBaseId DNABase Cytosine = Refl\ncomplementBaseId RNABase Cytosine = Refl\ncomplementBaseId DNABase Guanine = Refl\ncomplementBaseId RNABase Guanine = Refl\ncomplementBaseId DNABase Thymine = Refl\ncomplementBaseId RNABase Uracile = Refl\n\ncomplementId : (b : BaseType)\n -> (na : NucleicAcid b)\n -> complement b (complement b na) = na\ncomplementId b [] = Refl\ncomplementId b (x :: xs) =\n cong2 (::) (complementBaseId b x) (complementId b xs)\n\n-- 4\n\nreplaceVect : Fin n -> a -> Vect n a -> Vect n a\nreplaceVect FZ v (x :: xs) = v :: xs\nreplaceVect (FS k) v (x :: xs) = x :: replaceVect k v xs\n\nindexReplace : (ix : Fin n)\n -> (v : a)\n -> (as : Vect n a)\n -> index ix (replaceVect ix v as) = v\nindexReplace FZ v (x :: xs) = Refl\nindexReplace (FS k) v (x :: xs) = indexReplace k v xs\n\n-- 5\n\ninsertVect : (ix : Fin (S n)) -> a -> Vect n a -> Vect (S n) a\ninsertVect FZ v xs = v :: xs\ninsertVect (FS k) v (x :: xs) = x :: insertVect k v xs\n\nindexInsert : (ix : Fin (S n))\n -> (v : a)\n -> (as : Vect n a)\n -> index ix (insertVect ix v as) = v\nindexInsert FZ v xs = Refl\nindexInsert (FS k) v (x :: xs) = indexInsert k v xs\n\n--------------------------------------------------------------------------------\n-- Into the Void\n--------------------------------------------------------------------------------\n\n-- 1\n\nUninhabited (Vect (S n) Void) where\n uninhabited (_ :: _) impossible\n\n-- 2\n\nUninhabited a => Uninhabited (Vect (S n) a) where\n uninhabited = uninhabited . head\n\n-- 3\n\nnotSym : Not (a = b) -> Not (b = a)\nnotSym f prf = f $ sym prf\n\n-- 4\n\nnotTrans : a = b -> Not (b = c) -> Not (a = c)\nnotTrans ab f ac = f $ trans (sym ab) ac\n\n-- 5\n\ndata Crud : (i : Type) -> (a : Type) -> Type where\n Create : (value : a) -> Crud i a\n Update : (id : i) -> (value : a) -> Crud i a\n Read : (id : i) -> Crud i a\n Delete : (id : i) -> Crud i a\n\nUninhabited a => Uninhabited i => Uninhabited (Crud i a) where\n uninhabited (Create value) = uninhabited value\n uninhabited (Update id value) = uninhabited value\n uninhabited (Read id) = uninhabited id\n uninhabited (Delete id) = uninhabited id\n\n-- 6\n\nnamespace DecEq\n DecEq ColType where\n decEq I64 I64 = Yes Refl\n decEq I64 Str = No $ \\case Refl impossible\n decEq I64 Boolean = No $ \\case Refl impossible\n decEq I64 Float = No $ \\case Refl impossible\n\n decEq Str I64 = No $ \\case Refl impossible\n decEq Str Str = Yes Refl\n decEq Str Boolean = No $ \\case Refl impossible\n decEq Str Float = No $ \\case Refl impossible\n\n decEq Boolean I64 = No $ \\case Refl impossible\n decEq Boolean Str = No $ \\case Refl impossible\n decEq Boolean Boolean = Yes Refl\n decEq Boolean Float = No $ \\case Refl impossible\n\n decEq Float I64 = No $ \\case Refl impossible\n decEq Float Str = No $ \\case Refl impossible\n decEq Float Boolean = No $ \\case Refl impossible\n decEq Float Float = Yes Refl\n\n-- 7\n\nctNat : ColType -> Nat\nctNat I64 = 0\nctNat Str = 1\nctNat Boolean = 2\nctNat Float = 3\n\nctNatInjective : (c1,c2 : ColType) -> ctNat c1 = ctNat c2 -> c1 = c2\nctNatInjective I64 I64 Refl = Refl\nctNatInjective Str Str Refl = Refl\nctNatInjective Boolean Boolean Refl = Refl\nctNatInjective Float Float Refl = Refl\n\nDecEq ColType where\n decEq c1 c2 = case decEq (ctNat c1) (ctNat c2) of\n Yes prf => Yes $ ctNatInjective c1 c2 prf\n No contra => No $ contra . cong ctNat\n\n--------------------------------------------------------------------------------\n-- Rewrite Rules\n--------------------------------------------------------------------------------\n\n-- 1\n\npsuccRightSucc : (m,n : Nat) -> S (m + n) = m + S n\npsuccRightSucc 0 n = Refl\npsuccRightSucc (S k) n = cong S $ psuccRightSucc k n\n\n-- 2\n\nminusSelfZero : (n : Nat) -> minus n n = 0\nminusSelfZero 0 = Refl\nminusSelfZero (S k) = minusSelfZero k\n\n-- 3\n\nminusZero : (n : Nat) -> minus n 0 = n\nminusZero 0 = Refl\nminusZero (S k) = Refl\n\n-- 4\n\ntimesOneLeft : (n : Nat) -> 1 * n = n\ntimesOneLeft 0 = Refl\ntimesOneLeft (S k) = cong S $ timesOneLeft k\n\ntimesOneRight : (n : Nat) -> n * 1 = n\ntimesOneRight 0 = Refl\ntimesOneRight (S k) = cong S $ timesOneRight k\n\n\n-- 5\n\nplusCommutes : (m,n : Nat) -> m + n = n + m\nplusCommutes 0 n = rewrite plusZeroRightNeutral n in Refl\nplusCommutes (S k) n =\n rewrite sym (psuccRightSucc n k)\n in cong S (plusCommutes k n)\n\n-- 6\n\nmapOnto : (a -> b) -> Vect k b -> Vect m a -> Vect (k + m) b\nmapOnto _ xs [] =\n rewrite plusZeroRightNeutral k in reverse xs\nmapOnto {m = S m'} f xs (y :: ys) =\n rewrite sym (plusSuccRightSucc k m') in mapOnto f (f y :: xs) ys\n\nmapTR : (a -> b) -> Vect n a -> Vect n b\nmapTR f = mapOnto f Nil\n\n-- 7\n\nmapAppend : (f : a -> b)\n -> (xs : List a)\n -> (ys : List a)\n -> map f (xs ++ ys) = map f xs ++ map f ys\nmapAppend f [] ys = Refl\nmapAppend f (x :: xs) ys = cong (f x ::) $ mapAppend f xs ys\n\n-- 8\n\nzip2 : Table -> Table -> Maybe Table\nzip2 (MkTable s1 m rs1) (MkTable s2 n rs2) = case decEq m n of\n Yes Refl =>\n let rs2 = zipWith (++) rs1 rs2\n in Just $ MkTable (s1 ++ s2) _ (rewrite mapAppend IdrisType s1 s2 in rs2)\n No _ => Nothing\n", "meta": {"hexsha": "0e4c22a315a6d182be1106d4ff8c6498e48cbe7d", "size": 8418, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Solutions/Eq.idr", "max_stars_repo_name": "ska80/idris2-tutorial", "max_stars_repo_head_hexsha": "ab7c83cfea6761f2fd29841593c92e78c7dfc958", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 60, "max_stars_repo_stars_event_min_datetime": "2022-01-13T16:14:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T16:16:57.000Z", "max_issues_repo_path": "src/Solutions/Eq.idr", "max_issues_repo_name": "ska80/idris2-tutorial", "max_issues_repo_head_hexsha": "ab7c83cfea6761f2fd29841593c92e78c7dfc958", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2022-01-14T15:42:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T09:53:16.000Z", "max_forks_repo_path": "src/Solutions/Eq.idr", "max_forks_repo_name": "ska80/idris2-tutorial", "max_forks_repo_head_hexsha": "ab7c83cfea6761f2fd29841593c92e78c7dfc958", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2022-01-14T15:48:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T06:49:13.000Z", "avg_line_length": 27.0675241158, "max_line_length": 80, "alphanum_fraction": 0.564623426, "num_tokens": 2771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6568514339610128}} {"text": "module Sub01Apply18x3\r\n\r\nimport ProofColDivSeqBase\r\nimport ProofColDivSeqPostulate\r\n\r\n%default total\r\n-- %language ElabReflection\r\n\r\n\r\n-- 3(6x+1) --B[1,-2]--> 3x\r\nb18x3To3x :\r\n (k:Nat) -> P (S (plus (plus (plus k k) (plus k k)) (plus k k))) 2 -> P k 2\r\nb18x3To3x k prf =\r\n let prf2 = lvDown (S (plus (plus (plus k k) (plus k k)) (plus k k))) 2 prf in\r\n b18x3To3x' k prf2\r\nexport\r\napply18x3 : P (S (plus (plus (plus k k) (plus k k)) (plus k k))) 2\r\n -> (m : Nat **\r\n (LTE (S m) (S (plus (plus (plus k k) (plus k k)) (plus k k))), P m 2))\r\napply18x3 {k} col = let col2 = b18x3To3x k col in (k ** (lte18x3 k, col2)) where\r\n lte18x3 : (k:Nat) -> LTE (S k) (S (plus (plus (plus k k) (plus k k)) (plus k k)))\r\n lte18x3 Z = LTESucc LTEZero\r\n lte18x3 (S k) = rewrite (sym (plusSuccRightSucc k k)) in\r\n rewrite (sym (plusSuccRightSucc (plus k k) (S (plus k k)))) in\r\n rewrite (sym (plusSuccRightSucc (plus k k) (plus k k))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus k k) (plus k k)) (S (plus k k)))) in\r\n rewrite (sym (plusSuccRightSucc (plus (plus k k) (plus k k)) (plus k k))) in\r\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc) (lte18x3 k)\r\n-- ---------------------------\r\n", "meta": {"hexsha": "7d167ff3a686cc880ff29a6ea4e14317828c3d11", "size": 1243, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program/Sub01Apply18x3.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/Sub01Apply18x3.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/Sub01Apply18x3.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": 41.4333333333, "max_line_length": 103, "alphanum_fraction": 0.5921158488, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6566860853226717}} {"text": "module Functorial\n\ninterface Functor (f : Type -> Type) where\n map : (a -> b) -> f a -> f b\n\n mapPreservesId : (m : f a) -> map (\\x => x) m = m\n mapComposes : (m : f a) -> (ab : a -> b) -> (bc : b -> c) -> map (bc . ab) m = map bc (map ab m)\n\nFunctorial.Functor List where\n map f [] = []\n map f (x::xs) = f x :: Functorial.map f xs\n\n mapPreservesId [] = Refl\n mapPreservesId (x::xs) = rewrite mapPreservesId xs in Refl\n\n mapComposes [] f g = Refl\n mapComposes (x::xs) f g = rewrite mapComposes xs f g in Refl\n", "meta": {"hexsha": "b67c5616fd0a30645154d5a3190de8b8f23275c9", "size": 533, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "2020.01.22-to-bhk-lecture/idris/Functorial.idr", "max_stars_repo_name": "buzden/code-in-lectures", "max_stars_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-17T07:01:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T07:01:15.000Z", "max_issues_repo_path": "2020.01.22-to-bhk-lecture/idris/Functorial.idr", "max_issues_repo_name": "buzden/code-in-lectures", "max_issues_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "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": "2020.01.22-to-bhk-lecture/idris/Functorial.idr", "max_forks_repo_name": "buzden/code-in-lectures", "max_forks_repo_head_hexsha": "282eb243b1474a99a4d34c207bf40d4627fcc9d6", "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.6111111111, "max_line_length": 98, "alphanum_fraction": 0.5628517824, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7401743505760727, "lm_q1q2_score": 0.656686083982668}} {"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 | Absolute (Expr num)\n\neval : (Neg num, Abs 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 (Absolute 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\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 (Absolute x) = \"|\" ++ show x ++ \"|\"\n\n(Neg ty, Integral ty, Abs ty, Eq ty) => Eq (Expr ty) where\n (==) x y = eval x == eval y\n\n(Neg ty, Integral ty, Abs ty) => Cast (Expr ty) ty where\n cast expr = eval expr\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 (Absolute x) = Absolute (map f x)\n", "meta": {"hexsha": "7938b20fdc4f2aca2f530d8f86a61530905bfd6f", "size": 1438, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/Expr.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/Expr.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/Expr.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": 31.2608695652, "max_line_length": 60, "alphanum_fraction": 0.4867872045, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.6564407026591351}} {"text": "data TakeN: List a -> Type where\n Fewer: TakeN xs\n Exact: (nXs: List a) -> TakeN (nXs ++ rest)\n\ntotal takeN: (n: Nat) -> (xs: List a) -> TakeN xs\ntakeN Z xs = Exact []\ntakeN (S k) [] = Fewer\ntakeN (S k) (x :: xs) = case takeN k xs of\n Fewer => Fewer\n Exact nXs => Exact (x :: nXs)\n\ngroupByN: (n: Nat) -> (xs: List a) -> List (List a)\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n groupByN n (nXs ++ rest) | Exact nXs = nXs :: groupByN n rest\n\nhalves: List a -> (List a, List a)\nhalves xs =\n let\n halfLen = div (length xs) 2\n in\n splitInHalf halfLen xs\n where\n splitInHalf: Nat -> List a -> (List a, List a)\n splitInHalf n xs with (takeN n xs)\n splitInHalf n xs | Fewer = ([], xs)\n splitInHalf n (nXs ++ rest) | Exact nXs = (nXs, rest)\n\nexample: List Int\nexample = [1,2,3,4,5,6,7,8,9]\n\nemptyList: List Int\nemptyList = []\n", "meta": {"hexsha": "88e3172a44c4a9a15b3dbffe0561973700ee884c", "size": 908, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "TakeN.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": "TakeN.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": "TakeN.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": 26.7058823529, "max_line_length": 63, "alphanum_fraction": 0.5682819383, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6562876653593845}} {"text": "module Prims\n\nx : Int\nx = 42\n\nfoo : String\nfoo = \"Sausage machine\"\n\nbar : Char\nbar = 'Z'\n\nquux : Bool\nquux = False\n\nplus' : Nat -> Nat -> Nat\nplus' Z y = y\nplus' (S k) y = S (plus k y)\n\nmult' : Nat -> Nat -> Nat\nmult' Z y = Z\nmult' (S k) y = plus y (mult k y)\n\nreverse' : List a -> List a\nreverse' xs = revAcc [] xs where\n revAcc : List a -> List a -> List a\n revAcc acc [] = acc\n revAcc acc (x :: xs) = revAcc (x :: acc) xs\n\nfoo' : Int -> Int\nfoo' x = case isLT of \n YES => x*2\n NO => x*4\n where\n data MyLT = YES | NO\n \n isLT: MyLT\n isLT = if x<20 then YES else NO\n\n-- 一般 where 从句中定义的函数和其它顶层函数一样,都需要类型声明\n-- 函数 f 的类型声明可以在以下情况中省略\n-- 1. f 出现在顶层定义的右边\n-- 2. f 的类型完全可以通过其首次应用来确定\n\neven' : Nat -> Bool\neven' Z = True\neven' (S k) = odd' k where\n odd' Z = False\n odd' (S k) = even' k", "meta": {"hexsha": "7bdc3a421c279bcaa35a47bd3f2c0bc0b9234687", "size": 835, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "fp/idris/tutorial/src/prims.idr", "max_stars_repo_name": "lonelyhentai/workspace", "max_stars_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-26T16:37:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T01:26:19.000Z", "max_issues_repo_path": "fp/idris/tutorial/src/prims.idr", "max_issues_repo_name": "lonelyhentai/workspace", "max_issues_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "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": "fp/idris/tutorial/src/prims.idr", "max_forks_repo_name": "lonelyhentai/workspace", "max_forks_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-15T01:26:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T01:26:23.000Z", "avg_line_length": 17.3958333333, "max_line_length": 47, "alphanum_fraction": 0.5437125749, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6560447340818689}} {"text": "module Decidable.Decidable.Extra\n\nimport Data.Rel\nimport Data.Fun\nimport Data.Vect\nimport Data.HVect\nimport Data.Fun.Extra\nimport Decidable.Decidable\n\npublic export\nNotNot : {n : Nat} -> {ts : Vect n Type} -> (r : Rel ts) -> Rel ts\nNotNot r = map @{Nary} (Not . Not) r \n\n[DecidablePartialApplication] {x : t} -> (tts : Decidable (t :: ts) r) => Decidable ts (r x) where\n decide = decide @{tts} x\n\npublic export\ndoubleNegationElimination : {n : Nat} -> {0 ts : Vect n Type} -> {r : Rel ts} -> Decidable ts r =>\n (witness : HVect ts) -> \n uncurry (NotNot {ts} r) witness -> \n uncurry r witness\ndoubleNegationElimination {ts = [] } @{dec} [] prfnn = \n case decide @{dec} of\n Yes prf => prf\n No prfn => absurd $ prfnn prfn\ndoubleNegationElimination {ts = t :: ts} @{dec} (w :: witness) prfnn = \n doubleNegationElimination {ts} {r = r w} @{ DecidablePartialApplication @{dec} } witness prfnn\n\ndoubleNegationForall : {n : Nat} -> {0 ts : Vect n Type} -> {r : Rel ts} -> Decidable ts r =>\n All ts (NotNot {ts} r) -> All ts r\ndoubleNegationForall @{dec} forall_prf = \n let prfnn : (witness : HVect ts) -> uncurry (NotNot {ts} r) witness\n prfnn = uncurryAll forall_prf\n prf : (witness : HVect ts) -> uncurry r witness\n prf witness = doubleNegationElimination @{dec} witness (prfnn witness)\n in curryAll prf\n\npublic export\ndoubleNegationExists : {n : Nat} -> {0 ts : Vect n Type} -> {r : Rel ts} -> Decidable ts r =>\n Ex ts (NotNot {ts} r) -> \n Ex ts r\ndoubleNegationExists {ts} {r} @{dec} nnxs = \n let witness : HVect ts\n witness = extractWitness nnxs \n witnessingnn : uncurry (NotNot {ts} r) witness\n witnessingnn = extractWitnessCorrect nnxs\n witnessing : uncurry r witness\n witnessing = doubleNegationElimination @{dec} witness witnessingnn\n in introduceWitness witness witnessing\n\n", "meta": {"hexsha": "e8fe02f72ab3ee4637544a4db3d32ac72197971d", "size": 1890, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/contrib/Decidable/Decidable/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/Decidable/Decidable/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/Decidable/Decidable/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": 37.0588235294, "max_line_length": 98, "alphanum_fraction": 0.6428571429, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6560408368556915}} {"text": "import Data.Vect\n\nreadVectLen : (len : Nat) -> IO (Vect len String)\nreadVectLen Z = pure []\nreadVectLen (S k) = do x <- getLine\n xs <- readVectLen k\n pure (x :: xs)\n\ntestReadVect : IO ()\ntestReadVect = do output <- readVectLen 4\n putStrLn(show output)\n\ndata VectUnknown : Type -> Type where\n MkVect : (len : Nat) -> Vect len a -> VectUnknown a\n\nreadVect : IO (VectUnknown String)\nreadVect = do x <- getLine\n if (x == \"\")\n then pure (MkVect _ [])\n else do MkVect _ xs <- readVect\n pure (MkVect _ (x :: xs))\n\nprintVect : Show a => VectUnknown a -> IO ()\nprintVect (MkVect len xs)\n = putStrLn (show xs ++ \" (length \" ++ show len ++ \")\")\n\nmypair : (Int, String)\nmypair = (94, \"Pages\")\n\nanyVect : (n ** Vect n String)\nanyVect = (3 ** ?anyVect_rhs)\n\nreadVect2 : IO (len ** Vect len String)\nreadVect2 = do x <- getLine\n if (x == \"\")\n then pure (_ ** [])\n else do (_ ** xs) <- readVect2\n pure (_ ** x :: xs)\n\nzipInputs : IO ()\nzipInputs = do putStrLn \"Enter first vector (blank line to end):\"\n (len1 ** vec1) <- readVect2\n putStrLn \"Enter second vector (blank line to end):\"\n (len2 ** vec2) <- readVect2\n case exactLength len1 vec2 of\n Nothing => putStrLn \"Vectors are of different lengths\"\n Just vec2' => printLn (zip vec1 vec2')\n", "meta": {"hexsha": "3bf0cbe4ffec86d6a43764ff3856a21905aee730", "size": 1525, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ReadVect.idr", "max_stars_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_stars_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ReadVect.idr", "max_issues_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_issues_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ReadVect.idr", "max_forks_repo_name": "bkaflowski/tdd_with_idris_excercises", "max_forks_repo_head_hexsha": "3f6ecd4fdd05ef70363203ecb5a8915fae5f4835", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7708333333, "max_line_length": 72, "alphanum_fraction": 0.5127868852, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6559897901957662}} {"text": "module Toolkit.Data.List.Occurs\n\nimport Decidable.Equality\n\nimport Toolkit.Decidable.Informative\n\nimport Toolkit.Data.Nat\nimport Toolkit.Data.DList\nimport Toolkit.Data.List.Size\nimport Toolkit.Data.List.Interleaving\n\n%default total\n\n\npublic export\ndata Occurs : (type : Type)\n -> (p : type -> Type)\n -> (xs : List type)\n -> (cy : Nat)\n -> (cn : Nat)\n -> Type\n where\n O : (thrown : List type)\n -> (sizeThrown : Size thrown t)\n\n -> (kept : List type)\n -> (sizeKept : Size kept k)\n\n -> (prfOrigin : Interleaving kept thrown input)\n\n -> (prfKept : DList type holdsFor kept)\n -> (prfThrown : DList type (Not . holdsFor) throw)\n\n -> Occurs type holdsFor input k t\n\nnamespace Result\n\n public export\n data Occurs : (type : Type)\n -> (p : type -> Type)\n -> (xs : List type)\n -> Type\n where\n O : {type : Type}\n -> {p : type -> Type}\n -> (xs : List type)\n -> (cy,cn : Nat)\n -> (prf : Occurs type p xs cy cn)\n -> Occurs type p xs\n\n\nexport\noccurs : {type : Type}\n -> {p : type -> Type}\n -> (f : (this : type) -> Dec (p this))\n -> (xs : List type)\n -> Occurs type p xs\noccurs f []\n = O [] 0 0 (O [] Zero [] Zero Empty [] [])\n\noccurs f (x :: xs) with (f x)\n occurs f (x :: xs) | (Yes prf) with (occurs f xs)\n\n occurs f (x :: xs) | (Yes prf) | (O xs cy cn (O thrown sizeThrown kept sizeKept prfOrigin prfKept prfThrown))\n = O (x::xs) (S cy) cn (O thrown sizeThrown (x :: kept) (PlusOne sizeKept) (Left x prfOrigin) (prf :: prfKept) prfThrown)\n\n occurs f (x :: xs) | (No not) with (occurs f xs)\n occurs f (x :: xs) | (No not) | (O xs cy cn (O thrown sizeThrown kept sizeKept prfOrigin prfKept prfThrown))\n = O (x::xs) cy (S cn) (O (x :: thrown) (PlusOne sizeThrown) kept sizeKept (Right x prfOrigin) prfKept (not :: prfThrown))\n\n-- [ EOF ]\n", "meta": {"hexsha": "6acc02215265b22b2f5af7293f571f09fd238384", "size": 2037, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/List/Occurs.idr", "max_stars_repo_name": "gallais/linear-circuits", "max_stars_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-11-29T17:20:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T21:41:44.000Z", "max_issues_repo_path": "src/Toolkit/Data/List/Occurs.idr", "max_issues_repo_name": "gallais/linear-circuits", "max_issues_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Toolkit/Data/List/Occurs.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": 28.2916666667, "max_line_length": 127, "alphanum_fraction": 0.5267550319, "num_tokens": 626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.655890344117891}} {"text": "module Unitary\n\nimport Data.Vect\nimport Data.Nat\nimport System.File\nimport Injection\nimport Lemmas\n\ninfixr 9 .\ninfixr 10 #\n\n%default total\n\n\n------------------------QUANTUM CIRCUITS-----------------------\n\npublic export\ndata Unitary : Nat -> Type where\n IdGate : Unitary n\n H : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\n P : (p : Double) -> (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\n CNOT : (c : Nat) -> (t : Nat) -> \n {auto prf1 : (c < n) = True} -> {auto prf2 : (t < n) = True} -> {auto prf3 : (c /= t) = True} -> \n Unitary n -> Unitary n\n\n\n-- P p = [[1,0],[0,e^ip]]\n\n-------------------------------APPLY---------------------------\n|||Apply a smaller circuit of size i to a bigger one of size n\n|||The vector of wires on which we apply the circuit must follow some constraints:\n|||All the indices must be smaller than n, and they must be all different\npublic export\napply : {i : Nat} -> {n : Nat} -> \n Unitary i -> Unitary n -> \n (v : Vect i Nat) -> \n {auto prf : (isInjective n v) = True} -> \n Unitary n\napply IdGate g2 _ = g2\napply (H j g1) g2 v = \n let prf1 = indexInjectiveVect j n v {prf} \n in H (index j v) {prf = prf1} (apply g1 g2 v)\napply (P p j g1) g2 v = \n let prf1 = indexInjectiveVect j n v {prf}\n in P p (index j v) {prf = prf1} (apply g1 g2 v)\napply {i} {n} (CNOT c t {prf1} {prf2} {prf3} g1) g2 v = \n let prf4 = indexInjectiveVect c n v {prf = prf}\n prf5 = indexInjectiveVect t n v {prf = prf}\n prf6 = differentIndexInjectiveVect c t n {prf1 = prf3} v {prf2 = prf} {prf3 = prf1} {prf4 = prf2}\n in CNOT (index c v) (index t v) {prf1 = prf4} {prf2 = prf5} {prf3 = prf6} (apply g1 g2 v)\n\n---------------------------COMPOSE-----------------------------\n|||Compose 2 circuits of the same size\npublic export\ncompose : Unitary n -> Unitary n -> Unitary n\ncompose IdGate g1 = g1\ncompose (H j g1) g2 = H j (compose g1 g2)\ncompose (P p j g1) g2 = P p j (compose g1 g2)\ncompose (CNOT c t g1) g2 = CNOT c t (compose g1 g2)\n\npublic export\n(.) : Unitary n -> Unitary n -> Unitary n\n(.) = compose\n\n---------------------------ADJOINT-----------------------------\n|||Find the adjoint of a circuit\npublic export\nadjoint : Unitary n -> Unitary n\nadjoint IdGate = IdGate\nadjoint (H j g) = (adjoint g) . (H j IdGate)\nadjoint (P p j g) = (adjoint g) . (P (-p) j IdGate)\nadjoint (CNOT c t g) = (adjoint g) . (CNOT c t IdGate)\n\n\n---------------------TENSOR PRODUCT----------------------------\n|||Make the tensor product of two circuits\npublic export\ntensor : {n : Nat} -> {p : Nat} -> Unitary n -> Unitary p -> Unitary (n + p)\ntensor g1 g2 = \n let p1 = (allSmallerRangeVect 0 n)\n p2 = lemmaAnd (allSmallerRangeVect n p) (allDiffRangeVect n p)\n p3 = allSmallerPlus n p (rangeVect 0 n) p1 \n p4 = lemmaAnd p3 (allDiffRangeVect 0 n)\n g' = apply {i=n} {n = n+p} g1 (IdGate {n = n+p}) (rangeVect 0 n) {prf = p4}\n in apply {i = p} {n = n + p} g2 g' (rangeVect n p) {prf = p2}\n\npublic export\n(#) : {n : Nat} -> {p : Nat} -> Unitary n -> Unitary p -> Unitary (n + p)\n(#) = tensor\n\n----------------------CLASSICAL GATES--------------------------\npublic export\nHGate : Unitary 1\nHGate = H 0 IdGate\n\npublic export\nPGate : Double -> Unitary 1\nPGate r = P r 0 IdGate\n\npublic export\nCNOTGate : Unitary 2\nCNOTGate = CNOT 0 1 IdGate\n\npublic export\nT : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\nT j g = P (pi/4) j {prf} g\n\npublic export\nTGate : Unitary 1\nTGate = T 0 IdGate\n\npublic export\nTAdj : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\nTAdj j g = P (-pi/4) j {prf} g\n\npublic export\nTAdjGate : Unitary 1\nTAdjGate = TAdj 0 IdGate\n\npublic export\nS : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\nS j g = P (pi/2) j {prf} g\n\npublic export\nSGate : Unitary 1\nSGate = S 0 IdGate\n\npublic export\nSAdj : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\nSAdj j g = P (-pi/2) j {prf} g\n\npublic export\nSAdjGate : Unitary 1\nSAdjGate = SAdj 0 IdGate\n\npublic export\nZ : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\nZ j g = P pi j {prf} g\n\npublic export\nZGate : Unitary 1\nZGate = Z 0 IdGate\n\npublic export\nX : (j : Nat) -> {auto prf : (j < n) = True} -> Unitary n -> Unitary n\nX j g = H j (Z j (H j g))\n\npublic export\nXGate : Unitary 1\nXGate = X 0 IdGate\n\npublic export\nRxGate : Double -> Unitary 1\nRxGate p = HGate . PGate p . HGate\n\npublic export\nRyGate : Double -> Unitary 1\nRyGate p = SAdjGate . HGate . PGate (-p) . HGate . SGate\n\npublic export\nRzGate : Double -> Unitary 1\nRzGate p = PGate p \n\n\n---------------------CONTROLLED VERSIONS-----------------------\n|||Toffoli gate\npublic export\ntoffoli : Unitary 3\ntoffoli = \n let g1 = CNOT 1 2 (H 2 IdGate)\n g2 = CNOT 0 2 (TAdj 2 g1)\n g3 = CNOT 1 2 (T 2 g2)\n g4 = CNOT 0 2 (TAdj 2 g3)\n g5 = CNOT 0 1 (T 1 (H 2 (T 2 g4)))\n in CNOT 0 1 (T 0 (TAdj 1 g5))\n\n|||Controlled Hadamard gate\npublic export\ncontrolledH : Unitary 2\ncontrolledH =\n let h1 = (IdGate {n=1}) # (SAdjGate . HGate . TGate . HGate . SGate)\n h2 = (IdGate {n=1}) # (SAdjGate . HGate . TAdjGate . HGate . SGate)\n in h1 . CNOTGate . h2\n\n|||Controlled phase gate\npublic export\ncontrolledP : Double -> Unitary 2\ncontrolledP p = \n let p1 = CNOT 0 1 (P (p/2) 1 IdGate)\n in CNOT 0 1 (P (-p/2) 1 p1)\n\n|||Make the controlled version of a gate\npublic export\ncontrolled : {n : Nat} -> Unitary n -> Unitary (S n)\ncontrolled IdGate = IdGate\ncontrolled (H j g) = \n let p = lemmaControlledInj n j \n in apply {i = 2} {n = S n} controlledH (controlled g) [0, S j] {prf = p}\ncontrolled (P p j g) = \n let p1 = lemmaControlledInj n j\n in apply {i = 2} {n = S n} (controlledP p) (controlled g) [0, S j] {prf = p1}\ncontrolled (CNOT c t g) = \n let p = lemmaControlledInj2 n c t\n in apply {i = 3} {n = S n} toffoli (controlled g) [0, S c, S t] {prf = p}\n\n\n\n------------SOME USEFUL FUNCTIONS FOR CREATING GATES-----------\n\n|||Make n tensor products of the same unitary of size 1\npublic export\ntensorn : (n : Nat) -> Unitary 1 -> Unitary n\ntensorn 0 _ = IdGate\ntensorn (S k) g = g # (tensorn k g)\n\n|||Controls on the n-1 first qubits, target on the last\npublic export\nmultipleQubitControlledNOT : (n : Nat) -> Unitary n\nmultipleQubitControlledNOT 0 = IdGate\nmultipleQubitControlledNOT 1 = IdGate\nmultipleQubitControlledNOT 2 = CNOT 0 1 IdGate\nmultipleQubitControlledNOT (S k) = controlled (multipleQubitControlledNOT k)\n\n||| Tensor product of a Vector of Unitary operators\nexport\ntensorMap : {n : Nat} -> {m : Nat} -> (gates : Vect n (Unitary m)) -> Unitary (n*m)\ntensorMap [] = IdGate\ntensorMap (gate :: gates) = gate # (tensorMap gates)\n\n||| Tensor product of a Vector of single-qubit Unitary operators\nexport\ntensorMapSimple : {n : Nat} -> (gates : Vect n (Unitary 1)) -> Unitary n\ntensorMapSimple g = rewrite sym $ multOneRightNeutral n in tensorMap g\n\n---------------------------------------------------------------\n-- count the total number of atomic gates in a unitary circuit\nexport\ngateCount : Unitary n -> Nat\ngateCount IdGate = 0\ngateCount (H j x) = S (gateCount x)\ngateCount (P p j x) = S (gateCount x)\ngateCount (CNOT c t x) = S (gateCount x)\n\n--count the number of H gates in a unitary circuit\nexport\nHcount : Unitary n -> Nat\nHcount IdGate = 0\nHcount (H j x) = S (Hcount x)\nHcount (P p j x) = Hcount x\nHcount (CNOT c t x) = Hcount x\n\n--count the number of P gates in a unitary circuit\nexport\nPcount : Unitary n -> Nat\nPcount IdGate = 0\nPcount (H j x) = Pcount x\nPcount (P p j x) = S (Pcount x)\nPcount (CNOT c t x) = Pcount x\n\n\n--count the number of CNOT gates in a unitary circuit\nexport\nCNOTcount : Unitary n -> Nat\nCNOTcount IdGate = 0\nCNOTcount (H j x) = CNOTcount x\nCNOTcount (P p j x) = CNOTcount x\nCNOTcount (CNOT c t x) = S (CNOTcount x)\n\n----------------------------DEPTH------------------------------\n|||Compute the depth of circuit\n\naddDepth : Nat -> (j : Nat) -> Vect n Nat -> {auto prf : j < n = True} -> Vect n Nat\naddDepth j 0 (x :: xs) = j :: xs\naddDepth j (S k) (x :: xs) = x :: addDepth j k xs\n\nfindValue : (j : Nat) -> Vect n Nat -> {auto prf : j < n = True} -> Nat\nfindValue 0 (x::xs) = x\nfindValue (S k) (x::xs) = findValue k xs\n\ndepth' : {n : Nat} -> Unitary n -> Vect n Nat\ndepth' IdGate = replicate n 0\ndepth' (H j x) =\n let v = depth' x \n k = findValue j v\n in addDepth (S k) j v\ndepth' (P p j x) = \n let v = depth' x\n k = findValue j v\n in addDepth (S k) j v\ndepth' (CNOT c t x) = \n let v = depth' x \n k = findValue c v\n m = findValue t v\n in if k < m then\n let w = addDepth (S m) c v\n in addDepth (S m) t w\n else\n let w = addDepth (S k) c v\n in addDepth (S k) t w\n\nexport\ndepth : {n : Nat} -> Unitary n -> Nat\ndepth g = \n let v = depth' g \n in foldl max 0 v\n\n----------------------------SHOW-------------------------------\n|||For printing the phase gate (used for show, export to Qiskit and draw in the terminal)\n|||printPhase : phase -> precision -> string for pi -> String\nprivate\nprintPhase : Double -> Double -> String -> String\nprintPhase x epsilon s =\n if x >= pi - epsilon && x <= pi + epsilon then s\n else if x >= pi/2 - epsilon && x <= pi/2 + epsilon then s ++ \"/2\"\n else if x >= pi/3 - epsilon && x <= pi/3 + epsilon then s ++ \"/3\"\n else if x >= pi/4 - epsilon && x <= pi/4 + epsilon then s ++ \"/4\"\n else if x >= pi/6 - epsilon && x <= pi/6 + epsilon then s ++ \"/6\"\n else if x >= pi/8 - epsilon && x <= pi/8 + epsilon then s ++ \"/8\"\n else if x >= -pi - epsilon && x <= -pi + epsilon then \"-\" ++ s\n else if x >= -pi/2 - epsilon && x <= -pi/2 + epsilon then \"-\" ++ s ++ \"/2\"\n else if x >= -pi/3 - epsilon && x <= -pi/3 + epsilon then \"-\" ++ s ++ \"/3\"\n else if x >= -pi/4 - epsilon && x <= -pi/4 + epsilon then \"-\" ++ s ++ \"/4\"\n else if x >= -pi/6 - epsilon && x <= -pi/6 + epsilon then \"-\" ++ s ++ \"/6\"\n else if x >= -pi/8 - epsilon && x <= -pi/8 + epsilon then \"-\" ++ s ++ \"/8\"\n else show x\n\npublic export\nShow (Unitary n) where\n show IdGate = \"\"\n show (H j x) = \"(H \" ++ show j ++ \") \" ++ show x \n show (P p j x) = \"(P \" ++ printPhase p 0.001 \"π\" ++ \" \" ++ show j ++ \") \" ++ show x\n show (CNOT c t x) = \"(CNOT \" ++ show c ++ \" \" ++ show t ++ \") \" ++ show x\n\n\n\n-----------------DRAW CIRCUITS IN THE TERMINAL-----------------\n\nprivate\nnewWireQVect : (n : Nat) -> Vect n String\nnewWireQVect Z = []\nnewWireQVect (S k) = \"\" :: newWireQVect k\n\nprivate\naddSymbol : Nat -> Bool -> (String, String) -> Vect n String -> Vect n String\naddSymbol _ _ _ [] = []\naddSymbol 0 False (s1, s2) (x :: xs) = (x ++ s1) :: addSymbol 0 True (s1, s2) xs\naddSymbol 0 True (s1, s2) (x :: xs) = (x ++ s2) :: addSymbol 0 True (s1, s2) xs\naddSymbol (S k) _ (s1, s2) (x :: xs) = (x ++ s2) :: addSymbol k False (s1, s2) xs\n\nprivate\naddSymbolCNOT : (Nat, Nat) -> Bool -> Bool -> Vect n String -> Vect n String\naddSymbolCNOT _ _ _ [] = []\naddSymbolCNOT (0,0) False b (x :: xs) = (x ++ \"- • -\") :: addSymbolCNOT (0, 0) True b xs\naddSymbolCNOT (0, S k) False b (x :: xs) = (x ++ \"- • -\") :: addSymbolCNOT (0, k) True b xs\naddSymbolCNOT (0, 0) b False (x :: xs) = (x ++ \"- Θ -\") :: addSymbolCNOT (0, 0) b True xs\naddSymbolCNOT (S k, 0) b False (x :: xs) = (x ++ \"- Θ -\") :: addSymbolCNOT (k, 0) b True xs\naddSymbolCNOT (0, 0) True True (x :: xs) = (x ++ \"-----\") :: addSymbolCNOT (0, 0) True True xs\naddSymbolCNOT (S j, S k) _ _ (x :: xs) = (x ++ \"-----\") :: addSymbolCNOT (j, k) False False xs\naddSymbolCNOT (0, S k) True _ (x :: xs) = (x ++ \"--|--\") :: addSymbolCNOT (0, k) True False xs\naddSymbolCNOT (S k, 0) _ True (x :: xs) = (x ++ \"--|--\") :: addSymbolCNOT (k, 0) False True xs\n\nprivate\ndrawWirePhase : Nat -> String\ndrawWirePhase 0 = \"\"\ndrawWirePhase (S n) = \"-\" ++ drawWirePhase n\n\nprivate\ndrawGate : {n : Nat} -> Unitary n -> Vect n String\ndrawGate {n} IdGate = newWireQVect n\ndrawGate (H i g) = addSymbol i False (\"- H -\", \"-----\") (drawGate g)\ndrawGate (P p i g) =\n let epsilon = 0.001 in\n if pi/4 - epsilon <= p && pi/4 + epsilon >= p\n then addSymbol i False (\"- T -\", \"-----\") (drawGate g)\n else if -pi/4 - epsilon <= p && -pi/4 + epsilon >= p\n then addSymbol i False (\"- T+ -\", \"------\") (drawGate g)\n else if pi/2 - epsilon <= p && pi/2 + epsilon >= p\n then addSymbol i False (\"- S -\", \"-----\") (drawGate g)\n else if -pi/2 - epsilon <= p && -pi/2 + epsilon >= p\n then addSymbol i False (\"- S+ -\", \"------\") (drawGate g)\n else if pi - epsilon <= p && pi + epsilon >= p\n then addSymbol i False (\"- Z -\", \"-----\") (drawGate g)\n else let s = printPhase p epsilon \"π\"\n in addSymbol i False (\"- P(\" ++ s ++ \") -\", drawWirePhase (length s + 7)) (drawGate g)\ndrawGate (CNOT i j g) = addSymbolCNOT (i,j) False False (drawGate g)\n\n\nprivate\ndrawVect : Vect n String -> String\ndrawVect [] = \"\"\ndrawVect (x :: xs) = x ++ \"\\n\" ++ drawVect xs\n\n|||Draw a circuit in the terminal\npublic export\ndraw : {n : Nat} -> Unitary n -> IO ()\ndraw g =\n let vs1 = drawGate {n} g in\n let s = drawVect vs1 in\n putStrLn s\n\n\n\n--------------------------EXPORT TO QISKIT---------------------\n\nprivate\nunitarytoQiskit : Unitary n -> String\nunitarytoQiskit IdGate = \"\"\nunitarytoQiskit (H i g) = unitarytoQiskit g ++ \"qc.h(qr[\" ++ show i ++ \"])\\n\"\nunitarytoQiskit (P p i g) = unitarytoQiskit g ++ \"qc.p(\" ++ printPhase p 0.001 \"np.pi\" ++ \", qr[\" ++ show i ++ \"])\\n\" \nunitarytoQiskit (CNOT c t g) = unitarytoQiskit g ++ \"qc.cx(qr[\" ++ show c ++ \"], qr[\" ++ show t ++ \"])\\n\" \n\n\nprivate\ntoQiskit : {n : Nat} -> Unitary n -> String\ntoQiskit g =\n let s = unitarytoQiskit g in\n (\"import numpy as np\\n\" ++\n \"from qiskit import QuantumCircuit\\n\" ++\n \"from qiskit import QuantumRegister\\n\" ++\n \"qr = QuantumRegister(\" ++ show n ++ \")\\n\" ++\n \"qc = QuantumCircuit(qr)\\n\\n\" ++ s ++\n \"\\nqc.draw('mpl')\")\n\n|||Export a circuit to Qiskit code\npublic export\nexportToQiskit : {n : Nat} -> String -> Unitary n -> IO ()\nexportToQiskit str g =\n let s = toQiskit g in\n do\n a <- writeFile str s\n case a of\n Left e1 => putStrLn \"Error when writing file\"\n Right io1 => pure ()\n\n\n\n\n\n", "meta": {"hexsha": "f9565547dea8aa5ece326fc0bf3932a116edf1a7", "size": 14092, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Unitary.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": "Unitary.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": "Unitary.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": 32.1002277904, "max_line_length": 118, "alphanum_fraction": 0.5704655123, "num_tokens": 5059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6557958785481022}} {"text": "module PreorderReasoning\n\nimport Basic\nimport Path\n\ninfixl 2 |=>\nprefix 3 ||\ninfix 3 ...\n\n||| Reason about paths/identities transitively.\n||| Start at Reflexivity.\nnamespace PreorderReasoningPath\n public export\n data StepP : a -> b -> Type where\n (...) : (0 y : a) -> (0 step : x == y) -> StepP x y\n\n public export\n data DeriveP : (x : a) -> (y : b) -> Type where\n (||) : (0 x : a) -> DeriveP x x\n (|=>) : DeriveP x y -> {0 z : a} -> (step : StepP y z) -> DeriveP x z\n\n public export\n Chain : {x, y : a} -> DeriveP x y -> x == y\n Chain (|| x) = Refl x\n Chain ((|=>) der (_ ... Refl _)) = Chain der\n\n||| Reason about functions transitively.\n||| Start at Identity.\nnamespace PreorderReasoningFunction\n public export\n data StepF : a -> b -> Type where\n (...) : (b : Type) -> (f : a -> b) -> StepF a b\n\n public export\n data DeriveF : a -> b -> Type where\n (||) : (a : Type) -> DeriveF a a\n (|=>) : DeriveF a b\n -> StepF b c\n -> DeriveF a c\n\n public export\n Chain : DeriveF a b -> a -> b\n Chain (|| _) = id\n Chain (p |=> (_ ... f)) = f `compose` Chain p\n\n", "meta": {"hexsha": "551e3cdd72fae75b9795452cd6811e60c7d699d6", "size": 1104, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/PreorderReasoning.idr", "max_stars_repo_name": "Russoul/Idris2-HoTT", "max_stars_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-17T05:44:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T09:36:13.000Z", "max_issues_repo_path": "src/PreorderReasoning.idr", "max_issues_repo_name": "Russoul/Idris2-HoTT", "max_issues_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/PreorderReasoning.idr", "max_forks_repo_name": "Russoul/Idris2-HoTT", "max_forks_repo_head_hexsha": "0c11569ca8205caecd92e4cdb85fb7f10ca80454", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0, "max_line_length": 73, "alphanum_fraction": 0.5452898551, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6557921621311216}} {"text": "module Collections.BSTree.Map.Quantifiers\n\nimport Collections.BSTree.Map.Core\nimport Collections.Util.Bnd\nimport Decidable.Order.Strict\n\n||| A proof that a tree is non-empty.\npublic export\ndata NonEmpty : BST pre tot vTy mn mx -> Type where\n IsNode : {pre : StrictPreorder kTy sto} ->\n {tot : StrictOrdered kTy sto} ->\n {l : BST pre tot vTy mn (Mid k)} ->\n {r : BST pre tot vTy (Mid k) mx} ->\n NonEmpty (Node k v l r)\n", "meta": {"hexsha": "f9886ba88a012d317ec81a013fba05d3049b2d40", "size": 459, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Collections/BSTree/Map/Quantifiers.idr", "max_stars_repo_name": "polendri/idris-collections", "max_stars_repo_head_hexsha": "8492ab9ceffdef72d25a65c6b4296e561816f73c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-24T10:58:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-20T16:16:04.000Z", "max_issues_repo_path": "src/Collections/BSTree/Map/Quantifiers.idr", "max_issues_repo_name": "polendri/idris-collections", "max_issues_repo_head_hexsha": "8492ab9ceffdef72d25a65c6b4296e561816f73c", "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/Collections/BSTree/Map/Quantifiers.idr", "max_forks_repo_name": "polendri/idris-collections", "max_forks_repo_head_hexsha": "8492ab9ceffdef72d25a65c6b4296e561816f73c", "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.6, "max_line_length": 51, "alphanum_fraction": 0.6448801743, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6557542848721257}} {"text": "\nmodule Eval\n\n-- Evaluators for terms in the untyped\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 0) -> (e' : Term 0 ** (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 0 -> Term 0\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' 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 0) -> (e' : Term 0 ** (Value e', BigStep e e'))\nevalBigStep (TVar i) = absurd $ FinZAbsurd i\nevalBigStep (TAbs x) = (TAbs x ** (VAbs, BStValue VAbs))\nevalBigStep (TApp x y) = let (TAbs ex ** (_, bStx)) = evalBigStep x\n (ey ** (vy, bSty)) = evalBigStep y \n (er ** (vr, bStr)) = evalBigStep (subst ey FZ ex)\n in (er ** (vr, BStApp bStx bSty bStr))\nevalBigStep TZero = (TZero ** (VZero, BStValue VZero))\nevalBigStep (TSucc x) = let (ex ** (vx, bStx)) = evalBigStep x\n in (TSucc ex ** (VSucc vx, BStSucc bStx))\nevalBigStep (TPred x) = case evalBigStep x of\n (TZero ** (_, bStx)) => (TZero ** (VZero, BStPredZero bStx))\n (TSucc ex ** (VSucc vx, bStx)) => (ex ** (vx, BStPredSucc bStx))\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 ** (_, 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", "meta": {"hexsha": "efd2ebba3bdd803d42903360571fcba0ac07ca61", "size": 3439, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "untyped/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": "untyped/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": "untyped/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": 35.4536082474, "max_line_length": 86, "alphanum_fraction": 0.453038674, "num_tokens": 1032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6556619444009063}} {"text": "-- ----------------------------------------------------------- [ Chapter10.idr ]\n-- Module : Exercises.Chapter10\n-- Description : Solutions to the Chapter 10 exercises in Edwin Brady's\n-- book, \"Type-Driven Development with Idris.\"\n-- --------------------------------------------------------------------- [ EOH ]\nmodule Exercises.Chapter10\n\nimport Data.List.Views\nimport Data.Nat.Views\nimport Data.Vect\nimport Data.Vect.Views\nimport Test\n\n%access export\n%default total\n\n---------------------------------------------------------- [ Exercise 10.1.6.1 ]\n\npublic export\ndata TakeN : List a -> Type where\n Fewer : TakeN xs\n Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)\n\ntakeN : (n : Nat) -> (xs : List a) -> TakeN xs\ntakeN _ [] = Fewer\ntakeN Z _ = Exact []\ntakeN (S Z) (x :: xs) = Exact [x]\ntakeN (S k) (x :: xs) with (takeN k xs)\n takeN (S k) (x :: xs) | Fewer = Fewer\n takeN (S k) (x :: (n_xs ++ rest)) | (Exact n_xs) = Exact (x :: n_xs)\n\n-- partial\ngroupByN : (n : Nat) -> (xs : List a) -> List (List a)\ngroupByN Z _ = [[]] -- Provide a sensible base case.\ngroupByN n xs with (takeN n xs)\n groupByN n xs | Fewer = [xs]\n -- HACK: Assert to the totality checker that groupByN will always terminate.\n groupByN n (n_xs ++ rest) | Exact n_xs = n_xs :: assert_total (groupByN n rest)\n -- groupByN n (n_xs ++ rest) | Exact n_xs = n_xs :: groupByN n rest\n\n---------------------------------------------------------- [ Exercise 10.1.6.2 ]\n\npartial\nhalves : List a -> (List a, List a)\nhalves xs with (takeN (length xs `div` 2) xs)\n halves xs | Fewer = ([],xs)\n halves (n_xs ++ rest) | (Exact n_xs) {rest} = (n_xs,rest)\n\n---------------------------------------------------------- [ Exercise 10.2.5.1 ]\n\n{- NOTE: Here's isSuffix for reference. It's quite similar to equalSuffix.\nisSuffix : Eq a => List a -> List a -> Bool\nisSuffix input1 input2 with (snocList input1)\n isSuffix [] input2 | Empty = True\n isSuffix (xs ++ [x]) input2 | (Snoc rec) with (snocList input2)\n isSuffix (xs ++ [x]) [] | (Snoc rec) | Empty = False\n isSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec) =\n x == y && isSuffix xs ys | xsrec | ysrec\n-}\n\n-- FIXME: I don't love this. It would be great to accumulate a SnocList then\n-- convert it to a list at the end, though maybe that's no different from\n-- accumulating a singly linked list and then reversing it.\nequalSuffixHelp : Eq a => (acc, input1, input2 : List a) -> List a\nequalSuffixHelp acc input1 input2 with (snocList input1)\n equalSuffixHelp acc [] input2 | Empty = []\n equalSuffixHelp acc (xs ++ [x]) input2 | (Snoc xsrec) with (snocList input2)\n equalSuffixHelp acc (xs ++ [x]) [] | (Snoc xsrec) | Empty = []\n equalSuffixHelp acc (xs ++ [x]) (ys ++ [y]) | (Snoc xsrec) | (Snoc ysrec) =\n if x /= y then [] else x :: equalSuffixHelp acc xs ys | xsrec | ysrec\n\nequalSuffix : Eq a => (input1, input2 : List a) -> List a\nequalSuffix input1 input2 = reverse $ equalSuffixHelp [] input1 input2\n\n---------------------------------------------------------- [ Exercise 10.2.5.2 ]\n\nmergeSort : Ord a => Vect n a -> Vect n a\nmergeSort xs with (splitRec xs)\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\n---------------------------------------------------------- [ Exercise 10.2.5.3 ]\n\n-- FIXME: This is ineffecient due to the string appending, at least.\ntoBinary : (n : Nat) -> String\ntoBinary n with (halfRec n)\n toBinary Z | HalfRecZ = \"\"\n toBinary (x + x) | (HalfRecEven rec) = (toBinary x | rec) ++ \"0\"\n toBinary (S (x + x)) | (HalfRecOdd rec) = (toBinary x | rec) ++ \"1\"\n\n---------------------------------------------------------- [ Exercise 10.2.5.4 ]\n\npalindrome : Eq a => (xs : List a) -> Bool\npalindrome xs with (vList xs)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (x :: (ys ++ [y])) | (VCons rec) = x == y && palindrome ys | rec\n\n---------------------------------------------------------------------- [ Tests ]\n\n-- partial\ntestGroupByN : IO ()\ntestGroupByN = assertEq [[1,2,3],[4,5,6],[7,8,9],[10]] $\n the (List (List Integer)) (groupByN 3 [1..10])\n\npartial\ntestHalves10 : IO ()\ntestHalves10 = assertEq ([1..5], [6..10]) $ halves [1..10]\n\npartial\ntestHalves1 : IO ()\ntestHalves1 = assertEq ([], [1]) $ the (List Integer, List Integer) (halves [1])\n\ntestEqualSuffix1 : IO ()\ntestEqualSuffix1 = assertEq (the (List Integer) [4,5])\n (equalSuffix [1,2,4,5] [1..5])\n\ntestEqualSuffix2 : IO ()\ntestEqualSuffix2 = assertEq [] $ equalSuffix [1,2,4,5,6] [1..5]\n\ntestEqualSuffix3 : IO ()\ntestEqualSuffix3 = assertEq (the (List Integer) [4,5,6])\n (equalSuffix [1,2,4,5,6] [1..6])\n\ntestMergeSort1 : IO ()\ntestMergeSort1 = assertEq (fromList [1,2,3]) (mergeSort [3,2,1])\n\ntestMergeSort2 : IO ()\ntestMergeSort2 = assertEq (fromList [1..9]) (mergeSort [5,1,4,3,2,6,8,7,9])\n\ntestToBinary42 : IO ()\ntestToBinary42 = assertEq \"101010\" $ toBinary 42\n\ntestToBinary94 : IO ()\ntestToBinary94 = assertEq \"1011110\" $ toBinary 94\n\ntestToBinaryExercism : IO ()\ntestToBinaryExercism =\n assertEq (the (List String) [\"1\", \"10\", \"11\", \"100\", \"1001\", \"11010\"])\n (map toBinary [1,2,3,4,9,26])\n\ntestPalindrome1 : IO ()\ntestPalindrome1 = assertEq True $ palindrome (unpack \"abccba\")\n\ntestPalindrome2 : IO ()\ntestPalindrome2 = assertEq True $ palindrome (unpack \"abcba\")\n\ntestPalindrome3 : IO ()\ntestPalindrome3 = assertEq False $ palindrome (unpack \"abcb\")\n\n------------------------------------------------------------------------ [ EOF ]\n", "meta": {"hexsha": "3ed5bb8938ed72eecf459c508cdf23ae0bbf47ee", "size": 5755, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Exercises/Chapter10.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/Chapter10.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/Chapter10.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": 37.1290322581, "max_line_length": 80, "alphanum_fraction": 0.5527367507, "num_tokens": 1712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624890918021, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.6555737254154161}} {"text": "module Sub06Apply36x9\n\nimport ProofColDivSeqBase\nimport ProofColDivSeqPostulate\nimport ProofColDivSeqPostuProof\n\n%default total\n-- %language ElabReflection\n\n\n-- 3(12x+3) --E[2,-4]--> 3x\nexport\napply36x9 : (Not . P) (S (S (S (plus (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (plus (plus l l) (plus l l))))))\n -> (m : Nat ** (LTE (S m) (S (S (S (plus (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (plus (plus l l) (plus l l)))))), (Not . P) m))\napply36x9 {l} col = (l ** (lte36x9 l, e36x9To3x l col)) where\n lte36x9 : (l:Nat) -> LTE (S l) (S (S (S (plus (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (plus (plus l l) (plus l l))))))\n lte36x9 Z = (lteSuccRight . lteSuccRight . LTESucc) LTEZero\n lte36x9 (S l) = let lemma = lte36x9 l in\n rewrite (sym (plusSuccRightSucc l l)) in\n rewrite (sym (plusSuccRightSucc (plus l l) (S (plus l l)))) in\n rewrite (sym (plusSuccRightSucc (plus l l) (plus l l))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (plus l l)) (S (S (S (plus (plus l l) (plus l l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (plus l l)) (S (S (plus (plus l l) (plus l l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (plus l l)) (S (plus (plus l l) (plus l l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l)))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (S (S (S (plus (plus l l) (plus l l))))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (S (S (plus (plus l l) (plus l l)))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (S (plus (plus l l) (plus l l))))) in\n rewrite (sym (plusSuccRightSucc (plus (plus (plus l l) (plus l l)) (plus (plus l l) (plus l l))) (plus (plus l l) (plus l l)))) in\n (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc) lemma\n\n\n\n", "meta": {"hexsha": "2cd5a5fdef4118964f79e7ef67a3d45757603bbc", "size": 2154, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "program2/Sub06Apply36x9.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/Sub06Apply36x9.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/Sub06Apply36x9.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.3529411765, "max_line_length": 186, "alphanum_fraction": 0.6146703807, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6553520481100179}} {"text": "= Rel : Properties of Relations\n\n> module Rel\n>\n\n\\todo[inline]{Add hyperlinks}\n\nThis short (and optional) chapter develops some basic definitions and a few\ntheorems about binary relations in Idris. The key definitions are repeated where\nthey are actually used (in the `Smallstep` chapter), so readers who are already\ncomfortable with these ideas can safely skim or skip this chapter. However,\nrelations are also a good source of exercises for developing facility with\nIdris's basic reasoning facilities, so it may be useful to look at this material\njust after the `IndProp` chapter.\n\n> import Logic\n> import IndProp\n>\n\nA binary _relation_ on a set \\idr{t} is a family of propositions parameterized\nby two elements of \\idr{t} — i.e., a proposition about pairs of elements of\n\\idr{t}.\n\n> Relation : Type -> Type\n> Relation t = t -> t -> Type\n\n\\todo[inline]{Edit, there's n-relation \\idr{Data.Rel} in \\idr{contrib}, but no\n\\idr{Relation}}\n\nConfusingly, the Idris standard library hijacks the generic term \"relation\" for\nthis specific instance of the idea. To maintain consistency with the library, we\nwill do the same. So, henceforth the Idris identifier `relation` will always\nrefer to a binary relation between some set and itself, whereas the English word\n\"relation\" can refer either to the specific Idris concept or the more general\nconcept of a relation between any number of possibly different sets. The context\nof the discussion should always make clear which is meant.\n\n\\todo[inline]{There's a similar concept called \\idr{LTE} in \\idr{Prelude.Nat},\nbut it's defined by induction from zero}\n\nAn example relation on \\idr{Nat} is \\idr{Le}, the less-than-or-equal-to\nrelation, which we usually write \\idr{n1 <= n2}.\n\n```idris\nλΠ> the (Relation Nat) Le\nLe : Nat -> Nat -> Type\n```\n\n\\todo[inline]{Edit to show it (probably) doesn't matter in Idris}\n\n(Why did we write it this way instead of starting with \\idr{data Le : Relation\nNat ...}? Because we wanted to put the first \\idr{Nat} to the left of the\n\\idr{:}, which makes Idris generate a somewhat nicer induction principle for\nreasoning about \\idr{<='}.)\n\n\n== Basic Properties\n\nAs anyone knows who has taken an undergraduate discrete math course, there is a\nlot to be said about relations in general, including ways of classifying\nrelations (as reflexive, transitive, etc.), theorems that can be proved\ngenerically about certain sorts of relations, constructions that build one\nrelation from another, etc. For example...\n\n\n=== Partial Functions\n\nA relation \\idr{r} on a set \\idr{t} is a _partial function_ if, for every\n\\idr{x}, there is at most one \\idr{y} such that \\idr{r x y} — i.e., \\idr{r x y1}\nand \\idr{r x y2} together imply \\idr{y1 = y2}.\n\n> Partial_function : (r : Relation t) -> Type\n> Partial_function {t} r = (x, y1, y2 : t) -> r x y1 -> r x y2 -> y1 = y2\n\n\\todo[inline]{\"Earlier\" = in \\idr{IndProp}, add hyperlink?}\n\nFor example, the \\idr{Next_nat} relation defined earlier is a partial function.\n\n```idris\nλΠ> the (Relation Nat) Next_nat\nNext_nat : Nat -> Nat -> Type\n```\n\n> next_nat_partial_function : Partial_function Next_nat\n> next_nat_partial_function x (S x) (S x) Nn Nn = Refl\n\nHowever, the \\idr{<='} relation on numbers is not a partial function. (Assume,\nfor a contradiction, that \\idr{<='} is a partial function. But then, since\n\\idr{0 <=' 0} and \\idr{0 <=' 1}, it follows that \\idr{0 = 1}. This is nonsense,\nso our assumption was contradictory.)\n\n> le_not_a_partial_function : Not (Partial_function Le)\n> le_not_a_partial_function f = absurd $ f 0 0 1 Le_n (Le_S Le_n)\n\n\n==== Exercise: 2 stars, optional\n\n\\ \\todo[inline]{Again, \"earlier\" = \\idr{IndProp}}\n\nShow that the \\idr{Total_relation} defined in earlier is not a partial function.\n\n> -- FILL IN HERE\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional\n\nShow that the \\idr{Empty_relation} that we defined earlier is a partial\nfunction.\n\n> --FILL IN HERE\n\n$\\square$\n\n\n=== Reflexive Relations\n\nA _reflexive_ relation on a set \\idr{t} is one for which every element of\n\\idr{t} is related to itself.\n\n> Reflexive : (r : Relation t) -> Type\n> Reflexive {t} r = (a : t) -> r a a\n\n> le_reflexive : Reflexive Le\n> le_reflexive n = Le_n {n}\n\n\n=== Transitive Relations\n\nA relation \\idr{r} is _transitive_ if \\idr{r a c} holds whenever \\idr{r a b} and\n\\idr{r b c} do.\n\n> Transitive : (r : Relation t) -> Type\n> Transitive {t} r = (a, b, c : t) -> r a b -> r b c -> r a c\n\n> le_trans : Transitive Le\n> le_trans _ _ _ lab Le_n = lab\n> le_trans a b (S c) lab (Le_S lbc) = Le_S $ le_trans a b c lab lbc\n\n> lt_trans : Transitive Lt\n> lt_trans a b c lab lbc = le_trans (S a) (S b) c (Le_S lab) lbc\n\n\n==== Exercise: 2 stars, optional\n\nWe can also prove \\idr{lt_trans} more laboriously by induction, without using\n\\idr{le_trans}. Do this.\n\n> lt_trans' : Transitive Lt\n> -- Prove this by induction on evidence that a is less than c.\n> lt_trans' a b c lab lbc = ?lt_trans__rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional\n\n\\ \\todo[inline]{Not sure how is this different from \\idr{lt_trans'}?}\n\nProve the same thing again by induction on \\idr{c}.\n\n> lt_trans'' : Transitive Lt\n> lt_trans'' a b c lab lbc = ?lt_trans___rhs\n\n$\\square$\n\nThe transitivity of \\idr{Le}, in turn, can be used to prove some facts that will\nbe useful later (e.g., for the proof of antisymmetry below)...\n\n> le_Sn_le : ((S n) <=' m) -> (n <=' m)\n> le_Sn_le {n} {m} = le_trans n (S n) m (Le_S Le_n)\n\n\n==== Exercise: 1 star, optional\n\n> le_S_n : ((S n) <=' (S m)) -> (n <=' m)\n> le_S_n less = ?le_S_n_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional (le_Sn_n_inf)\n\nProvide an informal proof of the following theorem:\n\nTheorem: For every \\idr{n}, \\idr{Not ((S n) <=' n)}\n\nA formal proof of this is an optional exercise below, but try writing an\ninformal proof without doing the formal proof first.\n\nProof:\n\n> -- FILL IN HERE\n\n$\\square$\n\n\n==== Exercise: 1 star, optional\n\n> le_Sn_n : Not ((S n) <=' n)\n> le_Sn_n = ?le_Sn_n_rhs\n\n$\\square$\n\nReflexivity and transitivity are the main concepts we'll need for later\nchapters, but, for a bit of additional practice working with relations in Idris,\nlet's look at a few other common ones...\n\n\n=== Symmetric and Antisymmetric Relations\n\nA relation \\idr{r} is _symmetric_ if \\idr{r a b} implies \\idr{r b a}.\n\n> Symmetric : (r : Relation t) -> Type\n> Symmetric {t} r = (a, b : t) -> r a b -> r b a\n\n\n==== Exercise: 2 stars, optional\n\n> le_not_symmetric : Not (Symmetric Le)\n> le_not_symmetric = ?le_not_symmetric_rhs\n\n$\\square$\n\nA relation \\idr{r} is _antisymmetric_ if \\idr{r a b} and \\idr{r b a} together\nimply \\idr{a = b} — that is, if the only \"cycles\" in \\idr{r} are trivial ones.\n\n> Antisymmetric : (r : Relation t) -> Type\n> Antisymmetric {t} r = (a, b : t) -> r a b -> r b a -> a = b\n\n\n==== Exercise: 2 stars, optional\n\n> le_antisymmetric : Antisymmetric Le\n> le_antisymmetric = ?le_antisymmetric_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, optional\n\n> le_step : (n <' m) -> (m <=' (S p)) -> (n <=' p)\n> le_step ltnm lemsp = ?le_step_rhs\n\n$\\square$\n\n\n=== Equivalence Relations\n\nA relation is an _equivalence_ if it's reflexive, symmetric, and transitive.\n\n> Equivalence : (r : Relation t) -> Type\n> Equivalence r = (Reflexive r, Symmetric r, Transitive r)\n\n\n=== Partial Orders and Preorders\n\n\\ \\todo[inline]{Edit}\n\nA relation is a _partial order_ when it's reflexive, _anti_-symmetric, and\ntransitive. In the Idris standard library it's called just \"order\" for short.\n\n> Order : (r : Relation t) -> Type\n> Order r = (Reflexive r, Antisymmetric r, Transitive r)\n\nA preorder is almost like a partial order, but doesn't have to be antisymmetric.\n\n> Preorder : (r : Relation t) -> Type\n> Preorder r = (Reflexive r, Transitive r)\n\n> le_order : Order Le\n> le_order = (le_reflexive, le_antisymmetric, le_trans)\n\n\n== Reflexive, Transitive Closure\n\n\\ \\todo[inline]{Edit}\n\nThe _reflexive, transitive closure_ of a relation \\idr{r} is the smallest\nrelation that contains \\idr{r} and that is both reflexive and transitive.\nFormally, it is defined like this in the Relations module of the Idris standard\nlibrary:\n\n> data Clos_refl_trans : (r : Relation t) -> Relation t where\n> Rt_step : r x y -> Clos_refl_trans r x y\n> Rt_refl : Clos_refl_trans r x x\n> Rt_trans : Clos_refl_trans r x y -> Clos_refl_trans r y z ->\n> Clos_refl_trans r x z\n\nFor example, the reflexive and transitive closure of the \\idr{Next_nat} relation\ncoincides with the \\idr{Le} relation.\n\n> next_nat_closure_is_le : (n <=' m) <-> (Clos_refl_trans Next_nat n m)\n> next_nat_closure_is_le = (to, fro)\n> where\n> to : Le n m -> Clos_refl_trans Next_nat n m\n> to Le_n = Rt_refl\n> to (Le_S {m} le) = Rt_trans {y=m} (to le) (Rt_step Nn)\n> fro : Clos_refl_trans Next_nat n m -> Le n m\n> fro (Rt_step Nn) = Le_S Le_n\n> fro Rt_refl = Le_n\n> fro (Rt_trans {x=n} {y} {z=m} ny ym) =\n> le_trans n y m (fro ny) (fro ym)\n\nThe above definition of reflexive, transitive closure is natural: it says,\nexplicitly, that the reflexive and transitive closure of \\idr{r} is the least\nrelation that includes \\idr{r} and that is closed under rules of reflexivity and\ntransitivity. But it turns out that this definition is not very convenient for\ndoing proofs, since the \"nondeterminism\" of the \\idr{Rt_trans} rule can\nsometimes lead to tricky inductions. Here is a more useful definition:\n\n> data Clos_refl_trans_1n : (r : Relation t) -> (x : t) -> t -> Type where\n> Rt1n_refl : Clos_refl_trans_1n r x x\n> Rt1n_trans : r x y -> Clos_refl_trans_1n r y z -> Clos_refl_trans_1n r x z\n\n\\todo[inline]{Edit}\n\nOur new definition of reflexive, transitive closure \"bundles\" the \\idr{Rt_step}\nand \\idr{Rt_trans} rules into the single rule step. The left-hand premise of\nthis step is a single use of \\idr{r}, leading to a much simpler induction\nprinciple.\n\nBefore we go on, we should check that the two definitions do indeed define the\nsame relation...\n\nFirst, we prove two lemmas showing that \\idr{Clos_refl_trans_1n} mimics the\nbehavior of the two \"missing\" \\idr{Clos_refl_trans} constructors.\n\n> rsc_R : r x y -> Clos_refl_trans_1n r x y\n> rsc_R rxy = Rt1n_trans rxy Rt1n_refl\n\n\n==== Exercise: 2 stars, optional (rsc_trans)\n\n> rsc_trans : Clos_refl_trans_1n r x y -> Clos_refl_trans_1n r y z ->\n> Clos_refl_trans_1n r x z\n> rsc_trans crxy cryz = ?rsc_trans_rhs\n\n$\\square$\n\nThen we use these facts to prove that the two definitions of reflexive,\ntransitive closure do indeed define the same relation.\n\n\n==== Exercise: 3 stars, optional (rtc_rsc_coincide)\n\n> rtc_rsc_coincide : (Clos_refl_trans r x y) <-> (Clos_refl_trans_1n r x y)\n> rtc_rsc_coincide = ?rtc_rsc_coincide_rhs\n\n$\\square$\n", "meta": {"hexsha": "c4995122910305ad39496629c19d8952219aa9a7", "size": 10599, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Rel.lidr", "max_stars_repo_name": "diseraluca/software-foundations", "max_stars_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 452, "max_stars_repo_stars_event_min_datetime": "2016-06-23T10:03:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T22:25:00.000Z", "max_issues_repo_path": "src/Rel.lidr", "max_issues_repo_name": "diseraluca/software-foundations", "max_issues_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 53, "max_issues_repo_issues_event_min_datetime": "2016-06-27T07:14:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-23T06:16:57.000Z", "max_forks_repo_path": "src/Rel.lidr", "max_forks_repo_name": "diseraluca/software-foundations", "max_forks_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2016-11-21T10:55:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T00:21:55.000Z", "avg_line_length": 30.1107954545, "max_line_length": 80, "alphanum_fraction": 0.7064817436, "num_tokens": 3257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6553012643908271}} {"text": "module Functions\n\ndata Nat' = Z' | S' Nat'\n\nplus : Nat' -> Nat' -> Nat'\nplus Z' y = y\nplus (S' k) y = S' (plus k y)\n\nmult : Nat' -> Nat' -> Nat'\nmult Z' y = Z'\nmult (S' k) y = plus y (mult k y)\n\n", "meta": {"hexsha": "96b83ef55233ff4f7a513d2100f3070c958c23db", "size": 195, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "functions.idr", "max_stars_repo_name": "aztecrex/try-idris", "max_stars_repo_head_hexsha": "e2d96bb1094c1dac9cb002157956b7f1d10d7fe3", "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": "functions.idr", "max_issues_repo_name": "aztecrex/try-idris", "max_issues_repo_head_hexsha": "e2d96bb1094c1dac9cb002157956b7f1d10d7fe3", "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": "functions.idr", "max_forks_repo_name": "aztecrex/try-idris", "max_forks_repo_head_hexsha": "e2d96bb1094c1dac9cb002157956b7f1d10d7fe3", "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.0, "max_line_length": 33, "alphanum_fraction": 0.5076923077, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6548464317578127}} {"text": "\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\n%name Vect xs, ys, zs\n\n{- 1 -}\n\nheadUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} ->\n (contra : (x = y) -> Void) -> (x :: xs) = (y :: ys) -> Void\nheadUnequal contra Refl = contra Refl\n\ntailUnequal : DecEq a => {xs : Vect n a} -> {ys : Vect n a} ->\n (contra : (xs = ys) -> Void) -> (x :: xs) = (y :: ys) -> Void\ntailUnequal contra Refl = contra Refl\n\n{- 2 -}\n\nDecEq a => DecEq (Vect n a) where\n decEq [] [] = Yes Refl\n decEq (x :: xs) (y :: ys) = case decEq x y of\n No contra => No (headUnequal contra)\n Yes Refl => case decEq xs ys of\n Yes Refl => Yes Refl\n No contra => No (tailUnequal contra)", "meta": {"hexsha": "d05e25a498c143752d73afd0e01906980dc2e2cc", "size": 910, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-exercises/8_3.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/8_3.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/8_3.idr", "max_forks_repo_name": "0nkery/tt-tutorials", "max_forks_repo_head_hexsha": "a39926989c2f39c718893b99bd857b6d51a172b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0, "max_line_length": 90, "alphanum_fraction": 0.4230769231, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6547686195479719}} {"text": "\nmodule Term\n\n-- Simply-typed lambda calculus with \n-- (1) natural numbers as the only base type, and\n-- (2) primitive recursion.\n--\n-- Terms in the lambda calculus are initially untyped.\n-- The usual typing judgement is defined as a separate\n-- data type in a separate module.\n-- Note that meta-theory developed in yet other modules\n-- will rely on the typing judgement.\n--\n-- Note that variables in the lambda calculus are not\n-- named but identified by their de Bruijn index.\n-- Since terms in our lambda calculus are initially\n-- untyped, they may therefore also be ill-scoped.\n-- Hence, de Bruijn indices are represented simply\n-- by natural numbers (since they will only be\n-- required to be valid in a context that is chosen\n-- later, during typing of a term).\n\n\n%default total\n%access public export\n\n\n\n------------------------------------------------\n-- Begin: (UNTYPED) TERMS OF THE LAMBDA CALCULUS\n\ndata Term : Type where\n TVar : (i : Nat) -> Term\n TAbs : Term -> Term\n TApp : Term -> Term -> Term\n TRec : Term -> Term -> Term ->\n Term\n TZero : Term\n TSucc : Term -> Term\n TPred : Term -> Term\n TIfz : Term -> Term -> Term ->\n Term\n\n\n\n-- Construction of terms is a congruence for equality.\n-- The following straightforward lemmas are often useful\n-- for writing shorter proofs.\n\ncongVar : i = j -> TVar i = TVar j\ncongVar Refl = Refl\n\n\ncongAbs : e = e' -> TAbs e = TAbs e'\ncongAbs Refl = Refl\n\n\ncongApp : e1 = e1' -> e2 = e2' -> TApp e1 e2 = TApp e1' e2'\ncongApp Refl Refl = Refl\n\n\ncongRec : e1 = e1' -> e2 = e2' -> e3 = e3' ->\n TRec e1 e2 e3 = TRec e1' e2' e3'\ncongRec Refl Refl Refl = Refl\n\n\ncongZero : TZero = TZero\ncongZero = Refl\n\n\ncongSucc : e = e' -> TSucc e = TSucc e'\ncongSucc Refl = Refl\n\n\ncongPred : e = e' -> TPred e = TPred e'\ncongPred Refl = Refl\n\n\ncongIfz : e1 = e1' -> e2 = e2' -> e3 = e3' ->\n TIfz e1 e2 e3 = TIfz e1' e2' e3'\ncongIfz Refl Refl Refl = Refl\n\n-- End: (UNTYPED) TERMS OF THE LAMBDA CALCULUS\n----------------------------------------------\n\n\n\n\n---------------------------------------\n-- Begin: VALUES IN THE LAMBDA CALCULUS \n\n-- The following lambda calculus terms\n-- are values (i.e. normal forms for \n-- reduction under the \"Step\" relation):\n-- (1) lambda abstractions (that are\n-- not applied),\n-- (2) the constant 'Zero',\n-- (3) the natural number constants\n-- (formed by applying 'Succ' to\n-- another value). \ndata Value : Term -> Type where\n VZero : Value TZero\n VSucc : Value e -> Value (TSucc e)\n VAbs : Value (TAbs e)\n\n-- End: VALUES IN THE LAMBDA CALCULUS \n-------------------------------------\n", "meta": {"hexsha": "bafa0e8695c2d3109d54625469ff6f781a6e814e", "size": 2624, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "totality/src/Term.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "totality/src/Term.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "totality/src/Term.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2962962963, "max_line_length": 59, "alphanum_fraction": 0.6074695122, "num_tokens": 785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.870597265050901, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6547000948377957}} {"text": "\ndata Fin : Nat -> Type where\n FS : Fin k -> Fin (S k)\n FZ : Fin (S k)\n\n%builtin Natural Fin\n", "meta": {"hexsha": "1dfbbdbd76b5786df043d2e4ceb78f940ccb9225", "size": 99, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/builtin003/Test.idr", "max_stars_repo_name": "ska80/idris-jvm", "max_stars_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 396, "max_stars_repo_stars_event_min_datetime": "2016-07-17T08:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T22:47:13.000Z", "max_issues_repo_path": "tests/idris2/builtin003/Test.idr", "max_issues_repo_name": "ska80/idris-jvm", "max_issues_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-08-04T06:13:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T04:00:31.000Z", "max_forks_repo_path": "tests/idris2/builtin003/Test.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 14.1428571429, "max_line_length": 28, "alphanum_fraction": 0.5454545455, "num_tokens": 34, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6545802154427963}} {"text": "import Data.List\n\nack : Nat -> Nat -> Nat\nack 0 n = S n\nack (S k) 0 = ack k 1\nack (S j) (S k) = ack j (ack (S j) k)\n\nfoo : Nat -> Nat\nfoo Z = Z\nfoo (S Z) = (S Z)\nfoo (S (S k)) = foo (S k)\n\ndata Ord = Zero | Suc Ord | Sup (Nat -> Ord)\n\nordElim : (x : Ord) ->\n (p : Ord -> Type) ->\n (p Zero) ->\n ((x : Ord) -> p x -> p (Suc x)) ->\n ((f : Nat -> Ord) -> ((n : Nat) -> p (f n)) ->\n p (Sup f)) -> p x\nordElim Zero p mZ mSuc mSup = mZ\nordElim (Suc o) p mZ mSuc mSup = mSuc o (ordElim o p mZ mSuc mSup)\nordElim (Sup f) p mZ mSuc mSup =\n mSup f (\\n => ordElim (f n) p mZ mSuc mSup)\n\nmutual\n bar : Nat -> Lazy Nat -> Nat\n bar x y = mp x y\n\n mp : Nat -> Nat -> Nat\n mp Z y = y\n mp (S k) y = S (bar k y)\n\nmutual\n swapR : Nat -> Nat -> Nat\n swapR x (S y) = swapL y x\n swapR x Z = x\n\n swapL : Nat -> Nat -> Nat\n swapL (S x) y = swapR y (S x)\n swapL Z y = y\n\nloopy : a\nloopy = loopy\n\ndata Bin = EPS | C0 Bin | C1 Bin\n\nfoom : Bin -> Nat\nfoom EPS = Z\nfoom (C0 EPS) = Z\nfoom (C0 (C1 x)) = S (foom (C1 x))\nfoom (C0 (C0 x)) = foom (C0 x)\nfoom (C1 x) = S (foom x)\n\npfoom : Bin -> Nat\npfoom EPS = Z\npfoom (C0 EPS) = Z\npfoom (C0 (C1 x)) = S (pfoom (C0 x))\npfoom (C0 (C0 x)) = pfoom (C0 x)\npfoom (C1 x) = S (foom x)\n\neven : Nat -> Bool\neven Z = True\neven (S k) = odd k\n where\n odd : Nat -> Bool\n odd Z = False\n odd (S k) = even k\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nvtrans : Vect n a -> Vect n a -> List a\nvtrans [] _ = []\nvtrans (x :: xs) ys = x :: vtrans ys ys\n\ndata GTree : Type -> Type where\n MkGTree : List (GTree a) -> GTree a\n\nsize : GTree a -> Nat\nsize (MkGTree []) = Z\nsize (MkGTree xs) = sizeAll xs\n where\n plus : Nat -> Nat -> Nat\n plus Z y = y\n plus (S k) y = S (plus k y)\n\n sizeAll : List (GTree a) -> Nat\n sizeAll [] = Z\n sizeAll (x :: xs) = plus (size x) (sizeAll xs)\n\nqsortBad : Ord a => List a -> List a\nqsortBad [] = []\nqsortBad (x :: xs)\n = qsortBad (filter (< x) xs) ++ x :: qsortBad (filter (> x) xs)\n\nqsort : Ord a => List a -> List a\nqsort [] = []\nqsort (x :: xs)\n = qsort (assert_smaller (x :: xs) (filter (< x) xs)) ++\n x :: qsort (assert_smaller (x :: xs) (filter (> x) xs))\n\nqsort' : Ord a => List a -> List a\nqsort' [] = []\nqsort' (x :: xs)\n = let (xs_low, xs_high) = partition x xs in\n qsort' (assert_smaller (x :: xs) xs_low) ++\n x :: qsort' (assert_smaller (x :: xs) xs_high)\n where\n partition : a -> List a -> (List a, List a)\n partition x xs = (filter (< x) xs, filter (>= x) xs)\n\nmySorted : Ord a => List a -> Bool\nmySorted [] = True\nmySorted (x::xs) =\n case xs of\n Nil => True\n (y::ys) => x <= y && mySorted (y::ys)\n\nmyMergeBy : (a -> a -> Ordering) -> List a -> List a -> List a\nmyMergeBy order [] right = right\nmyMergeBy order left [] = left\nmyMergeBy order (x::xs) (y::ys) =\n case order x y of\n LT => x :: myMergeBy order xs (y::ys)\n _ => y :: myMergeBy order (x::xs) ys\n", "meta": {"hexsha": "3c82ff904bc8d2557f9cac78d66dbf48f256ed76", "size": 3048, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/total004/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/total004/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/total004/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": 23.8125, "max_line_length": 66, "alphanum_fraction": 0.5104986877, "num_tokens": 1183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6543479154771147}} {"text": "module Main\n\nimport Data.Fin\nimport Effects\nimport Effect.StdIO\nimport Data.Complex\nimport Graphics.Color\nimport Graphics.SDL2.SDL\nimport Graphics.SDL2.Effect\nimport Graphics.Cairo.Effect\nimport Graphics.Shape\n\n\n-- ================================================================\n-- Interactive Penrose Tiling\n-- ================================================================\n\n%default total\n\n-- ----------------------------------------------------------------\n-- a bit of infrastructure\n-- ----------------------------------------------------------------\n\n||| Type alias for convenience \nC : Type\nC = Complex Double\n\n||| Division of Complex Numbers\ndivC : C -> C -> C\ndivC (a:+b) (c:+d) = let real = (a*c+b*d) / (c*c+d*d)\n imag = (b*c-a*d) / (c*c+d*d)\n in\n (real:+imag)\n\n||| the golden ratio constant\ngoldenRatio : Double\ngoldenRatio = 0.5 * (1 + (sqrt 5))\n\n||| we model a triangle using a triple of complex numbers\nTri : Type\nTri = (C, C, C)\n\n-- ----------------------------------------------------------------\n-- Calculate the penrose tiling\n-- ----------------------------------------------------------------\n\ndata Penrose = Red Tri | Blue Tri\n\nimplementation Show Penrose where\n show (Red x) = \"Red \" ++ show x\n show (Blue x) = \"Blue \" ++ show x\n\n||| Penrose subdivide\n||| This computes a single step in the tiling\n||| see also: http://preshing.com/20110831/penrose-tiling-explained/\npenroseSubdivide : Penrose -> List Penrose\npenroseSubdivide (Blue (a, b, c)) = let q = b + ((a-b) `divC` (goldenRatio :+ 0))\n r = b + ((c-b) `divC` (goldenRatio :+ 0))\n in [Blue (r, c, a), Blue (q, r, b), Red (r, q, a)]\npenroseSubdivide (Red (a, b, c)) = let p = a + ((b-a) `divC` (goldenRatio :+ 0))\n in [Red (c, p, b), Blue (p, c, a)]\n\n||| A Stream of all Tilings for a given initial triangle\n||| a single tiliing consists of a list of triangles\npenroseTiling : Tri -> Stream (List Penrose)\npenroseTiling triangle = penroseTiling' [(Red triangle)]\n where penroseTiling' : (List Penrose) -> Stream (List Penrose) \n penroseTiling' triangles = iterate (\\tris => tris >>= penroseSubdivide) triangles\n\n\n||| Creates an initial upside down triangle \ninitialTriangle : (height: Int) -> (angle: Double) -> Tri\ninitialTriangle height angle = let rad = 2 * pi * angle / 360\n y = (tan (rad / 2)) * (cast height)\n in ( 0:+0, (-1) * y :+ (-1) * (cast height), y :+ (-1) * (cast height))\n\n||| computes the full tiling \n||| @level number of subdivide iterations\n||| @numTriangles the number of symetric triangles\npenroseTriangles : (level: Nat) -> (numTriangles: Int) -> List Penrose\npenroseTriangles level numTriangles = let angle = 360.0 / (cast numTriangles)\n tilings = penroseTiling $ initialTriangle 200 angle\n in head (drop level tilings)\n\n \n-- ----------------------------------------------------------------\n-- Cairo Rendering\n-- ----------------------------------------------------------------\n\nred : Color\nred = RGBA 250 140 89 255\n\ngreen : Color\ngreen = RGBA 143 206 94 255\n\n||| get the color for drawing each individual triangle\ngetColor : Penrose -> Color\ngetColor (Red _) = red\ngetColor (Blue _) = green\n\ngetTriangle : Penrose -> Tri\ngetTriangle (Red triangle) = triangle \ngetTriangle (Blue triangle) = triangle \n\n||| draws a single penrose triangle using the cairo effect \nrenderTriangle : Penrose -> { [CAIRO_ON] } Eff () \nrenderTriangle penrose = with Effects do\n setSourceRGBA $ getColor penrose\n setLineWidth 6\n let (x1:+y1, x2:+y2, x3:+y3) = getTriangle penrose\n triangle (x1, y1) (x2, y2) (x3, y3)\n fill\n\nrenderTriangles : List Penrose -> Double -> Nat -> { [CAIRO_ON] } Eff () \nrenderTriangles triangles angle Z = pure ()\nrenderTriangles triangles angle (S k) = with Effects do renderTriangle' triangles\n rotate angle\n renderTriangles triangles angle k\n where \n renderTriangle' : List Penrose -> { [CAIRO_ON] } Eff () \n renderTriangle' [] = pure ()\n renderTriangle' (t :: ts) = with Effects do\n renderTriangle t\n renderTriangle' ts\n\n-- ----------------------------------------------------------------\n-- Setup and Main Loop\n-- ----------------------------------------------------------------\n\n||| type synonym for the effectful programm\n||| we need at least the SDL and CAIRO effects\n||| STDIO is only needed for optional logging\nProg : (sdl: Type) -> (cairo: Type) -> (result : Type) -> Type\nProg sdl cairo t = { [SDL sdl, -- the SDL effect\n CAIRO cairo, -- Cairo effect\n STDIO] -- a std io effect \n } Eff t\n\n||| convenvience shorthand for a running program\nRunning : Type -> Type\nRunning t = Prog SDLCtx () t\n\n||| the application state containing the current subdivision level \n||| and number of initial triangles \ndata AppState = MkState Nat Nat\n\n||| draw the current application state\ndraw : AppState -> Running ()\ndraw (MkState angles level) = with Effects do\n renderClear white\n ctx <- getSdlCtx\n getCanvas ctx\n center\n\n let numTriangles = cast angles + 4\n let solution = penroseTriangles level numTriangles\n let angle = (2 * pi / (cast numTriangles))\n \n renderTriangles solution angle (cast numTriangles) \n\n closeCanvas \n render\n\n||| process sdl input events\nprocess : AppState -> Maybe Event -> Maybe AppState\nprocess _ (Just (KeyDown KeyEsc)) = Nothing\nprocess _ (Just (AppQuit)) = Nothing\nprocess (MkState angles level) (Just (KeyDown KeyUpArrow)) = Just (MkState (S angles) level)\nprocess (MkState Z level) (Just (KeyDown KeyDownArrow)) = Just (MkState Z level)\nprocess (MkState (S k) level) (Just (KeyDown KeyDownArrow)) = Just (MkState k level)\nprocess (MkState angles level) (Just (KeyDown KeyRightArrow)) = Just (MkState angles (S level))\nprocess (MkState angles Z) (Just (KeyDown KeyLeftArrow)) = Just (MkState angles Z)\nprocess (MkState angles (S k)) (Just (KeyDown KeyLeftArrow)) = Just (MkState angles k)\nprocess state _ = Just state\n\n\n%default partial\n\n||| the effectful main application and loop\nemain : Prog () () ()\nemain = do putStrLn \"Initialising\"\n initialise \"Penrose\" 800 600\n putStrLn \"Initialised\"\n eventLoop (MkState Z Z)\n quit\n pure ()\n where \n eventLoop : AppState -> Running ()\n eventLoop state = do draw state \n ev <- poll\n let res = process state ev\n case res of\n (Just newState) => eventLoop newState\n _ => pure ()\n\nmain : IO ()\nmain = runInit [(), -- initial state for the SDL2 effect (nothing needs to go in here)\n (),\n () -- initial state for the StdIO effect \n ] \n emain\n\n\n\n", "meta": {"hexsha": "48afb76843881fb3100b1c2838148c10a1461639", "size": 7494, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "examples/penrose/Main.idr", "max_stars_repo_name": "eckart/cairo-idris", "max_stars_repo_head_hexsha": "21ea0b261719e9c5c407e479e35e99b213b29014", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-28T12:25:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-17T19:39:53.000Z", "max_issues_repo_path": "examples/penrose/Main.idr", "max_issues_repo_name": "eckart/cairo-idris", "max_issues_repo_head_hexsha": "21ea0b261719e9c5c407e479e35e99b213b29014", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-12-15T10:08:47.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-15T10:08:47.000Z", "max_forks_repo_path": "examples/penrose/Main.idr", "max_forks_repo_name": "eckart/cairo-idris", "max_forks_repo_head_hexsha": "21ea0b261719e9c5c407e479e35e99b213b29014", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-13T00:32:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T00:32:34.000Z", "avg_line_length": 36.556097561, "max_line_length": 123, "alphanum_fraction": 0.5238857753, "num_tokens": 1742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172673767972, "lm_q2_score": 0.6893056231680121, "lm_q1q2_score": 0.6540940083240504}} {"text": "%default partial\n\ndata Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : a -> Vect k a -> Vect (S k) a\n\nappend : Vect n a -> Vect m a -> Vect (n + m) a\nappend [] ys = ys\n-- append (x :: xs) ys = x :: append xs ys\n\ndata Fin : Nat -> Type where\n FZ : Fin (S k)\n FS : Fin k -> Fin (S k)\n\nlookup : Fin n -> Vect n a -> a\nlookup FZ (x :: xs) = x\nlookup (FS k) (x :: xs) = lookup k xs\n\nzip : Vect n a -> Vect n b -> Vect n (a, b)\nzip [] [] = []\nzip (x :: xs) (y :: ys) = (x, y) :: zip xs ys\n\n", "meta": {"hexsha": "e9d57e0d3e52ffc16d6af938e83cfe3f444e80a5", "size": 510, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/coverage001/Vect.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/tests/idris2/coverage001/Vect.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/tests/idris2/coverage001/Vect.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1739130435, "max_line_length": 47, "alphanum_fraction": 0.4862745098, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6538919943195542}} {"text": "data Expr = Val Int\n | Add Expr Expr\n | Sub Expr Expr\n | Mult Expr Expr\n\nevaluate : Expr -> Int\nevaluate (Val x) = x\nevaluate (Add x y) = evaluate x + evaluate y\nevaluate (Sub x y) = evaluate x - evaluate y\nevaluate (Mult x y) = evaluate x * evaluate y\n", "meta": {"hexsha": "d9223d7b2c323d7c215ec11ee446f3af1c5d0500", "size": 280, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter4/Expr.idr", "max_stars_repo_name": "DimaSamoz/idris-book", "max_stars_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter4/Expr.idr", "max_issues_repo_name": "DimaSamoz/idris-book", "max_issues_repo_head_hexsha": "4f06668dbe38545344b90a1c9a4c197a35269701", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter4/Expr.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.4545454545, "max_line_length": 45, "alphanum_fraction": 0.6071428571, "num_tokens": 77, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6537755082507474}} {"text": "module HetTree\n\nimport Semiring\n\n%default total\n%access public export\n\ndata Tree a = Nil | End a | (::) (Tree a) (Tree a)\n\ndata BiVect : Tree Type -> Type where\n Leaf : BiVect Nil\n Node : a -> BiVect (End a)\n Branch : BiVect ls -> BiVect rs -> BiVect (ls::rs)\n\nusing (x : a, ls : Tree a, rs : Tree a)\n data Elem : a -> Tree a -> Type where\n Here : Elem x (End x)\n Left : Elem x ls -> Elem x (ls::rs)\n Right : Elem x rs -> Elem x (ls::rs)\n\nremove : (x : a) -> (xs : Tree a) -> Elem x xs -> Tree a\nremove x (End x) Here = Nil\nremove x (ls :: rs) (Left p) = remove x ls p :: rs\nremove x (ls :: rs) (Right p) = ls :: remove x rs p\n\naddBack\n : {xs : Tree Type}\n -> {x : Type}\n -> {auto elem : Elem x xs}\n -> (val : x)\n -> (vec : BiVect (remove x xs elem))\n -> BiVect xs\naddBack {elem = Here} val vec = Node val\naddBack {elem = (Left x)} val (Branch ls rs) = Branch (addBack val ls) rs\naddBack {elem = (Right x)} val (Branch ls rs) = Branch ls (addBack val rs)\n\ndata AllFinite : Tree Type -> Type where\n Empty : AllFinite Nil\n Both\n : (lhs : AllFinite ls)\n -> (rhs : AllFinite rs)\n -> AllFinite (ls::rs)\n Extra\n : (MinBound x, MaxBound x, Enum x)\n => AllFinite (End x)\n\nmarg : (Semiring n, MinBound a, MaxBound a, Enum a) => (a -> n) -> n\nmarg f = sum (map f [minBound .. maxBound])\n\nmargBiVec\n: Semiring n\n=> {xs : Tree Type}\n-> {auto prf : AllFinite xs}\n-> (BiVect xs -> n) -> n\nmargBiVec {xs=Nil} f = f Leaf\nmargBiVec {xs=End x} {prf=Extra} f = marg (\\y => f (Node y))\nmargBiVec {xs=ls::rs} {prf=Both lp rp} f = margBiVec (\\lhs => margBiVec (\\rhs => f (Branch lhs rhs)))\n\nmargOnce : (Semiring n, Enum x, MinBound x, MaxBound x) => {xs : Tree Type} -> {auto elem : Elem x xs} -> (BiVect xs -> n) -> BiVect (remove x xs elem) -> n\nmargOnce {elem} f tr = marg (\\x => f (addBack x tr))\n\nsplit : {auto elem : Elem x xs} -> BiVect xs -> (x, BiVect (remove x xs elem))\nsplit {elem = Here} (Node x) = (x, Leaf)\nsplit {elem = (Left p)} (Branch ls rs) = let (el,rm) = split {elem=p} ls in (el, Branch rm rs)\nsplit {elem = (Right p)} (Branch ls rs) = let (el,rm) = split {elem=p} rs in (el, Branch ls rm)\n\npop : {auto elem : Elem x xs} -> BiVect xs -> BiVect (remove x xs elem)\npop {elem = Here} (Node x) = Leaf\npop {elem = (Left p)} (Branch ls rs) = Branch (pop ls) rs\npop {elem = (Right p)} (Branch ls rs) = Branch ls (pop rs)\n", "meta": {"hexsha": "ac5534bae1dfb071e50f9617df2da5ea6b221356", "size": 2358, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "HetTree.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": "HetTree.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": "HetTree.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": 33.2112676056, "max_line_length": 156, "alphanum_fraction": 0.5894826124, "num_tokens": 837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206818021529, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6537754883468814}} {"text": "module Ch04.NaturalInduction\n\n-- TODO: Figure out how to implement the function below (if it's at all possible).\n\n--natural_induction_principle : {a,b : Type} -> \n-- (size : a -> Nat) ->\n-- (f : (x : a) -> Either b (x' : a ** LT (size x') (size x))) ->\n-- (g : (a -> b) ** (x : a) -> (case f x of\n-- Left y => (g x = y)\n-- Right (y ** _) => (g x = g y)))\n\nlemma : {x : Nat} ->\n LTE x 0 ->\n (x = 0)\nlemma {x = Z} pf = Refl\nlemma {x = (S k)} pf = absurd (succNotLTEzero pf)\n\npublic export\ninductive_construction : {a,b : Type} ->\n (size : a -> Nat) ->\n (f : (x : a) -> Either b (x' : a ** LT (size x') (size x))) ->\n a -> b\ninductive_construction {a} {b} size f x = helper x (size x) lteRefl where\n helper : (x : a) -> (k : Nat) -> LTE (size x) k -> b\n helper x k bound = case f x of\n Left y => y\n Right (x' ** pf) => case k of\n Z => let temp = replace (lemma bound) pf in\n absurd (succNotLTEzero temp)\n (S j) => helper x' j (fromLteSucc (lteTransitive pf bound))\n", "meta": {"hexsha": "97f621388bc7869085fc790d2065a99743458de4", "size": 1475, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Ch04/NaturalInduction.idr", "max_stars_repo_name": "mr-infty/tapl", "max_stars_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-02-27T13:52:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:38:28.000Z", "max_issues_repo_path": "Ch04/NaturalInduction.idr", "max_issues_repo_name": "mr-infty/tapl", "max_issues_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ch04/NaturalInduction.idr", "max_forks_repo_name": "mr-infty/tapl", "max_forks_repo_head_hexsha": "3934bfe42b93f84c1bf35b7b34cf30b3a7fd7399", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T04:56:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T07:08:45.000Z", "avg_line_length": 47.5806451613, "max_line_length": 111, "alphanum_fraction": 0.36, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.653582376987803}} {"text": "AdderType : (numType : Type) -> (argc : Nat) -> Type\nAdderType numType Z = numType\nAdderType numType (S k) = (next : numType) -> AdderType numType k\n\nadder : Num numType =>\n (argc : Nat) -> (acc : numType) -> AdderType numType argc\nadder Z acc = acc\nadder (S k) acc = \\next => adder k (acc + next)\n", "meta": {"hexsha": "bdbc31c0bdd2b8c9e79f9c0417647a4ff5af9771", "size": 299, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter-06/adder.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-06/adder.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-06/adder.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.2222222222, "max_line_length": 65, "alphanum_fraction": 0.6421404682, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942144788077, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6535823727140446}} {"text": "module Data.Bool\n\n%default total\n\nexport\nnotInvolutive : (x : Bool) -> not (not x) = x\nnotInvolutive True = Refl\nnotInvolutive False = Refl\n\n-- AND\n\nexport\nandSameNeutral : (x : Bool) -> x && x = x\nandSameNeutral False = Refl\nandSameNeutral True = Refl\n\nexport\nandFalseFalse : (x : Bool) -> x && False = False\nandFalseFalse False = Refl\nandFalseFalse True = Refl\n\nexport\nandTrueNeutral : (x : Bool) -> x && True = x\nandTrueNeutral False = Refl\nandTrueNeutral True = Refl\n\nexport\nandAssociative : (x, y, z : Bool) -> x && (y && z) = (x && y) && z\nandAssociative True _ _ = Refl\nandAssociative False _ _ = Refl\n\nexport\nandCommutative : (x, y : Bool) -> x && y = y && x\nandCommutative x True = andTrueNeutral x\nandCommutative x False = andFalseFalse x\n\nexport\nandNotFalse : (x : Bool) -> x && not x = False\nandNotFalse False = Refl\nandNotFalse True = Refl\n\n-- OR\n\nexport\norSameNeutral : (x : Bool) -> x || x = x\norSameNeutral False = Refl\norSameNeutral True = Refl\n\nexport\norFalseNeutral : (x : Bool) -> x || False = x\norFalseNeutral False = Refl\norFalseNeutral True = Refl\n\nexport\norTrueTrue : (x : Bool) -> x || True = True\norTrueTrue False = Refl\norTrueTrue True = Refl\n\nexport\norAssociative : (x, y, z : Bool) -> x || (y || z) = (x || y) || z\norAssociative True _ _ = Refl\norAssociative False _ _ = Refl\n\nexport\norCommutative : (x, y : Bool) -> x || y = y || x\norCommutative x True = orTrueTrue x\norCommutative x False = orFalseNeutral x\n\nexport\norNotTrue : (x : Bool) -> x || not x = True\norNotTrue False = Refl\norNotTrue True = Refl\n\n-- interaction & De Morgan's laws\n\nexport\norSameAndRightNeutral : (x, y : Bool) -> x || (x && y) = x\norSameAndRightNeutral False _ = Refl\norSameAndRightNeutral True _ = Refl\n\nexport\nandDistribOrR : (x, y, z : Bool) -> x && (y || z) = (x && y) || (x && z)\nandDistribOrR False _ _ = Refl\nandDistribOrR True _ _ = Refl\n\nexport\norDistribAndR : (x, y, z : Bool) -> x || (y && z) = (x || y) && (x || z)\norDistribAndR False _ _ = Refl\norDistribAndR True _ _ = Refl\n\nexport\nnotAndIsOr : (x, y : Bool) -> not (x && y) = not x || not y\nnotAndIsOr False _ = Refl\nnotAndIsOr True _ = Refl\n\nexport\nnotOrIsAnd : (x, y : Bool) -> not (x || y) = not x && not y\nnotOrIsAnd False _ = Refl\nnotOrIsAnd True _ = Refl\n\n-- Interaction with typelevel `Not`\n\nexport\nnotTrueIsFalse : {1 x : Bool} -> Not (x = True) -> x = False\nnotTrueIsFalse {x=False} _ = Refl\nnotTrueIsFalse {x=True} f = absurd $ f Refl\n\nexport\nnotFalseIsTrue : {1 x : Bool} -> Not (x = False) -> x = True\nnotFalseIsTrue {x=True} _ = Refl\nnotFalseIsTrue {x=False} f = absurd $ f Refl\n", "meta": {"hexsha": "ed2516026a890742ee5d23ad411b223a6b1ef854", "size": 2576, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/libs/base/Data/Bool.idr", "max_stars_repo_name": "Qqwy/Idris2-Erlang", "max_stars_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "idris2/libs/base/Data/Bool.idr", "max_issues_repo_name": "Qqwy/Idris2-Erlang", "max_issues_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "idris2/libs/base/Data/Bool.idr", "max_forks_repo_name": "Qqwy/Idris2-Erlang", "max_forks_repo_head_hexsha": "945f9c12d315d73bfda2d441bc5f9f20696b5066", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0, "max_line_length": 72, "alphanum_fraction": 0.6529503106, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6533686550419197}} {"text": "module AppendInjective\n\n%access export\n%default total\n\nappendInjectiveRight : (a, b, c : List x) -> a ++ b = a ++ c -> b = c\nappendInjectiveRight [] _ _ = id\nappendInjectiveRight (y::ys) b c = appendInjectiveRight ys b c . snd . consInjective\n\nlemma_bad_nat : (a, b : Nat) -> S a + b = b -> Void\nlemma_bad_nat a Z = rewrite plusZeroRightNeutral a in SIsNotZ\nlemma_bad_nat a (S k) = rewrite sym $ plusSuccRightSucc a k in\n lemma_bad_nat a k . succInjective (S (a + k)) k\n\nlemma_bad_append : (x : a) -> (xs, ys : List a) -> (x::xs) ++ ys = ys -> Void\nlemma_bad_append x xs ys = lemma_bad_nat (length xs) (length ys) . rewrite sym $ lengthAppend xs ys in cong {f=length}\n\nappendInjectiveLeft : (a, b, c : List x) -> a ++ c = b ++ c -> a = b\nappendInjectiveLeft [] [] _ _ = Refl\nappendInjectiveLeft (y::ys) (z::zs) c prf with (consInjective prf)\n | (p1, p2) = rewrite p1 in cong $ appendInjectiveLeft ys zs c p2\nappendInjectiveLeft [] (z::zs) c prf = absurd $ lemma_bad_append z zs c $ sym prf\nappendInjectiveLeft (y::ys) [] c prf = absurd $ lemma_bad_append y ys c prf\n", "meta": {"hexsha": "702a265838522233fe51f79304e1e8f36ca21de0", "size": 1099, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codewars/AppendInjective.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/AppendInjective.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/AppendInjective.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": 45.7916666667, "max_line_length": 118, "alphanum_fraction": 0.652411283, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6533324696316705}} {"text": "module BiNat.Properties.Mult\n\nimport BiNat\nimport BiNat.Properties.Plus\nimport BiNat.Properties.Induction\nimport BiNat.Properties.LT\n\n%access public export\n%default total\n\nmultDashAddsAccMinusJ : (m, n : BiNat) -> (acc : BiNat) ->\n mult' m n acc = pred $ plus (mult' m n J) acc\nmultDashAddsAccMinusJ J ns acc = rewrite plusJIsSucc ns in rewrite predOfSucc ns in Refl\nmultDashAddsAccMinusJ (ms -: O) ns acc = multDashAddsAccMinusJ ms (ns -: O) acc\nmultDashAddsAccMinusJ (ms -: I) ns acc =\n rewrite multDashAddsAccMinusJ ms (ns -: O) (plus' ns acc O []) in\n rewrite multDashAddsAccMinusJ ms (ns -: O) (plus' ns J O []) in\n rewrite plusAssociative (mult' ms (ns -: O) J) ns J in\n rewrite plusJIsSucc (plus' (mult' ms (ns -: O) J) ns O []) in\n rewrite predOfSucc (plus' (mult' ms (ns -: O) J) ns O []) in\n rewrite plusAssociative (mult' ms (ns -: O) J) ns acc in Refl\n\nmultDistributesPlusRight : (l, m, n : BiNat) -> mult l (plus m n) = plus (mult l m) (mult l n)\nmultDistributesPlusRight J m n =\n rewrite plusJIsSucc (plus' m n O []) in\n rewrite predOfSucc (plus' m n O []) in\n rewrite plusJIsSucc m in\n rewrite predOfSucc m in\n rewrite plusJIsSucc n in\n rewrite predOfSucc n in Refl\nmultDistributesPlusRight (ls -: O) m n =\n rewrite sym $ plusDashAppendsAcc m n O [O] in\n multDistributesPlusRight ls (m -: O) (n -: O)\nmultDistributesPlusRight (ls -: I) m n =\n rewrite plusJIsSucc (plus' m n O []) in\n rewrite multDashAddsAccMinusJ ls (plus' m n O [] -: O) (succ (plus' m n O [])) in\n rewrite predCommutesToPlusSnd (mult ls (plus m n -: O)) (succ (plus m n)) (succIsNotJ (plus m n)) in\n rewrite predOfSucc (plus m n) in\n rewrite sym $ plusDashAppendsAcc m n O [O] in\n rewrite plusJIsSucc m in\n rewrite plusJIsSucc n in\n rewrite multDashAddsAccMinusJ ls (m -: O) (succ m) in\n rewrite multDashAddsAccMinusJ ls (n -: O) (succ n) in\n rewrite predCommutesToPlusSnd (mult ls (m -: O)) (succ m) (succIsNotJ m) in\n rewrite predCommutesToPlusSnd (mult ls (n -: O)) (succ n) (succIsNotJ n) in\n rewrite predOfSucc m in\n rewrite predOfSucc n in\n rewrite sym $ plusAssociative (mult ls (m -: O)) m (plus (mult ls (n -: O)) n) in\n rewrite plusSymmetric m (plus (mult ls (n -: O)) n) in\n rewrite sym $ plusAssociative (mult ls (n -: O)) n m in\n rewrite plusSymmetric n m in\n rewrite plusAssociative (mult ls (m -: O)) (mult ls (n -: O)) (plus' m n O []) in\n rewrite multDistributesPlusRight ls (m -: O) (n -: O) in Refl\n\nmultJIsId : (n : BiNat) -> mult n J = n\nmultJIsId J = Refl\nmultJIsId (ns -: O) =\n rewrite multDistributesPlusRight ns J J in\n rewrite multJIsId ns in\n rewrite shiftLeftDoubles ns in Refl\nmultJIsId (ns -: I) =\n rewrite multDashAddsAccMinusJ ns (J -: O) (J -: O) in\n rewrite multDistributesPlusRight ns J J in\n rewrite multJIsId ns in\n rewrite sym $ shiftLeftDoubles ns in\n rewrite plusDashAppendsAcc ns J O [O] in\n rewrite plusJIsSucc ns in\n rewrite predOfDoubled (succ ns) (succIsNotJ ns) in\n rewrite predOfSucc ns in Refl\n\njMultIsId : (n : BiNat) -> mult J n = n\njMultIsId J = Refl\njMultIsId (ns -: O) = Refl\njMultIsId (ns -: I) =\n rewrite succDashAppendsAcc ns [O] in\n rewrite predOfDoubled (succ ns) (succIsNotJ ns) in\n rewrite predOfSucc ns in Refl\n\nmultDistributesPlusLeft : (l, m, n : BiNat) -> mult (plus l m) n = plus (mult l n) (mult m n)\nmultDistributesPlusLeft l m n =\n induction\n (\\k => mult (plus l m) k = plus (mult l k) (mult m k))\n (\\k, pk =>\n rewrite sym $ plusJIsSucc k in\n rewrite multDistributesPlusRight (plus' l m O []) k J in\n rewrite pk in\n rewrite multJIsId (plus' l m O []) in\n rewrite multDistributesPlusRight l k J in\n rewrite multDistributesPlusRight m k J in\n rewrite multJIsId l in\n rewrite multJIsId m in\n rewrite sym $ plusAssociative (mult l k) l (plus (mult m k) m) in\n rewrite plusSymmetric l (plus (mult m k) m) in\n rewrite sym $ plusAssociative (mult m k) m l in\n rewrite plusSymmetric m l in\n sym $ plusAssociative (mult l k) (mult m k) (plus l m)\n )\n (rewrite multJIsId (plus l m) in rewrite multJIsId l in rewrite multJIsId m in Refl)\n n\n\nmultOfSuccLeft : (m, n : BiNat) -> mult (succ m) n = plus n (mult m n)\nmultOfSuccLeft m n =\n rewrite sym $ jPlusIsSucc m in\n rewrite multDistributesPlusLeft J m n in\n rewrite plusJIsSucc n in\n rewrite predOfSucc n in Refl\n\nmultOfSuccRight : (m, n : BiNat) -> mult m (succ n) = plus (mult m n) m\nmultOfSuccRight m n =\n rewrite sym $ plusJIsSucc n in\n rewrite multDistributesPlusRight m n J in\n rewrite multJIsId m in Refl\n\nmultSymmetric : (m, n : BiNat) -> mult m n = mult n m\nmultSymmetric m n =\n induction\n (\\k => mult k n = mult n k)\n (\\k, pk =>\n rewrite sym $ plusJIsSucc k in\n rewrite multDistributesPlusLeft k J n in\n rewrite multDistributesPlusRight n k J in\n rewrite plusJIsSucc n in\n rewrite predOfSucc n in\n rewrite multJIsId n in\n rewrite pk in Refl\n )\n (\n rewrite plusJIsSucc n in\n rewrite predOfSucc n in\n rewrite multJIsId n in Refl\n )\n m\n\nmultAssociative : (l, m, n : BiNat) -> mult l (mult m n) = mult (mult l m) n\nmultAssociative l m n =\n induction\n (\\k => mult k (mult m n) = mult (mult k m) n)\n (\\k, pk =>\n rewrite sym $ plusJIsSucc k in\n rewrite multDistributesPlusLeft k J (mult m n) in\n rewrite jMultIsId (mult m n) in\n rewrite multDistributesPlusLeft k J m in\n rewrite jMultIsId m in\n rewrite multDistributesPlusLeft (mult k m) m n in\n rewrite pk in Refl\n )\n (\n rewrite jMultIsId (mult m n) in\n rewrite jMultIsId m in Refl\n )\n l\n\nappendOIsTwice : (n : BiNat) -> n -: O = mult n (J -: O)\nappendOIsTwice n =\n induction\n (\\k => k -: O = mult k (J -: O))\n (\\k, pk =>\n rewrite sym $ plusJIsSucc k in\n rewrite multDistributesPlusLeft k J (J -: O) in\n rewrite sym pk in\n sym $ plusDashAppendsAcc k J O [O]\n )\n Refl\n n\n\nappendIIsTwicePlusJ : (n : BiNat) -> n -: I = plus (mult n (J -: O)) J\nappendIIsTwicePlusJ n = rewrite sym $ appendOIsTwice n in Refl\n\nmultNKeepsLT : (l, m : BiNat) -> LT l m -> (n : BiNat) -> LT (mult l n) (mult m n)\nmultNKeepsLT l m lt n =\n induction\n (\\k => LT (mult l k) (mult m k))\n (\\k, pk =>\n rewrite sym $ plusJIsSucc k in\n rewrite multDistributesPlusRight l k J in\n rewrite multDistributesPlusRight m k J in\n rewrite multJIsId l in\n rewrite multJIsId m in\n lessThanTransitive\n (plusNKeepsLessThan (mult l k) (mult m k) pk l)\n (\n rewrite plusSymmetric (mult m k) l in\n rewrite plusSymmetric (mult m k) m in\n plusNKeepsLessThan l m lt (mult m k)\n )\n )\n (rewrite multJIsId l in rewrite multJIsId m in lt)\n n\n", "meta": {"hexsha": "66de24fc8a7d493dacc27d9f77d7b0979036c16c", "size": 6738, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "BiNat/Properties/Mult.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/Mult.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/Mult.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": 35.6507936508, "max_line_length": 102, "alphanum_fraction": 0.6539032354, "num_tokens": 2330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6528504575527977}} {"text": "> module Tuple.Properties\n\n> import Control.Isomorphism\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n> |||\n> tuplePairIso3 : {A, B, C : Type} -> Iso (A, B, C) ((A, B), C)\n> tuplePairIso3 {A} {B} {C} = MkIso to from ok1 ok2\n> where to : (A, B, C) -> ((A, B), C)\n> to (x, y, z) = ((x, y), z)\n> from : ((A, B), C) -> (A, B, C)\n> from ((x, y), z) = (x, y, z)\n> ok1 : (x : ((A, B), C)) -> to (from x) = x\n> ok1 ((x, y), z) = Refl\n> ok2 : (x : (A, B, C)) -> from (to x) = x\n> ok2 (x, y, z) = Refl \n\n> |||\n> tuplePairIso4 : {A, B, C, D : Type} -> Iso (A, B, C, D) ((A, B, C), D)\n> tuplePairIso4 {A} {B} {C} {D} = MkIso to from ok1 ok2\n> where to : (A, B, C, D) -> ((A, B, C), D)\n> to (a, b, c, d) = ((a, b, c), d)\n> from : ((A, B, C), D) -> (A, B, C, D)\n> from ((a, b, c), d) = (a, b, c, d)\n> ok1 : (x : ((A, B, C), D)) -> to (from x) = x\n> ok1 ((a, b, c), d) = Refl\n> ok2 : (x : (A, B, C, D)) -> from (to x) = x\n> ok2 (a, b, c, d) = Refl \n", "meta": {"hexsha": "812de724816757a56303690a3fe54671b90e31d2", "size": 1071, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Tuple/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": "Tuple/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": "Tuple/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.46875, "max_line_length": 72, "alphanum_fraction": 0.3865546218, "num_tokens": 486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6527672854734705}} {"text": "module Interpreter\n\nimport Data.Fin\nimport Data.Vect\n\ndata Ty = TyInt | TyBool | TyFun Ty Ty\n\n\ninterpTy : Ty -> Type\ninterpTy TyInt = Integer\ninterpTy TyBool = Bool\ninterpTy (TyFun x y) = interpTy x -> interpTy y\n\nusing (G : Vect n Ty)\n -- See 'De Bruijn index'\n\n -- HasType i G t means variable i in context G has type t\n -- This type acts like a Nat, like an index to variables\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) ->\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 f) = \\x => interp (x :: env) f\n interp env (App f x) = (interp env f) (interp env x)\n interp env (Op f x y) = f (interp env x) (interp env y)\n interp env (If b x y) = if interp env b\n then interp env x\n else interp env y\n", "meta": {"hexsha": "19f7b14c591e2460658a7927b1ea97aacffd70f3", "size": 1547, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris-tutorial/interpreter.idr", "max_stars_repo_name": "shouya/thinking-dumps", "max_stars_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-14T17:18:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:02:15.000Z", "max_issues_repo_path": "idris-tutorial/interpreter.idr", "max_issues_repo_name": "shouya/thinking-dumps", "max_issues_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-06-14T06:07:33.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-04T22:05:11.000Z", "max_forks_repo_path": "idris-tutorial/interpreter.idr", "max_forks_repo_name": "shouya/thinking-dumps", "max_forks_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-12-02T02:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-03T06:32:26.000Z", "avg_line_length": 31.5714285714, "max_line_length": 73, "alphanum_fraction": 0.5623787977, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6524489916548664}} {"text": "> module Fraction.NormalizeProperties\n\n> import Syntax.PreorderReasoning\n\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.Normalize\n> import Fraction.Predicates\n> import Fraction.Normal\n> import Fraction.BasicProperties\n> import Fraction.EqProperties\n> import Fraction.LTEProperties\n> import PNat.PNat\n> import PNat.Operations\n> import PNat.Properties\n> import Nat.Positive\n> import Basic.Operations\n> import Nat.LTEProperties\n> import Nat.LTProperties\n> import Nat.OperationsProperties\n> import Nat.GCD\n> import Nat.GCDOperations\n> import Nat.GCDProperties\n> import Nat.Divisor\n> import Nat.DivisorOperations\n> import Nat.DivisorProperties\n> import Nat.Coprime\n> import Nat.CoprimeProperties\n> import Nat.GCDAlgorithm\n> import Nat.GCDEuclid\n> import Pairs.Operations\n> import Sigma.Sigma\n\n> %default total\n> %access public export\n> -- %access export\n\n\nBasic properties of |normalize|:\n\n> ||| \n> normalNormalize : (x : Fraction) -> Normal (normalize x)\n> normalNormalize (m, n') =\n> let n : Nat\n> = toNat n' in \n> let zLTn : (Z `LT` n)\n> = toNatLTLemma n' in\n> let d : Nat\n> = gcdAlg m n in\n> let dGCDmn : (GCD d m n)\n> = gcdAlgLemma m n in\n> let dDm : (d `Divisor` m)\n> = gcdDivisorFst dGCDmn in\n> let dDn : (d `Divisor` n)\n> = gcdDivisorSnd dGCDmn in\n> let zLTd : (Z `LT` d)\n> = gcdPreservesPositivity2 zLTn (MkSigma d dGCDmn) in\n> MkNormal (gcdCoprimeLemma d m n dDm dDn zLTd dGCDmn)\n> %freeze normalNormalize\n\n\n> ||| Normalization of normal fraction is identity\n> normalizePreservesNormal : (x : Fraction) -> Normal x -> normalize x = x \n> normalizePreservesNormal (m, n') (MkNormal (MkCoprime prf)) =\n> let n : Nat\n> = toNat n' in \n> let d : Nat\n> = gcdAlg m n in\n> let dGCDmn : (GCD d m n)\n> = gcdAlgLemma m n in \n> let dDm : (d `Divisor` m)\n> = gcdDivisorFst dGCDmn in\n> let dDn : (d `Divisor` n)\n> = gcdDivisorSnd dGCDmn in\n> let o : Nat\n> = quotient m d dDm in\n> let p : Nat\n> = quotient n d dDn in\n> let zLTn : (Z `LT` n)\n> = toNatLTLemma n' in \n> let zLTp : (Z `LT` p) \n> = quotientPreservesPositivity n d dDn zLTn in\n> let dEQ1 : (d = S Z)\n> = prf in\n> \n> ( normalize (m, n') )\n> ={ Refl }=\n> ( (o, fromNat p zLTp) )\n> ={ cong2 (quotientAnyOneAny m d dDm dEQ1) (toNatEqLemma (quotientAnyOneAny n d dDn dEQ1)) }=\n> ( (m, n') )\n> QED\n> %freeze normalizePreservesNormal\n\n\n> ||| normalize is idempotent\n> normalizeIdempotent : (x : Fraction) -> normalize (normalize x) = normalize x\n> normalizeIdempotent x = \n> ( normalize (normalize x) )\n> ={ normalizePreservesNormal (normalize x) (normalNormalize x) }=\n> ( normalize x )\n> QED\n> %freeze normalizeIdempotent\n\n\n> |||\n> normalizeUpscaleLemma : (x : Fraction) -> (e : PNat) -> normalize (upscale x e) = normalize x\n> normalizeUpscaleLemma (m, d') e' =\n> let d : Nat\n> = toNat d' in \n> let g : Nat\n> = gcdAlg m d in\n> let gmd : (GCD g m d)\n> = gcdAlgLemma m d in \n> let gDm : (g `Divisor` m)\n> = gcdDivisorFst gmd in\n> let gDd : (g `Divisor` d)\n> = gcdDivisorSnd gmd in\n> let qmg : Nat\n> = quotient m g gDm in\n> let qdg : Nat\n> = quotient d g gDd in\n> let zLTd : (Z `LT` d)\n> = toNatLTLemma d' in \n> let zLTg : (Z `LT` g)\n> = gcdPreservesPositivity2 zLTd (MkSigma g gmd) in \n> let zLTqdg : (Z `LT` qdg) \n> = quotientPreservesPositivity d g gDd zLTd in\n> let e : Nat\n> = toNat e' in\n> let zLTe : (Z `LT` e)\n> = toNatLTLemma e' in \n> let ed : Nat\n> = toNat (e' * d') in\n> let h : Nat\n> = gcdAlg (e * m) ed in\n> let hemed : (GCD h (e * m) ed)\n> = gcdAlgLemma (e * m) ed in \n> let hDem : (h `Divisor` (e * m))\n> = gcdDivisorFst hemed in\n> let hDed : (h `Divisor` ed)\n> = gcdDivisorSnd hemed in\n> let qemh : Nat\n> = quotient (e * m) h hDem in\n> let qedh : Nat\n> = quotient ed h hDed in\n> let zLTed : (Z `LT` ed)\n> = toNatLTLemma (e' * d') in \n> let zLTqedh : (Z `LT` qedh) \n> = quotientPreservesPositivity ed h hDed zLTed in\n\n> let edEQed : (toNat (e' * d') = e * d)\n> = toNatMultLemma in\n> let hemed' : (GCD h (e * m) (e * d))\n> = replace {P = \\ ZUZU => GCD h (e * m) ZUZU} edEQed hemed in\n> let hEQeg : (h = e * g)\n> = gcdScaleInvariant g m d h e gmd hemed' in\n> let egemed : (GCD (e * g) (e * m) (e * d))\n> = replace {P = \\ ZUZU => GCD ZUZU (e * m) (e * d)} hEQeg hemed' in \n> let egDem : ((e * g) `Divisor` (e * m))\n> = gcdDivisorFst egemed in\n> let egDed : ((e * g) `Divisor` (e * d))\n> = gcdDivisorSnd egemed in\n> let qemeg : Nat\n> = quotient (e * m) (e * g) egDem in\n> let qedeg : Nat\n> = quotient (e * d) (e * g) egDed in\n> let zLTed' : (Z `LT` (e * d))\n> = multZeroLTZeroLT e d zLTe zLTd in\n> let zLTqedeg : (Z `LT` qedeg) \n> = quotientPreservesPositivity (e * d) (e * g) egDed zLTed' in\n> let nhEQZ : (Not (h = Z))\n> = gtZisnotZ (gcdPreservesPositivity2 zLTed (MkSigma h hemed)) in \n> let negEQZ : (Not (e * g = Z))\n> = gtZisnotZ (multZeroLTZeroLT e g zLTe zLTg) in\n> let qemhEQqemeg : (qemh = qemeg)\n> = quotientEqLemma (e * m) h hDem (e * m) (e * g) egDem Refl hEQeg nhEQZ in\n> let qedhEQqedeg : (qedh = qedeg)\n> = quotientEqLemma ed h hDed (e * d) (e * g) egDed edEQed hEQeg nhEQZ in\n> let qemegEQqmg : (qemeg = qmg)\n> = sym (quotientScaleInvariant m g e negEQZ gDm egDem) in\n> let qedegEQqdg : (qedeg = qdg)\n> = sym (quotientScaleInvariant d g e negEQZ gDd egDed) in\n> let qedh' : PNat\n> = fromNat qedh zLTqedh in\n> let qedeg' : PNat\n> = fromNat qedeg zLTqedeg in\n> let qedh'EQqedeg' : (qedh' = qedeg')\n> = toNatEqLemma {x = fromNat qedh zLTqedh} {y = fromNat qedeg zLTqedeg} qedhEQqedeg in\n> let qdg' : PNat\n> = fromNat qdg zLTqdg in\n> let qedeg'EQqdg' : (qedeg' = qdg')\n> = toNatEqLemma {x = fromNat qedeg zLTqedeg} {y = fromNat qdg zLTqdg} qedegEQqdg in\n> \n> ( normalize (upscale (m, d') e') )\n> ={ Refl }=\n> ( normalize (m * e, d' * e') )\n> ={ cong {f = \\ ZUZU => normalize (ZUZU, d' * e')} (multCommutative m e) }=\n> ( normalize (e * m, d' * e') )\n> ={ cong {f = \\ ZUZU => normalize (e * m, ZUZU)} (multCommutative d' e') }=\n> ( normalize (e * m, e' * d') )\n> ={ Refl }=\n> ( (qemh, qedh') )\n> ={ cong {f = \\ ZUZU => (ZUZU, qedh')} qemhEQqemeg }=\n> ( (qemeg, qedh') )\n> ={ cong {f = \\ ZUZU => (qemeg, ZUZU)} qedh'EQqedeg' }=\n> ( (qemeg, qedeg') )\n> ={ cong {f = \\ ZUZU => (ZUZU, qedeg')} qemegEQqmg }=\n> ( (qmg, qedeg') )\n> ={ cong {f = \\ ZUZU => (qmg, ZUZU)} qedeg'EQqdg' }=\n> ( (qmg, qdg') )\n> ={ Refl }=\n> ( normalize (m, d') )\n> QED\n> %freeze normalizeUpscaleLemma\n\n\nProperties of |normalize|, |Eq|:\n\n> |||\n> normalizeEqLemma1 : (x : Fraction) -> (normalize x) `Eq` x\n> normalizeEqLemma1 (m, n') =\n> let n : Nat\n> = toNat n' in \n> let d : Nat\n> = gcdAlg m n in\n> let v : (GCD d m n)\n> = gcdAlgLemma m n in \n> let dDm : (d `Divisor` m)\n> = gcdDivisorFst v in\n> let dDn : (d `Divisor` n)\n> = gcdDivisorSnd v in\n> \n> flipQuotientLemma m n d dDm dDn\n> %freeze normalizeEqLemma1\n\n\n> |||\n> normalizeEqLemma2 : (x : Fraction) -> (y : Fraction) -> \n> x `Eq` y -> normalize x = normalize y\n> normalizeEqLemma2 (m1, n1') (m2, n2') m1n2EQm2n1 = \n> let n1 = toNat n1' in\n> let n2 = toNat n2' in\n> \n> ( normalize (m1, n1') )\n> ={ sym (normalizeUpscaleLemma (m1, n1') n2') }=\n> ( normalize (m1 * n2, n1' * n2') )\n> ={ cong {f = \\ ZUZU => normalize (ZUZU, n1' * n2')} m1n2EQm2n1 }=\n> ( normalize (m2 * n1, n1' * n2') )\n> ={ cong {f = \\ ZUZU => normalize (m2 * n1, ZUZU)} (multCommutative n1' n2') }=\n> ( normalize (m2 * n1, n2' * n1') )\n> ={ normalizeUpscaleLemma (m2, n2') n1' }=\n> ( normalize (m2, n2') )\n> QED\n> %freeze normalizeEqLemma2\n\n\nFurther properties of |normalize|:\n\n> |||\n> normalizePlusElimLeft : (x : Fraction) -> (y : Fraction) -> \n> normalize (normalize x + y) = normalize (x + y)\n> normalizePlusElimLeft x y = \n> let nxEqx = normalizeEqLemma1 x in\n> let nxyEqxy = plusPreservesEq (normalize x) x y y nxEqx EqReflexive in\n> normalizeEqLemma2 (normalize x + y) (x + y) nxyEqxy\n> %freeze normalizePlusElimLeft\n\n\n> |||\n> normalizePlusElimRight : (x : Fraction) -> (y : Fraction) -> \n> normalize (x + normalize y) = normalize (x + y)\n> normalizePlusElimRight x y = \n> let nyEqy = normalizeEqLemma1 y in\n> let xnyEqxy = plusPreservesEq x x (normalize y) y EqReflexive nyEqy in\n> normalizeEqLemma2 (x + normalize y) (x + y) xnyEqxy\n> %freeze normalizePlusElimRight\n\n\n> |||\n> normalizePlusElim : (x : Fraction) -> (y : Fraction) -> \n> normalize (normalize x + normalize y) = normalize (x + y)\n> normalizePlusElim x y = \n> let nxEqx = normalizeEqLemma1 x in\n> let nyEqy = normalizeEqLemma1 y in\n> let nxnyEqxy = plusPreservesEq (normalize x) x (normalize y) y nxEqx nyEqy in\n> normalizeEqLemma2 (normalize x + normalize y) (x + y) nxnyEqxy\n> %freeze normalizePlusElim\n\n\n> |||\n> normalizeMultElimLeft : (x : Fraction) -> (y : Fraction) -> \n> normalize ((normalize x) * y) = normalize (x * y)\n> normalizeMultElimLeft x y = \n> let nxEqx = normalizeEqLemma1 x in\n> let nxyEqxy = multPreservesEq (normalize x) x y y nxEqx EqReflexive in\n> normalizeEqLemma2 ((normalize x) * y) (x * y) nxyEqxy\n> %freeze normalizeMultElimLeft\n\n\n> |||\n> normalizeMultElimRight : (x : Fraction) -> (y : Fraction) -> \n> normalize (x * (normalize y)) = normalize (x * y)\n> normalizeMultElimRight x y = \n> let nyEqy = normalizeEqLemma1 y in\n> let xnyEqxy = multPreservesEq x x (normalize y) y EqReflexive nyEqy in\n> normalizeEqLemma2 (x * (normalize y)) (x * y) xnyEqxy\n> %freeze normalizeMultElimRight\n\n\n> |||\n> normalizeMultElim : (x : Fraction) -> (y : Fraction) -> \n> normalize ((normalize x) * (normalize y)) = normalize (x * y)\n> normalizeMultElim x y = \n> let nxEqx = normalizeEqLemma1 x in\n> let nyEqy = normalizeEqLemma1 y in\n> let nxnyEqxy = multPreservesEq (normalize x) x (normalize y) y nxEqx nyEqy in\n> normalizeEqLemma2 ((normalize x) * (normalize y)) (x * y) nxnyEqxy\n> %freeze normalizeMultElim\n\n\n> |||\n> normalizeLTELemma : (x : Fraction) -> (y : Fraction) -> \n> x `LTE` y -> normalize x `LTE` normalize y\n> normalizeLTELemma (nx, dx') (ny, dy') xLTEy = s11 where\n> \n> dx : Nat\n> dx = toNat dx'\n> zLTdx : Z `LT` dx\n> zLTdx = toNatLTLemma dx'\n> \n> dy : Nat\n> dy = toNat dy'\n> zLTdy : Z `LT` dy\n> zLTdy = toNatLTLemma dy'\n> \n> gx : Nat\n> gx = gcdAlg nx dx\n> pgx : GCD gx nx dx\n> pgx = gcdAlgLemma nx dx\n> gxDnx : gx `Divisor` nx\n> gxDnx = gcdDivisorFst pgx\n> gxDdx : gx `Divisor` dx\n> gxDdx = gcdDivisorSnd pgx\n> zLTgx : Z `LT` gx\n> zLTgx = gcdPreservesPositivity2 zLTdx (MkSigma gx pgx)\n> \n> gy : Nat\n> gy = gcdAlg ny dy\n> pgy : GCD gy ny dy\n> pgy = gcdAlgLemma ny dy\n> gyDny : gy `Divisor` ny\n> gyDny = gcdDivisorFst pgy\n> gyDdy : gy `Divisor` dy\n> gyDdy = gcdDivisorSnd pgy\n> zLTgy : Z `LT` gy\n> zLTgy = gcdPreservesPositivity2 zLTdy (MkSigma gy pgy)\n> \n> nnx : Nat\n> nnx = quotient nx gx gxDnx\n> dnx : Nat\n> dnx = quotient dx gx gxDdx\n> zLTdnx : Z `LT` dnx\n> zLTdnx = quotientPreservesPositivity dx gx gxDdx zLTdx\n> dnx' : PNat\n> dnx' = fromNat dnx zLTdnx\n> \n> nny : Nat\n> nny = quotient ny gy gyDny\n> dny : Nat\n> dny = quotient dy gy gyDdy\n> zLTdny : Z `LT` dny\n> zLTdny = quotientPreservesPositivity dy gy gyDdy zLTdy\n> dny' : PNat\n> dny' = fromNat dny zLTdny\n> \n> nxdy : Nat\n> nxdy = nx * dy\n> nydx : Nat\n> nydx = ny * dx\n> gxgy : Nat\n> gxgy = gx * gy\n> gygx : Nat\n> gygx = gy * gx\n> gxgyDnxdy : gxgy `Divisor` nxdy\n> gxgyDnxdy = divisorMultLemma1 nx gx gxDnx dy gy gyDdy\n> gygxDnydx : gygx `Divisor` nydx \n> gygxDnydx = divisorMultLemma1 ny gy gyDny dx gx gxDdx\n> ngxgyZ : Not (gxgy = Z)\n> ngxgyZ = multNotZeroNotZero gx gy (gtZisnotZ zLTgx) (gtZisnotZ zLTgy)\n\n> s01 : LTE nxdy nydx\n> s01 = xLTEy\n> s02 : LTE ((quotient nxdy gxgy gxgyDnxdy) * gxgy) nydx\n> s02 = replace {P = \\ ZUZ => LTE ZUZ nydx} \n> (sym (quotientLemma' nxdy gxgy gxgyDnxdy)) s01\n> s03 : LTE ((quotient nxdy gxgy gxgyDnxdy) * gxgy) ((quotient nydx gygx gygxDnydx) * gygx)\n> s03 = replace {P = \\ ZUZ => LTE ((quotient nxdy gxgy gxgyDnxdy) * gxgy) ZUZ} \n> (sym (quotientLemma' nydx gygx gygxDnydx)) s02\n> s04 : LTE (quotient nxdy gxgy gxgyDnxdy) (quotient nydx gygx gygxDnydx)\n> s04 = elimRightMultLTE s03 (multCommutative gx gy) ngxgyZ\n> s05 : LTE ((quotient nx gx gxDnx) * (quotient dy gy gyDdy)) (quotient nydx gygx gygxDnydx) \n> s05 = replace {P = \\ ZUZ => LTE ZUZ (quotient nydx gygx gygxDnydx)} \n> (sym (quotientMultLemma nx gx gxDnx dy gy gyDdy)) s04\n> s06 : LTE ((quotient nx gx gxDnx) * (quotient dy gy gyDdy)) ((quotient ny gy gyDny) * (quotient dx gx gxDdx))\n> s06 = replace {P = \\ ZUZ => LTE ((quotient nx gx gxDnx) * (quotient dy gy gyDdy)) ZUZ} \n> (sym (quotientMultLemma ny gy gyDny dx gx gxDdx)) s05\n> s07 : LTE (nnx * dny) (nny * dnx)\n> s07 = s06\n> s08 : LTE (nnx * (toNat dny')) (nny * dnx)\n> s08 = replace {P = \\ ZUZ => LTE (nnx * ZUZ) (nny * dnx)} (sym (toNatfromNatLemma dny zLTdny)) s07\n> s09 : LTE (nnx * (toNat dny')) (nny * (toNat dnx'))\n> s09 = replace {P = \\ ZUZ => LTE (nnx * (toNat dny')) (nny * ZUZ)} (sym (toNatfromNatLemma dnx zLTdnx)) s08\n> s10 : (nnx, dnx') `LTE` (nny, dny')\n> s10 = s09\n> s11 : normalize (nx, dx') `LTE` normalize (ny, dy')\n> s11 = s10\n> %freeze normalizeLTELemma\n\n\n> {-\n\n> ---}\n\n", "meta": {"hexsha": "3292d92d046132212837a61dbb48bed9b17086ce", "size": 15386, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fraction/NormalizeProperties.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/NormalizeProperties.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/NormalizeProperties.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.2877358491, "max_line_length": 119, "alphanum_fraction": 0.5314571689, "num_tokens": 5631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6521831081161912}} {"text": "module Ordinals\n\ndata Ord : Type where\n Zero : Ord\n Suc : (x : Ord) -> Ord\n Lim : (f : Nat -> Ord) -> Ord\n\n(+) : Ord -> Ord -> Ord\n(+) Zero m = m\n(+) (Suc n) m = Suc $ n + m\n(+) (Lim f) m = Lim (\\x => f x + m)\n\n(*) : Ord -> Ord -> Ord\n(*) Zero m = Zero\n(*) (Suc n) m = n + m\n(*) (Lim f) m = Lim (\\x => f x * m)\n\nexp : Ord -> Ord -> Ord\nexp Zero m = Suc Zero\nexp (Suc n) m = n * m\nexp (Lim f) m = Lim (\\x => exp (f x) m)\n\n\nomega : Ord\nomega = Lim rec\n where\n rec : Nat -> Ord\n rec Z = Zero\n rec (S n) = Suc $ rec n\n\nepsilonNought : Ord\nepsilonNought = Lim rec\n where\n rec : Nat -> Ord\n rec Z = omega\n rec (S n) = exp omega (rec n)\n", "meta": {"hexsha": "049332b2f84b9af848866b653db201a2e143b89a", "size": 655, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Ordinals.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/Ordinals.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/Ordinals.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": 17.7027027027, "max_line_length": 39, "alphanum_fraction": 0.4839694656, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552528, "lm_q2_score": 0.6825737214979745, "lm_q1q2_score": 0.6520757327279034}} {"text": "import Data.List.Views\nimport Data.List.Views.Extra\nimport Data.Nat.Views\n\n||| Returns maximum equal suffix of two input lists\n-- idris2 cannot check inside pairs so totality check fails\n-- equalSuffix : Eq a => List a -> List a -> List a\n-- equalSuffix input1 input2 with (snocList input1, snocList input2)\n-- equalSuffix (xs ++ [x]) (ys ++ [y]) | ((Snoc x xs xsrec), (Snoc y ys ysrec)) \n-- = if x == y then equalSuffix xs ys ++ [x] else []\n-- equalSuffix _ _ | (Empty, _) = []\n-- equalSuffix _ _ | (_, Empty) = []\n\n||| Returns maximum equal suffix of two input lists\nequalSuffix : Eq a => List a -> List a -> List a\nequalSuffix input1 input2 with (snocList input1)\n equalSuffix [] _ | Empty = []\n equalSuffix (xs ++ [x]) input2 | (Snoc x xs rec) with (snocList input2)\n equalSuffix (xs ++ [x]) [] | (Snoc x xs rec) | Empty = []\n equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc x xs rec) | (Snoc y ys z) \n = if x == y then equalSuffix xs ys ++ [x] else []\n\n-- with recursion, but bug\n-- equalSuffix : Eq a => List a -> List a -> List a\n-- equalSuffix input1 input2 with (snocList input1)\n-- equalSuffix [] _ | Empty = []\n-- equalSuffix (xs ++ [x]) input2 | (Snoc x xs recxs) with (snocList input2)\n-- equalSuffix (xs ++ [x]) [] | (Snoc x xs recxs) | Empty = []\n-- equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc x xs recxs) | (Snoc y ys recys)\n-- = if x == y then (equalSuffix xs ys | recxs | recys) ++ [x] else []\n\n||| Turns Nat into binary string (slow)\ntoBinary : Nat -> String\ntoBinary n with (halfRec n)\n toBinary 0 | HalfRecZ = \"\"\n toBinary (k + k) | (HalfRecEven k rec) = (toBinary k | rec) ++ \"0\"\n toBinary (S (k + k)) | (HalfRecOdd k rec) = (toBinary k | rec) ++ \"1\"\n\n||| Returns True if a List is traversed the same forwards and backwards\npalindrome : Eq a => List a -> Bool\npalindrome input with (vList input)\n palindrome [] | VNil = True\n palindrome [x] | VOne = True\n palindrome (x :: (xs ++ [y])) | (VCons rec) = \n if x == y then (palindrome xs | rec) else False\n\n", "meta": {"hexsha": "e75eba6949bbbc40cda63a23135e6a1e8cf09c8c", "size": 2025, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/ch10/ex_10_2.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/ch10/ex_10_2.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/ch10/ex_10_2.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": 43.085106383, "max_line_length": 82, "alphanum_fraction": 0.6074074074, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.652064152577334}} {"text": "module Toolkit.Data.List.Filter\n\nimport Toolkit.Data.DList\nimport Toolkit.Data.List.Interleaving\n\n%default total\n\npublic export\ndata Filter : (holdsFor : type -> Type)\n -> (input : List type)\n -> Type\n where\n MkFilter : {thrown : List type}\n -> (kept : List type)\n -> (prfOrdering : Interleaving kept thrown input)\n -> (prfKept : DList type holdsFor kept)\n -> (prfThrown : DList type (Not . holdsFor) thrown)\n -> Filter holdsFor input\n\nexport\nfilter : (test : (value : type) -> Dec (holds value))\n -> (input : List type)\n -> Filter holds input\nfilter test [] = MkFilter [] Empty [] []\nfilter test (x :: xs) with (filter test xs)\n filter test (x :: xs) | (MkFilter kept prfOrdering prfKept prfThrown) with (test x)\n filter test (x :: xs) | (MkFilter kept prfOrdering prfKept prfThrown) | (Yes prf)\n = MkFilter (x::kept) (Left x prfOrdering) (prf :: prfKept) prfThrown\n filter test (x :: xs) | (MkFilter kept prfOrdering prfKept prfThrown) | (No contra)\n = MkFilter kept (Right x prfOrdering) prfKept (contra :: prfThrown)\n\nexport\nextract : Filter p xs\n -> (ks ** DList type p ks)\nextract (MkFilter kept prfOrdering prfKept prfThrown)\n = (kept ** prfKept)\n\n\n-- [ EOF ]\n", "meta": {"hexsha": "658325eb43b5f6e89c864176f61246d04055f006", "size": 1289, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/Toolkit/Data/List/Filter.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": 9, "max_stars_repo_stars_event_min_datetime": "2020-11-03T11:33:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:11:38.000Z", "max_issues_repo_path": "src/Toolkit/Data/List/Filter.idr", "max_issues_repo_name": "gallais/linear-circuits", "max_issues_repo_head_hexsha": "5d13d955eafc2d92beae363e96d3cec8695830f2", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Toolkit/Data/List/Filter.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": 32.225, "max_line_length": 87, "alphanum_fraction": 0.6214119472, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6520217829356925}} {"text": "-- a mini prelude\n\nmodule Stuff\n\npublic export\ndata Bool = True | False\n\npublic export\nnot : Bool -> Bool\nnot True = False\nnot False = True\n\npublic export\ndata Maybe : Type -> Type where\n Nothing : Maybe a\n Just : (1 x : a) -> Maybe a\n\npublic export\ndata Either : Type -> Type -> Type where\n Left : (1 x : a) -> Either a b\n Right : (1 y : b) -> Either a b\n\npublic export\nintToBool : Int -> Bool\nintToBool 0 = False\nintToBool x = True\n\npublic export\nifThenElse : Bool -> Lazy a -> Lazy a -> a\nifThenElse True t e = t\nifThenElse False t e = e\n\npublic export\ndata Nat : Type where\n Z : Nat\n S : (1 _ : Nat) -> Nat\n\npublic export\nfromInteger : Integer -> Nat\nfromInteger x = ifThenElse (intToBool (prim__eq_Integer x 0))\n Z (S (fromInteger (prim__sub_Integer x 1)))\n\npublic export\nplus : Nat -> Nat -> Nat\nplus Z y = y\nplus (S k) y = S (plus k y)\n\ninfixr 5 ::\n\npublic export\ndata List : Type -> Type where\n Nil : List a\n (::) : (1 _ : a) -> (1 _ : List a) -> List a\n\npublic export\ndata Eq : a -> b -> Type where\n Refl : (x : a) -> Eq x x\n\npublic export\ndata Unit = MkUnit\n\npublic export\ndata Pair : Type -> Type -> Type where\n MkPair : {a, b : Type} -> a -> b -> Pair a b\n\npublic export\nthe : (a : Type) -> a -> a\nthe _ x = x\n", "meta": {"hexsha": "abb61fa56a77fcd3ffd7fc2fc4bf198bace2622e", "size": 1283, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "tests/idris2/linear004/Stuff.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/linear004/Stuff.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/linear004/Stuff.idr", "max_forks_repo_name": "ska80/idris-jvm", "max_forks_repo_head_hexsha": "66223d026d034578876b325e9fcd95874faa6052", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-09-15T15:19:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T13:05:48.000Z", "avg_line_length": 18.5942028986, "max_line_length": 65, "alphanum_fraction": 0.6017147311, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6519485291288176}} {"text": "> module SequentialDecisionProblems.TabBackwardsInduction2\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> %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\n-- \n\nIf equality on values of type |State t| is decidable\n\n> decidableEqState : (t : Nat) -> DecEq (State t)\n\nwe can store the result of looking up the index of a reachable and\nviable state in |vectReachableAndViableState t n| into a table\n\n> iat : {t, n : Nat} -> \n> Not (Z = cardReachableAndViableState t n) ->\n> Vect (cardState t) (Fin (cardReachableAndViableState t n)) \n> iat {t} {n} prf = toVect iatf where\n> iatf : (Fin (cardState t) -> Fin (cardReachableAndViableState t n))\n> iatf k with (lookup' (decidableEqState t) \n> (from (iso (finiteState t)) k) \n> (map outl (vectReachableAndViableState t n)))\n> | Nothing with (cardReachableAndViableState t n) proof contra\n> | Z = void (prf Refl)\n> | S m = FZ {k = m} \n> | Just k' = k'\n\nThe table can then be used to replace lookups (like in |tabSval|, see\nbelow) with |index| operations. The idea is that indexing can in\nprinciple (Blodwin feature?) be done in constant time whereas lookups\n(searcing) takes liner time.\n\n--\n\nIn this case, we can implement a \"tabulated\" versions of |backwardsInduction| \n\n< backwardsInduction : (t : Nat) -> (n : Nat) -> PolicySeq t n\n< backwardsInduction t Z = Nil\n< backwardsInduction t (S n) = let ps = backwardsInduction (S t) n in\n< optExt ps :: ps\n\nThe idea is to replace policies as functions from states to control with\npolicy tables. In analogy to policies as defined in the CoreTheory, the\ntype of a policy table that supports zero decision steps is just the\nsingleton type. A policy table that supports |S m| further decision\nsteps at decision step |t| is a vector with as many entries as there are\nstates in |State t| that are reachable and viable |S m| steps:\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\nSimilarly, sequences of policy tables are either empty or made up of a\npolicy table consed with a tail sequence:\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\nWith these notions in place, a tabulated version of backwards induction\nwill be a function of type\n\n< (t : Nat) -> (n : Nat) -> PolicyTableSeq t n\n\nIn order to implement this function, some additional notions are needed. ...\n\n> ||| \n> ValueTable : Nat -> Nat -> Type\n> ValueTable t n = Vect (cardReachableAndViableState t n) Val\n\n> |||\n> zeroVec : (n : Nat) -> Vect n Val\n> zeroVec Z = Nil\n> zeroVec (S n) = zero :: zeroVec n\n\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\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> Vect (cardState (S t)) (Fin (cardReachableAndViableState (S t) n)) ->\n> PossibleNextState x (ctrl gy) -> Val\n> tabSval' {t} {n} x r v gy vt iat (MkSigma x' x'emx') =\n> let y : Ctrl t x\n> = ctrl gy in\n> let k : Fin (cardReachableAndViableState (S t) n)\n> = index (to (iso (finiteState (S t))) x') iat in\n> reward t x y x' `plus` index k vt\n\n\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\n\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> Vect (cardState (S t)) (Fin (cardReachableAndViableState (S t) n)) ->\n> GoodCtrl t x n -> Val\n> tabCval' {t} x r v vt iat gy = let y : Ctrl t x\n> = ctrl gy in\n> let mx' : M (State (S t))\n> = nexts t x y in\n> let tmp : Vect (cardState (S t)) (Fin (cardReachableAndViableState (S t) n))\n> = iat in\n> meas (fmap (tabSval' x r v gy vt iat) (tagElem mx'))\n> -}\n\n> |||\n> tabCvalargmaxMax : {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, Val)\n\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 : Nat} -> (vt : ValueTable (S t) n) -> PolicyTable t (S n)\n> tabOptExt {t} {n} vt =\n> let ptf : ((k : Fin (cardReachableAndViableState t (S n))) -> \n> (Sigma (State t) (\\ x => (ReachableAndViable {t = t} (S n) x, GoodCtrl t x n))))\n> = \\ k => let xrvk : Sigma (State t) (ReachableAndViable {t = t} (S n))\n> = index k (vectReachableAndViableState t (S n)) in\n> let x : State t\n> = outl xrvk in\n> let rv : ReachableAndViable {t = t} (S n) x\n> = outr xrvk in\n> let gy : GoodCtrl t x n\n> = tabCvalargmax {t = t} {n = n} x (fst rv) (snd rv) vt in\n> MkSigma x (rv, gy) in\n> let pt : PolicyTable t (S n)\n> = toVect ptf in\n> pt\n\n> |||\n> tabOptExt' : {t, n : Nat} -> \n> (vt : ValueTable (S t) n) -> \n> (PolicyTable t (S n), ValueTable t (S n))\n> tabOptExt' {t} {n} vt =\n> let pt : PolicyTable t (S n)\n> = tabOptExt vt in\n> -- let tmp = iat {t = S t} {n = n} (believe_me 42) in\n> let vtf' : ((k : Fin (cardReachableAndViableState t (S n))) -> Val)\n> = \\ k => let ptk : Sigma (State t) (\\ x => (ReachableAndViable {t = t} (S n) x, GoodCtrl t x n))\n> = index k pt in\n> let x : State t\n> = outl ptk in\n> let rv : ReachableAndViable {t = t} (S n) x\n> = fst (outr ptk) in\n> let gy : GoodCtrl t x n\n> = snd (outr ptk) in\n> tabCval x (fst rv) (snd rv) vt gy in\n> -- tabCval' x (fst rv) (snd rv) vt tmp in\n> let vt' : ValueTable t (S n)\n> = toVect vtf' in\n> (pt, vt') \n\n... finally\n\n> |||\n> tabBackwardsInduction' : (t : Nat) -> (n : Nat) -> (PolicyTableSeq t n, ValueTable t n)\n> tabBackwardsInduction' t Z = (Nil, zeroVec (cardReachableAndViableState t Z))\n> tabBackwardsInduction' t (S n) = let (pts, vt) = tabBackwardsInduction' (S t) n in\n> let (pt, vt') = tabOptExt' vt in\n> (pt :: pts, vt')\n\n> |||\n> tabBackwardsInduction : (t : Nat) -> (n : Nat) -> PolicyTableSeq t n\n> tabBackwardsInduction t Z = Nil\n> tabBackwardsInduction t (S n) = let (pts, vt) = tabBackwardsInduction' (S t) n in\n> let pt = tabOptExt vt in\n> pt :: pts\n \n\n> {-\n\n> ---}\n", "meta": {"hexsha": "31c6ee90ae351b854572f90f7191f3140c80eff8", "size": 11653, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/TabBackwardsInduction3.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/TabBackwardsInduction3.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/TabBackwardsInduction3.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.5016949153, "max_line_length": 111, "alphanum_fraction": 0.5373723505, "num_tokens": 3703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6516712378829491}} {"text": "= Logic : Logic in Idris\n\n> module Logic\n\n> import Basics\n> import Induction\n> import Tactics\n\n> %hide Basics.Numbers.pred\n> %hide Basics.Playground2.plus\n\n> %access public export\n> %default total\n\nIn previous chapters, we have seen many examples of factual claims\n(_propositions_) and ways of presenting evidence of their truth (_proofs_). In\nparticular, we have worked extensively with equality propositions of the form\n\\idr{e1 = e2}, with implications (\\idr{p -> q}), and with quantified\npropositions (\\idr{x -> P(x)}). In this chapter, we will see how Idris can be\nused to carry out other familiar forms of logical reasoning.\n\nBefore diving into details, let's talk a bit about the status of mathematical\nstatements in Idris. Recall that Idris is a _typed_ language, which means that\nevery sensible expression in its world has an associated type. Logical claims\nare no exception: any statement we might try to prove in Idris has a type,\nnamely \\idr{Type}, the type of _propositions_. We can see this with the \\idr{:t}\ncommand:\n\n```idris\nλΠ> :t 3 = 3\n3 = 3 : Type\n```\n\n```idris\nλΠ> :t (n, m : Nat) -> n + m = m + n\n(n : Nat) -> (m : Nat) -> n + m = m + n : Type\n```\n\nNote that _all_ syntactically well-formed propositions have type \\idr{Type} in\nIdris, regardless of whether they are true or not.\n\nSimply being a proposition is one thing; being provable is something else!\n\n```idris\nλΠ> :t (n : Nat) -> n = 2\n(n : Nat) -> n = 2 : Type\n```\n\n```idris\nλΠ> :t 3 = 4\n3 = 4 : Type\n```\n\nIndeed, propositions don't just have types: they are _first-class objects_ that\ncan be manipulated in the same ways as the other entities in Idris's world. So\nfar, we've seen one primary place that propositions can appear: in functions'\ntype signatures.\n\n> plus_2_2_is_4 : 2 + 2 = 4\n> plus_2_2_is_4 = Refl\n\nBut propositions can be used in many other ways. For example, we can give a name\nto a proposition as a value on its own, just as we have given names to\nexpressions of other sorts (you'll soon see why we start the name with a capital\nletter).\n\n> Plus_fact : Type\n> Plus_fact = 2+2=4\n\n```idris\nλΠ> :t Plus_fact\nPlus_fact : Type\n```\n\nWe can later use this name in any situation where a proposition is expected --\nfor example, in a function declaration.\n\n> plus_fact_is_true : Plus_fact\n> plus_fact_is_true = Refl\n\n(Here's the reason - recall that names starting with lowercase letters are\nconsidered implicits in Idris, so \\idr{plus_fact} would be considered a free\nvariable!)\n\nWe can also write _parameterized_ propositions -- that is, functions that take\narguments of some type and return a proposition. For instance, the following\nfunction takes a number and returns a proposition asserting that this number is\nequal to three:\n\n> is_three : Nat -> Type\n> is_three n = n=3\n\n```idris\nλΠ> :t is_three\nis_three : Nat -> Type\n```\n\nIn Idris, functions that return propositions are said to define _properties_ of\ntheir arguments.\n\nFor instance, here's a (polymorphic) property defining the familiar notion of an\n_injective function_.\n\n> Injective : (f : a -> b) -> Type\n> Injective {a} {b} f = (x, y : a) -> f x = f y -> x = y\n\n> succ_inj : Injective S\n> succ_inj x x Refl = Refl\n\nThe equality operator \\idr{=} is also a function that returns a \\idr{Type}.\n\nThe expression \\idr{n = m} is syntactic sugar for \\idr{(=) n m}, defined\ninternally in Idris. Because \\idr{=} can be used with elements of any type, it\nis also polymorphic:\n\n```idris\nλΠ> :t (=)\n(=) : A -> B -> Type\n```\n\n\n== Logical Connectives\n\n=== Conjunction\n\nThe _conjunction_ (or _logical and_) of propositions \\idr{a} and \\idr{b} in\nIdris is the same as the pair of \\idr{a} and \\idr{b}, written \\idr{(a, b)},\nrepresenting the claim that both \\idr{a} and \\idr{b} are true.\n\n> and_example : (3 + 4 = 7, 2 * 2 = 4)\n\nTo prove a conjunction, we can use value-level pair syntax:\n\n> and_example = (Refl, Refl)\n\nFor any propositions \\idr{a} and \\idr{b}, if we assume that \\idr{a} is true and\nwe assume that \\idr{b} is true, we can trivially conclude that \\idr{(a,b)} is\nalso true.\n\n> and_intro : a -> b -> (a, b)\n> and_intro = MkPair\n\n\n==== Exercise: 2 stars (and_exercise)\n\n> and_exercise : (n, m : Nat) -> n + m = 0 -> (n = 0, m = 0)\n> and_exercise n m prf = ?and_exercise_rhs\n\n$\\square$\n\nSo much for proving conjunctive statements. To go in the other direction --\ni.e., to _use_ a conjunctive hypothesis to help prove something else -- we\nemploy pattern matching.\n\n\nIf the proof context contains a hypothesis \\idr{h} of the form \\idr{(a,b)}, case\nsplitting will replace it with a pair pattern \\idr{(a,b)}.\n\n> and_example2 : (n, m : Nat) -> (n = 0, m = 0) -> n + m = 0\n> and_example2 Z Z (Refl,Refl) = Refl\n> and_example2 (S _) _ (Refl,_) impossible\n> and_example2 _ (S _) (_,Refl) impossible\n\nYou may wonder why we bothered packing the two hypotheses \\idr{n = 0} and \\idr{m\n= 0} into a single conjunction, since we could have also stated the theorem with\ntwo separate premises:\n\n> and_example2' : (n, m : Nat) -> n = 0 -> m = 0 -> n + m = 0\n> and_example2' Z Z Refl Refl = Refl\n> and_example2' (S _) _ Refl _ impossible\n> and_example2' _ (S _) _ Refl impossible\n\nFor this theorem, both formulations are fine. But it's important to understand\nhow to work with conjunctive hypotheses because conjunctions often arise from\nintermediate steps in proofs, especially in bigger developments. Here's a simple\nexample:\n\n> and_example3 : (n, m : Nat) -> n + m = 0 -> n * m = 0\n> and_example3 n m prf =\n> let (nz, _) = and_exercise n m prf in\n> rewrite nz in Refl\n\n\\todo[inline]{Remove lemma and exercise, use \\idr{fst} and \\idr{snd} directly?}\n\nAnother common situation with conjunctions is that we know \\idr{(a,b)} but in\nsome context we need just \\idr{a} (or just \\idr{b}). The following lemmas are\nuseful in such cases:\n\n> proj1 : (p, q) -> p\n> proj1 = fst\n\n\n==== Exercise: 1 star, optional (proj2)\n\n> proj2 : (p, q) -> q\n> proj2 x = ?proj2_rhs\n\n$\\square$\n\nFinally, we sometimes need to rearrange the order of conjunctions and/or the\ngrouping of multi-way conjunctions. The following commutativity and\nassociativity theorems are handy in such cases.\n\n> and_commut : (p, q) -> (q, p)\n> and_commut (p, q) = (q, p)\n\n\n==== Exercise: 2 stars (and_assoc)\n\n\\todo[inline]{Remove or demote to 1 star?}\n\n> and_assoc : (p, (q, r)) -> ((p, q), r)\n> and_assoc x = ?and_assoc_rhs\n\n$\\square$\n\n\n=== Disjunction\n\n\\todo[inline]{Hide \\idr{Basics.Booleans} analogues and make syntax synonyms\n\\idr{(/\\)} and \\idr{(\\/)} for \\idr{(,)} and \\idr{Either}?}\n\nAnother important connective is the _disjunction_, or _logical or_ of two\npropositions: \\idr{a `Either` b} is true when either \\idr{a} or \\idr{b} is. The\nfirst case has be tagged with \\idr{Left}, and the second with \\idr{Right}.\n\nTo use a disjunctive hypothesis in a proof, we proceed by case analysis, which,\nas for \\idr{Nat} or other data types, can be done with pattern matching. Here is\nan example:\n\n> or_example : (n, m : Nat) -> ((n = 0) `Either` (m = 0)) -> n * m = 0\n> or_example Z _ (Left Refl) = Refl\n> or_example (S _) _ (Left Refl) impossible\n> or_example n Z (Right Refl) = multZeroRightZero n\n> or_example _ (S _) (Right Refl) impossible\n\nConversely, to show that a disjunction holds, we need to show that one of its\nsides does. This can be done via aforementioned \\idr{Left} and \\idr{Right}\nconstructors. Here is a trivial use...\n\n> or_intro : a -> a `Either` b\n> or_intro = Left\n\n... and a slightly more interesting example requiring both \\idr{Left} and\n\\idr{Right}:\n\n> zero_or_succ : (n : Nat) -> ((n = 0) `Either` (n = S (pred n)))\n> zero_or_succ Z = Left Refl\n> zero_or_succ (S _) = Right Refl\n\n\n==== Exercise: 1 star (mult_eq_0)\n\n> mult_eq_0 : n * m = 0 -> ((n = 0) `Either` (m = 0))\n> mult_eq_0 prf = ?mult_eq_0_rhs\n\n$\\square$\n\n\n==== Exercise: 1 star (or_commut)\n\n> or_commut : (p `Either` q) -> (q `Either` p)\n> or_commut x = ?or_commut_rhs\n\n$\\square$\n\n\n=== Falsehood and Negation\n\nSo far, we have mostly been concerned with proving that certain things are\n_true_ -- addition is commutative, appending lists is associative, etc. Of\ncourse, we may also be interested in _negative_ results, showing that certain\npropositions are _not_ true. In Idris, such negative statements are expressed\nwith the negation typelevel function \\idr{Not}.\n\n\\todo[inline]{Add hyperlink}\n\nTo see how negation works, recall the discussion of the _principle of explosion_\nfrom the previous chapter; it asserts that, if we assume a contradiction, then\nany other proposition can be derived. Following this intuition, we could define\n\\idr{Not p} as \\idr{q -> (p -> q)}. Idris actually makes a slightly different\nchoice, defining \\idr{Not p} as \\idr{p -> Void}, where \\idr{Void} is a\n_particular_ contradictory proposition defined in the standard library as a\ndata type with no constructors.\n\n```idris\ndata Void : Type where\n\nNot : Type -> Type\nNot a = a -> Void\n```\n\n\\todo[inline]{Discuss difference between \\idr{void} and \\idr{absurd}}\n\nSince \\idr{Void} is a contradictory proposition, the principle of explosion also\napplies to it. If we get \\idr{Void} into the proof context, we can call\n\\idr{void} or \\idr{absurd} on it to complete any goal:\n\n> ex_falso_quodlibet : Void -> p\n> ex_falso_quodlibet = void\n\nThe Latin _ex falso quodlibet_ means, literally, \"from falsehood follows\nwhatever you like\"; this is another common name for the principle of explosion.\n\n\n==== Exercise: 2 stars, optional (not_implies_our_not)\n\nShow that Idris's definition of negation implies the intuitive one mentioned\nabove:\n\n> not_implies_our_not : Not p -> (q -> (p -> q))\n> not_implies_our_not notp q p = ?not_implies_our_not_rhs\n\n$\\square$\n\nThis is how we use \\idr{Not} to state that \\idr{0} and \\idr{1} are different\nelements of \\idr{Nat}:\n\n\\todo[inline]{Explain \\idr{Refl}-lambda syntax and \\idr{Uninhabited}, keep in\nmind https://github.com/idris-lang/Idris-dev/issues/3943}\n\n> zero_not_one : Not (Z = S _)\n> zero_not_one = \\Refl impossible\n\nWe could also rely on the \\idr{Uninhabited} instance in stdlib and write this as\n\n```idris\nzero_not_one = uninhabited\n```\n\nIt takes a little practice to get used to working with negation in Idris. Even\nthough you can see perfectly well why a statement involving negation is true, it\ncan be a little tricky at first to get things into the right configuration so\nthat Idris can understand it! Here are proofs of a few familiar facts to get you\nwarmed up.\n\n> not_False : Not Void\n> not_False = absurd\n\n> contradiction_implies_anything : (p, Not p) -> q\n> contradiction_implies_anything (p, notp) = absurd $ notp p\n\n> double_neg : p -> Not $ Not p\n> double_neg p notp = notp p\n\n\n==== Exercise: 2 stars, advanced, recommended (double_neg_inf)\n\nWrite an informal proof of \\idr{double_neg}:\n\n_Theorem_: \\idr{p} implies \\idr{Not $ Not p}, for any proposition \\idr{p}.\n\n> -- FILL IN HERE\n\n$\\square$\n\n\n==== Exercise: 2 stars, recommended (contrapositive)\n\n> contrapositive : (p -> q) -> (Not q -> Not p)\n> contrapositive pq = ?contrapositive_rhs\n\n$\\square$\n\n\n==== Exercise: 1 star (not_both_true_and_false)\n\n> not_both_true_and_false : Not (p, Not p)\n> not_both_true_and_false = ?not_both_true_and_false_rhs\n\n$\\square$\n\n\n==== Exercise: 1 star, advanced (informal_not_PNP)\n\nWrite an informal proof (in English) of the proposition \\idr{Not (p, Not p)}.\n\n> -- FILL IN HERE\n\n$\\square$\n\nSimilarly, since inequality involves a negation, it requires a little practice\nto be able to work with it fluently. Here is one useful trick. If you are trying\nto prove a goal that is nonsensical (e.g., the goal state is \\idr{False =\nTrue}), apply \\idr{absurd} to change the goal to \\idr{Void}. This makes it\neasier to use assumptions of the form \\idr{Not p} that may be available in the\ncontext -- in particular, assumptions of the form \\idr{Not (x=y)}.\n\n> not_true_is_false : (b : Bool) -> Not (b = True) -> b = False\n> not_true_is_false False h = Refl\n> not_true_is_false True h = absurd $ h Refl\n\n\n=== Truth\n\nBesides \\idr{Void}, Idris's standard library also defines \\idr{Unit}, a proposition that is\ntrivially true. To prove it, we use the predefined constant \\idr{()}:\n\n> True_is_true : Unit\n> True_is_true = ()\n\nUnlike \\idr{Void}, which is used extensively, \\idr{Unit} is used quite rarely in\nproofs, since it is trivial (and therefore uninteresting) to prove as a goal,\nand it carries no useful information as a hypothesis. But it can be quite useful\nwhen defining complex proofs using conditionals or as a parameter to\nhigher-order proofs. We will see examples of such uses of \\idr{Unit} later on.\n\n\n=== Logical Equivalence\n\nThe handy \"if and only if\" connective, which asserts that two propositions have\nthe same truth value, is just the conjunction of two implications.\n\n> namespace MyIff\n\n> iff : {p,q : Type} -> Type\n> iff {p} {q} = (p -> q, q -> p)\n\nIdris's stdlib has a more general form of this, \\idr{Iso}, in\n\\idr{Control.Isomorphism}.\n\n> syntax [p] \"<->\" [q] = iff {p} {q}\n\n> iff_sym : (p <-> q) -> (q <-> p)\n> iff_sym (pq, qp) = (qp, pq)\n\n\n> not_true_iff_false : (Not (b = True)) <-> (b = False)\n> not_true_iff_false {b} = (not_true_is_false b, not_true_and_false b)\n> where\n> not_true_and_false : (b : Bool) -> (b = False) -> Not (b = True)\n> not_true_and_false False _ Refl impossible\n> not_true_and_false True Refl _ impossible\n\n\n==== Exercise: 1 star, optional (iff_properties)\n\nUsing the above proof that \\idr{<->} is symmetric (\\idr{iff_sym}) as a guide,\nprove that it is also reflexive and transitive.\n\n> iff_refl : p <-> p\n> iff_refl = ?iff_refl_rhs\n\n> iff_trans : (p <-> q) -> (q <-> r) -> (p <-> r)\n> iff_trans piq qir = ?iff_trans_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars (or_distributes_over_and)\n\n> or_distributes_over_and : (p `Either` (q,r)) <-> (p `Either` q, p `Either` r)\n> or_distributes_over_and = ?or_distributes_over_and_rhs\n\n$\\square$\n\n\\todo[inline]{Edit the rest of the section. What to do with Setoids? We could\nprobably just use profunctors here}\n\nSome of Idris's tactics treat iff statements specially, avoiding the need for\nsome low-level proof-state manipulation. In particular, rewrite and reflexivity\ncan be used with iff statements, not just equalities. To enable this behavior,\nwe need to import a special Idris library that allows rewriting with other\nformulas besides equality (setoids).\n\nHere is a simple example demonstrating how these tactics work with iff. First,\nlet's prove a couple of basic iff equivalences...\n\n> mult_0 : (n * m = Z) <-> ((n = Z) `Either` (m = Z))\n> mult_0 {n} {m} = (to n m, or_example n m)\n> where\n> to : (n, m : Nat) -> (n * m = Z) -> (n = 0) `Either` (m = 0)\n> to Z _ Refl = Left Refl\n> to (S _) Z _ = Right Refl\n> to (S _) (S _) Refl impossible\n\n> or_assoc : (p `Either` (q `Either` r)) <-> ((p `Either` q) `Either` r)\n> or_assoc = (to, fro)\n> where\n> to : Either p (Either q r) -> Either (Either p q) r\n> to (Left p) = Left $ Left p\n> to (Right (Left q)) = Left $ Right q\n> to (Right (Right r)) = Right r\n> fro : Either (Either p q) r -> Either p (Either q r)\n> fro (Left (Left p)) = Left p\n> fro (Left (Right q)) = Right $ Left q\n> fro (Right r) = Right $ Right r\n\nWe can now use these facts with \\idr{rewrite} and \\idr{Refl} to give smooth\nproofs of statements involving equivalences. Here is a ternary version of the\nprevious \\idr{mult_0} result:\n\n> mult_0_3 : (n * m * p = Z) <->\n> ((n = Z) `Either` ((m = Z) `Either` (p = Z)))\n> mult_0_3 = (to, fro)\n> where\n> to : (n * m * p = Z) -> ((n = Z) `Either` ((m = Z) `Either` (p = Z)))\n> to {n} {m} {p} prf = let\n> (nm_p_to, _) = mult_0 {n=(n*m)} {m=p}\n> (n_m_to, _) = mult_0 {n} {m}\n> (_, or_a_fro) = or_assoc {p=(n=Z)} {q=(m=Z)} {r=(p=Z)}\n> in or_a_fro $ case nm_p_to prf of\n> Left prf => Left $ n_m_to prf\n> Right prf => Right prf\n> fro : ((n = Z) `Either` ((m = Z) `Either` (p = Z))) -> (n * m * p = Z)\n> fro (Left Refl) = Refl\n> fro {n} (Right (Left Refl)) = rewrite multZeroRightZero n in Refl\n> fro {n} {m} (Right (Right Refl)) = rewrite multZeroRightZero (n*m) in Refl\n\nThe apply tactic can also be used with \\idr{<->}. When given an equivalence as\nits argument, apply tries to guess which side of the equivalence to use.\n\n> apply_iff_example : (n, m : Nat) -> n * m = Z -> ((n = Z) `Either` (m = Z))\n> apply_iff_example n m = fst $ mult_0 {n} {m}\n\n\n=== Existential Quantification\n\nAnother important logical connective is existential quantification. To say that\nthere is some \\idr{x} of type \\idr{t} such that some property \\idr{p} holds of\n\\idr{x}, we write \\idr{(x : t ** p)}. The type annotation \\idr{: t} can be\nomitted if Idris is able to infer from the context what the type of \\idr{x}\nshould be.\n\nTo prove a statement of the form \\idr{(x ** p)}, we must show that \\idr{p} holds\nfor some specific choice of value for \\idr{x}, known as the _witness_ of the\nexistential. This is done in two steps: First, we explicitly tell Idris which\nwitness \\idr{t} we have in mind by writing it on the left side of \\idr{**}. Then\nwe prove that \\idr{p} holds after all occurrences of \\idr{x} are replaced by\n\\idr{t}.\n\n> four_is_even : (n : Nat ** 4 = n + n)\n> four_is_even = (2 ** Refl)\n\nConversely, if we have an existential hypothesis \\idr{(x ** p)} in the context,\nwe can pattern match on it to obtain a witness \\idr{x} and a hypothesis stating\nthat \\idr{p} holds of \\idr{x}.\n\n> exists_example_2 : (m : Nat ** n = 4 + m) -> (o : Nat ** n = 2 + o)\n> exists_example_2 (m ** pf) = (2 + m ** pf)\n\n\n==== Exercise: 1 star (dist_not_exists)\n\nProve that \"\\idr{p} holds for all \\idr{x}\" implies \"there is no \\idr{x} for\nwhich \\idr{p} does not hold.\"\n\n> dist_not_exists : {p : a -> Type} -> ((x : a) -> p x) -> Not (x ** Not $ p x)\n> dist_not_exists f = ?dist_not_exists_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars (dist_exists_or)\n\nProve that existential quantification distributes over disjunction.\n\n> dist_exists_or : {p, q : a -> Type} -> (x ** (p x `Either` q x)) <->\n> ((x ** p x) `Either` (x ** q x))\n> dist_exists_or = ?dist_exists_or_rhs\n\n$\\square$\n\n== Programming with Propositions\n\nThe logical connectives that we have seen provide a rich vocabulary for defining\ncomplex propositions from simpler ones. To illustrate, let's look at how to\nexpress the claim that an element \\idr{x} occurs in a list \\idr{l}. Notice that\nthis property has a simple recursive structure:\n\n - If \\idr{l} is the empty list, then \\idr{x} cannot occur on it, so the\n property \"\\idr{x} appears in \\idr{l}\" is simply false.\n\n - Otherwise, \\idr{l} has the form \\idr{x' :: xs}. In this case, \\idr{x} occurs\n in \\idr{l} if either it is equal to \\idr{x'} or it occurs in \\idr{xs}.\n\nWe can translate this directly into a straightforward recursive function from\ntaking an element and a list and returning a proposition:\n\n> In : (x : a) -> (l : List a) -> Type\n> In x [] = Void\n> In x (x' :: xs) = (x' = x) `Either` In x xs\n\nWhen \\idr{In} is applied to a concrete list, it expands into a concrete sequence\nof nested disjunctions.\n\n> In_example_1 : In 4 [1, 2, 3, 4, 5]\n> In_example_1 = Right $ Right $ Right $ Left Refl\n\n> In_example_2 : In n [2, 4] -> (n' : Nat ** n = 2 * n')\n> In_example_2 (Left Refl) = (1 ** Refl)\n> In_example_2 (Right $ Left Refl) = (2 ** Refl)\n> In_example_2 (Right $ Right prf) = absurd prf\n\n(Notice the use of \\idr{absurd} to discharge the last case.)\n\nWe can also prove more generic, higher-level lemmas about \\idr{In}.\n\nNote, in the next, how \\idr{In} starts out applied to a variable and only gets\nexpanded when we do case analysis on this variable:\n\n> In_map : (f : a -> b) -> (l : List a) -> (x : a) -> In x l ->\n> In (f x) (map f l)\n> In_map _ [] _ ixl = absurd ixl\n> In_map f (x' :: xs) x (Left prf) = rewrite prf in Left Refl\n> In_map f (x' :: xs) x (Right r) = Right $ In_map f xs x r\n\nThis way of defining propositions recursively, though convenient in some cases,\nalso has some drawbacks. In particular, it is subject to Idris's usual\nrestrictions regarding the definition of recursive functions, e.g., the\nrequirement that they be \"obviously terminating.\" In the next chapter, we will\nsee how to define propositions _inductively_, a different technique with its own\nset of strengths and limitations.\n\n\n==== Exercise: 2 stars (In_map_iff)\n\n> In_map_iff : (f : a -> b) -> (l : List a) -> (y : b) ->\n> (In y (map f l)) <-> (x ** (f x = y, In x l))\n> In_map_iff f l y = ?In_map_iff_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars (in_app_iff)\n\n> in_app_iff : (In a (l++l')) <-> (In a l `Either` In a l')\n> in_app_iff = ?in_app_iff_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars (All)\n\nRecall that functions returning propositions can be seen as _properties_ of\ntheir arguments. For instance, if \\idr{p} has type \\idr{Nat -> Type}, then\n\\idr{p n} states that property \\idr{p} holds of \\idr{n}.\n\nDrawing inspiration from \\idr{In}, write a recursive function \\idr{All} stating\nthat some property \\idr{p} holds of all elements of a list \\idr{l}. To make sure\nyour definition is correct, prove the \\idr{All_In} lemma below. (Of course, your\ndefinition should _not_ just restate the left-hand side of \\idr{All_In}.)\n\n> All : (p : t -> Type) -> (l : List t) -> Type\n> All p l = ?All_rhs\n\n> All_In : ((x:t) -> In x l -> p x) <-> (All p l)\n> All_In = ?All_In_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars (combine_odd_even)\n\nComplete the definition of the \\idr{combine_odd_even} function below. It takes\nas arguments two properties of numbers, \\idr{podd} and \\idr{peven}, and it\nshould return a property \\idr{p} such that \\idr{p n} is equivalent to \\idr{podd\nn} when \\idr{n} is odd and equivalent to \\idr{peven n} otherwise.\n\n> combine_odd_even : (podd, peven : Nat -> Type) -> (Nat -> Type)\n> combine_odd_even podd peven = ?combine_odd_even_rhs\n\nTo test your definition, prove the following facts:\n\n> combine_odd_even_intro : (n : Nat) ->\n> (oddb n = True -> podd n) ->\n> (oddb n = False -> peven n) ->\n> combine_odd_even podd peven n\n> combine_odd_even_intro n oddp evenp = ?combine_odd_even_intro_rhs\n\n> combine_odd_even_elim_odd : (n : Nat) ->\n> combine_odd_even podd peven n ->\n> oddb n = True ->\n> podd n\n> combine_odd_even_elim_odd n x prf = ?combine_odd_even_elim_odd_rhs\n\n> combine_odd_even_elim_even : (n : Nat) ->\n> combine_odd_even podd peven n ->\n> oddb n = False ->\n> peven n\n> combine_odd_even_elim_even n x prf = ?combine_odd_even_elim_even_rhs\n\n$\\square$\n\n\n== Applying Theorems to Arguments\n\nOne feature of Idris that distinguishes it from many other proof assistants is\nthat it treats _proofs_ as first-class objects.\n\n\\todo[inline]{`nameref` the chapters when they're done}\n\nThere is a great deal to be said about this, but it is not necessary to\nunderstand it in detail in order to use Idris. This section gives just a taste,\nwhile a deeper exploration can be found in the optional chapters\n`ProofObjects` and `IndPrinciples`.\n\nWe have seen that we can use the \\idr{:t} command to ask Idris to print the type\nof an expression. We can also use \\idr{:t} to ask what theorem a particular\nidentifier refers to.\n\n```idris\nλΠ> :t plusCommutative\nplusCommutative : (left : Nat) -> (right : Nat) -> left + right = right + left\n```\n\nIdris prints the _statement_ of the \\idr{plusCommutative} theorem in the same\nway that it prints the _type_ of any term that we ask it to check. Why?\n\nThe reason is that the identifier \\idr{plusCommutative} actually refers to a\n_proof object_ -- a data structure that represents a logical derivation\nestablishing of the truth of the statement \\idr{(n, m : Nat) -> n + m = m + n}.\nThe type of this object _is_ the statement of the theorem that it is a proof of.\n\nIntuitively, this makes sense because the statement of a theorem tells us what\nwe can use that theorem for, just as the type of a computational object tells us\nwhat we can do with that object -- e.g., if we have a term of type \\idr{Nat ->\nNat -> Nat}, we can give it two \\idr{Nat}s as arguments and get a \\idr{Nat}\nback. Similarly, if we have an object of type \\idr{n = m -> n + n = m + m} and\nwe provide it an \"argument\" of type \\idr{n = m}, we can derive \\idr{n + n = m +\nm}.\n\nOperationally, this analogy goes even further: by applying a theorem, as if it\nwere a function, to hypotheses with matching types, we can specialize its result\nwithout having to resort to intermediate assertions. For example, suppose we\nwanted to prove the following result:\n\n> plus_comm3 : (n, m, p : Nat) -> n + (m + p) = (p + m) + n\n\n\\todo[inline]{Edit, we have already done this in previous chapters (add a\nhyperlink?)}\n\nIt appears at first sight that we ought to be able to prove this by rewriting\nwith \\idr{plusCommutative} twice to make the two sides match. The problem,\nhowever, is that the second \\idr{rewrite} will undo the effect of the first.\n\n```coq\nProof.\n intros n m p.\n rewrite plus_comm.\n rewrite plus_comm.\n (* We are back where we started... *)\nAbort.\n```\n\nOne simple way of fixing this problem, using only tools that we already know, is\nto use assert to derive a specialized version of plus_comm that can be used to\nrewrite exactly where we want.\n\n```coq\nLemma plus_comm3_take2 :\n ∀n m p, n + (m + p) = (p + m) + n.\nProof.\n intros n m p.\n rewrite plus_comm.\n assert (H : m + p = p + m).\n { rewrite plus_comm. reflexivity. }\n rewrite H.\n reflexivity.\nQed.\n```\n\nA more elegant alternative is to apply \\idr{plusCommutative} directly to the\narguments we want to instantiate it with, in much the same way as we apply a\npolymorphic function to a type argument.\n\n> plus_comm3 n m p = rewrite plusCommutative n (m+p) in\n> rewrite plusCommutative m p in Refl\n\nYou can \"use theorems as functions\" in this way with almost all tactics that\ntake a theorem name as an argument. Note also that theorem application uses the\nsame inference mechanisms as function application; thus, it is possible, for\nexample, to supply wildcards as arguments to be inferred, or to declare some\nhypotheses to a theorem as implicit by default. These features are illustrated\nin the proof below.\n\n> lemma_application_ex : (n : Nat) -> (ns : List Nat) ->\n> In n (map (\\m => m * 0) ns) -> n = 0\n> lemma_application_ex _ [] prf = absurd prf\n> lemma_application_ex _ (y :: _) (Left prf) =\n> rewrite sym $ multZeroRightZero y in sym prf\n> lemma_application_ex n (_ :: xs) (Right prf) =\n> lemma_application_ex n xs prf\n\nWe will see many more examples of the idioms from this section in later chapters.\n\n\n== Idris vs. Set Theory\n\n\\todo[inline]{Edit, Idris's core is likely some variant of MLTT}\n\nCoq's logical core, the Calculus of Inductive Constructions, differs in some\nimportant ways from other formal systems that are used by mathematicians for\nwriting down precise and rigorous proofs. For example, in the most popular\nfoundation for mainstream paper-and-pencil mathematics, Zermelo-Fraenkel Set\nTheory (ZFC), a mathematical object can potentially be a member of many\ndifferent sets; a term in Idris's logic, on the other hand, is a member of at\nmost one type. This difference often leads to slightly different ways of\ncapturing informal mathematical concepts, but these are, by and large, quite\nNatural and easy to work with. For example, instead of saying that a natural\nnumber \\idr{n} belongs to the set of even numbers, we would say in Idris that\n\\idr{ev n} holds, where \\idr{ev : Nat -> Type} is a property describing even\nnumbers.\n\nHowever, there are some cases where translating standard mathematical reasoning\ninto Idris can be either cumbersome or sometimes even impossible, unless we\nenrich the core logic with additional axioms. We conclude this chapter with a\nbrief discussion of some of the most significant differences between the two\nworlds.\n\n\n=== Functional Extensionality\n\nThe equality assertions that we have seen so far mostly have concerned elements\nof inductive types (\\idr{Nat}, \\idr{Bool}, etc.). But since Idris's equality\noperator is polymorphic, these are not the only possibilities -- in particular,\nwe can write propositions claiming that two _functions_ are equal to each other:\n\n> function_equality_ex1 : plus 3 = plus (pred 4)\n> function_equality_ex1 = Refl\n\nIn common mathematical practice, two functions `f` and `g` are considered equal\nif they produce the same outputs:\n\n\\[\n \\left(\\forall x, f(x) = g(x)\\right) \\to f = g\n\\]\n\nThis is known as the principle of _functional extensionality_.\n\nInformally speaking, an \"extensional property\" is one that pertains to an\nobject's observable behavior. Thus, functional extensionality simply means that\na function's identity is completely determined by what we can observe from it --\ni.e., in Idris terms, the results we obtain after applying it.\n\nFunctional extensionality is not part of Idris's basic axioms. This means that\nsome \"reasonable\" propositions are not provable.\n\n```idris\nfunction_equality_ex2 : (\\x => plus x 1) = (\\x => plus 1 x)\nfunction_equality_ex2 = ?stuck\n```\n\n\\todo[inline]{Explain \\idr{believe_me} vs \\idr{really_believe_me}?}\n\nHowever, we can add functional extensionality to Idris's core logic using the\n\\idr{really_believe_me} command.\n\n> functional_extensionality : ((x : a) -> f x = g x) -> f = g\n> functional_extensionality = really_believe_me\n\nUsing \\idr{really_believe_me} has the same effect as stating a theorem and\nskipping its proof using a hole, but it alerts the reader (and type checker)\nthat this isn't just something we're going to come back and fill in later!\n\nWe can now invoke functional extensionality in proofs:\n\n> function_equality_ex2 : (\\x => plus x 1) = (\\x => plus 1 x)\n> function_equality_ex2 = functional_extensionality $ \\x => plusCommutative x 1\n\nNaturally, we must be careful when adding new axioms into Idris's logic, as they\nmay render it _inconsistent_ -- that is, they may make it possible to prove\nevery proposition, including \\idr{Void}!\n\nUnfortunately, there is no simple way of telling whether an axiom is safe to\nadd: hard work is generally required to establish the consistency of any\nparticular combination of axioms.\n\nHowever, it is known that adding functional extensionality, in particular, _is_\nconsistent.\n\n\\todo[inline]{Is there such a command in Idris?}\n\nTo check whether a particular proof relies on any additional axioms, use the\n`Print Assumptions` command.\n\n```coq\nPrint Assumptions function_equality_ex2.\n(* ===>\n Axioms:\n functional_extensionality :\n forall (X Y : Type) (f g : X -> Y),\n (forall x : X, f x = g x) -> f = g *)\n```\n\n\n==== Exercise: 4 stars (tr_rev)\n\nOne problem with the definition of the list-reversing function \\idr{rev} that we\nhave is that it performs a call to \\idr{++} on each step; running \\idr{++} takes\ntime asymptotically linear in the size of the list, which means that \\idr{rev}\nhas quadratic running time.\n\nWe can improve this with the following definition:\n\n> rev_append : (l1, l2 : List x) -> List x\n> rev_append [] l2 = l2\n> rev_append (x :: xs) l2 = rev_append xs (x :: l2)\n\n> tr_rev : (l : List x) -> List x\n> tr_rev l = rev_append l []\n\n(This is very similar to how \\idr{reverse} is defined in \\idr{Prelude.List}.)\n\nThis version is said to be _tail-recursive_, because the recursive call to the\nfunction is the last operation that needs to be performed (i.e., we don't have\nto execute \\idr{++} after the recursive call); a decent compiler will generate\nvery efficient code in this case. Prove that the two definitions are indeed\nequivalent.\n\n> tr_rev_correct : (x : List a) -> tr_rev x = rev x\n> tr_rev_correct = ?tr_rev_correct_rhs\n\n$\\square$\n\n\n=== Propositions and Booleans\n\nWe've seen two different ways of encoding logical facts in Idris: with\n_booleans_ (of type \\idr{Bool}), and with _propositions_ (of type \\idr{Type}).\n\nFor instance, to claim that a number \\idr{n} is even, we can say either\n\n - (1) that \\idr{evenb n} returns \\idr{True}, or\n\n - (2) that there exists some \\idr{k} such that \\idr{n = double k}. Indeed,\n these two notions of evenness are equivalent, as can easily be shown with a\n couple of auxiliary lemmas.\n\nWe often say that the boolean \\idr{evenb n} _reflects_ the proposition \\idr{(k\n** n = double k)}.\n\n> evenb_double : evenb (double k) = True\n> evenb_double {k = Z} = Refl\n> evenb_double {k = (S k')} = evenb_double {k=k'}\n\n\n==== Exercise: 3 stars (evenb_double_conv)\n\n> evenb_double_conv : (k ** n = if evenb n then double k else S (double k))\n\n*Hint*: Use the \\idr{evenb_S} lemma from \\idr{Induction}.\n\n> evenb_double_conv = ?evenb_double_conv_rhs\n\n$\\square$\n\n> even_bool_prop : (evenb n = True) <-> (k ** n = double k)\n> even_bool_prop = (to, fro)\n> where\n> to : evenb n = True -> (k ** n = double k)\n> to {n} prf =\n> let (k ** p) = evenb_double_conv {n}\n> in (k ** rewrite p in rewrite prf in Refl)\n> fro : (k ** n = double k) -> evenb n = True\n> fro {n} (k**prf) = rewrite prf in evenb_double {k}\n\nSimilarly, to state that two numbers \\idr{n} and \\idr{m} are equal, we can say\neither (1) that \\idr{n == m} returns \\idr{True} or (2) that \\idr{n = m}. These\ntwo notions are equivalent.\n\n> beq_nat_true_iff : (n1, n2 : Nat) -> (n1 == n2 = True) <-> (n1 = n2)\n> beq_nat_true_iff n1 n2 = (to, fro n1 n2)\n> where\n> to : (n1 == n2 = True) -> (n1 = n2)\n> to = beq_nat_true {n=n1} {m=n2}\n> fro : (n1, n2 : Nat) -> (n1 = n2) -> (n1 == n2 = True)\n> fro n1 n1 Refl = sym $ beq_nat_refl n1\n\nHowever, while the boolean and propositional formulations of a claim are\nequivalent from a purely logical perspective, they need not be equivalent\n_operationally_. Equality provides an extreme example: knowing that \\idr{n == m\n= True} is generally of little direct help in the middle of a proof involving\n\\idr{n} and \\idr{m}; however, if we convert the statement to the equivalent form\n\\idr{n = m}, we can rewrite with it.\n\nThe case of even numbers is also interesting. Recall that, when proving the\nbackwards direction of \\idr{even_bool_prop} (i.e., \\idr{evenb_double}, going\nfrom the propositional to the boolean claim), we used a simple induction on\n\\idr{k}. On the other hand, the converse (the \\idr{evenb_double_conv} exercise)\nrequired a clever generalization, since we can't directly prove \\idr{(k ** n =\ndouble k) -> evenb n = True}.\n\nFor these examples, the propositional claims are more useful than their boolean\ncounterparts, but this is not always the case. For instance, we cannot test\nwhether a general proposition is true or not in a function definition; as a\nconsequence, the following code fragment is rejected:\n\n```idris\nis_even_prime : Nat -> Bool\nis_even_prime n = if n = 2 then True else False\n```\n\nIdris complains that \\idr{n = 2} has type \\idr{Type}, while it expects an\nelement of \\idr{Bool} (or some other inductive type with two elements). The\nreason for this error message has to do with the _computational_ nature of\nIdris's core language, which is designed so that every function that it can\nexpress is computable and total. One reason for this is to allow the extraction\nof executable programs from Idris developments. As a consequence, \\idr{Type} in\nIdris does _not_ have a universal case analysis operation telling whether any\ngiven proposition is true or false, since such an operation would allow us to\nwrite non-computable functions.\n\nAlthough general non-computable properties cannot be phrased as boolean\ncomputations, it is worth noting that even many _computable_ properties are\neasier to express using \\idr{Type} than \\idr{Bool}, since recursive function\ndefinitions are subject to significant restrictions in Idris. For instance, the\nnext chapter shows how to define the property that a regular expression matches\na given string using \\idr{Type}. Doing the same with \\idr{Bool} would amount to\nwriting a regular expression matcher, which would be more complicated, harder to\nunderstand, and harder to reason about.\n\nConversely, an important side benefit of stating facts using booleans is\nenabling some proof automation through computation with Idris terms, a technique\nknown as _proof by reflection_. Consider the following statement:\n\n> even_1000 : (k ** 1000 = double k)\n\nThe most direct proof of this fact is to give the value of \\idr{k} explicitly.\n\n> even_1000 = (500 ** Refl)\n\nOn the other hand, the proof of the corresponding boolean statement is even\nsimpler:\n\n> even_1000' : evenb 1000 = True\n> even_1000' = Refl\n\nWhat is interesting is that, since the two notions are equivalent, we can use\nthe boolean formulation to prove the other one without mentioning the value 500\nexplicitly:\n\n> even_1000'' : (k ** 1000 = double k)\n> even_1000'' = (fst $ even_bool_prop {n=1000}) Refl\n\n\\todo[inline]{Add http://www.ams.org/journals/notices/200811/tx081101382p.pdf as\na link}\n\nAlthough we haven't gained much in terms of proof size in this case, larger\nproofs can often be made considerably simpler by the use of reflection. As an\nextreme example, the Coq proof of the famous _4-color theorem_ uses reflection\nto reduce the analysis of hundreds of different cases to a boolean computation.\nWe won't cover reflection in great detail, but it serves as a good example\nshowing the complementary strengths of booleans and general propositions.\n\n\n==== Exercise: 2 stars (logical_connectives)\n\nThe following lemmas relate the propositional connectives studied in this\nchapter to the corresponding boolean operations.\n\n> andb_true_iff : (b1, b2 : Bool) -> (b1 && b2 = True) <->\n> (b1 = True, b2 = True)\n> andb_true_iff b1 b2 = ?andb_true_iff_rhs\n\n> orb_true_iff : (b1, b2 : Bool) -> (b1 || b2 = True) <->\n> ((b1 = True) `Either` (b2 = True))\n> orb_true_iff b1 b2 = ?orb_true_iff_rhs\n\n$\\square$\n\n\n==== Exercise: 1 star (beq_nat_false_iff)\n\nThe following theorem is an alternate \"negative\" formulation of\n\\idr{beq_nat_true_iff} that is more convenient in certain situations (we'll see\nexamples in later chapters).\n\n> beq_nat_false_iff : (x, y : Nat) -> (x == y = False) <-> (Not (x = y))\n> beq_nat_false_iff x y = ?beq_nat_false_iff_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars (beq_list)\n\nGiven a boolean operator \\idr{beq} for testing equality of elements of some type\n\\idr{a}, we can define a function \\idr{beq_list beq} for testing equality of\nlists with elements in \\idr{a}. Complete the definition of the \\idr{beq_list}\nfunction below. To make sure that your definition is correct, prove the lemma\n\\idr{beq_list_true_iff}.\n\n> beq_list : (beq : a -> a -> Bool) -> (l1, l2 : List a) -> Bool\n> beq_list beq l1 l2 = ?beq_list_rhs\n\n> beq_list_true_iff : (beq : a -> a -> Bool) ->\n> ((a1, a2 : a) -> (beq a1 a2 = True) <-> (a1 = a2)) ->\n> ((l1, l2 : List a) -> (beq_list beq l1 l2 = True) <-> (l1 = l2))\n> beq_list_true_iff beq f l1 l2 = ?beq_list_true_iff_rhs\n\n$\\square$\n\n\n==== Exercise: 2 stars, recommended (All_forallb)\n\nRecall the function \\idr{forallb}, from the exercise\n\\idr{forall_exists_challenge} in chapter `Tactics`:\n\n> forallb : (test : x -> Bool) -> (l : List x) -> Bool\n> forallb _ [] = True\n> forallb test (x :: xs) = test x && forallb test xs\n\nProve the theorem below, which relates \\idr{forallb} to the \\idr{All} property\nof the above exercise.\n\n> forallb_true_iff : (l : List x) -> (forallb test l = True) <->\n> (All (\\x => test x = True) l)\n> forallb_true_iff l = ?forallb_true_iff_rhs\n\nAre there any important properties of the function \\idr{forallb} which are not\ncaptured by this specification?\n\n> -- FILL IN HERE\n\n$\\square$\n\n\n=== Classical vs. Constructive Logic\n\nWe have seen that it is not possible to test whether or not a proposition\n\\idr{p} holds while defining a Idris function. You may be surprised to learn\nthat a similar restriction applies to _proofs_! In other words, the following\nintuitive reasoning principle is not derivable in Idris:\n\n```idris\nexcluded_middle : p `Either` (Not p)\n```\n\nTo understand operationally why this is the case, recall that, to prove a\nstatement of the form \\idr{p `Either` q}, we use the \\idr{Left} and \\idr{Right}\npattern matches, which effectively require knowing which side of the disjunction\nholds. But the universally quantified \\idr{p} in \\idr{excluded_middle} is an\narbitrary proposition, which we know nothing about. We don't have enough\ninformation to choose which of \\idr{Left} or \\idr{Right} to apply, just as Idris\ndoesn't have enough information to mechanically decide whether \\idr{p} holds or\nnot inside a function.\n\nHowever, if we happen to know that \\idr{p} is reflected in some boolean term\n\\idr{b}, then knowing whether it holds or not is trivial: we just have to check\nthe value of \\idr{b}.\n\n> restricted_excluded_middle : (p <-> b = True) -> p `Either` Not p\n> restricted_excluded_middle {b = True} (_, bp) = Left $ bp Refl\n> restricted_excluded_middle {b = False} (pb, _) = Right $ uninhabited . pb\n\nIn particular, the excluded middle is valid for equations \\idr{n = m}, between\nnatural numbers \\idr{n} and \\idr{m}.\n\n\\todo[inline]{Is there a simpler way to write this? Maybe with setoids?}\n\n> restricted_excluded_middle_eq : (n, m : Nat) -> (n = m) `Either` Not (n = m)\n> restricted_excluded_middle_eq n m =\n> restricted_excluded_middle (to n m, fro n m)\n> where\n> to : (n, m : Nat) -> (n=m) -> (n==m)=True\n> to Z Z prf = Refl\n> to Z (S _) Refl impossible\n> to (S _) Z Refl impossible\n> to (S k) (S j) prf = to k j (succInjective k j prf)\n> fro : (n, m : Nat) -> (n==m)=True -> (n=m)\n> fro Z Z Refl = Refl\n> fro Z (S _) Refl impossible\n> fro (S _) Z Refl impossible\n> fro (S k) (S j) prf = rewrite fro k j prf in Refl\n\n(Idris has a built-in version of this, called \\idr{decEq}.)\n\nIt may seem strange that the general excluded middle is not available by default\nin Idris; after all, any given claim must be either true or false. Nonetheless,\nthere is an advantage in not assuming the excluded middle: statements in Idris\ncan make stronger claims than the analogous statements in standard mathematics.\nNotably, if there is a Idris proof of \\idr{(x ** p x)}, it is possible to\nexplicitly exhibit a value of \\idr{x} for which we can prove \\idr{p x} -- in\nother words, every proof of existence is necessarily _constructive_.\n\nLogics like Idris's, which do not assume the excluded middle, are referred to as\n_constructive logics_.\n\nMore conventional logical systems such as ZFC, in which the excluded middle does\nhold for arbitrary propositions, are referred to as _classical_.\n\nThe following example illustrates why assuming the excluded middle may lead to\nnon-constructive proofs:\n\n\\todo[inline]{Use proper TeX?}\n\n_Claim_: There exist irrational numbers `a` and `b` such that `a ^ b` is\nrational.\n\n_Proof_: It is not difficult to show that `sqrt 2` is irrational. If `sqrt 2 ^\nsqrt 2` is rational, it suffices to take `a = b = sqrt 2` and we are done.\nOtherwise, `sqrt 2 ^ sqrt 2` is irrational. In this case, we can take `a = sqrt\n2 ^ sqrt 2` and `b = sqrt 2`, since `a ^ b = sqrt 2 ^ (sqrt 2 * sqrt 2)` = sqrt\n2 ^ 2 = 2`. $\\square$\n\nDo you see what happened here? We used the excluded middle to consider\nseparately the cases where `sqrt 2 ^ sqrt 2` is rational and where it is not,\nwithout knowing which one actually holds! Because of that, we wind up knowing\nthat such `a` and `b` exist but we cannot determine what their actual values are\n(at least, using this line of argument).\n\nAs useful as constructive logic is, it does have its limitations: There are many\nstatements that can easily be proven in classical logic but that have much more\ncomplicated constructive proofs, and there are some that are known to have no\nconstructive proof at all! Fortunately, like functional extensionality, the\nexcluded middle is known to be compatible with Idris's logic, allowing us to add\nit safely as an axiom. However, we will not need to do so in this book: the\nresults that we cover can be developed entirely within constructive logic at\nnegligible extra cost.\n\nIt takes some practice to understand which proof techniques must be avoided in\nconstructive reasoning, but arguments by contradiction, in particular, are\ninfamous for leading to non-constructive proofs. Here's a typical example:\nsuppose that we want to show that there exists \\idr{x} with some property\n\\idr{p}, i.e., such that \\idr{p x}. We start by assuming that our conclusion is\nfalse; that is, \\idr{Not (x : a ** p x)}. From this premise, it is not hard to\nderive \\idr{(x : a) -> Not $ p x}. If we manage to show that this intermediate\nfact results in a contradiction, we arrive at an existence proof without ever\nexhibiting a value of \\idr{x} for which \\idr{p x} holds!\n\nThe technical flaw here, from a constructive standpoint, is that we claimed to\nprove \\idr{(x ** p x)} using a proof of \\idr{Not $ Not (x ** p x)}. Allowing\nourselves to remove double negations from arbitrary statements is equivalent to\nassuming the excluded middle, as shown in one of the exercises below. Thus, this\nline of reasoning cannot be encoded in Idris without assuming additional axioms.\n\n\n==== Exercise: 3 stars (excluded_middle_irrefutable)\n\nThe consistency of Idris with the general excluded middle axiom requires\ncomplicated reasoning that cannot be carried out within Idris itself. However,\nthe following theorem implies that it is always safe to assume a decidability\naxiom (i.e., an instance of excluded middle) for any _particular_ type \\idr{p}.\nWhy? Because we cannot prove the negation of such an axiom; if we could, we\nwould have both \\idr{Not (p `Either` Not p)} and \\idr{Not $ Not (p `Either` Not\np)}, a contradiction.\n\n> excluded_middle_irrefutable : Not $ Not (p `Either` Not p)\n> excluded_middle_irrefutable = ?excluded_middle_irrefutable_rhs\n\n$\\square$\n\n\n==== Exercise: 3 stars, advanced (not_exists_dist)\n\nIt is a theorem of classical logic that the following two assertions are\nequivalent:\n\n```idris\n Not (x : a ** Not p x)\n (x : a) -> p x\n```\n\n\\todo[inline]{Add a hyperlink}\n\nThe \\idr{dist_not_exists} theorem above proves one side of this equivalence.\nInterestingly, the other direction cannot be proved in constructive logic. Your\njob is to show that it is implied by the excluded middle.\n\n> not_exists_dist : {p : a -> Type} -> Not (x ** Not $ p x) -> ((x : a) -> p x)\n> not_exists_dist prf x = ?not_exists_dist_rhs\n> where\n> excluded_middle : (a : Type) -> a `Either` (Not a)\n> excluded_middle p = really_believe_me p\n\n$\\square$\n\n\n==== Exercise: 5 stars, optional (classical_axioms)\n\nFor those who like a challenge, here is an exercise taken from the Coq'Art book\nby Bertot and Casteran (p. 123). Each of the following four statements, together\nwith \\idr{excluded_middle}, can be considered as characterizing classical logic.\nWe can't prove any of them in Idris, but we can consistently add any one of them\nas an axiom if we wish to work in classical logic.\n\nProve that all five propositions (these four plus \\idr{excluded_middle}) are\nequivalent.\n\n> peirce : ((p -> q) -> p) -> p\n\n> double_negation_elimination : Not $ Not p -> p\n\n> de_morgan_not_and_not : Not (Not p, Not q) -> p `Either` q\n\n> implies_to_or : (p -> q) -> ((Not p) `Either` q)\n\n> -- FILL IN HERE\n\n$\\square$\n", "meta": {"hexsha": "567305bb034f50cdb9c5d9f8922a698297b1d1ef", "size": 47292, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "src/Logic.lidr", "max_stars_repo_name": "diseraluca/software-foundations", "max_stars_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 452, "max_stars_repo_stars_event_min_datetime": "2016-06-23T10:03:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T22:25:00.000Z", "max_issues_repo_path": "src/Logic.lidr", "max_issues_repo_name": "diseraluca/software-foundations", "max_issues_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 53, "max_issues_repo_issues_event_min_datetime": "2016-06-27T07:14:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-23T06:16:57.000Z", "max_forks_repo_path": "src/Logic.lidr", "max_forks_repo_name": "diseraluca/software-foundations", "max_forks_repo_head_hexsha": "03e178fc616e50019c4168fb488f67fbfb46fafa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2016-11-21T10:55:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T00:21:55.000Z", "avg_line_length": 36.6320681642, "max_line_length": 91, "alphanum_fraction": 0.7025924046, "num_tokens": 13747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143776, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.651671213361663}} {"text": "import Data.So\nimport Data.Vect\n\n--------------------------------------------------------------------------------\n-- Utility\n\n-- Makes a best effort to return an error message.\n-- Use this only on code paths that you can deduce should be unreachable. \nunsafeError : String -> a\nunsafeError message = believe_me message\n\n-- Unwraps a `Just a` to a plain `a`.\n-- Useful for command-line debugging but unsafe for general program usage.\nunsafeUnwrapJust : (Maybe a) -> a\nunsafeUnwrapJust (Just x) =\n x\nunsafeUnwrapJust (Nothing) =\n unsafeError \"The specified Maybe was not a Just.\"\n\n--------------------------------------------------------------------------------\n-- IsLte\n\n-- Proof that `x <= y`.\nIsLte : Ord e => (x:e) -> (y:e) -> Type\nIsLte x y = So (x <= y)\n\nmkIsLte : Ord e => (x:e) -> (y:e) -> Maybe (IsLte x y)\nmkIsLte x y =\n case choose (x <= y) of \n Left proofXLteY =>\n Just proofXLteY\n Right proofNotXLteY =>\n Nothing\n\n-- Given an `x` and a `y`, returns a proof that either `x <= y` or `y <= x`.\nchooseLte :\n Ord e => \n (x:e) -> (y:e) -> \n Either (IsLte x y) (IsLte y x)\nchooseLte x y =\n case choose (x <= y) of \n Left proofXLteY =>\n Left proofXLteY\n Right proofNotXLteY =>\n -- Given: not (x <= y)\n -- Derive: x > y\n -- Derive: y < x\n -- Derive: y <= x\n --\n -- Unfortunately Ord doesn't guarantee the preceding\n -- even though any sane implementation will conform\n -- to those rules. \n case choose (y <= x) of \n Left proofYLteX =>\n Right proofYLteX\n Right proofNotYLteX =>\n unsafeError \"Impossible with a sane Ord implementation.\"\n\n--------------------------------------------------------------------------------\n-- IsSorted\n\n-- Proof that `xs` is sorted.\ndata IsSorted : (xs:Vect n e) -> Type where\n IsSortedZero :\n IsSorted Nil\n IsSortedOne :\n Ord e =>\n (x:e) ->\n IsSorted (x::Nil)\n IsSortedMany :\n Ord e => \n (x:e) -> (y:e) -> (ys:Vect n'' e) -> -- (n'' == (n - 2))\n (IsLte x y) -> IsSorted (y::ys) ->\n IsSorted (x::(y::ys))\n\nmkIsSorted : Ord e => (xs:Vect n e) -> Maybe (IsSorted xs)\nmkIsSorted Nil =\n Just IsSortedZero\nmkIsSorted (x::Nil) =\n Just (IsSortedOne x)\nmkIsSorted (x::(y::ys)) =\n case (mkIsLte x y) of\n Just proofXLteY =>\n case (mkIsSorted (y::ys)) of\n Just proofYYsIsSorted =>\n Just (IsSortedMany x y ys proofXLteY proofYYsIsSorted)\n Nothing =>\n Nothing\n Nothing =>\n Nothing\n\n--------------------------------------------------------------------------------\n-- ElemsAreSame\n\n-- Proof that set `xs` and set `ys` contain the same elements.\ndata ElemsAreSame : (xs:Vect n e) -> (ys:Vect n e) -> Type where\n NilIsNil : \n ElemsAreSame Nil Nil\n PrependXIsPrependX :\n (x:e) -> ElemsAreSame zs zs' ->\n ElemsAreSame (x::zs) (x::zs')\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\nXsIsXs : (xs:Vect n e) -> ElemsAreSame xs xs\nXsIsXs Nil =\n NilIsNil\nXsIsXs (x::ys) =\n PrependXIsPrependX x (XsIsXs ys)\n\nflip : ElemsAreSame xs ys -> ElemsAreSame ys xs\nflip NilIsNil =\n NilIsNil\nflip (PrependXIsPrependX x proofXsTailIsYsTail) =\n PrependXIsPrependX x (flip proofXsTailIsYsTail)\nflip (PrependXYIsPrependYX x y proofXsLongtailIsYsLongtail) =\n PrependXYIsPrependYX y x (flip proofXsLongtailIsYsLongtail)\nflip (SamenessIsTransitive proofXsIsZs proofZsIsYs) =\n let proofYsIsZs = flip proofZsIsYs in\n let proofZsIsXs = flip proofXsIsZs in\n let proofYsIsXs = SamenessIsTransitive proofYsIsZs proofZsIsXs in\n proofYsIsXs\n\n-- NOTE: Needed to explicitly pull out the {x}, {y}, {zs}, {us} implicit parameters.\nswapFirstAndSecondOfLeft : ElemsAreSame (x::(y::zs)) us -> ElemsAreSame (y::(x::zs)) us\nswapFirstAndSecondOfLeft {x} {y} {zs} {us} proofXYZsIsUs =\n let proofYXZsIsXYZs = PrependXYIsPrependYX y x (XsIsXs zs) in\n let proofYZZsIsUs = SamenessIsTransitive proofYXZsIsXYZs proofXYZsIsUs in\n proofYZZsIsUs\n\n--------------------------------------------------------------------------------\n-- HeadIs, HeadIsEither\n\n-- Proof that the specified vector has the specified head.\ndata HeadIs : Vect n e -> e -> Type where\n MkHeadIs : HeadIs (x::xs) x\n\n-- Proof that the specified vector has one of the two specified heads.\n-- \n-- NOTE: Could implement this as an `Either (HeadIs xs x) (HeadIs xs y)`,\n-- but an explicit formulation feels cleaner.\ndata HeadIsEither : Vect n e -> (x:e) -> (y:e) -> Type where\n HeadIsLeft : HeadIsEither (x::xs) x y\n HeadIsRight : HeadIsEither (x::xs) y x\n\n--------------------------------------------------------------------------------\n-- Insertion Sort\n\n-- Inserts an element into a non-empty sorted vector, returning a new\n-- sorted vector containing the new element plus the original elements.\ninsert' :\n Ord e =>\n (xs:Vect (S n) e) -> (y:e) -> (IsSorted xs) -> (HeadIs xs x) ->\n (xs':(Vect (S (S n)) e) ** ((IsSorted xs'), (HeadIsEither xs' x y), (ElemsAreSame (y::xs) xs')))\ninsert' (x::Nil) y (IsSortedOne x) MkHeadIs =\n case (chooseLte x y) of\n Left proofXLteY =>\n let yXNilSameXYNil = PrependXYIsPrependYX y x (XsIsXs Nil) in\n (x::(y::Nil) **\n (IsSortedMany x y Nil proofXLteY (IsSortedOne y),\n HeadIsLeft,\n yXNilSameXYNil))\n Right proofYLteX =>\n let yXNilSameYXNil = XsIsXs (y::(x::Nil)) in\n (y::(x::Nil) ** \n (IsSortedMany y x Nil proofYLteX (IsSortedOne x),\n HeadIsRight,\n yXNilSameYXNil))\ninsert' (x::(y::ys)) z proofXYYsIsSorted MkHeadIs =\n case proofXYYsIsSorted of\n (IsSortedMany x y ys proofXLteY proofYYsIsSorted) =>\n case (chooseLte x z) of\n Left proofXLteZ =>\n -- x::(insert' (y::ys) z)\n let proofHeadYYsIsY = the (HeadIs (y::ys) y) MkHeadIs in\n case (insert' (y::ys) z proofYYsIsSorted proofHeadYYsIsY) of\n -- rest == (_::tailOfRest)\n ((y::tailOfRest) ** (proofRestIsSorted, HeadIsLeft, proofZYYsSameRest)) =>\n let proofXZYYsIsXRest = PrependXIsPrependX x proofZYYsSameRest in\n let proofZXYYsIsXRest = swapFirstAndSecondOfLeft proofXZYYsIsXRest in\n (x::(y::tailOfRest) **\n (IsSortedMany x y tailOfRest proofXLteY proofRestIsSorted,\n HeadIsLeft,\n proofZXYYsIsXRest))\n ((z::tailOfRest) ** (proofRestIsSorted, HeadIsRight, proofZYYsSameRest)) =>\n let proofXZYYsIsXRest = PrependXIsPrependX x proofZYYsSameRest in\n let proofZXYYsIsXRest = swapFirstAndSecondOfLeft proofXZYYsIsXRest in\n (x::(z::tailOfRest) **\n (IsSortedMany x z tailOfRest proofXLteZ proofRestIsSorted,\n HeadIsLeft,\n proofZXYYsIsXRest))\n Right proofZLteX =>\n -- z::(x::(y::ys))\n let proofZXYYsIsZXYYs = XsIsXs (z::(x::(y::ys))) in\n (z::(x::(y::ys)) **\n (IsSortedMany z x (y::ys) proofZLteX proofXYYsIsSorted,\n HeadIsRight,\n proofZXYYsIsZXYYs))\n\n-- Inserts an element into a sorted vector, returning a new\n-- sorted vector containing the new element plus the original elements.\ninsert :\n Ord e =>\n (xs:Vect n e) -> (y:e) -> (IsSorted xs) -> \n (xs':(Vect (S n) e) ** ((IsSorted xs'), (ElemsAreSame (y::xs) xs')))\ninsert Nil y IsSortedZero =\n ([y] ** (IsSortedOne y, XsIsXs [y]))\ninsert (x::xs) y proofXXsIsSorted =\n let proofHeadOfXXsIsX = the (HeadIs (x::xs) x) MkHeadIs in\n case (insert' (x::xs) y proofXXsIsSorted proofHeadOfXXsIsX) of\n (xs' ** (proofXsNewIsSorted, proofHeadXsNewIsXOrY, proofYXXsIsXsNew)) =>\n (xs' ** (proofXsNewIsSorted, proofYXXsIsXsNew))\n\n-- Sorts the specified vector,\n-- returning a new sorted vector with the same elements.\ninsertionSort :\n Ord e =>\n (xs:Vect n e) ->\n (xs':Vect n e ** (IsSorted xs', ElemsAreSame xs xs'))\ninsertionSort Nil =\n (Nil ** (IsSortedZero, NilIsNil))\ninsertionSort (x::ys) =\n case (insertionSort ys) of\n (ysNew ** (proofYsNewIsSorted, proofYsIsYsNew)) =>\n case (insert ysNew x proofYsNewIsSorted) of\n (result ** (proofResultIsSorted, proofXYsNewIsResult)) =>\n let proofXYsIsXYsNew = PrependXIsPrependX x proofYsIsYsNew in\n let proofXYsIsResult = SamenessIsTransitive proofXYsIsXYsNew proofXYsNewIsResult in\n (result ** (proofResultIsSorted, proofXYsIsResult))\n\n--------------------------------------------------------------------------------\n-- Main\n\n-- Parses an integer from a string, returning 0 if there is an error.\nparseInt : String -> Integer\nparseInt s =\n the Integer (cast s)\n\n-- Joins a list of elements with the provided separator,\n-- returning a separator-separated string.\nintercalate : Show e => (xs:Vect n e) -> (sep:String) -> String\nintercalate Nil sep =\n \"\"\nintercalate (x::Nil) sep =\n show x\nintercalate (x::(y::zs)) sep =\n (show x) ++ sep ++ (intercalate (y::zs) sep)\n\nmain : IO ()\nmain = do\n putStrLn \"Please type a space-separated list of integers: \"\n csv <- getLine\n let numbers = map parseInt (words csv)\n let (sortedNumbers ** (_, _)) = insertionSort (fromList numbers)\n putStrLn \"After sorting, the integers are: \"\n putStrLn (intercalate sortedNumbers \" \")\n\n--------------------------------------------------------------------------------\n", "meta": {"hexsha": "77fb647712b76cc44b4b7086978e1dcd20925474", "size": 10238, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "data/github.com/davidfstr/idris-insertion-sort/bf1c39a8eb4cdbd6d6b8d9fda8797703c2082e4c/InsertionSort.idr", "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-11-27T19:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-24T06:35:17.000Z", "max_issues_repo_path": "data/github.com/davidfstr/idris-insertion-sort/bf1c39a8eb4cdbd6d6b8d9fda8797703c2082e4c/InsertionSort.idr", "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 91, "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_forks_repo_path": "data/github.com/davidfstr/idris-insertion-sort/bf1c39a8eb4cdbd6d6b8d9fda8797703c2082e4c/InsertionSort.idr", "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-12-18T02:21:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-12T07:50:37.000Z", "avg_line_length": 38.7803030303, "max_line_length": 103, "alphanum_fraction": 0.5529400273, "num_tokens": 2931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6514483533030226}} {"text": "module AltRandomBinaryAccessList\n\nimport RandomAccessList\n\n%default total\n%access private\n\nexport\ndata BinaryList a = Nil | Zero (BinaryList (a, a)) | One a (BinaryList (a,a))\n\nuncons : BinaryList a -> (a, BinaryList a)\nuncons Nil = idris_crash \"empty list\"\nuncons (One x Nil) = (x, Nil)\nuncons (One x ps) = (x, Zero ps)\nuncons (Zero ps) = let ((x, y), ps') = uncons ps in (x, One y ps')\n\nmutual\n fupdate : (a -> a) -> Int -> BinaryList a -> BinaryList a\n fupdate f i Nil = idris_crash \"bad subscript\"\n fupdate f 0 (One x ps) = One (f x) ps\n fupdate f i (One x ps) = cons x (fupdate f (i - 1) (assert_smaller (One x ps) $ Zero ps))\n fupdate f i (Zero ps) = let i' = assert_total $ i `div` 2\n r = assert_total $ i `mod` 2\n f' = \\(x, y) => if 0 == r then (f x, y) else (x, f y)\n in Zero (fupdate f' i' ps)\n\n export\n RandomAccessList BinaryList where\n empty = Nil\n isEmpty Nil = True\n isEmpty _ = False\n\n cons x Nil = One x Nil\n cons x (Zero ps) = One x ps\n cons x (One y ps) = Zero (cons (x, y) ps)\n\n head xs = fst (uncons xs)\n tail xs = snd (uncons xs)\n\n lookup i Nil = idris_crash \"bad subscript\"\n lookup 0 (One x ps) = x\n lookup i (One x ps) = lookup (i - 1) (assert_smaller (One x ps) $ Zero ps)\n lookup i (Zero ps) = let i' = assert_total $ i `div` 2\n r = assert_total $ i `mod` 2\n (x, y) = lookup i' ps\n in if 0 == r then x else y\n\n update i y xs = fupdate (\\x => y) i xs\n", "meta": {"hexsha": "ff31a47f7b25eb2ed2148b16d635ae5b808fd551", "size": 1597, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "src/AltBinaryRandomAccessList.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/AltBinaryRandomAccessList.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/AltBinaryRandomAccessList.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": 32.5918367347, "max_line_length": 91, "alphanum_fraction": 0.5416405761, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6514483458760968}} {"text": "\nmodule Determinism\n\n\n\nimport Step\nimport Term\n\n\n%default total\n%access export\n\n\n\nstepDeterministic : {e1 : Term} -> {e2 : Term} -> {e3 : Term} ->\n (Step e1 e2) -> (Step e1 e3) ->\n e2 = e3\n-- case split in the following order: (Step e1 e2), (Step e1 e3)\nstepDeterministic (StApp1 st1) (StApp1 st2) = \n let ih = stepDeterministic st1 st2\n in congApp ih Refl\nstepDeterministic (StApp1 st1) (StApp2 v2 st2) = \n absurd $ valueIrreducible _ v2 st1\nstepDeterministic (StApp1 st1) (StBeta v2) impossible\n--\nstepDeterministic (StApp2 v1 _) (StApp1 st) = \n absurd $ valueIrreducible _ v1 st\nstepDeterministic (StApp2 v1 st1) (StApp2 v2 st2) = \n let ih = stepDeterministic st1 st2\n in congApp Refl ih\nstepDeterministic (StApp2 v1 st1) (StBeta v2) =\n absurd $ valueIrreducible _ v2 st1\n--\nstepDeterministic (StBeta v1) (StApp2 v2 st2) =\n absurd $ valueIrreducible _ v1 st2 \nstepDeterministic (StBeta v1) (StBeta _) = Refl\n\n--\nstepDeterministic (StRec st1) (StRec st2) = \n let ih = stepDeterministic st1 st2\n in congRec ih Refl Refl\nstepDeterministic (StRec st1) StRecZero impossible\nstepDeterministic (StRec st1) (StRecSucc v) = \n absurd $ valueIrreducible _ v st1\n--\nstepDeterministic StRecZero (StRec _) impossible\nstepDeterministic StRecZero StRecZero = Refl\n--\nstepDeterministic (StRecSucc v) (StRec st) = \n absurd $ valueIrreducible _ v st\nstepDeterministic (StRecSucc v) (StRecSucc _) = Refl\n--\nstepDeterministic (StSucc st1) (StSucc st2) = \n congSucc $ stepDeterministic st1 st2\n--\nstepDeterministic (StPred st1) (StPred st2) = \n congPred $ stepDeterministic st1 st2\nstepDeterministic (StPred st1) StPredZero impossible\nstepDeterministic (StPred st1) (StPredSucc v) = \n absurd $ valueIrreducible _ (VSucc v) st1\n--\nstepDeterministic StPredZero (StPred _) impossible\nstepDeterministic StPredZero StPredZero = Refl\n--\nstepDeterministic (StPredSucc v1) (StPred st) =\n absurd $ valueIrreducible _ (VSucc v1) st\nstepDeterministic (StPredSucc v1) (StPredSucc _) = Refl \n--\nstepDeterministic (StIfz st1) (StIfz st2) = \n let ih = stepDeterministic st1 st2\n in congIfz ih Refl Refl\nstepDeterministic (StIfz st1) StIfzZero impossible\nstepDeterministic (StIfz st1) (StIfzSucc v) = \n absurd $ valueIrreducible _ (VSucc v) st1\n--\nstepDeterministic StIfzZero (StIfz _) impossible\nstepDeterministic StIfzZero StIfzZero = Refl\n--\nstepDeterministic (StIfzSucc v1) (StIfz st2) =\n absurd $ valueIrreducible _ (VSucc v1) st2\nstepDeterministic (StIfzSucc v1) (StIfzSucc v2) = Refl\n\n\n\n\ntransStepDeterministic : (v2 : Value e2) -> (TransStep e1 e2) ->\n (v3 : Value e3) -> (TransStep e1 e3) ->\n e2 = e3\n--\ntransStepDeterministic v2 (TStRefl e3) v3 (TStRefl e3) = Refl\n--\ntransStepDeterministic v2 (TStRefl e2) v3 (TStTrans x y) = \n absurd $ valueIrreducible e2 v2 x\n--\ntransStepDeterministic v2 (TStTrans x z) v3 (TStRefl e3) = \n absurd $ valueIrreducible e3 v3 x\n--\ntransStepDeterministic {e2 = e2} v2 (TStTrans x z) v3 (TStTrans y w) =\n let eq = stepDeterministic x y\n z' = replace {P = \\x => x} (cong {f = \\e => TransStep e e2} eq) z\n in transStepDeterministic v2 z' v3 w\n\n\n\n", "meta": {"hexsha": "76fdf0c2383b82e474cf9f736c2992f873e19cbd", "size": 3165, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "totality/src/Determinism.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "totality/src/Determinism.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "totality/src/Determinism.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": 30.1428571429, "max_line_length": 71, "alphanum_fraction": 0.7105845182, "num_tokens": 1119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6513847538967281}} {"text": "> module Fraction.EqProperties\n\n> import Syntax.PreorderReasoning\n\n> import Fraction.Fraction\n> import Fraction.BasicOperations\n> import Fraction.Predicates\n> import Fraction.BasicProperties\n> import PNat.PNat\n> import PNat.Operations\n> import PNat.Properties\n> import Nat.LTProperties\n> import Nat.OperationsProperties\n> import Nat.Positive\n\n> %default total\n> %access export\n> -- %access public export\n\n> -- %logging 5\n\n\n* |Eq| is an equivalence:\n\n> ||| Eq is reflexive\n> EqReflexive : {x : Fraction} -> x `Eq` x\n> EqReflexive {x = (m, d')} = Refl\n\n\n> ||| Eq is symmetric\n> EqSymmetric : {x, y : Fraction} -> x `Eq` y -> y `Eq` x\n> EqSymmetric {x = (m, d')} {y = (n, e')} = sym\n\n\n> ||| Eq is transitive\n> EqTransitive : {x, y, z : Fraction} -> x `Eq` y -> y `Eq` z -> x `Eq` z\n> EqTransitive {x = (m, d')} {y = (n, e')} {z = (o, f')} xy yz = \n> let d = toNat d' in\n> let e = toNat e' in\n> let f = toNat f' in\n> let neEQZ : (Not (e = Z))\n> = gtZisnotZ (toNatLTLemma e') in\n> let s1 : ((m * e) * f = (n * d) * f)\n> = multPreservesEq (m * e) (n * d) f f xy Refl in \n> let s2 : (m * (e * f) = (n * d) * f)\n> = replace {P = \\ ZUZU => ZUZU = (n * d) * f} (sym (multAssociative m e f)) s1 in\n> let s3 : (m * (f * e) = (n * d) * f)\n> = replace {P = \\ ZUZU => m * ZUZU = (n * d) * f} (multCommutative e f) s2 in\n> let s4 : ((m * f) * e = (n * d) * f)\n> = replace {P = \\ ZUZU => ZUZU = (n * d) * f} (multAssociative m f e) s3 in\n> let s5 : ((m * f) * e = n * (d * f))\n> = replace {P = \\ ZUZU => (m * f) * e = ZUZU} (sym (multAssociative n d f)) s4 in\n> let s6 : ((m * f) * e = n * (f * d))\n> = replace {P = \\ ZUZU => (m * f) * e = n * ZUZU} (multCommutative d f) s5 in\n> let s7 : ((m * f) * e = (n * f) * d)\n> = replace {P = \\ ZUZU => (m * f) * e = ZUZU} (multAssociative n f d) s6 in\n> let s8 : ((m * f) * e = (o * e) * d)\n> = replace {P = \\ ZUZU => (m * f) * e = ZUZU * d} yz s7 in \n> let s9 : ((m * f) * e = o * (e * d))\n> = replace {P = \\ ZUZU => (m * f) * e = ZUZU} (sym (multAssociative o e d)) s8 in\n> let s10 : ((m * f) * e = o * (d * e))\n> = replace {P = \\ ZUZU => (m * f) * e = o * ZUZU} (multCommutative e d) s9 in\n> let s11 : ((m * f) * e = (o * d) * e)\n> = replace {P = \\ ZUZU => (m * f) * e = ZUZU} (multAssociative o d e) s10 in\n>\n> multMultElimRight (m * f) (o * d) e e Refl neEQZ s11\n\n\n* |Eq| decidable\n\n> |||\n> decEq : (x : Fraction) -> (y : Fraction) -> Dec (x `Eq` y)\n> decEq (m, d') (n, e') = let d = toNat d' in\n> let e = toNat e' in\n> decEq (m * e) (n * d)\n\n\n* Properties of |(=)| and |Eq|:\n\n> ||| Equality implies `Eq`\n> eqEq : {x, y : Fraction} -> x = y -> x `Eq` y\n> eqEq {x = (m, d')} {y = (m, d')} Refl = Refl\n\n\nProperties of |plus| and |Eq|:\n\n> |||\n> plusPreservesEq : (x, x', y, y' : Fraction) -> \n> (x `Eq` x') -> (y `Eq` y') -> (x + y) `Eq` (x' + y')\n> plusPreservesEq (n, Element d _) (n', Element d' _) \n> (m, Element e _) (m', Element e' _) \n> nd'EQn'd me'EQm'e = pf where\n> helper2 : (a, b, c, d, a', c' : Nat) -> (a * c = a' * c') ->\n> ((a * b) * (c * d)) = ((a' * d) * (c' * b))\n> helper2 a b c d a' c' acEQa'c' =\n> ((a * b) * (c * d)) ={ multFlipCentre a b c d }=\n> ((a * c) * (b * d)) ={ cong {f = \\x => x * (b * d)} acEQa'c' }=\n> ((a' * c') * (b * d)) ={ cong {f = \\x => (a' * c') * x} (multCommutative b d) }=\n> ((a' * c') * (d * b)) ={ multFlipCentre a' c' d b }=\n> ((a' * d) * (c' * b)) QED \n> pf : ((n * e) + (m * d)) * (d' * e') = ((n' * e') + (m' * d')) * (d * e)\n> pf = \n> (((n * e) + (m * d)) * (d' * e')) \n> ={ multDistributesOverPlusLeft (n * e) (m * d) (d' * e') }=\n> (((n * e) * (d' * e')) + ((m * d) * (d' * e')))\n> ={ cong {f = \\x => x + ((m * d) * (d' * e'))} (helper2 n e d' e' n' d nd'EQn'd) }=\n> (((n' * e') * (d * e)) + ((m * d) * (d' * e')))\n> ={ cong {f = \\x => ((n' * e') * (d * e)) + ((m * d) * x)} (multCommutative d' e') }=\n> (((n' * e') * (d * e)) + ((m * d) * (e' * d')))\n> ={ cong {f = \\x => ((n' * e') * (d * e)) + x} (helper2 m d e' d' m' e me'EQm'e) }=\n> (((n' * e') * (d * e)) + ((m' * d') * (e * d)))\n> ={ cong {f = \\x => ((n' * e') * (d * e)) + ((m' * d') * x)} (multCommutative e d) }=\n> (((n' * e') * (d * e)) + ((m' * d') * (d * e)))\n> ={ sym (multDistributesOverPlusLeft (n' * e') (m' * d') (d * e)) }=\n> (((n' * e') + (m' * d')) * (d * e))\n> QED\n\n\nProperties of |mult|, |Eq|:\n\n> |||\n> multZeroRightEqZero : (x : Fraction) -> x * 0 `Eq` 0\n> multZeroRightEqZero (m, d') =\n> let d = toNat d' in\n> ( (m * 0) * 1 )\n> ={ cong {f = \\ ZUZU => ZUZU * 1} (multZeroRightZero m) }=\n> ( 0 * 1 )\n> ={ multZeroLeftZero 1 }= \n> ( 0 ) \n> ={ sym (multZeroLeftZero (d * 1)) }=\n> ( 0 * (d * 1) )\n> QED \n\n\n> |||\n> multZeroLeftEqZero : (x : Fraction) -> 0 * x `Eq` 0\n> multZeroLeftEqZero x = \n> let zxEqxz : (0 * x `Eq` x * 0)\n> = eqEq (multCommutative 0 x) in\n> let xzEqz : (x * 0 `Eq` 0)\n> = multZeroRightEqZero x in\n> EqTransitive zxEqxz xzEqz\n\n\n> ||| \n> multPreservesEq : (x, x', y, y' : Fraction) -> \n> (x `Eq` x') -> (y `Eq` y') -> (x * y) `Eq` (x' * y')\n> multPreservesEq (n, Element d _) (n', Element d' _) \n> (m, Element e _) (m', Element e' _) \n> nd'EQn'd me'EQm'e = pf where\n> pf : (n * m) * (d' * e') = (n' * m') * (d * e)\n> pf = \n> ((n * m) * (d' * e')) ={ multFlipCentre n m d' e' }=\n> ((n * d') * (m * e')) ={ cong {f = \\x => x * (m * e')} nd'EQn'd }=\n> ((n' * d) * (m * e')) ={ cong {f = \\x => (n' * d) * x} me'EQm'e }=\n> ((n' * d) * (m' * e)) ={ multFlipCentre n' d m' e }=\n> ((n' * m') * (d * e)) QED\n\n\nProperties of |plus|, |mult|, |Eq|:\n\n> |||\n> multDistributesOverPlusRightEq : {x, y, z : Fraction} -> x * (y + z) `Eq` (x * y) + (x * z)\n> multDistributesOverPlusRightEq {x = (m, d')} {y = (n, e')} {z = (o, f')} = \n> let d = toNat d' in\n> let e = toNat e' in\n> let f = toNat f' in\n> ( (m * (n * f + o * e)) * (toNat ((d' * e') * (d' * f'))) )\n> ={ cong {f = \\ ZUZU => (m * (n * f + o * e)) * ZUZU} toNatMultLemma }=\n> ( (m * (n * f + o * e)) * ((toNat (d' * e')) * (toNat (d' * f'))) )\n> ={ cong {f = \\ ZUZU => (m * (n * f + o * e)) * (ZUZU * (toNat (d' * f')))} toNatMultLemma }=\n> ( (m * (n * f + o * e)) * ((d * e) * (toNat (d' * f'))) ) \n> ={ cong {f = \\ ZUZU => (m * (n * f + o * e)) * ((d * e) * ZUZU)} toNatMultLemma }=\n> ( (m * (n * f + o * e)) * ((d * e) * (d * f)) ) \n> ={ cong {f = \\ ZUZU => (m * (n * f + o * e)) * ZUZU} (multFlipCentre d e d f) }=\n> ( (m * (n * f + o * e)) * ((d * d) * (e * f)) ) \n> ={ cong {f = \\ ZUZU => (m * (n * f + o * e)) * ZUZU} (sym (multAssociative d d (e * f))) }=\n> ( (m * (n * f + o * e)) * (d * (d * (e * f))) ) \n> ={ multAssociative (m * (n * f + o * e)) d (d * (e * f)) }=\n> ( ((m * (n * f + o * e)) * d) * (d * (e * f)) ) \n> ={ cong {f = \\ ZUZU => (ZUZU * d) * (d * (e * f))} (multDistributesOverPlusRight m (n * f) (o * e)) }=\n> ( ((m * (n * f) + m * (o * e)) * d) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => ((ZUZU + m * (o * e)) * d) * (d * (e * f))} (multAssociative m n f) }=\n> ( (((m * n) * f + m * (o * e)) * d) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => (((m * n) * f + ZUZU) * d) * (d * (e * f))} (multAssociative m o e) }= \n> ( (((m * n) * f + (m * o) * e) * d) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => ZUZU * (d * (e * f))} (multDistributesOverPlusLeft ((m * n) * f) ((m * o) * e) d)}= \n> ( (((m * n) * f) * d + ((m * o) * e) * d) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => (ZUZU + ((m * o) * e) * d) * (d * (e * f))} (sym (multAssociative (m * n) f d)) }=\n> ( ((m * n) * (f * d) + ((m * o) * e) * d) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => ((m * n) * (f * d) + ZUZU) * (d * (e * f))} (sym (multAssociative (m * o) e d)) }= \n> ( ((m * n) * (f * d) + (m * o) * (e * d)) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => ((m * n) * (f * d) + (m * o) * ZUZU) * (d * (e * f))} (multCommutative e d) }=\n> ( ((m * n) * (f * d) + (m * o) * (d * e)) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => ((m * n) * ZUZU + (m * o) * (d * e)) * (d * (e * f))} (multCommutative f d) }=\n> ( ((m * n) * (d * f) + (m * o) * (d * e)) * (d * (e * f)) )\n> ={ cong {f = \\ ZUZU => ((m * n) * (d * f) + (m * o) * (d * e)) * (d * ZUZU)} (sym toNatMultLemma) }= \n> ( ((m * n) * (d * f) + (m * o) * (d * e)) * (d * (toNat (e' * f'))) )\n> ={ cong {f = \\ ZUZU => ((m * n) * (d * f) + (m * o) * (d * e)) * ZUZU} (sym toNatMultLemma) }= \n> ( ((m * n) * (d * f) + (m * o) * (d * e)) * (toNat (d' * (e' * f'))) )\n> ={ cong {f = \\ ZUZU => ((m * n) * (d * f) + (m * o) * ZUZU) * (toNat (d' * (e' * f')))} \n> (sym toNatMultLemma) }=\n> ( ((m * n) * (d * f) + (m * o) * (toNat (d' * e'))) * (toNat (d' * (e' * f'))) )\n> ={ cong {f = \\ ZUZU => ((m * n) * ZUZU + (m * o) * (toNat (d' * e'))) * (toNat (d' * (e' * f')))} \n> (sym toNatMultLemma) }=\n> ( ((m * n) * (toNat (d' * f')) + (m * o) * (toNat (d' * e'))) * (toNat (d' * (e' * f'))) )\n> QED\n\n\n> {-\n\n> ---}\n\n", "meta": {"hexsha": "9a79d014ccdfc3e4278431083211c87553a14577", "size": 9467, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "Fraction/EqProperties.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/EqProperties.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/EqProperties.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": 44.238317757, "max_line_length": 112, "alphanum_fraction": 0.3739304954, "num_tokens": 4310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6513275219858511}} {"text": "injToDec : {0 f : a -> b} -> ({0 x, y : a} -> f x = f y -> x = y) -> Dec (f x = f y) -> Dec (x = y)\ninjToDec inj $ Yes p = Yes $ inj p\ninjToDec _ $ No up = No $ up . cong f\n", "meta": {"hexsha": "092db52b564f21b0c91aaa2897e5d618806aa3dc", "size": 175, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "DecFromInj.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": "DecFromInj.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": "DecFromInj.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": 43.75, "max_line_length": 99, "alphanum_fraction": 0.4457142857, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6510391973576853}} {"text": "module Main\n\nimport Data.Vect\n\nStringOrInt: (x: 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\naverage: (str: String) -> Double\naverage str = let numWords = wordCount str\n totalLenght = sum(allLengths (words str)) in\n cast totalLenght / cast numWords\n where\n wordCount : String -> Nat\n wordCount str = length (words str)\n\n allLengths : List String -> List Nat\n allLengths strs = map length strs \n\ndouble: Num input => input -> input\ndouble input = input + input\n\ntwice: (f: a -> a) -> (x: a) -> a\ntwice f x = f (f x)\n\npalindrome2: String -> Bool\npalindrome2 x = toLower x == toLower (reverse x)\n\npalindrome4: Nat -> String -> Bool\npalindrome4 len str = if length str > len then palindrome2 str else False\n\npalindrome3: String -> Bool\npalindrome3 x = palindrome4 10 x\n\ncounts: String -> (Nat, Nat)\ncounts str = let numOfWords = length (words str)\n numOfChars = length str in\n (numOfWords, numOfChars)\n\ntop_ten: Ord a => List a -> List a\ntop_ten list = let sorted = reverse (sort list)\n topTen = take 10 sorted in\n topTen\n\nover_length: Nat -> List String -> Nat\nover_length len list = length (filter (\\x => length(x) > len) list)\n\nallLengths: Vect len String -> Vect len Nat\nallLengths [] = []\nallLengths (x :: xs) = length x :: allLengths xs\n\ninsertList: Ord elem => elem -> (xsSorted : Vect len elem) -> Vect (S len) elem\ninsertList x [] = [x]\ninsertList x (y :: xs) = if x < y\n then x :: y :: xs\n else y :: insertList x xs\n\ninsSort: Ord elem => Vect n elem -> Vect n elem\ninsSort [] = []\ninsSort (x :: tail) =\n let\n sortedTail = insSort tail\n in\n insertList x sortedTail\n\ntotal my_length: List a -> Nat\nmy_length [] = 0\nmy_length (x :: xs) = 1 + my_length xs\n\ntotal pushToEnd : a -> List a -> List a\npushToEnd x [] = [x]\npushToEnd x (y :: ys) = y :: pushToEnd x ys\n\ntotal my_reverse: List a -> List a\nmy_reverse [] = []\nmy_reverse (x :: xs) =\n let reversed = my_reverse xs\n in pushToEnd x reversed\n\ntotal my_map: (a -> b) -> List a -> List b\nmy_map f [] = []\nmy_map f (x :: xs) = f x :: my_map f xs\n\ntotal my_vect_map: (a -> b) -> Vect n a -> Vect n b\nmy_vect_map f [] = []\nmy_vect_map f (x :: xs) = f x :: my_vect_map f xs\n\ntotal createEmpties : Vect n (Vect 0 elem)\ncreateEmpties = replicate _ []\n\ntotal transposeHelper : (x : Vect n elem) -> (xsTrans : Vect n (Vect len elem)) -> Vect n (Vect (S len) elem)\ntransposeHelper [] [] = []\ntransposeHelper (x :: xs) (y :: ys) = (x :: y) :: transposeHelper xs ys\n\ntotal transposeMat: Vect m (Vect n elem) -> Vect n (Vect m elem)\ntransposeMat [] = createEmpties\ntransposeMat (x :: xs) =\n let xsTrans = transposeMat xs\n in transposeHelper x xsTrans\n\ndata Direction = North | East | South | West\n\nturnClockwise: Direction -> Direction\nturnClockwise North = East\nturnClockwise East = South\nturnClockwise South = West\nturnClockwise West = North\n\ndata Shape = Triangle Double Double\n | Rectangle Double Double\n | Circle Double\n\narea: Shape -> Double\narea (Triangle base height) = 0.5 * base * height\narea (Rectangle length height) = length * height\narea (Circle radius) = pi * radius * radius\n\ndata BSTree : Type -> Type where\n Leaf : Ord elem => BSTree elem\n Node : Ord elem => (left: BSTree elem) -> (val: elem) -> (right: BSTree elem) -> BSTree elem\n\ntotal insertTree: elem -> BSTree elem -> BSTree elem\ninsertTree x Leaf = Node Leaf x Leaf\ninsertTree x orig@(Node left val right) =\n case compare x val of\n LT => Node (insertTree x left) val right\n EQ => orig\n GT => Node left val (insertTree x right)\n\nlistToTree: Ord a => List a -> BSTree a\nlistToTree [] = Leaf\nlistToTree (x :: xs) =\n let tailAsTree = listToTree xs\n in insertTree x tailAsTree\n\ntreeToList: BSTree a -> List a\ntreeToList Leaf = []\ntreeToList (Node left val right) =\n let leftPart = treeToList left\n rightPart = val :: treeToList right\n in leftPart ++ rightPart\n\ndata Expr = Val Int \n | Add Expr Expr\n | Sub Expr Expr\n | Mult Expr Expr\n\ntotal evaluate: Expr -> Int\nevaluate (Val value) = value\nevaluate (Add l r) = evaluate l + evaluate r\nevaluate (Sub l r) = evaluate l - evaluate r\nevaluate (Mult l r) = evaluate l * evaluate r\n\ntotal maxMaybe: Ord a => Maybe a -> Maybe a -> Maybe a\nmaxMaybe Nothing Nothing = Nothing\nmaxMaybe Nothing (Just x) = Just x\nmaxMaybe (Just x) Nothing = Just x\nmaxMaybe (Just x) (Just y) =\n let max = if x > y then x else y\n in Just max\n\ndata Picture = Primitive Shape\n | Combine Picture Picture\n | Rotate Double Picture\n | Translate Double Double Picture\n\ntotal biggestTriangle: Picture -> Maybe Double\nbiggestTriangle (Primitive shape@(Triangle x y)) = Just(area shape)\nbiggestTriangle (Primitive (Rectangle x y)) = Nothing\nbiggestTriangle (Primitive (Circle x)) = Nothing\nbiggestTriangle (Combine left right) =\n let maybeLeft = biggestTriangle left\n maybeRight = biggestTriangle right \n in maxMaybe maybeLeft maybeRight\nbiggestTriangle (Rotate _ pic) = biggestTriangle pic\nbiggestTriangle (Translate _ _ pic) = biggestTriangle pic\n\ndata PowerSource = Petrol | Pedal\ndata Vehicle : PowerSource -> Type where\n Bicycle: Vehicle Pedal\n Car : (fuel: Nat) -> Vehicle Petrol\n Bus : (fuel: Nat) -> Vehicle Petrol\n\nwheels : Vehicle _ -> Nat\nwheels Bicycle = 2\nwheels Car = 4\nwheels Bus = 4\n\nrefuel: Vehicle Petrol -> Vehicle Petrol\nrefuel (Car _) = Car 100\nrefuel (Bus _) = Bus 200\nrefuel Bicycle impossible\n\nappend_nil : Vect m elem -> Vect (plus m 0) elem\nappend_nil {m} xs = rewrite plusZeroRightNeutral m in xs\n\nappend_xs : Vect (S (m + len)) elem -> Vect (plus m (S len)) elem\nappend_xs {m} {len} xs = rewrite sym (plusSuccRightSucc m len) in xs\n\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)\n\ntotal my_zip : Vect n a -> Vect n b -> Vect n (a, b)\nmy_zip [] [] = []\nmy_zip (x :: xs) (y :: ys) = (x, y) :: zip xs ys\n\ntryIndex : Integer -> Vect n a -> Maybe a\ntryIndex {n} i vector =\n case integerToFin i n of\n Nothing => Nothing\n (Just idx) => Just (index idx vector)\n\nvectTake: (n: Nat) -> Vect (n + m) elem -> Vect n elem\nvectTake Z xs = []\nvectTake (S k) (x :: xs) = x :: vectTake k xs\n\ntotal sumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a\nsumEntries {n} pos left right =\n case integerToFin pos n of\n Nothing => Nothing\n (Just x) => let leftVal = index x left \n rightVal = index x right\n in Just (leftVal + rightVal)\n \n\nmain : IO ()\nmain = repl \"\\n> \" reverse\n\n", "meta": {"hexsha": "bc3db716130ae1ac0424e53088e67f56673a647a", "size": 6909, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "hello.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": "hello.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": "hello.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": 29.2754237288, "max_line_length": 109, "alphanum_fraction": 0.6361267911, "num_tokens": 1959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738152021788, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.650955435379288}} {"text": "module PlusComm\n\n%access export\n%default total\n\nnamespace Conat\n %access public export\n\n codata Conat : Type where\n Coz : Conat\n Cos : Conat -> Conat\n\n codata Bisimulation : Conat -> Conat -> Type where\n Biz : Bisimulation Coz Coz\n Bis : {a : Conat} -> {b : Conat} ->\n (Bisimulation a b) ->\n (Bisimulation (Cos a) (Cos b))\n\n MuGen : Conat\n MuGen = Cos MuGen\n\nmuGenSucc : Bisimulation (Cos MuGen) MuGen\nmuGenSucc = Bis muGenSucc\n\npublic export\nAdd : Conat -> Conat -> Conat\nAdd Coz Coz = Coz\nAdd (Cos a) Coz = Cos a\nAdd Coz (Cos b) = Cos b\nAdd (Cos a) (Cos b) = Cos $ Cos $ Add a b\n\nbiX : (x : Conat) -> Bisimulation x x\nbiX Coz = Biz\nbiX (Cos x) = Bis $ biX x\n\ntotal\nplusCommutative : (a : Conat) -> (b : Conat) -> Bisimulation (Add a b) (Add b a)\nplusCommutative Coz Coz = Biz\nplusCommutative Coz (Cos y) = biX $ Cos y\nplusCommutative (Cos x) Coz = biX $ Cos x\nplusCommutative (Cos x) (Cos y) = Bis $ Bis $ plusCommutative x y\n", "meta": {"hexsha": "dd593dbef83fa3a7ca14fd21ca9ee041230538e8", "size": 999, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codewars/PlusComm.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/PlusComm.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/PlusComm.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": 23.7857142857, "max_line_length": 80, "alphanum_fraction": 0.6166166166, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6509551339136487}} {"text": "||| In this Kata you'll learn Bisimulation\nmodule BisiProof\n\n%default total\n%access export\n\nnamespace Bisimulation\n\n\t--This is the definition of Bisimulation: the inductive parts should\n\t--equivalent, and the coinductive parts should bisimulate.\n\t--With Cubical Model we can prove that Bisimulation is an equivlance,\n\t--aka Coinductive Proof Principle.\n\t--However, you don't have Cubical Model in Idris :(\n\n\tinfixr 10 :=:\n\tpublic export\n\tcodata Bisimulation : (x : Stream a) -> (y : Stream a) -> Type where\n\t\t(:=:) : {x : Stream a} -> {y : Stream a} ->\n\t\t\t\t\t\t(head x = head y) ->\n\t\t\t\t\t\t(Bisimulation (tail x) (tail y)) ->\n\t\t\t\t\t\t(Bisimulation x y)\n\n||| Example: consider an infinite list of ones\nOnes : Stream Nat\nOnes = 1 :: Ones\n\nonesBisimulation : Bisimulation Ones Ones\nonesBisimulation = Refl :=: onesBisimulation\n\npublic export\nOdd : Stream a -> Stream a\nOdd l = head (tail l) :: Odd (tail (tail l))\n\npublic export\nEven : Stream a -> Stream a\nEven l = head l :: Even (tail (tail l))\n\npublic export\nMerge : Stream a -> Stream a -> Stream a\nMerge a b = head a :: head b :: Merge (tail a) (tail b)\n\npublic export\nMergeOddEvenIsBisimulation : (x : Stream a) -> Bisimulation (Merge (Even x) (Odd x)) x\nMergeOddEvenIsBisimulation x = Refl :=: Refl :=: MergeOddEvenIsBisimulation (tail . tail $ x)\n", "meta": {"hexsha": "573ba60ea7dc762ec94954c8e759e9ce0b79765f", "size": 1296, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "codewars/BisiProof.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/BisiProof.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/BisiProof.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.8, "max_line_length": 93, "alphanum_fraction": 0.6875, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6508270433137148}} {"text": "module Sortings\n\nimport Data.Fin\nimport Data.Vect\nimport Data.So\n\n%default total\n\n||| Structural inductive rules for prooving that one vector is a permutation of another.\npublic export\ndata Permutation : Vect n a -> Vect n a -> Type where\n EmptyPerm : Permutation [] []\n InsertPerm : {xs : Vect _ a} -> {lys : Vect lm a} -> {rys : Vect rm a}\n -> Permutation xs (lys ++ rys) -> Permutation (x::xs) (rewrite plusSuccRightSucc lm rm in lys ++ x::rys)\n\npublic export\ndata Sorted : {auto ord : Ord a} -> Vect n a -> Type where\n Empty : Ord a => Sorted []\n Singleton : Ord a => Sorted [x]\n Comp : {x, y : a} -> Sorted {ord} (x::xs) -> So (y <= x) -> Sorted (y::x::xs)\n\nexport\nsoAbsurd : So b -> So (not b) -> Void\nsoAbsurd sb snb with (sb)\n | Oh = uninhabited snb\n\nexport\nsoNotToNotSo : So (not b) -> Not (So b)\nsoNotToNotSo = flip soAbsurd\n\nexport\nisSorted : Ord a => (xs : Vect n a) -> (s : Bool ** if s then Sorted xs else Not (Sorted xs))\nisSorted [] = (True ** Empty)\nisSorted [_] = (True ** Singleton)\nisSorted (y::x::xs) = case choose (y <= x) of\n Left yx => case isSorted (x::xs) of\n (True ** prf) => (True ** Comp prf yx)\n (False ** prf) => (False ** \\(Comp s _) => prf s)\n Right yxNEq => (False ** \\(Comp _ yxEq) => soAbsurd yxEq yxNEq)\n\npublic export\nsorted : Ord a => Vect n a -> Bool\nsorted [] = True\nsorted [_] = True\nsorted (y::x::xs) = (y <= x) && sorted (x::xs)\n\nexport\ntotal doubleNotDisappears : (b : Bool) -> not (not b) = b\ndoubleNotDisappears True = Refl\ndoubleNotDisappears False = Refl\n\nexport\ntakeSoConjPart : So b -> So (b && c) -> So c\ntakeSoConjPart sb sbc with (sb)\n takeSoConjPart _ sbc | Oh with (sbc)\n takeSoConjPart _ _ | Oh | Oh = Oh\n\nexport\nsoConjAbsurd : So b -> So (not b && c) -> Void\nsoConjAbsurd sb sbc with (sb)\n | Oh = uninhabited sbc\n\nexport total\nsplitSoConj : So (b && c) -> (So b, So c)\nsplitSoConj {b=True} sbc with (sbc)\n | Oh = (Oh, Oh)\n\nnamespace SortedProperties\n export\n valueToType : Ord a => So (Sortings.sorted xs) -> Sorted xs\n valueToType {xs=[]} _ = Empty\n valueToType {xs=[_]} _ = Singleton\n valueToType {xs=y::x::xs} so = let (soyx, soxxs) = splitSoConj so in\n Comp (valueToType soxxs) soyx\n\n export\n typeToValue : Ord a => Sorted xs -> So (Sortings.sorted xs)\n typeToValue = ?typeToValue_impl\n\n export\n notValueToNotType : Ord a => So (not $ Sortings.sorted xs) -> Not (Sorted xs)\n notValueToNotType = ?notValueToNotType_impl\n\n export\n notTypeToNotValue : Ord a => Not (Sorted xs) -> So (not $ Sortings.sorted xs)\n notTypeToNotValue = ?notTypeToNotValue_impl\n\n||| Sorting with direct encoding of first-order logic formulae of sortedness properties\nexport\nsortDirect : Ord a => (v : Vect n a) -> (s : Vect n a ** (v `Permutation` s, Sorted s))\nsortDirect = ?sortDirect_impl\n", "meta": {"hexsha": "c804d7c9c4b4106c0c9e063d0bfa318b2943ebe7", "size": 2934, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Sortings.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": "Sortings.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": "Sortings.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": 31.8913043478, "max_line_length": 116, "alphanum_fraction": 0.6114519427, "num_tokens": 950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6507218977800293}} {"text": "-- Idea: use types as first class language construct: i.e. allow them to be passed as arguments,\n-- returned from functions and assigned to variables.\n-- Idea first-class language constructs:\n-- let's start with C:\n-- numbers are first-class\n-- pointers are first-class\n-- arrays are not (can not be returned or assigned)\n-- functions are not (you have function pointers but you can not have a \n-- function that returns a function)\n-- Python:\n-- numbers, lists, functions, but not types.\n\n-- Types are used at multiple levels:\n-- in assembley they represent how a register should be interpreted\n-- (signed, unsigned, 16, 32 bit, etc, float, double, etc)\n-- at compiler level, how different parts of the program interpret data at runtime\n-- (how many bytes to push to the stash for another function to act on them)\n-- by the programmer: to abstract away various concepts that they use when\n-- designing the program (humans don't think in numbers, they think in\n-- abstractions)\n\n-- What is type driven development: use types as a \"plan\". In the same way as we\n-- use UML diagrams, use types to specify the input and output of functions.\n\n-- Type, define refine loop:\n-- start with generic type (say Matrix), define your adder function,\n-- notice invalid cases => refine your type.\n\n-- Exercise\n-- Vect n elem -> Vect n elem\n-- reverse function\n-- Vect n elem -> Vect (n * 2) elem\n-- duplicate each element?\n-- Vect (1 + n) elem -> Vect n elem\n-- remove an element\n-- Note: this is something we can not do in most other langauges (o.l.):\n-- specify Vect (1 + n) elem as a type\n-- Bounded n, Vect n elem -> elem\n-- get the nth element.\n-- Note: this starts illustrating the power of dependent types:\n-- Bounded n is a property, meaning it is a type that poves that\n-- the number is between 0 and n-1. We can not express this in o.l.\n\n-- Why pure functions? Super easy to debug and to reason about:\n-- output based only on inputs.\n\n-- Environment setup: vim-idris\n-- to open idris-response buffer, i\n-- if closed, just :b idris-response\n-- bindings:\n-- t: type\n-- e: eval window\n-- r: reload and typecheck\n-- h: help\n--\n-- d: define\n-- c: case split\n\nmodule Chapter1\n\nmain : IO ()\nmain = putStrLn \"Hello, Idris World!\"\n\n-- Holes\nmain2 : IO ()\nmain2 = putStrLn ?greeting -- position cursor on ?greeting and ask for type.\n\nmain3 : IO ()\n--main3 = putStrLn 'x' --type error\n--main3 = putStrLn (?convert 'x')\nmain3 = putStrLn (cast 'x')\n\n-- First class types\nStringOrInt : Bool -> Type -- leader_d for define\n--StringOfInt x = ?StringOfInt_rhs -- leader_c for case split\nStringOrInt False = String\nStringOrInt True = Int -- leader_c for case split\n\ngetStringOrInt : (x : Bool) -> StringOrInt x -- here we go :)\ngetStringOrInt False = \"Ninety four\"\ngetStringOrInt True = 94\n\n\nvalToString : (x : Bool) -> StringOrInt x -> String\nvalToString x y = case x of\n True => cast val\n False => val\n\n\n", "meta": {"hexsha": "7459818bd60c5376e4bc8ed3a96826ec12740f93", "size": 3006, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Chapter1.idr", "max_stars_repo_name": "neduard/type-driven-development", "max_stars_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter1.idr", "max_issues_repo_name": "neduard/type-driven-development", "max_issues_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter1.idr", "max_forks_repo_name": "neduard/type-driven-development", "max_forks_repo_head_hexsha": "38aba26d97c196a06d99e8aedec7cb779c61c49b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4, "max_line_length": 96, "alphanum_fraction": 0.6823020625, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6507077884098382}} {"text": "> module SequentialDecisionProblems.FullTheory\n\n> import SequentialDecisionProblems.CoreTheory\n\n> import Sigma.Sigma\n> import Sigma.Operations\n\n> %default total\n> %access public export\n> %auto_implicits off\n\n> -- %hide Prelude.Nat.LTE\n\n\n* Preliminaries\n\nIn order to prove the correctness of |backwardsInduction| (see\n|CoreTheory|), we need a number of additional assumptions, which we\nintroduce here. These result in proof obligations for the user of the\nframework. As in |CoreTheory|, they are represented as meta-variables\n(or ``holes''). Once the user has discharged these obligations, type\nchecking this file will prove the optimality of |backwardsInduction|\n(with some caveats related to the current Idris implementation).\n\n\n* |LTE|\n\nThe binary relation introduced in |CoreTheory| for comparing values of\nsequences of policies has to be a preorder:\n\n> reflexiveLTE : (a : Val) -> a `LTE` a\n> transitiveLTE : (a : Val) -> (b : Val) -> (c : Val) -> a `LTE` b -> b `LTE` c -> a `LTE` c\n\nAdditionally, |plus| is required to be monotonic with respect to |LTE|:\n\n> monotonePlusLTE : {a, b, c, d : Val} -> a `LTE` b -> c `LTE` d -> (a `plus` c) `LTE` (b `plus` d)\n\n\n* |meas|\n\nThe function |meas| introduced in |CoreTheory| to describe how a\ndecision maker measures the possible rewards entailed by (lists,\nprobability distributions, etc. of) possible next states is required to\nfulfill a monotonicity condition:\n\n> measMon : {A : Type} ->\n> (f : A -> Val) -> (g : A -> Val) ->\n> ((a : A) -> (f a) `LTE` (g a)) ->\n> (ma : M A) -> meas (fmap f ma) `LTE` meas (fmap g ma)\n\nIn a nutshell, |measMon| says that, if |ma| and |mb| are similar\n|M|-structures and |ma| is smaller or equal to |mb|, than it cannot be\nthe case that the measure of |ma| is greater than the measure of |mb|.\n\nThis conditions was originally formalized by Ionescu in [2] to give a\nconsistent meaning to harm measures in vulnerability studies.\n\n\n* |cvalargmax|\n\nThe function |cvalargmax| introduced in |CoreTheory| must deliver\noptimal controls. We need the function |cvalmax|, returning the value\nof those optimal controls, in order to fully specify |cvalargmax|:\n\n> cvalmax : {t, n : Nat} -> \n> (x : State t) -> (r : Reachable x) -> (v : Viable (S n) x) ->\n> (ps : PolicySeq (S t) n) -> Val\n\n\n> cvalargmaxSpec : {t : Nat} -> {n : Nat} ->\n> (x : State t) -> (r : Reachable x) -> \n> (v : Viable (S n) x) -> (ps : PolicySeq (S t) n) ->\n> cvalmax x r v ps = cval x r v ps (cvalargmax x r v ps)\n\n> cvalmaxSpec : {t : Nat} -> {n : Nat} ->\n> (x : State t) -> (r : Reachable x) -> \n> (v : Viable (S n) x) -> (ps : PolicySeq (S t) n) ->\n> (y : GoodCtrl t x n) ->\n> (cval x r v ps y) `LTE` (cvalmax x r v ps)\n\nThe reason for using these very specific functions, instead of more\ngeneral |argmax|, |max|, |argmaxSpec| and |maxSpec| like for instance\n\n< argmax : {t : Nat} -> {n : Nat} ->\n< (x : State t) -> (Viable (S n) x) ->\n< (f : GoodCtrl t x n -> Val) -> GoodCtrl t x n\n\n< max : {t : Nat} -> {n : Nat} ->\n< (x : State t) -> (Viable (S n) x) ->\n< (f : GoodCtrl t x n -> Val) -> Val\n\n< argmaxSpec : {t : Nat} -> {n : Nat} ->\n< (x : State t) -> (v : Viable (S n) x) ->\n< (f : GoodCtrl t x n -> Val) ->\n< max x v f = f (argmax x v f)\n\n< maxSpec : {t : Nat} -> {n : Nat} ->\n< (x : State t) -> (v : Viable (S n) x) ->\n< (f : GoodCtrl t x n -> Val) -> (y : GoodCtrl t x n) ->\n< (f y) `LTE` (max x v f)\n\nis that optimisation is, in most case, not computable. The assumptions\non |cvalmax| and |cvalargmax| are the minimal requirements for the\ncomputability of optimal extensions. Anything more general risks being\nnon-implementable.\n\n\n* The proof of correctness of |backwardsInduction|:\n\n** Policy sequences of length zero are optimal\n\n> |||\n> nilOptPolicySeq : OptPolicySeq Nil\n> nilOptPolicySeq ps' x r v = reflexiveLTE zero\n\n\n** Bellman's principle of optimality:\n\n> |||\n> Bellman : {t, m : Nat} -> \n> (ps : PolicySeq (S t) m) -> OptPolicySeq ps ->\n> (p : Policy t (S m)) -> OptExt ps p ->\n> OptPolicySeq (p :: ps)\n\n> Bellman {t} {m} ps ops p oep = opps where\n> opps : OptPolicySeq (p :: ps)\n> {-\n> opps (p' :: ps') x r v = transitiveLTE (val x r v (p' :: ps')) \n> (val x r v (p' :: ps)) \n> (val x r v (p :: ps)) \n> s4 s5 where\n> -}\n> opps x r v (p' :: ps') = transitiveLTE (val x r v (p' :: ps')) \n> (val x r v (p' :: ps)) \n> (val x r v (p :: ps)) \n> s4 s5 where\n> gy' : GoodCtrl t x m\n> gy' = p' x r v \n> y' : Ctrl t x\n> y' = ctrl gy'\n> mx' : M (State (S t))\n> mx' = nexts t x y'\n> av' : All (Viable m) mx'\n> av' = allViable gy'\n> f' : PossibleNextState x (ctrl gy') -> Val\n> f' = sval x r v gy' ps'\n> f : PossibleNextState x (ctrl gy') -> Val\n> f = sval x r v gy' ps\n> s1 : (x' : State (S t)) -> (r' : Reachable x') -> (v' : Viable m x') ->\n> val x' r' v' ps' `LTE` val x' r' v' ps\n> -- s1 x' r' v' = ops ps' x' r' v'\n> s1 x' r' v' = ops x' r' v' ps' \n> s2 : (z : PossibleNextState x (ctrl gy')) -> (f' z) `LTE` (f z)\n> s2 (MkSigma x' x'emx') = \n> monotonePlusLTE (reflexiveLTE (reward t x y' x')) (s1 x' r' v') where \n> ar' : All Reachable mx'\n> ar' = reachableSpec1 x r y'\n> r' : Reachable x'\n> r' = allElemSpec0 x' mx' ar' x'emx'\n> v' : Viable m x'\n> v' = allElemSpec0 x' mx' av' x'emx'\n> s3 : meas (fmap f' (tagElem mx')) `LTE` meas (fmap f (tagElem mx'))\n> s3 = measMon f' f s2 (tagElem mx')\n> s4 : val x r v (p' :: ps') `LTE` val x r v (p' :: ps)\n> s4 = s3\n> s5 : val x r v (p' :: ps) `LTE` val x r v (p :: ps)\n> -- s5 = oep p' x r v\n> s5 = oep x r v p'\n\n\n> |||\n> optExtLemma : {t, n : Nat} -> \n> (ps : PolicySeq (S t) n) -> OptExt ps (optExt ps)\n> {- \n> optExtLemma {t} {n} ps p' x r v = s5 where\n> p : Policy t (S n)\n> p = optExt ps\n> gy : GoodCtrl t x n\n> gy = p x r v\n> y : Ctrl t x\n> y = ctrl gy\n> av : All (Viable n) (nexts t x y)\n> av = allViable gy\n> gy' : GoodCtrl t x n\n> gy' = p' x r v\n> y' : Ctrl t x\n> y' = ctrl gy'\n> av' : All (Viable n) (nexts t x y')\n> av' = allViable gy'\n> f : PossibleNextState x (ctrl gy) -> Val\n> f = sval x r v gy ps\n> f' : PossibleNextState x (ctrl gy') -> Val\n> f' = sval x r v gy' ps\n> s1 : cval x r v ps gy' `LTE` cvalmax x r v ps\n> s1 = cvalmaxSpec x r v ps gy'\n> s2 : cval x r v ps gy' `LTE` cval x r v ps (cvalargmax x r v ps)\n> s2 = replace {P = \\ z => (cval x r v ps gy' `LTE` z)} (cvalargmaxSpec x r v ps) s1\n> -- the rest of the steps are for the (sort of) human reader\n> s3 : cval x r v ps gy' `LTE` cval x r v ps gy\n> s3 = s2\n> s4 : meas (fmap f' (tagElem (nexts t x y'))) `LTE` meas (fmap f (tagElem (nexts t x y)))\n> s4 = s3\n> s5 : val x r v (p' :: ps) `LTE` val x r v (p :: ps)\n> s5 = s4\n> -}\n> optExtLemma {t} {n} ps x r v p' = s5 where\n> p : Policy t (S n)\n> p = optExt ps\n> gy : GoodCtrl t x n\n> gy = p x r v\n> y : Ctrl t x\n> y = ctrl gy\n> av : All (Viable n) (nexts t x y)\n> av = allViable gy\n> gy' : GoodCtrl t x n\n> gy' = p' x r v\n> y' : Ctrl t x\n> y' = ctrl gy'\n> av' : All (Viable n) (nexts t x y')\n> av' = allViable gy'\n> f : PossibleNextState x (ctrl gy) -> Val\n> f = sval x r v gy ps\n> f' : PossibleNextState x (ctrl gy') -> Val\n> f' = sval x r v gy' ps\n> s1 : cval x r v ps gy' `LTE` cvalmax x r v ps\n> s1 = cvalmaxSpec x r v ps gy'\n> s2 : cval x r v ps gy' `LTE` cval x r v ps (cvalargmax x r v ps)\n> s2 = replace {P = \\ z => (cval x r v ps gy' `LTE` z)} (cvalargmaxSpec x r v ps) s1\n> -- the rest of the steps are for the (sort of) human reader\n> s3 : cval x r v ps gy' `LTE` cval x r v ps gy\n> s3 = s2\n> s4 : meas (fmap f' (tagElem (nexts t x y'))) `LTE` meas (fmap f (tagElem (nexts t x y)))\n> s4 = s3\n> s5 : val x r v (p' :: ps) `LTE` val x r v (p :: ps)\n> s5 = s4\n\n** Correctness of backwards induction\n\n> backwardsInductionLemma : (t : Nat) -> (n : Nat) -> OptPolicySeq (backwardsInduction t n)\n> backwardsInductionLemma t Z = nilOptPolicySeq\n> backwardsInductionLemma t (S n) = Bellman ps ops p oep where\n> ps : PolicySeq (S t) n\n> ps = backwardsInduction (S t) n\n> ops : OptPolicySeq ps\n> ops = backwardsInductionLemma (S t) n\n> p : Policy t (S n)\n> p = optExt ps\n> oep : OptExt ps p\n> oep = optExtLemma ps\n\nThus, we can compute provably optimal sequences of policies for\narbitrary SDPs and number of decision steps. \n\n\n> {-\n\n> ---}\n\n\n[1] Bellman, Richard; \"Dynamic Programming\", Princeton University Press,\n 1957\n\n[2] Ionescu, Cezar; \"Vulnerability Modelling and Monadic Dynamical\n Systems\", Freie Universitaet Berlin, 2009\n", "meta": {"hexsha": "ca18e6e33dd260b38413b48e3133eb3764b4f035", "size": 9498, "ext": "lidr", "lang": "Idris", "max_stars_repo_path": "SequentialDecisionProblems/FullTheory.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/FullTheory.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/FullTheory.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.841509434, "max_line_length": 99, "alphanum_fraction": 0.5238997684, "num_tokens": 3401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6503881188605377}} {"text": "data Vect : Nat -> Type -> Type where\n Nil : Vect Z a\n (::) : (x : a) -> (xs : Vect k a) -> Vect (S k) a\n\nEq e => Eq (Vect n e) where\n (==) Nil Nil = True\n (==) (x :: xs) (y :: ys) = (x == y) && (xs == ys)\n (==) _ _ = False\n\nFoldable (Vect n) where\n foldr f acc [] = acc\n foldr f acc (x :: xs) = f x (foldr f acc xs)\n", "meta": {"hexsha": "74321012fbf3f2fa632e2c801867b1acad38078f", "size": 324, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "B_type_driven_development/Week_7/week7_1_p_206_ex_2.idr", "max_stars_repo_name": "JnxF/advanced-software-analysis", "max_stars_repo_head_hexsha": "3ad336918f4aa6272d6d2feebf4e02ee264e8e0b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-26T11:16:02.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T11:20:06.000Z", "max_issues_repo_path": "B_type_driven_development/Week_7/week7_1_p_206_ex_2.idr", "max_issues_repo_name": "JnxF/advanced-software-analysis", "max_issues_repo_head_hexsha": "3ad336918f4aa6272d6d2feebf4e02ee264e8e0b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "B_type_driven_development/Week_7/week7_1_p_206_ex_2.idr", "max_forks_repo_name": "JnxF/advanced-software-analysis", "max_forks_repo_head_hexsha": "3ad336918f4aa6272d6d2feebf4e02ee264e8e0b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9230769231, "max_line_length": 51, "alphanum_fraction": 0.462962963, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.650388111426221}} {"text": "\nmodule Step\n\n-- Relation 'Step' for reducing terms\n-- in the simply-typed lambda calculus.\n \n\nimport Term\nimport Subst\n\n\n%default total\n%access public export\n\n\n\n-------------------------------------------------------------------------\n-- Begin: SMALL-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n\ndata Step : (x : Term) -> (y : Term) -> Type where\n StApp1 : Step t1 t1' ->\n Step (TApp t1 t2) (TApp t1' t2)\n --\n StApp2 : Value v -> Step t2 t2' ->\n Step (TApp v t2) (TApp v t2')\n --\n StBeta : Value v -> \n Step (TApp (TAbs t) v) (subst v Z t)\n --\n StRec : Step t t' -> \n Step (TRec t t0 t1) (TRec t' t0 t1)\n --\n StRecZero : Step (TRec TZero t0 t1) t0\n --\n StRecSucc : Value (TSucc n) ->\n Step (TRec (TSucc n) t0 t1) \n (TApp ((TApp t1) n) (TRec n t0 t1))\n --\n StSucc : Step t t' -> \n Step (TSucc t) (TSucc t')\n --\n StPred : Step t t' -> \n Step (TPred t) (TPred t')\n -- \n StPredZero : Step (TPred TZero) TZero\n --\n StPredSucc : Value v ->\n Step (TPred (TSucc v)) v\n --\n StIfz : Step t1 t1' ->\n Step (TIfz t1 t2 t3) (TIfz t1' t2 t3)\n --\n StIfzZero : Step (TIfz TZero t1 t2) t1\n --\n StIfzSucc : Value v ->\n Step (TIfz (TSucc v) t1 t2) t2\n \n-- End: SMALL-STEP EVALUATION RELATION FOR TERMS IN THE LAMBDA CALCULUS\n-----------------------------------------------------------------------\n\n\n\n\n--------------------------------\n-- Begin: VALUES ARE IRREDUCIBLE\n\nvalueIrreducible : (e : Term) ->\n Value e -> \n (Step e e' -> Void)\nvalueIrreducible TZero VZero step impossible\nvalueIrreducible (TSucc e) (VSucc v) (StSucc step) =\n valueIrreducible e v step\nvalueIrreducible (TAbs e) VAbs step impossible\n\n-- End: VALUES ARE IRREDUCIBLE\n------------------------------\n\n\n\n\n----------------------------\n-- Begin: TRANSITIVE CLOSURE\n\n-- Data type for representing the transistive closure\n-- of an arbitrary relation 'rel : a -> a -> Type'.\nusing (a : Type, rel : a -> a -> Type)\n data TransCl : {a : Type} -> (a -> a -> Type) -> (a -> a -> Type) where\n TClRefl : (x : a) -> TransCl rel x x \n TClSingle : rel x y -> TransCl rel x y\n TClTrans : TransCl rel x y -> TransCl rel y z -> TransCl rel x z\n\n \n-- Data type specifically for representing the\n-- transitive closure of the 'Step' relation.\ndata TransStep : Term -> Term -> Type where\n TStRefl : (e : Term) -> TransStep e e\n TStTrans : {e : Term} -> {e' : Term} -> {e'' : Term} ->\n Step e e' -> TransStep e' e'' -> TransStep e e''\n\n\n-- 'TransStep' is indeed transitive.\ntransStepTransitive : TransStep e1 e2 -> TransStep e2 e3 -> TransStep e1 e3\ntransStepTransitive (TStRefl _) y = y\ntransStepTransitive (TStTrans x y) z = TStTrans x (transStepTransitive y z)\n\n\n-- Correctness proof for 'TransStep', i.e.: TransStep => (TransCl Step).\ntransStepCorrect : TransStep e e' -> TransCl Step e e'\ntransStepCorrect (TStRefl e) = TClRefl e\ntransStepCorrect (TStTrans x y) = TClTrans (TClSingle x) (transStepCorrect y)\n\n\n-- Completeness proof for 'TransStep', i.e.: (TransCl Step) => TransStep.\ntransStepComplete : TransCl Step e e' -> TransStep e e'\ntransStepComplete (TClRefl e) = TStRefl e\ntransStepComplete (TClSingle x) = TStTrans x (TStRefl _)\ntransStepComplete (TClTrans x z) = transStepTransitive (transStepComplete x)\n (transStepComplete z)\n\n-- Operators for compact notation:\ninfixl 10 .++.\n(.++.) : TransStep e1 e2 -> TransStep e2 e3 -> TransStep e1 e3\n(.++.) = transStepTransitive \n\ninfixl 10 .+.\n(.+.) : TransStep e1 e2 -> Step e2 e3 -> TransStep e1 e3\n(.+.) x y = x .++. (TStTrans y (TStRefl _))\n\n-- End: TRANSITIVE CLOSURE\n--------------------------\n\n\n\n\n--------------------\n-- Begin: CONGRUENCE\n\n-- Construction of terms is a congruence\n-- for the transitive closure of 'Step'.\n\n-- Congruence lemma for '(TApp _ e)':\ncongApp1 : TransStep e1 e2 -> TransStep (TApp e1 e) (TApp e2 e)\ncongApp1 (TStRefl e1) = TStRefl (TApp e1 _)\ncongApp1 (TStTrans x y) = TStTrans (StApp1 x) (congApp1 y)\n\n\n-- Congruence lemma for '(TApp e _)':\ncongApp2 : {v : Value e} -> \n TransStep e1 e2 -> TransStep (TApp e e1) (TApp e e2)\ncongApp2 (TStRefl e1) = TStRefl (TApp _ e1)\ncongApp2 {v = v} (TStTrans x y) = TStTrans (StApp2 v x) (congApp2 {v = v} y)\n\n\n-- Congruence lemma for '(Succ _)':\ncongSucc : TransStep e1 e2 -> TransStep (TSucc e1) (TSucc e2)\ncongSucc (TStRefl e1) = TStRefl (TSucc e1)\ncongSucc (TStTrans x y) = TStTrans (StSucc x) (congSucc y)\n\n\n-- Congruence lemma for '(Pred _)':\ncongPred : TransStep e1 e2 -> TransStep (TPred e1) (TPred e2)\ncongPred (TStRefl e1) = TStRefl (TPred e1)\ncongPred (TStTrans x y) = TStTrans (StPred x) (congPred y)\n\n\n-- Congruence lemma for '(Ifz _ ez es)':\ncongIfz : TransStep e1 e2 -> TransStep (TIfz e1 ez es) (TIfz e2 ez es)\ncongIfz (TStRefl e1) = TStRefl (TIfz e1 _ _)\ncongIfz (TStTrans x y) = TStTrans (StIfz x) (congIfz y)\n\n\n-- Congruence lemma for '(TRec _ e0 e1)':\ncongRec : TransStep e e' -> TransStep (TRec e e0 e1) (TRec e' e0 e1)\ncongRec (TStRefl e) = TStRefl (TRec e _ _)\ncongRec (TStTrans x y) = TStTrans (StRec x) (congRec y)\n\n-- End: CONGRUENCE\n------------------\n", "meta": {"hexsha": "58d1aba5e166331c295a23f2aeb6774bd6efed79", "size": 5369, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "totality/src/Step.idr", "max_stars_repo_name": "normanrink/PCF", "max_stars_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "totality/src/Step.idr", "max_issues_repo_name": "normanrink/PCF", "max_issues_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "totality/src/Step.idr", "max_forks_repo_name": "normanrink/PCF", "max_forks_repo_head_hexsha": "6b817263fc7d64f0ed0e5535261814d572292192", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9944134078, "max_line_length": 77, "alphanum_fraction": 0.572546098, "num_tokens": 1827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6503881039919042}} {"text": "module Using\n\ninterface MagmaT a where\n op: a -> a -> a\n\ninterface MagmaT a => SemigroupT a where\n assoc: (x, y, z: a) -> (x `op` y) `op` z = x `op` (y `op` z)\n\n[NamedMagma1] MagmaT Bool where\n False `op` False = False\n _ `op` _ = True\n\n[NamedMagma2] MagmaT Bool where\n True `op` True = True\n _ `op` _ = False\n\n[NamedSemigroup1] SemigroupT Bool using NamedMagma1 where\n assoc = ?hole1\n\n[NamedSemigroup2] SemigroupT Bool using NamedMagma2 where\n assoc = ?hole2\n", "meta": {"hexsha": "0fd7c1d7e290ab63f0c287e54da75b6e06532c3f", "size": 482, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "idris2/tests/idris2/reg016/Using.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/reg016/Using.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/reg016/Using.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": 21.9090909091, "max_line_length": 62, "alphanum_fraction": 0.6473029046, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6503851346839941}} {"text": "-- Code modified from Alex Zhukovsky's one from DepTyp telegram chat (https://t.me/c/1062361327/39965)\n-- Code modifiation is mostly a further usage of function extensionality.\n\nrecord State s a where\n constructor MkState\n runState : s -> (a,s)\n\nfunext : {0 f, g : a -> b} -> ((x : a) -> f x = g x) -> f = g\nfunext = believe_me\n\ninjectiveProjections : (0 ab : (a,b)) -> (fst ab, snd ab) = ab\ninjectiveProjections {ab=(x,y)} = Refl\n\nstateMap : (a -> b) -> (s -> (a, s)) -> s -> (b, s)\nstateMap f = (mapFst f .)\n\nstateMapIdIsId : stateMap Prelude.id rs = rs\nstateMapIdIsId = funext \\x => rewrite sym $ injectiveProjections $ rs x in Refl\n\nFunctor (State s) where\n map f (MkState rs) = MkState $ stateMap f rs\n\ninterface Functor f => VerifiedFunctor (0 f : Type -> Type) where\n functorIdentity : {0 a : Type} -> map {f} {a} Prelude.id = Prelude.id\n\nVerifiedFunctor (State s) where\n functorIdentity = funext \\(MkState _) => cong MkState stateMapIdIsId\n", "meta": {"hexsha": "2de571b8348fc5ee64a5018368c02d6529414050", "size": 950, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "ZhukFunext.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": "ZhukFunext.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": "ZhukFunext.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": 33.9285714286, "max_line_length": 102, "alphanum_fraction": 0.6663157895, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6500470517750724}} {"text": "module Data.Functor\n\n%access public\n%default total\n\n-- class Functor (f : Type -> Type) where\n-- map : (a -> b) -> f a -> f b\n\ninstance Functor (\\a => c -> a) where\n map f g = f . g\n\n-- FIXME:\n-- instance Functor (\\a => (a, c)) where\n-- map f (x,y) = (f x, y)\n\n-- instance Functor (Either a) where\n-- map _ (Left x) = Left x\n-- map f (Right x) = Rignt $ f x\n\n\n\n-- functor_law_1: map id == id\n-- functor_law_2: map (f.g) == map f . map g\n\nclass CoFunctor (f : Type -> Type) where\n map' : f b -> f a -> (b -> a)\n\n\n\n-- contravariant_law1: contramap id == id\n-- contravariant_law2: contramap (g.f) = contramap f . contramap g\nclass Contravariant (f : Type -> Type) where\n contramap : (a -> b) -> f b -> f a\n\ninstance Contravariant (\\b => b -> c) where\n contramap f g = g . f\n\n\nclass CoContravariant (f : Type -> Type) where\n contramap' : f a -> f b -> (b -> a)\n\n\nclass Bifunctor (f : Type -> Type -> Type) where\n bimap : (a -> b) -> (c -> d) -> f a c -> f b d\n\ninstance Bifunctor Either where\n bimap f _ (Left x) = Left $ f x\n bimap _ g (Right x) = Right $ g x\n\n\n\n\nclass CoBifunctor (f : Type -> Type -> Type) where\n bimap' : f b d -> f a c -> (d -> c) -> (b -> a)\n\n\nclass Profunctor (f : Type -> Type -> Type) where\n dimap : (a -> b) -> (c -> d) -> f b c -> f a d\n\ninstance Profunctor (\\b => \\c => b -> c) where\n dimap f g h = g . h . f\n\nclass CoProfunctor (f : Type -> Type -> Type) where\n dimap' : f a d -> f b c -> (d -> c) -> (b -> a)\n\n\n", "meta": {"hexsha": "d5c73a3928a3bad9a55325a9ef8bf594629e7088", "size": 1457, "ext": "idr", "lang": "Idris", "max_stars_repo_path": "Data/Functor.idr", "max_stars_repo_name": "seagull-kamome/idris-toy", "max_stars_repo_head_hexsha": "5e4b7c5969fab57dedac314d972211affc6e4785", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-06-04T16:11:33.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-04T16:11:33.000Z", "max_issues_repo_path": "Data/Functor.idr", "max_issues_repo_name": "seagull-kamome/idris-toy", "max_issues_repo_head_hexsha": "5e4b7c5969fab57dedac314d972211affc6e4785", "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.idr", "max_forks_repo_name": "seagull-kamome/idris-toy", "max_forks_repo_head_hexsha": "5e4b7c5969fab57dedac314d972211affc6e4785", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7462686567, "max_line_length": 66, "alphanum_fraction": 0.5490734386, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6500118382464992}}