﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
4971	More issues with Complex multiplication in NF	Francesco Casella	Per Östlund	"Please run the following model with the NF
{{{
model TestSqrt
  Complex z,w;
equation
  z = Complex(time, 1);
  w = sqrt(3)*z;
end TestSqrt;
}}}
The following error is reported:
{{{
TestSqrt_functions.c: In function 'omc_omplex__omcQuot_2A_multiply__eval1':
TestSqrt_functions.c:56:3: error: '_c3' undeclared (first use in this function)
   _c3._re = tmp1._re;
   ^
TestSqrt_functions.c:56:3: note: each undeclared identifier is reported only once for each function it appears in
}}}
With the old FE, the model is flattened to
{{{
function Complex.'*'.multiply ""Inline before index reduction"" ""Multiply two complex numbers""
  input Complex c1 ""Complex number 1"";
  input Complex c2 ""Complex number 2"";
  output Complex c3 ""= c1*c2"";
algorithm
  c3 := Complex(c1.re * c2.re - c1.im * c2.im, c1.re * c2.im + c1.im * c2.re);
end Complex.'*'.multiply;

class TestSqrt
  Real z.re ""Real part of complex number"";
  Real z.im ""Imaginary part of complex number"";
  Real w.re ""Real part of complex number"";
  Real w.im ""Imaginary part of complex number"";
equation
  z.re = time;
  z.im = 1.0;
  w = Complex.'*'.multiply(Complex.'constructor'.fromReal(1.732050807568877, 0.0), z);
end TestSqrt;
}}}

while the NF gives
{{{
function Complex.'*'.multiply ""Inline before index reduction"" ""Multiply two complex numbers""
  input Complex c1 ""Complex number 1"";
  input Complex c2 ""Complex number 2"";
  output Complex c3 ""= c1*c2"";
algorithm
  c3 := Complex.'constructor'.fromReal(c1.re * c2.re - c1.im * c2.im, c1.re * c2.im + c1.im * c2.re);
end Complex.'*'.multiply;

class TestSqrt
  Real z.re ""Real part of complex number"";
  Real z.im ""Imaginary part of complex number"";
  Real w.re ""Real part of complex number"";
  Real w.im ""Imaginary part of complex number"";
equation
  z = Complex.'constructor'.fromReal(time, 1.0);
  w = Complex.'*'.multiply(Complex.'constructor'.fromReal(1.732050807568877, 0.0), z);
end TestSqrt;
}}}
First of all, the NF does not expand the first equation into its scalar components, which may later prevent futher symbolic manipulation (e.g. symbolic Jacobian computation).

Furthermore, it does not expand the Complex constructor in the body of the multiplication function algorithm, which probably causes some problem with the generated code.

BTW, it would be really good if also the Complex equation involving {{{w}}} was eventually expanded into its scalar components, even if the old FE didn't do that. This would again allow for more optimizations in the code generation phase."	defect	closed	high	2.0.0	New Instantiation		fixed		
