# Logical operators in octave_code #9533

Closed
opened this Issue Jun 16, 2015 · 0 comments

Projects
None yet
2 participants

### rgbrown commented Jun 16, 2015

 When expressions include logical operators, like &, octave_code uses the wrong logical operator in the produced code. For example the following code: ``````from sympy import Piecewise from sympy.abc import x from sympy.printing import octave_code print octave_code(Piecewise((1, (x > 0) & (x < 1)), (0, True))) `````` produces output ``````((x > 0 && x < 1).*(1) + (~(x > 0 && x < 1)).*(0)) `````` The logical ands (&&) should be single ampersands (&) so that the expression works with vector arguments x in Octave/MATLAB

### cbm755 added a commit to cbm755/sympy that referenced this issue Jun 17, 2015

``` codegen: use vectorized and/or for octave code ```
```Previously it generated code using && and ||.  These are fine
for scalar operations (and in some cases preferable as they
shortcircuit).  But for numerical code, & and | are better as
they are vectoried.  Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy#9533.```
``` faeb0f4 ```

Merged

### cbm755 added a commit to cbm755/sympy that referenced this issue Jun 17, 2015

``` codegen: use vectorized and/or for octave code ```
```Previously it generated code using && and ||.  These are fine
for scalar operations (and in some cases preferable as they
shortcircuit).  But for numerical code, & and | are better as
they are vectorized.  Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy#9533.```
``` 278e3db ```

### cbm755 added a commit to cbm755/sympy that referenced this issue Jun 17, 2015

``` codegen: use vectorized and/or for octave code ```
```Previously it generated code using && and ||. These are fine
for scalar operations (and in some cases preferable as they
shortcircuit). But for numerical code, & and | are better as
they are vectorized. Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy#9533.```
``` 7cc1598 ```

### skirpichev added a commit to diofant/diofant that referenced this issue Sep 28, 2015

``` codegen: use vectorized and/or for octave code ```
```Previously it generated code using && and ||. These are fine
for scalar operations (and in some cases preferable as they
shortcircuit). But for numerical code, & and | are better as
they are vectorized. Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy/sympy#9533.```
``` fc68b13 ```