{"record":{"id":"ebe2b7db12d33681","repo":"TheAlgorithms/Python","slug":"acceptor-concentration-should-be-greater-than-intr","errorCode":null,"errorMessage":"Acceptor concentration should be greater than intrinsic concentration","messagePattern":"Acceptor concentration should be greater than intrinsic concentration","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/builtin_voltage.py","lineNumber":52,"sourceCode":"    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__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":34,"sourceCodeEnd":68,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/builtin_voltage.py#L34-L68","documentation":"Raised by builtin_voltage() when acceptor_conc <= intrinsic_conc while all earlier checks pass (donor_conc > 0, acceptor_conc > 0, intrinsic_conc > 0, donor_conc > intrinsic_conc). The formula requires Na > ni so the junction is meaningfully doped on both sides; equality also triggers it. Final gate before the Boltzmann/log computation.","triggerScenarios":"Calling builtin_voltage(donor_conc=3000, acceptor_conc=1000, intrinsic_conc=2000) as in the doctest; any input where 0 < donor_conc, intrinsic_conc < donor_conc, and acceptor_conc <= intrinsic_conc.","commonSituations":"Swapped donor/acceptor arguments (Na value passed as Nd and vice versa can make one side fail the ni comparison); unit mismatch between Na and ni; lightly doped p-region near intrinsic level.","solutions":["Verify argument order and values: donor_conc first, acceptor_conc second, both above ni.","Align units across all three concentrations (cm^-3 vs m^-3 mismatch is the classic cause).","If modeling a real lightly-doped junction, use the full depletion approximation equations instead of this simplified check."],"exampleFix":"# before\nbuiltin_voltage(donor_conc=3000, acceptor_conc=1000, intrinsic_conc=2000)  # ValueError\n\n# after\nbuiltin_voltage(donor_conc=1e16, acceptor_conc=1e15, intrinsic_conc=1e10)","handlingStrategy":"validation","validationCode":"def valid_junction(nd: float, na: float, ni: float) -> bool:\n    return nd > ni > 0 and na > ni","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Watch for swapped donor/acceptor arguments.","Unify units across Nd, Na, ni before computing.","Reserve this function for properly doped junctions (both sides >> ni)."],"tags":["electronics","physics","units"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}