UnitsEqual? - Possible Bug

9 views
Skip to first unread message

Christopher McCormick

unread,
May 31, 2019, 3:04:21 PM5/31/19
to mathpiper-dev
Ted

I have been working on the documentation for the files in scripts4/units and had a question about the UnitsEqual? procedure. Based on UnitsGreaterThan? and UnitsLessThan? procedures, I believe the purpose of UnitsEqual? is to return True if the arguments passed to the procedure are equal. Here is a screenshot of some tests of the procedure:

   UnitsEqual_LeftSide.png   UnitsEqual_RightSide.png


It appears to me that the procedure will evaluate as True as long as the left side argument is less than or equal to the right side argument. I am wondering if I am misunderstanding the purpose of the procedure or if it might be a bug. 


Thanks, CJ

Ted Kosan

unread,
May 31, 2019, 3:47:27 PM5/31/19
to mathpi...@googlegroups.com
Christopher,

This is indeed a bug. It is a good example of what can happen when the person who creates a procedure does not create tests for it due to lack of discipline (in this case me, because I created this procedure!)

Try changing

NM(ValueOf(ConvertUnits(a~u, v) - b~v) <? .000001);

to

NM(AbsN(ValueOf(ConvertUnits(a~u, v) - b~v)) <? .000001);


Also, tests have different levels of quality. Techniques exist for writing high-quality tests (see https://www.guru99.com/software-testing-techniques.html). However, the current goal is to provide at least some test coverage for all the procedures in the library. After this has been achieved, an effort will be made to increase the quality of these tests using standard software engineering principles.

Ted




--
You received this message because you are subscribed to the Google Groups "mathpiper-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathpiper-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/19dc619f-858b-42c9-b274-d9a21a1bd4e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher McCormick

unread,
Jun 5, 2019, 12:41:00 PM6/5/19
to mathpiper-dev
Ted,

The new code does seem to fix the problem. Thank you!

I am continuing to work on units based procedures. In a similar issue, UnitsStrip seems to only remove the units from constants:

In> UnitsStrip(c_ ~ d_)
Result: c_

In> UnitsStrip(3 ~ mA)
Result: 3~mA

I am adding documentation and such now, would you like me to experiment with a way to change this procedure or leave it as is?

Christopher

Ted Kosan

unread,
Jun 5, 2019, 1:08:44 PM6/5/19
to mathpi...@googlegroups.com
The current behavior of UnitsStrip is the correct one. I just checked,
and formulas such as "["15.20", Formula(P?dBm~dBm == 10 * Log10D(P?P~W
/ 1~mW), Label:"15.20", Page:"475")]," break if values such as "1~mW"
have their units stripped. See problem 15.25 in the electronics book
for an example.
> --
> You received this message because you are subscribed to the Google Groups "mathpiper-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mathpiper-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/8e7f6ed3-9703-4d04-94f6-a36df2210dbd%40googlegroups.com.

Christopher McCormick

unread,
Jun 5, 2019, 1:46:34 PM6/5/19
to mathpiper-dev
Okay I think I see what you mean. Thanks much!
Reply all
Reply to author
Forward
0 new messages