compute-engine icon indicating copy to clipboard operation
compute-engine copied to clipboard

`\cdot y` parses incorrectly

Open bengolds opened this issue 4 years ago • 3 comments

There are a few different signs that can be used for multiplication: *, \cdot, and \times. They are inconsistent in how they parse when an argument is missing.

x * y       => [ 'Multiply', 'x', 'y' ]       👍
x \cdot y   => [ 'Multiply', 'x', 'y' ]       👍
x \times y  => [ 'Multiply', 'x', 'y' ]       👍

-- Right side missing
x *         => [ 'Multiply', 'x', 'Missing' ] 👍
x \cdot     => [ 'Multiply', 'x', 'Missing' ] 👍
x \times    => [ 'Multiply', 'x', 'Missing' ] 👍

-- Left side missing
  * y       => [ 'Multiply', 'Missing', 'y' ] 👍
  \cdot y   => [ 'Multiply', '\\cdot', 'y' ]  ❌ 
  \times y  => [ 'Multiply', '\\times', 'y' ] ❌ 

bengolds avatar Feb 16 '22 00:02 bengolds

Tested this out in 0.4.3 - and there are still some inconsistencies:

  'x * y'        --> [ 'Multiply', 'x', 'y' ]
  'x \\cdot y'   --> [ 'Multiply', 'x', 'y' ] 
  'x \\times y'  --> [ 'Multiply', 'x', 'y' ]
  'x *'          --> [ 'Error', 'x', "'syntax-error'", [Array] ]
  'x \\cdot'     --> [ 'Error', 'x', "'syntax-error'", [Array] ] 
  'x \\times'    --> [ 'Multiply', 'x', 'Missing' ]
  '* y'          --> [ 'Error', 'Nothing', "'syntax-error'", [Array] ]
  '\\cdot y'     --> [ 'Error', [Array], "'syntax-error'", [Array] ]
  '\\times y'    --> [ 'Error', [Array], "'syntax-error'", [Array] ] ]

strickinato avatar Mar 24 '22 21:03 strickinato

Maybe this is the wrong context, but each of these can mean different conceptualizations (and computations) of multiplication depending on the types of x and y. For instance, when dealing with matrices \times denotes the cross product of two vectors and \cdot the dot product. Wouldn't this need to be taken into account?

DataDaoDe avatar Aug 25 '22 16:08 DataDaoDe

With 0.8.0 the output is:

x * y         => x \cdot y
x \cdot y     => x \cdot y
x \times y    => ["Multiply", "x", "y"]
x *           => ["Sequence", "x", ["Error", [ "ErrorCode", "'unexpected-token'",... ["Latex", "'*'"]]]
x \cdot       => ["Sequence", "x", ["Error", [ "ErrorCode", "'unexpected-command'",... ["Latex", "'\\cdot'"]]]
x \times      => ["Multiply", "x", ["Error", "'missing'"]]
* y           => ["Multiply", ["Error", "'missing'", ["Latex", "'*'"]], "y"
\cdot y       => ["Multiply", ["Error", "'missing'", ["Latex", "'\\cdot'"]], "y"
\times y      => ["Multiply", ["Error", "'missing'", ["Latex", "'\\ times'"]], "y"]

@DataDaoDe yes, but the default setup of the Compute Engine is to assume that unknown symbols are Real numbers. The domain of the symbols can be taken into account during parsing to determine if this is a scalar multiplication or a cross product.

arnog avatar Oct 03 '22 01:10 arnog