{"record":{"id":"cec4cf5e7ac24cd3","repo":"TheAlgorithms/Go","slug":"arguments-cannot-be-zero","errorCode":null,"errorMessage":"arguments cannot be zero","messagePattern":"arguments cannot be zero","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"math/liouville.go","lineNumber":22,"sourceCode":"// For any positive integer n, define λ(n) as the sum of the primitive nth roots of unity.\n// It has values in {−1, 1} depending on the factorization of n into prime factors:\n//   λ(n) = +1 if n is a positive integer with an even number of prime factors.\n//   λ(n) = −1 if n is a positive integer with an odd number of prime factors.\n// wikipedia: https://en.wikipedia.org/wiki/Liouville_function\n// time complexity: O(log n)\n// space complexity: O(1)\n// author: Akshay Dubey (https://github.com/itsAkshayDubey)\n// see liouville_test.go\n\npackage math\n\nimport (\n\t\"errors\"\n\n\t\"github.com/TheAlgorithms/Go/math/prime\"\n)\n\nvar ErrNonZeroArgsOnly error = errors.New(\"arguments cannot be zero\")\n\n// Lambda is the liouville function\n// This function returns λ(n) for given number\nfunc LiouvilleLambda(n int) (int, error) {\n\tswitch {\n\tcase n < 0:\n\t\treturn 0, ErrPosArgsOnly\n\tcase n == 0:\n\t\treturn 0, ErrNonZeroArgsOnly\n\tcase len(prime.Factorize(int64(n)))%2 == 0:\n\t\treturn 1, nil\n\tdefault:\n\t\treturn -1, nil\n\t}\n}\n","sourceCodeStart":4,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/math/liouville.go#L4-L38","documentation":"A generic sentinel guard (math.ErrNonZeroArgsOnly) returned when Liouville's function is called with n == 0: the Liouville lambda is only defined over the positive integers, so a zero argument has no factorization to count prime factors from.","triggerScenarios":"Thrown at math/liouville.go:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check n>0 before calling","Return a domain default (e.g. 0) for zero input at the call site","Document the positive-integer-only domain"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}