lgwagner/SpeAR

Unit division by scalar

Closed this issue · 1 comments

In the following example:

Specification unit_division

Units:
  s "second"

  m "meters"  
  m_per_s : m/s "meters per second"
  
Types:
  time_type is a real s

  length_type is a real m

  velocity_type is a real m_per_s

Constants:
  TIMESTEP is a time_type = 1.0 s

  PI is a real = 3.14159

Inputs:
  input_x is a length_type
  input_y is a velocity_type
  
Outputs:
  output_z is a length_type

Requirements:
  r_broken_1:
    output_z == input_x + input_y/PI * TIMESTEP

  r_working_1:
    output_z == input_x + (input_y/PI) * TIMESTEP

Properties:

the first constraint fails validation with the error: "Operator '+' not defined on units m, m/s*s". The second constraint, on the other hand, succeeds, suggesting that there is some issue with the way in which operators are being grouped.

This was due to a precedence issue in the parser. This was fixed by adding extra rules to the parser to enforce the BODMAS order of operations in the parser.

Previously multiplication and division were at the same precedence which is incorrect.