Method on @sym: logical (eq)

Test if expression is "structurally" true.

This should probably be used with if/else flow control.

Example:

syms x y
logical(x*(1+y) == x*(y+1))
  ⇒ 1
logical(x == y)
  ⇒ 0

Note this is different from isAlways which tries to determine mathematical truth:

isAlways(x*(1+y) == x+x*y)
  ⇒ 1
logical(x*(1+y) == x+x*y)
  ⇒ 0

Sometimes we end up with a symbolic logical values; logical can convert these to native logical values:

sym(true)
  ⇒ ans = (sym) True
logical(ans)
  ⇒ ans = 1

logical treats objects according to:

  • @logical true/false: as is.
  • symbolic logical true/false: convert to true/false.
  • equalities (==), unequalities (~=): check for structural equivalence (whether lhs and rhs match without simplifying.)
  • numbers: true if nonzero, false if zero.
  • nan, oo, zoo: FIXME
  • boolean expr: And, Or: FIXME
  • other objects raise error.

See also: @sym/isAlways, @sym/isequal, @sym/eq.

Package: symbolic