G-XR8P2XJ088

AI-Written Python: Decide What Counts as Close to Zero

Imagine a small print studio testing an AI-written script that checks how far a design is offset from the centre of a page. An exported measurement says the design is 0.03 millimetres to the right. The studio has decided that anything within 0.10 millimetres of centre can pass this particular check. Yet the script flags the file. It uses Python’s math.isclose(), which sounds like the right tool, but nobody told it what ‘close’ means for the job.

The natural reaction is to ask the AI to make the comparison less strict. That can fix one example while breaking the rest. Start by naming the quantity you are measuring, the units it is in and the decision the check controls. In this case the number is a signed offset, measured in millimetres, and a pass means no further adjustment is needed under the studio’s illustrative rule.

Why a percentage alone does not work at zero

The Python documentation for math.isclose() distinguishes two kinds of tolerance. A relative tolerance lets the allowed difference grow with the larger magnitude of the two numbers. An absolute tolerance gives the difference a fixed allowance in the units of those numbers. Python checks the difference against whichever allowance is larger. Relative tolerance is useful when you want an error to be judged in proportion to the size of the measurement.

The rule behaves differently when one value is zero. With the default absolute tolerance of zero, a comparison of 0.03 with zero allows only a tiny fraction of 0.03 as the difference. The actual difference is all of 0.03, so the comparison fails. PEP 485, the original proposal for the function, explains why comparisons near zero need a separate absolute allowance. Raising the relative tolerance from one small fraction to another cannot make a nonzero offset pass this particular comparison.

Choose a tolerance you can explain

For the hypothetical studio, math.isclose(offset_mm, 0.0, rel_tol=0.0, abs_tol=0.10) expresses a fixed band around centre. A positive or negative 0.03 millimetre offset passes. A positive or negative 0.12 millimetre offset fails. The studio could also express the same rule by checking that the absolute value of a finite offset is at most 0.10 millimetres. Either way, 0.10 is a choice made for this example, not a specification for printers in general.

Keep the units visible in the variable names and the report. If a supplier changes an export from millimetres to micrometres, a value of 30 now represents 0.03 millimetres. Feeding 30 into a check expecting millimetres turns a pass into a failure. Convert measurements at the point where they enter the script and test that two source files expressing the same offset in different units produce the same decision.

There is a separate choice about rounding. If the studio displays offsets to two decimal places but checks the underlying measurements, the screen might show 0.10 while the script correctly rejects a value just above the limit. Decide which representation defines acceptance and keep the report consistent with it. If the rule is defined in whole micrometres, an exact integer comparison may express it more clearly than converting to a floating point number first.

Keep missing measurements separate from small ones

A blank value means the studio does not know how far the design is offset. It is not evidence that the design is centred. Do not turn a blank or failed conversion into zero just to make the check finish. The Python reference also explains that a not-a-number value is never close to anything, and that an infinity is close only to itself. For a measurement workflow, handle non-finite values as invalid input before deciding whether to adjust the design. Give the operator a reason they can act on.

Keep the signed value in the report even if the pass rule uses its magnitude. A run of small offsets in one direction may give the studio a reason to look at the setup. The same idea applies to a different kind of check in our guide to keeping shortages visible in a stock report: a summary decision should leave enough evidence to see which way the underlying values moved.

Ask for tests that describe the rule

  • Test exact zero, a small offset on both sides, the intended limit and a value just outside it. State whether the limit itself passes.
  • Test the same measurement in each supported unit. Compare both the displayed value and the decision after conversion.
  • Test a blank, an unrecognised unit and a non-finite value. Check that each produces a useful message instead of a pass.
  • If one direction has a different consequence, write separate left and right bounds. A symmetric closeness test cannot express an asymmetric rule on its own.

Test the rule against a few actual decisions before rolling it out. Have the operator label a small set of proofs as ‘leave alone’, ‘adjust’ or ‘cannot measure’ without seeing the script’s output. Where the results differ, check whether the measurement describes the part of the artwork the operator cares about. A perfectly implemented tolerance on the wrong measurement still sends the wrong files for review.

A near-zero check is a small piece of code with a surprisingly specific job. The useful review question is whether someone who runs the studio can explain why a file passed and what to do when one fails. Let that answer define the tolerance. The AI can then help write and test the comparison.

Sources


Discover more from Marychuks.com AI, Psychology, Business & CreativeVerse

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from Marychuks.com AI, Psychology, Business & CreativeVerse

Subscribe now to keep reading and get access to the full archive.

Continue reading