{"record":{"id":"70fea80404282d27","repo":"TheAlgorithms/Python","slug":"intrinsic-concentration-should-be-positive","errorCode":null,"errorMessage":"Intrinsic concentration should be positive","messagePattern":"Intrinsic concentration should be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/builtin_voltage.py","lineNumber":46,"sourceCode":"    Traceback (most recent call last):\n      ...\n    ValueError: Intrinsic concentration should be positive\n    >>> builtin_voltage(donor_conc=1000, acceptor_conc=3000, intrinsic_conc=2000)\n    Traceback (most recent call last):\n      ...\n    ValueError: Donor concentration should be greater than intrinsic concentration\n    >>> builtin_voltage(donor_conc=3000, acceptor_conc=1000, intrinsic_conc=2000)\n    Traceback (most recent call last):\n      ...\n    ValueError: Acceptor concentration should be greater than intrinsic concentration\n    \"\"\"\n\n    if donor_conc <= 0:\n        raise ValueError(\"Donor concentration should be positive\")\n    elif acceptor_conc <= 0:\n        raise ValueError(\"Acceptor concentration should be positive\")\n    elif intrinsic_conc <= 0:\n        raise ValueError(\"Intrinsic concentration should be positive\")\n    elif donor_conc <= intrinsic_conc:\n        raise ValueError(\n            \"Donor concentration should be greater than intrinsic concentration\"\n        )\n    elif acceptor_conc <= intrinsic_conc:\n        raise ValueError(\n            \"Acceptor concentration should be greater than intrinsic concentration\"\n        )\n    else:\n        return (\n            Boltzmann\n            * T\n            * log((donor_conc * acceptor_conc) / intrinsic_conc**2)\n            / physical_constants[\"electron volt\"][0]\n        )\n\n\nif __name__ == \"__main__\":","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/builtin_voltage.py#L28-L64","documentation":"Raised by builtin_voltage() when intrinsic_conc <= 0 while donor and acceptor concentrations are already positive. ni appears squared in the denominator of the log argument, and ni <= 0 is non-physical (silicon at 300K has ni ≈ 1e10 cm^-3). Third check in the ordered elif chain.","triggerScenarios":"Calling builtin_voltage(donor_conc=1e16, acceptor_conc=1e15, intrinsic_conc=0) or intrinsic_conc=-1e10. Fires only when both donor_conc > 0 and acceptor_conc > 0.","commonSituations":"Omitting intrinsic_conc and having it default/decay to 0; computing ni from a temperature-dependent formula that underflows to 0.0 at low T; using ni for a different material where the value was never set.","solutions":["Use a physically correct ni (e.g. 1e10 cm^-3 or 1.45e10 depending on convention; 1.5e10 in the module's doctest style).","If ni is computed from temperature, guard the formula's valid range and check the result > 0.","Keep units consistent — ni, Nd, Na must be in the same volume units."],"exampleFix":"# before\nbuiltin_voltage(donor_conc=1e16, acceptor_conc=1e15, intrinsic_conc=0)  # ValueError\n\n# after\nbuiltin_voltage(donor_conc=1e16, acceptor_conc=1e15, intrinsic_conc=1e10)","handlingStrategy":"validation","validationCode":"def valid_intrinsic(ni: float) -> bool:\n    return ni > 0  # silicon at 300K: ~1e10 cm^-3","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Hard-code a known-good ni (1e10 or 1.45e10 cm^-3) rather than deriving it.","Guard temperature-based ni formulas against underflow to 0.0.","Keep ni in the same units as Nd and Na."],"tags":["electronics","physics","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}