simplify

Sympy - Simplify expression within domain

痴心易碎 提交于 2021-02-05 10:50:50
问题 Can Sympy automatically simplify an expression that includes terms like this one: cos(x)/(cos(x)**2)**(1/2) which can be simplified to 1 in the domain that I am interested in 0 <= x <= pi/2 ? (Examples of other terms that could be simplified in that domain: acos(cos(x)); sqrt(sin(x)**2); sqrt(cos(2*x) + 1); etc.) 回答1: If you know the functions that are in your expression (such as sin , cos and tan ), you can do the following according to this stack overflow question: from sympy import * x =

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 !

Simplify Python code (Rock, Paper, Scissors)

爷,独闯天下 提交于 2021-01-29 06:15:42
问题 I am a complete python newbie and this is my first question on stackoverflow, so please be patient with me :) So to get some excersise, I tried programming my own rock, paper, scissors game in Python. However, my code is relatively long compared to other rock, paper, scissor programs. This is because I programmed every single possible option in the game. Is there a possibility to simplify this code? As in not having to programm every single possibiliy in the game? Because doing so might be

Simplifying nested Maybe pattern matching

余生长醉 提交于 2020-01-13 05:21:08
问题 I have the following construct in my code: f :: Maybe A -> X f a = case a of Nothing -> x (Just b) -> case b of Nothing -> y (Just c) -> case c of Nothing -> z (Just d) -> d I'm not seeing an obvious way to simplify this instead of using nested maybe functions, which wouldn't make the whole thing look much better. Are there any clever - but still understandable - tricks that would help make this construct more "elegant"? 回答1: UPDATED 2 Monad Either is for you import Data.Maybe (maybe) maybeE

Combining mysql queries that recycle multiple self joins

六眼飞鱼酱① 提交于 2019-12-23 02:38:33
问题 I have the following set of MySQL queries, used to track user progress through a website. Is there a good way to simplify them? #How many people reached stage 2 SELECT COUNT(DISTINCT a.session_id) as "total" FROM formation_page_hits a WHERE a.progress = 2 AND DATE(a.datetime) = "2011-03-23"; #How many people reached stage 4 having reached stage 2 SELECT COUNT(DISTINCT a.session_id) as "total" FROM formation_page_hits a, (SELECT f.session_id, f.`datetime` FROM formation_page_hits f WHERE f

Simplify this regular expression

一曲冷凌霜 提交于 2019-12-22 04:54:16
问题 I'm doing some pre-exam exercises for my compilers class, and needed to simplify this regular expression. (a U b)*(a U e)b* U (a U b)*(b U e)a* Quite obviously, the e is the empty string, and the U stands for union. So far, I think one of the (a U b)* can be removed, as the union of a U a = a. However, I can't find any other simplifications, and am not doing so well with the other problems thus far. :( Any help is appreciated, thanks very much! 回答1: Little rusty on regex, but if * still

How to reduce the number of points in a curve while preserving its overall shape?

浪尽此生 提交于 2019-12-20 11:36:13
问题 I have a list of points that make a curve, and I would like to reduce the number of points, but still keep the overall shape of the curve. Basically, I want to go from this: To this: So the algorithm would remove the points that are redundant but preserve those that really define the shape (like the points at the bottom of the curve). Is there any known algorithm to do that? I expect there is but I'm not sure what to search for on Google. Any help would be appreciated. 回答1: Consider Douglas

Expression templates: improving performance in evaluating expressions?

☆樱花仙子☆ 提交于 2019-12-19 08:17:08
问题 By the expression templates technique, a matrix expression like D = A*B+sin(C)+3.; is pretty much equivalent, in terms of computing performance, to a hand-written for loop. Now, suppose that I have the following two expressions D = A*B+sin(C)+3.; F = D*E; cout << F << "\n"; In a "classical" implementation by expression templates, the computing performance will be pretty much the same as that of two for loops in sequence. This is because the expressions are evaluated immediately after the =

Get mathematica to simplify expression with another equation

社会主义新天地 提交于 2019-12-18 10:27:14
问题 I have a very complicated mathematica expression that I'd like to simplify by using a new, possibly dimensionless parameter. An example of my expression is: K=a*b*t/((t+f)c*d); (the actual expression is monstrously large, thousands of characters). I'd like to replace all occurrences of the expression t/(t+f) with p p=t/(t+f); The goal here is to find a replacement so that all t's and f's are replaced by p. In this case, the replacement p is a nondimensionalized parameter, so it seems like a

Simplifying CNF formula while preserving all solutions wrt certain variables

随声附和 提交于 2019-12-13 17:25:01
问题 Related: CNF simplification (in fact, I think the submitter of that question might have been after what I want here) A number of tools exist for simplifying (or "preprocessing" before solving) DIMACS format CNF formulas, and most SAT solvers incorporate some. However, all that I am aware of simplify a trivially satisfiable formula into a trivially satisfiable CNF with zero or one variables, i.e. they only attempt to preserve the satisfiability of the formula. I have tried at least SatELite