/* Copyright (C) 2026 Viktor T. Toth <https://www.vttoth.com/>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * Supplement to itensor.lisp: aggressive tensor simplification
 *
 * Apply all simplifications to the argument using both settings
 * of flipflag. Return a final, further simplified version.
 *
 */

isimplify(T):=block([T:T],
  T:rename(contract(contract(canform(rename(simpmetderiv(expand(T))))))),
  flipflag: not flipflag,
  T:rename(contract(contract(canform(rename(simpmetderiv(expand(T))))))),
  flipflag:not flipflag,
  rename(simpmetderiv(canform(T))));

