ianhinder / Kranc

A Mathematica package for generating code for solving time dependent partial differential equations
http://kranccode.org
GNU General Public License v2.0
29 stars 10 forks source link

Support multi-argument Max/Min #38

Closed eschnett closed 13 years ago

eschnett commented 13 years ago

Support multi-argument Max and Min calls in Kranc.

eschnett commented 13 years ago
Subject: Support multi-argument Max/Min
From: Erik Schnetter <eschnetter@perimeterinstitute.ca>
Date: 2011-08-30

Support multi-argument Max and Min calls in Kranc.

diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m
index 93b1740..17654a8 100644
--- repos/Kranc/Tools/CodeGen/CodeGen.m
+++ repos/Kranc/Tools/CodeGen/CodeGen.m
@@ -961,8 +967,9 @@ ReplacePowers[expr_, vectorise_] :=
              (* there have been some problems doing the Max/Min
                 replacement via the preprocessor for C, so we do it
                 here *)
-             rhs = rhs /. Max[xx_, yy_] -> fmax[xx, yy];
-             rhs = rhs /. Min[xx_, yy_] -> fmin[xx, yy];
+             (* Note: Mathematica simplifies Max[xx_] -> xx automatically *)
+             rhs = rhs //. Max[xx_, yy__] -> fmax[xx, Max[yy]];
+             rhs = rhs //. Min[xx_, yy__] -> fmin[xx, Min[yy]];

              rhs = rhs /. Power[xx_, power_] -> pow[xx, power];
ianhinder commented 13 years ago

Looks good. Thanks. Please commit.

eschnett commented 13 years ago

Pushed.