Question: Remove Assumptions for Code Generation

Hi,

this has been asked before but none of the other answers worked for me. I want to generate code from expressions that were simplified using some assumptions. I the assumptions remain on the variables Maple replaces variable names wich I don't understand.

Here is my script where I tried to remove the assumptions based on the answers of previous questions. Unfortunately, even though assumptions are removed in the end, Code generation still replaces the variables.

Thank you in advance!

Here is my minimal exaple Code:

> 

 

> 

restart:

> 

 

> 

# test removing assumptions

> 

funa:=x+y

x+y

(1)
> 

 Maple_proc := codegen[makeproc](funa,(ListTools[Flatten]([eval(alist,1)])));

proc (alist) x+y end proc

(2)
> 

# make some assumptions

> 

assume(x,real);assume(y,real);

> 

x,y

x, y

(3)
> 

#place variables in a list

> 

alist:=[x,y];

[x, y]

(4)
> 

# make cool interferences with assumptions...

> 

# clear assumptions

> 

# try 1 from https://www.mapleprimes.com/questions/207601-Remove-Assumptions-

> 

nms:=convert(indets(alist,name),list);
nmsS:=convert~(nms,string);
L:=StringTools:-Substitute~(nmsS,"~",""); #Removing "~"
L1:=parse~(L);
S:=nms=~L1;
Expr:=subs(S,expr);

[x, y]

 

["x~", "y~"]

 

["x", "y"]

 

[x, y]

 

[x = x, y = y]

 

expr

(5)
> 

hasassumptions(x)

true

(6)
> 

# try 2

> 

nops(alist)

2

(7)
> 

for i from 1 to nops(alist) do
parse(cat(StringTools[Substitute]~(alist[i],"~",""),":='",StringTools[Substitute]~(alist[i],"~",""),"'"));
end do;

'x'

 

'y'

(8)
> 

# check if assumtions are there

> 

hasassumptions(x)

true

(9)
> 

#try 3 https://www.mapleprimes.com/questions/39555-Unassume

> 

for u in alist do
`property/object`[u]:=evaln(`property/object`[u]);
`property/OrigName`[u]:=evaln(`property/OrigName`[u]);
end do;

`property/object`[x]

 

`property/OrigName`[x]

 

`property/object`[y]

 

`property/OrigName`[y]

(10)
> 

hasassumptions(x)

false

(11)
> 

hasassumptions(y)

false

(12)
> 

alist

[x, y]

(13)
> 

funb:=x+y

x+y

(14)
> 

 Maple_proc := codegen[makeproc](funb,(ListTools[Flatten]([eval(alist,1)])));

proc (x, y) x+y end proc

(15)
> 

 Maple_proc := codegen[makeproc](funa,(ListTools[Flatten]([eval(alist,1)])));

proc (x, y) x+y end proc

(16)
> 

 

> 

 CodeGeneration[C](Maple_proc, optimize, declare=[x::float,y::float], defaulttype=float, deducetypes=false, coercetypes=false, output="fun.c");

Warning, the following variable name replacements were made: x~ -> cg, y~ -> cg1

 
> 

 

>

 

> 

 

> 

 

> 

 

> 

 

> 

 

> 

 

>   


 

Download testunassuming.mw

Please Wait...