simplification

Sympy: How to minimize the number of multiplications in multivariate expressions?

浪尽此生 提交于 2021-02-19 07:43:11
问题 I have a lot of expressions which sympy default writes as sums of products of variables. These expressions can get quite long. I would like to simplify these expressions to have as few as possible multiplications. A reduced example: from sympy import symbols, cse, factor, simplify, count_ops, collect a,b,c=symbols("a b c", integer=True, positive=True) e = a*a*b + a*a + a*b*b + a*b*c + 4*a*b + a*c + 3*a + b*b*c + 4*b*c + 3*c + 1 What I would like to get is something like: (a + b + 3) * (a + c)

Is there any way to get CGAL's polyline simplification to work for inner/shared boundaries?

对着背影说爱祢 提交于 2021-02-10 05:22:08
问题 I've been trying to carry out line simplification on polygons belonging to maps with the help of this CGAL guide, e.g. South Korea. This is a screenshot of South Korea after line simplification with CGAL. I carried out the line simplification by adding each polygon to CGAL::Constrained_triangulation_plus_2<CDT> ct and then running CGAL::Polyline_simplification_2::simplify(ct, Cost(), Stop(0.5)); . The outer boundaries will get simplified but the inner/shared boundaries (between provinces)

maple - Can you simplify an expression in terms of pre defined variables?

别等时光非礼了梦想. 提交于 2021-01-29 15:26:02
问题 I have some particular dimensionless numbers commonly used in fluid mechanics. I want to express a certain expression in terms of these variables. If I define my dimensionless numbers and then do simplify(*expression*) where the expression is a function of variables that have all been used at least once in the definition of the dimensionless numbers, is it able to give this expression in terms of these dimensionless numbers? Can it be used to save time with this sort of algebra? Many thanks !

Turning Map(“a” -> 2, “b” -> 1) into seq(“a”,“a”,“b”) using map

拟墨画扇 提交于 2021-01-20 09:43:01
问题 I am trying to turn a Map("a" -> 2, "b" -> 1) into seq("a","a","b") through the map function, Currently I am trying to run the code below giving me the desired result. Is there a smarter way to do this? Possibly a better way through the map function? var multiset : Seq[T] = Seq[T]() var variables : Seq[T] = data.map(x => x._1).toSeq var variableCounts : Seq[Int] = data.map(x => x._2).toSeq for(x <- 0 until variables.length){ for(y <- 0 until variableCounts(x)) multiset = multiset :+ variables

Turning Map(“a” -> 2, “b” -> 1) into seq(“a”,“a”,“b”) using map

这一生的挚爱 提交于 2021-01-20 09:42:11
问题 I am trying to turn a Map("a" -> 2, "b" -> 1) into seq("a","a","b") through the map function, Currently I am trying to run the code below giving me the desired result. Is there a smarter way to do this? Possibly a better way through the map function? var multiset : Seq[T] = Seq[T]() var variables : Seq[T] = data.map(x => x._1).toSeq var variableCounts : Seq[Int] = data.map(x => x._2).toSeq for(x <- 0 until variables.length){ for(y <- 0 until variableCounts(x)) multiset = multiset :+ variables

Turning Map(“a” -> 2, “b” -> 1) into seq(“a”,“a”,“b”) using map

人走茶凉 提交于 2021-01-20 09:41:10
问题 I am trying to turn a Map("a" -> 2, "b" -> 1) into seq("a","a","b") through the map function, Currently I am trying to run the code below giving me the desired result. Is there a smarter way to do this? Possibly a better way through the map function? var multiset : Seq[T] = Seq[T]() var variables : Seq[T] = data.map(x => x._1).toSeq var variableCounts : Seq[Int] = data.map(x => x._2).toSeq for(x <- 0 until variables.length){ for(y <- 0 until variableCounts(x)) multiset = multiset :+ variables

disabling automatic simplification in sympy

半城伤御伤魂 提交于 2020-06-13 04:04:46
问题 i want to disable automatic simplification in sympy, for example solving the equation x*y-x i want to get x/x instead of 1 import sympy from sympy.abc import x,y,z expr = x*y-x sympy.solve(expr,y) => 1 # i want unsimplified x/x instead of 1 From the sympy manual, i found UnevaluatedExpr for this purpose, but it returns empty list for the example given from sympy import UnevaluatedExpr expr1 = UnevaluatedExpr(x)*UnevaluatedExpr(y)-UnevaluatedExpr(x) sympy.solve(expr1,y) => [] my question is

disabling automatic simplification in sympy

旧城冷巷雨未停 提交于 2020-06-13 04:04:10
问题 i want to disable automatic simplification in sympy, for example solving the equation x*y-x i want to get x/x instead of 1 import sympy from sympy.abc import x,y,z expr = x*y-x sympy.solve(expr,y) => 1 # i want unsimplified x/x instead of 1 From the sympy manual, i found UnevaluatedExpr for this purpose, but it returns empty list for the example given from sympy import UnevaluatedExpr expr1 = UnevaluatedExpr(x)*UnevaluatedExpr(y)-UnevaluatedExpr(x) sympy.solve(expr1,y) => [] my question is

How can I combine a conditional with a for loop in Python?

天大地大妈咪最大 提交于 2019-12-31 06:30:47
问题 I have a simple example I've drawn up. I thought it was possible to combine if statements and for loops with minimal effort in Python. Given: sublists = [number1, number2, number3] for sublist in sublists: if sublist: print(sublist) I thought I could condense the for loop to: for sublist in sublists if sublist: but this results in invalid syntax. I'm not too particular on this example, I just want a method of one lining simple if statements with loops. 回答1: if you want to filter out all the

How can I combine a conditional with a for loop in Python?

十年热恋 提交于 2019-12-31 06:30:24
问题 I have a simple example I've drawn up. I thought it was possible to combine if statements and for loops with minimal effort in Python. Given: sublists = [number1, number2, number3] for sublist in sublists: if sublist: print(sublist) I thought I could condense the for loop to: for sublist in sublists if sublist: but this results in invalid syntax. I'm not too particular on this example, I just want a method of one lining simple if statements with loops. 回答1: if you want to filter out all the