SWRL divide by decimal - protege

It seems SWRL divide function does not accept decimal .
this is my query:
universityproject:professor(?x) ^ universityproject:has_height(?x, ?h) ^ universityproject:has_weight(?x, ?w) ^ swrlb:pow(?phm, ?h, 2) ^ swrlb:divide(?res, ?w, ?phm) ^ swrlb:greaterThan(?res, 30) -> sqwrl:select(?x, ?h, ?w, ?phm)
this is output error in protege sqwrl tab:
Exception running SQWRL query S12: error running SQWRL queries: error inserting asserted OWL axioms into Drools:
[Error: invoker.invoke("S12", "swrlb:divide", 1, false, new VPATH($h), new BAVNs("res", "w", "phm"), new UBA("res"), $w, $phm): runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S12", "swrlb:d ....}]
^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.: error inserting asserted OWL axioms into Drools:
[Error: invoker.invoke("S12", "swrlb:divide", 1, false, new VPATH($h), new BAVNs("res", "w", "phm"), new UBA("res"), $w, $phm): runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S12", "swrlb:d ....}]
^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.: [Error: invoker.invoke("S12", "swrlb:divide", 1, false, new VPATH($h), new BAVNs("res", "w", "phm"), new UBA("res"), $w, $phm): runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S12", "swrlb:d ....}]
^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.
How can i do a decimal division in swrl syntax?

Related

why is my int() conversion looking so weird?

I'm trying to take a number and divide it by 100 to get 1%, but when i tried to convert it to integer using the int(), it's giving me some weird output. i have no clue what i'm doing wrong here.
totalsupply = 1000000000000000000000000000000
onepercent = int((totalsupply/100))
print(totalsupply)
print(onepercent)
the output is coming out as such:
1000000000000000000000000000000
9999999999999999583119736832
[Finished in 68ms]
I was expecting the onepercent to be this: 10000000000000000000000000000.
According to this post, python tries to convert the number to a float on a division. However, floats are limited to 1.7976931348623157e+308. A workaround is to use the // operator which returns an int from the division, so for your example:
totalsupply = 1000000000000000000000000000000
onepercent = totalsupply//100
print(totalsupply)
print(onepercent)
Python has a built-in integer type that has infinite precision. That's what you are creating with your first line
totalsupply = 1000000000000000000000000000000
However, python has two division operators. The standard division "slash" operator ("/") is floating-point operation, whereas the double-slash gives integers.
Hence totalsupply/100 is a floating point number, which has finite precision, and so the closest it can do is 9999999999999999583119736832.
However, if instead you do
onepercent = totalsupply//100
print(onepercent)
you get the expected 100000000000000000000000000000.

Classify literal and expression in negative numbers

For example a negative number -1
I think this is an expression with a unary operator '-' and a numeric literal '1'.
But I cannot be sure.
In terms of the Python grammar, -1 is not a literal. It's a unary negation applied to a literal 1. As well as being deducible from the lexical rules of Python, this is also explicitly stated in the documentation of Python's lexical structure:
Note that numeric literals do not include a sign; a phrase like -1 is actually an expression composed of the unary operator ‘-‘ and the literal 1.
Most of the time, though, people will refer to -1 as a literal, much the same way they refer to [1, 2, 3] as a "list literal" even though the grammar calls that a "list display".
Well, I could say, "a little of this and a little of that", check this expressions in a python's prompt:
2-3
=> -1
--1
=> 1
-1
=> -1
---1
=> -1
----1
=> 1
-(5+10)
=> -15
It depends on the context though, look at this example:
-1
=> -1
here, - denotes the negative of the int , but look at this one:
2-3
=> -1
here is unary operation:
-(5+10)
=> -15
here, the - denotes the sub function, and the others... just cancelations.

Confusion with valueError vs ValueType try/exception

