[go: up one dir, main page]

Menu

[r11]: / src / operands.cpp  Maximize  Restore  History

Download this file

661 lines (615 with data), 24.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/***************************************************************************
operands.cpp - description
-------------------
begin : Wed Jun 26 2002
copyright : (C) 2002 by Jan Rheinlaender
email : jrheinlaender@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
//#include "../config/config.h" // *** added in 1.3.1
#include <sstream>
#include "operands.h"
#include "printing.h"
#include "msgdriver.h" // *** added in 1.3.1
#include "equation.h" // *** added in 1.2
#include "ncsymbol.h" // *** added in 1.4.3
exrec::exrec (const expression &exp, const operands &op1, const operands &op2)
: e(exp), o1(op1), o2(op2), hits(0) {};
exrec::~exrec() {
MSG_INFO(0) << hits << " hits for " << e << endline;
} // ~exrec()
ex mul_ops(const ex &op1, const ex &op2) {
return (op1 * op2);
} //mul_ops()
ex add_ops(const ex &op1, const ex &op2) {
return (op1 + op2);
} //add_ops()
operands::operands(const int ops_type) throw(std::invalid_argument) {
// *** added matrices in 1.0, integrals in 1.3.1
if ((ops_type != GINAC_ADD) && (ops_type != GINAC_MUL))
throw std::invalid_argument("operands::operands(): Type must be ADD or MUL");
symbols = constants = units = functions = integrals = adds = muls = powers = matrices = others = coefficient = ops_type;
oper = ((ops_type == GINAC_ADD) ? &add_ops : &mul_ops);
type = ops_type;
} //operands()
operands::~operands() {}
void operands::split_ex(const expression &e, operands &o1, operands &o2) throw(std::runtime_error) {
// Split the ex into different types of operands (symbols, functions etc.)
// *** changed ex& to expression& in 0.9
// *** removed ex_to<> in argument of include() in 1.0
// *** added caching of split_ex() results in 1.0
MSG_INFO(3) << "Splitting expression " << e <<
", number of operands: " << e.nops() << endline;
unsigned hash = e.gethash();
if ((remember_split[hash] != NULL) && (remember_split[hash]->e.is_equal(e))) {
o1 = remember_split[hash]->o1;
o2 = remember_split[hash]->o2;
remember_split[hash]->hits++;
MSG_INFO(3) << "split_ex: Cache hit for " << e << endline;
return;
}
if (is_a<mul>(e))
for (const_iterator i = e.begin(); i != e.end(); i++) {
// *** changed to const_iterator in 0.7
if (is_negpower(*i))
o2.include(pow(*i, -1));
else if (is_a<numeric>(*i)) // *** changed in 1.2, separating numerator and denominator make no sense
o1.include(*i);
else
o1.include(*i);
}
else if (is_a<add>(e))
for (const_iterator i = e.begin(); i != e.end(); i++) {
// *** changed to const_iterator in 0.7
if (is_negex(*i))
o2.include(-*i);
else
o1.include(*i);
}
else if (is_negpower(e))
o2.include(pow(e, -1));
else if (is_a<power>(e))
o1.include(e);
else if (is_a<numeric>(e)) // *** changed in 1.2, separating numerator and denominator make no sense
o1.include(e);
else if (is_a<constant>(e)) // Pi etc.
o1.include(e); // *** added in 1.2
else if (is_a<function>(e))
o1.include(e); // *** added in 0.6
else if (is_a<func>(e))
o1.include(e); // *** added in 0.6
else if (is_a<integral>(e))
o1.include(e); // *** added in 1.3.1
else if (is_a<matrix>(e))
o1.include(e); // *** added in 1.0
else if (e.nops() == 0)
o1.include(e);
else // *** changed in 0.6 because throwing an exception makes no sense
msg::error(0) << "Internal error: Unexpected expression type in split_ex()" << endline;
if (msg::info().checkprio(4)) {
std::ostringstream os;
o1.print(os);
o2.print(os);
msg::info() << os.str();
}
// *** added in 1.0
remember_split[hash] = new exrec(e, o1, o2);
MSG_INFO(3) << "split_ex: Cached result for " << e << endline;
} // split_ex()
void operands::include(const ex &what) {
// Find the type of what and include it in the receiver
if (is_a<symbol>(what) || is_a<ncsymbol>(what)) symbols = oper(symbols, what);
else if (is_a<constant>(what)) constants = oper(constants, what); // *** added in 1.2
else if (is_a<Unit>(what)) units = oper(units, what);
else if (is_a<func>(what)) functions = oper(functions, what); // *** added in 0.5
else if (is_a<function>(what)) functions = oper(functions, what);
else if (is_a<integral>(what)) integrals = oper(integrals, what); // *** added in 1.3.1
else if (is_a<add>(what)) adds = oper(adds, what);
else if (is_a<mul>(what)) muls = oper(muls, what);
else if (is_a<matrix>(what)) matrices = oper(matrices, what); // *** added in 1.0
else if (is_a<power>(what)) {
power pow = ex_to<power>(what);
ex base = get_basis(pow); // *** changed to get_.. in 1.2
ex exponent = get_exp(pow);
if (is_a<numeric>(exponent) && (is_a<Unit>(base))) {
units = oper(units, what);
} else if (is_a<numeric>(exponent) && (is_a<symbol>(base) || is_a<ncsymbol>(base))) { // *** added in 1.2
symbols = oper(symbols, what);
} else if (is_a<numeric>(exponent) && (is_a<constant>(base))) { // *** added in 1.2
constants = oper(constants, what);
} else {
powers = oper(powers, what);
}
} else if (is_a<numeric>(what))
coefficient = ex_to<numeric>(oper(coefficient, what));
else others = oper(others, what);
MSG_INFO(6) << "Included expression " << what << endline;
} //operands::include()
void operands::exclude(const ex &what) { // *** added in 1.2
// Find the type of what and include it in the receiver
if (is_a<symbol>(what) || is_a<ncsymbol>(what)) symbols = oper(symbols, 1 / what);
else if (is_a<constant>(what)) constants = oper(constants, 1 / what);
else if (is_a<Unit>(what)) units = oper(units, 1 / what);
else if (is_a<func>(what)) functions = oper(functions, 1 / what); // *** added in 0.5
else if (is_a<function>(what)) functions = oper(functions, 1 / what);
else if (is_a<integral>(what)) integrals = oper(integrals, 1 / what); // *** added in 1.3.1
else if (is_a<add>(what)) adds = oper(adds, 1 / what);
else if (is_a<mul>(what)) muls = oper(muls, 1 / what);
else if (is_a<matrix>(what)) matrices = oper(matrices, 1 / what); // *** added in 1.0
else if (is_a<power>(what)) {
power pow = ex_to<power>(what);
ex base = get_basis(pow); // *** changed to get_.. in 1.2
ex exponent = get_exp(pow);
if (is_a<numeric>(exponent) && (is_a<Unit>(base))) {
units = oper(units, 1 / what);
} else if (is_a<numeric>(exponent) && (is_a<symbol>(base) || is_a<ncsymbol>(base))) {
symbols = oper(symbols, 1 / what);
} else if (is_a<numeric>(exponent) && (is_a<constant>(base))) {
constants = oper(constants, 1 / what);
} else {
powers = oper(powers, 1 / what);
}
} else if (is_a<numeric>(what))
coefficient = ex_to<numeric>(oper(coefficient, 1 / what));
else others = oper(others, 1 / what);
} //operands::exclude()
void operands::exclude_all(const ex &what) {
if ((is_a<mul>(what) && (type == GINAC_MUL)) || (is_a<add>(what) && (type == GINAC_ADD))) {
for (const_iterator i = what.begin(); i != what.end(); i++) {
exclude(*i);
}
} else {
exclude(what);
}
} // operands::exclude_all()
bool checkmatrix(const matrix &m) { // *** added in 1.0
for (unsigned i = 0; i < m.nops(); i++) {
if (is_a<matrix>(m.op(i))) {
if (!checkmatrix(ex_to<matrix>(m.op(i))))
return false;
} else {
if (!m.op(i).info(info_flags::numeric))
return false;
}
}
return true;
} // checkmatrix()
// TODO: Store the result of these queries for the next time!
const bool operands::is_quantity() const {
// *** added matrices in 1.0, GiNac objects to doing matrices == type!
/* if (!is_a<mul>(matrices) && !is_a<add>(matrices)) {
if (is_a<matrix>(matrices) && !checkmatrix(ex_to<matrix>(matrices))) // *** changed in 1.0
return false;
} else
return false;
*/
// *** added integrals in 1.3.1
return ((check_symbols(type)) && (constants == type) && (functions == type) && (integrals == type) && (adds == type) &&
(muls == type) && (powers == type) && (others == type) && check_matrices(type));
} // operands::is_quantity()
const bool operands::is_number() const {
return (this->is_quantity() && (units == type));
} // operands::is_number()
const bool operands::is_trivial() const {
return (this->is_number() && (abs(coefficient) == type));
} // operands::is_trivial()
const bool operands::is_symbol() const { // *** added in 1.2, added integrals in 1.3.1
return ((coefficient == type) && (!check_symbols(type)) && (constants == type) && (functions == type) && (adds == type) &&
(muls == type) && (powers == type) && (check_matrices(type)) && (others == type) && (integrals == type));
} // operands::is_symbol()
const bool operands::is_add() const {
return (type == GINAC_ADD);
} // operands::is_add()
const bool operands::is_mul() const {
return (type == GINAC_MUL);
} // operands::is_mul()
void checksplit(const bool toplevel, const int opnum, std::ostream &os) {
if (toplevel) {
if (opnum == optstack::options->get(o_eqsplit).integer) {
MSG_INFO(1) << "Splitting equation at operand " << opnum << endline;
MSG_INFO(2) << "Interjected text: " << *optstack::options->get(o_eqsplittext).str << endline;
if (optstack::options->get(o_eqalign).align == onlyleft) {
os << "\\\\" << std::endl;
if (*optstack::options->get(o_eqsplittext).str == "") {
os << "&\\quad\\,\\,";
} else {
os << *optstack::options->get(o_eqsplittext).str;
}
} else if (optstack::options->get(o_eqalign).align == both) {
os << "\\nonumber\\\\" << std::endl;
if (*optstack::options->get(o_eqsplittext).str == "") {
os << "&&";
} else {
os << *optstack::options->get(o_eqsplittext).str;
}
} else {
os << "\\\\" << std::endl << *optstack::options->get(o_eqsplittext).str;
}
}
}
} // operands::checksplit()
const bool operands::check_matrices(const unsigned type) const {
if (matrices.info(info_flags::numeric)) {
return (matrices == type);
} else {
return (false);
}
}
const bool operands::check_symbols(const unsigned type) const {
if (symbols.info(info_flags::numeric)) {
return (symbols == type);
} else {
return (false);
}
}
void print_ltx_ops (const ex &e, const std::string &sym, std::ostream &os, const bool toplevel, int &opnum) {
// *** replaced first with opnum in 1.2
if (opnum > 0) {
os << sym;
checksplit(toplevel, opnum, os); // *** added in 1.2
}
if (is_a<symbol>(e))
print_ltx(ex_to<symbol>(e), os);
else if (is_a<ncsymbol>(e))
print_ltx(ex_to<ncsymbol>(e), os);
else if (is_a<power>(e))
print_ltx(ex_to<power>(e), os);
else if (is_a<Unit>(e))
print_ltx(ex_to<Unit>(e), os);
else if (is_a<func>(e))
print_ltx(ex_to<func>(e), os); // *** added in 0.5
else if (is_a<function>(e))
print_ltx(ex_to<function>(e), os);
else if (is_a<integral>(e))
print_ltx(ex_to<integral>(e), os); // *** added in 1.3.1
else if (is_a<matrix>(e)) {
print_ltx(ex_to<matrix>(e), os); // *** added in 1.0
} else if (is_a<add>(e)) {
for (const_iterator i = e.begin(); i != e.end(); i++) {
// *** changed to const_iterator in 0.7
if (i != e.begin()) checksplit(toplevel, opnum, os);
if (is_a<Unit>(*i)) {
os << "\\unit{1}{"; // *** added in 1.2, toplevel has a new meaning now
print_ltx(ex_to<Unit>(*i), os);
os << "}";
} else
print_ltx(*i, os);
if ((i != e.end()-1) && !is_negex(*(i+1)))
os << sym;
opnum++;
}
return; // Don't increment opnum again!
} else if (is_a<mul>(e)) {
for (const_iterator i = e.end(); i != e.begin();) { // *** changed to const_iterator in 0.7
if (i != e.end()) checksplit(toplevel, opnum, os);
i--;
if (is_a<add>(*i)) {
os << "\\left(";
print_ltx(ex_to<add>(*i), os, false, 0);
os << "\\right)";
} else {
print_ltx(*i, os);
}
if (i != e.begin()) os << sym;
opnum++;
//std::cout << "Incremented opnum after printing " << *i << ", value: " << opnum << std::endl;
}
return;
} else
os << latex << e << dflt; // *** changed print to << in 0.8
opnum++;
} // print_ltx_ops()
void operands::print_ltx_mul(std::ostream &os, const bool toplevel, const int ops) const throw(std::invalid_argument) {
if (!type == GINAC_MUL)
throw std::invalid_argument("Receiver must be of type GINAC_MUL");
if (msg::info().checkprio(5)) {
msg::info() << "Printing Latex mul ";
std::ostringstream os;
this->print(os);
msg::info() << os.str();
}
// Print the coefficient
//bool first = true; // *** changed in 1.2
int opnum = ops;
if (!is_equal_one(coefficient) || is_trivial()) { // *** changed to is_equal_one() in 1.0
//std::cout << "Printing coefficient " << coefficient << std::endl;
if (coefficient.is_real())
print_ltx(coefficient, os);
else {
os << "\\left(";
print_ltx(coefficient, os);
os << "\\right)";
}
opnum++;
}
const std::string separator = "\\,"; // *** added in 1.0
// Print powers of numerics *** added in 1.2
ex restpowers = 1;
if (is_a<mul>(powers)) {
for (const_iterator i = powers.begin(); i != powers.end(); i++) {
if (is_a<numeric>(get_basis(ex_to<power>(*i))) && is_a<numeric>(get_exp(ex_to<power>(*i)))) {
print_ltx_ops(*i, separator, os, toplevel, opnum);
} else {
restpowers = restpowers * *i;
}
}
} else if (powers != 1) {
if (is_a<numeric>(get_basis(ex_to<power>(powers))) && is_a<numeric>(get_exp(ex_to<power>(powers)))) {
print_ltx_ops(powers, separator, os, toplevel, opnum);
} else {
restpowers = powers;
}
}
// Functions must be printed last to avoid ambiguities like tan xa -> tan (x*a) or tan (x) * a ?
// TODO: Print constants right after that!
if (units != 1) // *** moved here in 1.2
print_ltx_ops(units, separator, os, toplevel, opnum);
if (constants != 1)
print_ltx_ops(constants, separator, os, toplevel, opnum);
if (!check_symbols(1))
print_ltx_ops(symbols, separator, os, toplevel, opnum);
if (restpowers != 1)
print_ltx_ops(restpowers, separator, os, toplevel, opnum);
if (adds != 1) { // *** changed in 0.6 to avoid unnecessary brackets
if (opnum > 0) os << separator;
if (is_a<mul>(adds)) { // There are several adds in this mul
opnum++; // suppress op_symbol here!
print_ltx_ops(adds, separator, os, toplevel, opnum);
opnum--; // correct operator count
} else {
if ((opnum == 0) && (others == 1) && (functions == 1) &&
(muls == 1) && (integrals == 1) && check_matrices(1)) {
// *** added in 0.6, added muls in 0.9, added matrices in 1.0, integrals in 1.3.1
// *** removed units in 1.2
// In other words, if there is only this one add in the mul
print_ltx(ex_to<add>(adds), os, toplevel, opnum);
} else {
os << "\\left(";
print_ltx(ex_to<add>(adds), os, false, 0);
os << "\\right) ";
}
checksplit(toplevel, opnum, os);
}
}
// Warning: The preceding code depends on these statements following AFTER it!
if (muls != 1) { // *** added in 0.9
print_ltx(ex_to<mul>(muls), os, toplevel, opnum);
opnum += muls.nops();
}
if (!check_matrices(1)) {// *** added in 1.0
// Matrices cannot be compared to a numeric! Because of non-commutativity.
print_ltx_ops(matrices, separator, os, toplevel, opnum);
}
if (others != 1)
print_ltx_ops(others, separator, os, toplevel, opnum);
if (functions != 1)
print_ltx_ops(functions, separator, os, toplevel, opnum);
if (integrals != 1) // *** added in 1.3.1
print_ltx_ops(integrals, separator, os, toplevel, opnum);
os << ' ';
} // operands::print_ltx_mul()
void operands::print_ltx_add(const operands &neg, std::ostream &os, const bool toplevel, const int ops) const throw(std::invalid_argument) {
// *** added opnum in 1.2, replaces first
if (!type == GINAC_ADD)
throw std::invalid_argument("Receiver must be of type GINAC_ADD");
// *** added integrals in 1.3.1
bool coefficient_later = false, units_later = false, symbols_later = false, constants_later = false, muls_later = false,
powers_later = false, adds_later = false, matrices_later = false, others_later = false, functions_later = false, integrals_later = false;
int opnum = ops; // *** added in 1.2
checksplit(toplevel, opnum, os); // *** added in 1.2
if (!coefficient.is_zero()) {
print_ltx(coefficient, os);
opnum++;
}
if (!neg.get_coefficient().is_zero()) {
if (opnum == 0) { // *** added code to always print something with a posivite sign first in 1.2
coefficient_later = true;
} else {
os << "-";
checksplit(toplevel, opnum, os);
print_ltx(neg.get_coefficient(), os);
opnum++;
}
}
std::string addsym = "+"; // *** added in 1.0
std::string subsym = "-";
if (units != 0) { // *** moved here in 1.2
os << "\\unit{1}{"; // *** changed in 1.2, toplevel has a new meaning now
print_ltx_ops(units, addsym, os, toplevel, opnum); // *** changed first to opnum in 1.2
os << "}";
}
if (neg.get_units() != 0) { // *** moved here in 1.2
if (opnum == 0) { // *** changed first to opnum == 0
units_later = true;
} else {
os << "\\unit{1}{"; // *** added in 1.2 instead of first = false
print_ltx_ops(neg.get_units(), subsym, os, toplevel, opnum);
os << "}";
}
}
if (constants != 0)
print_ltx_ops(constants, addsym, os, toplevel, opnum);
if (neg.get_constants() != 0) {
if (opnum == 0) {
constants_later = true;
} else {
print_ltx_ops(neg.get_constants(), subsym, os, toplevel, opnum);
}
}
if (!check_symbols(0))
print_ltx_ops(symbols, addsym, os, toplevel, opnum);
if (!neg.check_symbols(0)) {
if (opnum == 0) {
symbols_later = true;
} else {
print_ltx_ops(neg.get_symbols(), subsym, os, toplevel, opnum);
}
}
if (powers != 0)
print_ltx_ops(powers, addsym, os, toplevel, opnum);
if (neg.get_powers() != 0) {
if (opnum == 0) {
powers_later = true;
} else {
print_ltx_ops(neg.get_powers(), subsym, os, toplevel, opnum);
}
}
if (muls != 0) {
if (is_a<add>(muls)) { // There are several muls in this add
print_ltx_ops(muls, addsym, os, toplevel, opnum);
} else { // There is only one mul
if (opnum > 0) {
os << addsym;
checksplit(toplevel, opnum, os);
}
print_ltx(ex_to<mul>(muls), os, false, 0);
opnum++;
}
}
if (neg.get_muls() != 0) {
if (opnum == 0) {
muls_later = true;
} else {
if (is_a<add>(neg.get_muls())) {
print_ltx_ops(neg.get_muls(), subsym, os, toplevel, opnum);
} else {
checksplit(toplevel, opnum, os);
print_ltx(ex_to<mul>(-neg.get_muls()), os, false, 0);
opnum++;
}
}
}
if (adds != 0) { // *** added in 0.9
print_ltx(ex_to<add>(adds), os, toplevel, opnum);
opnum += adds.nops();
}
if (neg.get_adds() != 0) { // *** added in 0.9
if (opnum == 0) {
adds_later = true;
} else {
print_ltx(ex_to<add>(neg.get_adds()), os, toplevel, opnum);
opnum += adds.nops();
}
}
if (!check_matrices(0)) // *** added in 1.0
print_ltx_ops(matrices, addsym, os, toplevel, opnum);
ex negmatrices = neg.get_matrices();
if (is_a<matrix>(negmatrices) || is_a<add>(negmatrices)) { // *** added in 1.0
if (opnum == 0) {
matrices_later = true;
} else {
print_ltx_ops(neg.get_matrices(), subsym, os, toplevel, opnum);
}
}
if (others != 0)
print_ltx_ops(others, addsym, os, toplevel, opnum);
if (neg.get_others()!= 0) {
if (opnum == 0) {
others_later = true;
} else {
print_ltx_ops(neg.get_others(), subsym, os, toplevel, opnum);
}
}
if (functions != 0)
print_ltx_ops(functions, addsym, os, toplevel, opnum);
if (neg.get_functions() != 0) {
if (opnum == 0) {
functions_later = true;
} else {
print_ltx_ops(neg.get_functions(), subsym, os, toplevel, opnum);
}
}
if (integrals != 0) // *** added in 1.3.1
print_ltx_ops(integrals, addsym, os, toplevel, opnum);
if (neg.get_integrals() != 0) {
if (opnum == 0) {
integrals_later = true;
} else {
print_ltx_ops(neg.get_integrals(), subsym, os, toplevel, opnum);
}
}
if (coefficient_later) {
if (opnum != 0) checksplit(toplevel, opnum, os);
os << subsym;
print_ltx(neg.get_coefficient(), os);
opnum++;
} else if (opnum == 0) {
os << subsym;
}
if (units_later) { // TODO: Does this ever occur? *** removed unit{1}{... in 1.2
//os << "\\unit{1}{"; // *** changed in 1.2, toplevel has a new meaning now
print_ltx_ops(neg.get_units(), subsym, os, toplevel, opnum);
//os << "}";
}
if (constants_later)
print_ltx_ops(neg.get_constants(), subsym, os, toplevel, opnum);
if (symbols_later)
print_ltx_ops(neg.get_symbols(), subsym, os, toplevel, opnum);
if (muls_later) {
if (is_a<add>(neg.get_muls())) {
print_ltx_ops(neg.get_muls(), subsym, os, toplevel, opnum);
} else {
if (opnum != 0) {
checksplit(toplevel, opnum, os);
os << subsym;
}
print_ltx(ex_to<mul>(neg.get_muls()), os);
opnum++;
}
}
if (powers_later)
print_ltx_ops(neg.get_powers(), subsym, os, toplevel, opnum);
if (adds_later) { // *** changed neg to -neg in 1.2
print_ltx(ex_to<add>(-neg.get_adds()), os, toplevel, opnum);
opnum += adds.nops();
}
if (matrices_later)
print_ltx_ops(neg.get_matrices(), subsym, os, toplevel, opnum);
if (others_later)
print_ltx_ops(neg.get_others(), subsym, os, toplevel, opnum);
if (functions_later)
print_ltx_ops(neg.get_functions(), subsym, os, toplevel, opnum);
if (integrals_later) // *** added in 1.3.1
print_ltx_ops(neg.get_integrals(), subsym, os, toplevel, opnum);
os << " ";
} // print_ltx_add()
void operands::print(std::ostream &os) const {
os << "Symbols: " << symbols << std::endl;
os << "Constants: " << constants << std::endl;
os << "Units: " << units << std::endl;
os << "Functions: " << functions << std::endl;
os << "Adds: " << adds << std::endl;
os << "Muls: " << muls << std::endl;
os << "Powers: " << powers << std::endl;
os << "Numerics: " << ex(coefficient) << std::endl;
os << "Matrices: " << matrices << std::endl; // *** added in 1.3.0
os << "Integrals: " << integrals << std::endl; // *** added in 1.3.1
os << "Others: " << others << std::endl;
os << "Quantity: " << (is_quantity() ? "true" : "false") << std::endl;
os << "Number: " << (is_number() ? "true" : "false") << std::endl;
os << "Trivial: " << (is_trivial() ? "true" : "false") << std::endl;
} //operands::print()
/*void operands::print(message &ms) const {
ms << "Symbols: " << symbols << endline;
ms << "Constants: " << constants << endline;
ms << "Units: " << units << endline;
ms << "Functions: " << functions << endline;
ms << "Adds: " << adds << endline;
ms << "Muls: " << muls << endline;
ms << "Powers: " << powers << endline;
ms << "Numerics: " << ex(coefficient) << endline;
ms << "Matrices: " << matrices << endline; // *** added in 1.3.0
ms << "Integrals: " << integrals << endline; // *** added in 1.3.1
ms << "Others: " << others << endline;
ms << "Quantity: " << (is_quantity() ? "true" : "false") << endline;
ms << "Number: " << (is_number() ? "true" : "false") << endline;
ms << "Trivial: " << (is_trivial() ? "true" : "false") << endline;
} //operands::print()
*/