@@ -35,11 +35,12 @@ mutable struct BookKeeping
3535 v_array4 :: Vector{Symbol}
3636 v_preamb :: Vector{Union{Symbol,Expr}}
3737 retvar :: Symbol
38+ numaux :: Int
3839
3940 function BookKeeping ()
4041 return new (Dict {Symbol, Expr} (), Dict {Union{Symbol,Expr}, Number} (),
4142 Dict {Symbol, Expr} (), Symbol[], Symbol[], Symbol[], Symbol[], Symbol[], Symbol[],
42- Union{Symbol,Expr}[], :nothing )
43+ Union{Symbol,Expr}[], :nothing , 0 )
4344 end
4445end
4546
@@ -343,7 +344,7 @@ function _preamble_body(fnbody, fnargs)
343344 bkkeep = BookKeeping ()
344345
345346 # Rename vars to have the body in non-indexed form; bkkeep has different entries
346- # for bookkeeping variables/symbolds , including indexed ones
347+ # for bookkeeping variables/symbols , including indexed ones
347348 fnbody, bkkeep. d_indx = _rename_indexedvars (fnbody)
348349
349350 # Create `newfnbody` which corresponds to `fnbody`, cleaned (without irrelevant comments)
@@ -372,7 +373,7 @@ function _preamble_body(fnbody, fnargs)
372373 newfnbody = subs (newfnbody, bkkeep. d_indx)
373374
374375 # Define retvar; for scalar eqs is the last entry included in v_newvars
375- bkkeep. retvar = length (fnargs) == 3 ? subs (bkkeep. v_newvars[end ], bkkeep. d_indx) : fnargs[1 ]
376+ bkkeep. retvar = length (fnargs) == 3 ? subs (bkkeep. v_newvars[end - bkkeep . numaux ], bkkeep. d_indx) : fnargs[1 ]
376377
377378 return defspreamble, defsprealloc, newfnbody, bkkeep
378379end
@@ -836,10 +837,11 @@ function _replacecalls!(bkkeep::BookKeeping, fnold::Expr, newvar::Symbol)
836837 end
837838
838839 elseif ll == 3
839- # Binary call; no auxiliary expressions needed
840+ # Binary call
840841 newarg2 = fnold. args[3 ]
841842
842843 # Replacements
844+ # @show TaylorSeries._dict_binary_calls[dcall]
843845 fnexpr, def_fnexpr, aux_fnexpr = TaylorSeries. _dict_binary_calls[dcall]
844846 fnexpr = subs (fnexpr,
845847 Dict (:_res => newvar, :_arg1 => newarg1, :_arg2 => newarg2, :_k => :ord ))
@@ -861,6 +863,28 @@ function _replacecalls!(bkkeep::BookKeeping, fnold::Expr, newvar::Symbol)
861863 # Dict(:_res => newvar, :_arg1 => :(constant_term($(newarg1))),
862864 # :_arg2 => :(constant_term($(newarg2))), :_k => :ord))
863865
866+ # Auxiliary expression
867+ if aux_fnexpr. head != :nothing
868+ newaux = genname ()
869+
870+ aux_alloc = :( _res = Taylor1 ($ (aux_fnexpr. args[2 ]), order) )
871+ aux_alloc = subs (aux_alloc,
872+ Dict (:_res => newaux, :_arg1 => :(constant_term ($ (newarg1))), :_aux => newaux))
873+
874+ aux_fnexpr = Expr (:block ,
875+ :(TaylorSeries. zero! (_res)),
876+ :(_res. coeffs[1 ] = $ (aux_fnexpr. args[2 ])) )
877+ aux_fnexpr = subs (aux_fnexpr,
878+ Dict (:_res => newaux, :_arg1 => :(constant_term ($ (newarg1))), :_aux => newaux))
879+
880+ fnexpr = subs (fnexpr, Dict (:_aux => newaux))
881+ if newvar ∈ bkkeep. v_arraydecl
882+ push! (bkkeep. v_arraydecl, newaux)
883+ else
884+ bkkeep. numaux += 1
885+ push! (bkkeep. v_newvars, newaux)
886+ end
887+ end
864888 else
865889 # Recognized call, but not a unary or binary call; copy expression
866890 fnexpr = :($ newvar = $ fnold)
0 commit comments