I have a follow up question to a post I saw on converting a str() input to a int() type. Based on the definitions of valueError and valueType I would expect the valueType exception to have been used however, it doesn't work (when i tried it). ValueError works but I'm not sure why, isn't int('some string') an example of a wrong type?
Link to original post i'm referring to: Converting String to Int using try/except in Python
From the docs:
class int(x, base=10) Return an integer object constructed from a
number or string x, or return 0 if no arguments are given. If x is a
number, return x.int(). For floating point numbers, this truncates
towards zero.
If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in radix
base. Optionally, the literal can be preceded by + or - (with no space
in between) and surrounded by whitespace. A base-n literal consists of
the digits 0 to n-1, with a to z (or A to Z) having values 10 to 35.
The default base is 10. The allowed values are 0 and 2–36. Base-2, -8,
and -16 literals can be optionally prefixed with 0b/0B, 0o/0O, or
0x/0X, as with integer literals in code. Base 0 means to interpret
exactly as a code literal, so that the actual base is 2, 8, 10, or 16,
and so that int('010', 0) is not legal, while int('010') is, as well
as int('010', 8).
When you call the int() function on a string it will try to convert it to the specified base in the arguments (by default base-10) by iterating over the string and converting the string object over to an int object in the desired base. If it reaches a point where the conversion can not be made due to illegal syntax , it will raise a ValueError so terminate the program early. If for some reason you want to go forward you can but a try: except block in the code to catch the exception.
From the Docs:
exception ValueError Raised when a built-in operation or function
receives an argument that has the right type but an inappropriate
value, and the situation is not described by a more precise exception
such as IndexError.

Performing arithmetic on string values

I would like to ask something about data types in Lua.
I get from serial link some message (command:value) like this:
tmp_string = "BRAKE:1"
then I parse this string to command and value in two different functions (one is for command and other one is for value). This is function for parsing value
function parser(value)
index = string.find(value, ":")
result = value.sub(value, index+1)
return result
end
I would like to now what sort of data type result is? If I use string match it works.
...if string.match(state, "1") then...
However it also works when I do something like this
x = (state*65536)/3.2808)
I thought the result is string, but I don't understand why it works also with numerical operations. Thank you in advance.
Lua 5.3 Reference Manual, §3.4.1 - Arithmetic Operators
With the exception of exponentiation and float division, the arithmetic operators work as follows: If both operands are integers, the operation is performed over integers and the result is an integer. Otherwise, if both operands are numbers or strings that can be converted to numbers (see §3.4.3), then they are converted to floats, the operation is performed following the usual rules for floating-point arithmetic (usually the IEEE 754 standard), and the result is a float.
Emphasis is mine.
When dealing with operations, Lua will attempt to convert string operands to floats, and if it works - it works. If it fails, you get an error.
>| '55' / 2
<| 27.5
>| 'foo' / 2
<| error: [string "return 'foo' / 2"]:1: attempt to perform arithmetic on a string value
If you want to be explicit about this (and safe) use tonumber, and handle the nil-case.
If you need to know the type of a value in Lua, you can pass the variable to type and check the resulting string.

Convert TextBox string to Byte

how to convert TextBox string value to Byte. I have:
array<Byte>^ mybytes = gcnew array<Byte>{6,2,1};
mybytes[1] = motor1ForwardTextBox->Text->System::IConvertible::ToByte;
System::Diagnostics::Debug::Write(mybytes[1]);
but there is error in second line:
Error 2 error C2440: '=' : cannot convert from 'unsigned char (__clrcall System::IConvertible::* )(System::IFormatProvider ^)' to 'unsigned char' c:\users\guest4\documents\avr\serial2\serial2\Form1.h 563 1 serial2 (Visual Studio 2010)
A straightforward way is:
mybytes[1] = Byte::Parse(motor1ForwardTextBox->Text);
After all, the nature of the conversion you want is parsing decimal digits.
Either way you'll get exceptions if the characters are not digits with optional + and -, or the value is not in the range 0 to 255. And, unfortunately, even though parsing to Byte does not accept "," or ".", the acceptable digit characters do depend on the culture. So, if necessary, pass an IFormatProvider.
String does an explicit implementation of the IConvertible::ToByte method, so you'll need to cast it.
And of course, you'll need to actually call the method. That error message is saying that it can't convert from a method that returns unsigned char, to an unsigned char.
mybytes[1] = dynamic_cast<IConvertible^>(motor1ForwardTextBox->Text)->ToByte();
^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^

Resources