GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-cbinop.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2013 Jaroslav Hajek
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "error.h"
28 #include "oct-obj.h"
29 #include "ov.h"
30 #include "pt-cbinop.h"
31 #include "pt-bp.h"
32 #include "pt-unop.h"
33 #include "pt-walk.h"
34 
35 // If a tree expression is a transpose or hermitian transpose, return
36 // the argument and corresponding operator.
37 
40 {
41  if (exp->is_unary_expression ())
42  {
43  tree_unary_expression *uexp =
44  dynamic_cast<tree_unary_expression *> (exp);
45 
46  octave_value::unary_op op = uexp->op_type ();
47 
50  exp = uexp->operand ();
51  else
53 
54  return op;
55  }
56  else
58 }
59 
62 {
63  if (exp->is_unary_expression ())
64  {
65  tree_unary_expression *uexp =
66  dynamic_cast<tree_unary_expression *> (exp);
67 
68  octave_value::unary_op op = uexp->op_type ();
69 
70  if (op == octave_value::op_not)
71  exp = uexp->operand ();
72  else
74 
75  return op;
76  }
77  else
79 }
80 
81 // Possibly convert multiplication to trans_mul, mul_trans, herm_mul,
82 // or mul_herm.
83 
86 {
89 
91 
92  if (opa == octave_value::op_hermitian)
94  else if (opa == octave_value::op_transpose)
96  else
97  {
99 
100  if (opb == octave_value::op_hermitian)
102  else if (opb == octave_value::op_transpose)
104  }
105 
106  return retop;
107 }
108 
109 // Possibly convert left division to trans_ldiv or herm_ldiv.
110 
113 {
116 
118 
119  if (opa == octave_value::op_hermitian)
121  else if (opa == octave_value::op_transpose)
123 
124  return retop;
125 }
126 
127 // Possibly contract and/or with negation.
128 
132 {
135 
137 
138  if (opa == octave_value::op_not)
139  {
140  if (op == octave_value::op_el_and)
142  else if (op == octave_value::op_el_or)
144  }
145  else
146  {
148 
149  if (opb == octave_value::op_not)
150  {
151  if (op == octave_value::op_el_and)
153  else if (op == octave_value::op_el_or)
155  }
156  }
157 
158  return retop;
159 }
160 
163  int l, int c, octave_value::binary_op t)
164 {
165  tree_expression *ca = a, *cb = b;
167 
168  switch (t)
169  {
171  ct = simplify_mul_op (ca, cb);
172  break;
173 
175  ct = simplify_ldiv_op (ca, cb);
176  break;
177 
180  ct = simplify_and_or_op (ca, cb, t);
181  break;
182 
183  default:
185  break;
186  }
187 
189  ? new tree_binary_expression (a, b, l, c, t)
190  : new tree_compound_binary_expression (a, b, l,
191  c, t, ca,
192  cb, ct);
193 
194  return ret;
195 }