Post Reply 
2010 Ti Nspire Faster than G2 HP Prime
09-18-2022, 01:43 PM
Post: #7
RE: 2010 Ti Nspire Faster than G2 HP Prime
(09-18-2022 07:50 AM)parisse Wrote:  Everybody can look at the source code of giac and see what happens here, let me explain how. Untar the source code (https://www-fourier.univ-grenoble-alpes....stable.tgz), go to the src directory and run
Code:
grep at_expand *.cc
(all user commands have a corresponding at_-prefixed object defined in the C++ source).
There are a few lines returned, the interesting one is
Code:
lin.cc:  define_unary_function_ptr( at_expand ,alias_at_expand ,&__expand);
Therefore expand source code is located in lin.cc. Open lin.cc with your favorite text editor, and search at_expand, you'll see just above expand source code (most user commands have an equivalent C++ code with the same prototype and either the same name or the same name prefixed with _):
Code:

  gen expand(const gen & e,GIAC_CONTEXT){
    if (is_equal(e))
      return apply_to_equal(e,expand,contextptr);
    if (e.type==_SYMB && (e._SYMBptr->sommet==at_and || e._SYMBptr->sommet==at_ou)){
      ...
    }
   vector<const unary_function_ptr *> v;
    vector< gen_op_context > w;
    v.push_back(at_prod);
    v.push_back(at_pow);
    v.push_back(at_neg);
    w.push_back(&prod_expand);
    w.push_back(&expand_pow_expand);
    w.push_back(&expand_neg_expand);
    return _simplifier(subst(e,v,w,false,contextptr),contextptr);
  }
It means that expand is done by substitution of rational operators by expanding code for each operator. Then a quick look at prod_expand and expand_pow_expand will show you that expand is implemented by applying rules only (e.g. distribution rule of * vs +/-), it does not take advantage of the fact that the input is a univariate polynomial while the TI obviously does.
You can also see how the expansion is done step by step on this example, run from the giac directory
Code:
export CXXFLAGS=-g &&  ./configure && cd src && make
then open gdb on .libs/icas (icas is the name of the giac shell executable), set a breakpoint at giac::expand_pow_expand, and run from gdb console:
Code:
r 'expand((x^2+7x+4)^5)'

Now the conclusion is that expand on the Prime is *not* the equivalent of expand on the TI Nspire, in fact it should be compared to normal/simplify on the Prime, or more precisely to partfrac on the Prime (the expand commandname on the Nspire is a bit misleading, it does not only expand, but also does partial fraction expansion).
The Prime CAS has more options/commands than the TI Nspire CAS, which means that before drawing conclusions on a benchmark, one should dig a little bit. Since this will probably not happen, I have now modified giac source code accordingly, see:
https://github.com/geogebra/giac/commits/master
Unfortunately, I have no idea when the change will be released in a public Prime firmware...

Thank you so very much for this in depth explanation; truly appreciated!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: 2010 Ti Nspire Faster than G2 HP Prime - gastondefer - 09-18-2022 01:43 PM



User(s) browsing this thread: 3 Guest(s)