mergeFactors of FactoredFunctionUtilities will modify
its second argument:
(1) -> a:=factor 14
(1) 2 7
Type: Factored(Integer)
(2) -> b:=factor 15
(2) 3 5
Type: Factored(Integer)
(3) -> )expose FactoredFunctionUtilities
FactoredFunctionUtilities is now explicitly exposed in frame frame1
(3) -> mergeFactors(a,b)
(3) 2 3 5 7
Type: Factored(Integer)
(4) -> b
(4) 3 5 7
Type: Factored(Integer)
The reason is that:
(1). factorList returns not a copy but a reference.
So any destructive operations on the resutlt of factorList
is dangerous.
(2). makeFR uses SimplifyFactorization, which is destructive,
so argument passed to makeFR will be modified, users should
make copy if the argument is referenced somewhere else.
So the patch, along with a few cleanups:
--- a/src/algebra/fr.spad
+++ b/src/algebra/fr.spad
@@ -500,7 +500,7 @@
FR ==> Factored R
Exports ==> with
- refine : (FR, R-> FR) -> FR
+ refine : (FR, R -> FR) -> FR
++ refine(u, fn) is used to apply the function \userfun{fn} to
++ each factor of \spadvar{u} and then build a new factored
++ object from the results. For example, if \spadvar{u} were
@@ -517,13 +517,11 @@
++ the lists of factors.
Implementation ==> add
- fg : FR
- func : R -> FR
fUnion ==> Union("nil", "sqfr", "irred", "prime")
FF ==> Record(flg : fUnion, fctr : R, xpnt : Integer)
mergeFactors(f, g) ==
- makeFR(unit(f)*unit(g), append(factorList f, factorList g))
+ makeFR(unit(f)*unit(g), append(factorList f, copy factorList g))
refine(f, func) ==
u := unit(f)
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.