2018-09-17 16:18:29 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim:fenc=utf-8
|
|
|
|
#
|
|
|
|
# Copyright © 2017 lafrite <lafrite@Poivre>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
|
|
|
|
"""
|
2018-09-20 16:40:04 +00:00
|
|
|
Generate and compute like a student!
|
|
|
|
|
|
|
|
:example:
|
|
|
|
|
|
|
|
>>> e = Expression.from_str("2+3*4")
|
|
|
|
>>> e_simplified = e.simplify()
|
|
|
|
>>> print(e_simplified)
|
|
|
|
14
|
|
|
|
>>> for s in e_simplified.explain():
|
|
|
|
... print(s)
|
|
|
|
2 + 3 * 4
|
|
|
|
2 + 12
|
|
|
|
14
|
2018-10-10 08:40:40 +00:00
|
|
|
|
2018-09-20 16:40:04 +00:00
|
|
|
>>> e = Expression.from_str("2+3/2")
|
|
|
|
>>> e_simplified = e.simplify()
|
|
|
|
>>> print(e_simplified)
|
|
|
|
7 / 2
|
|
|
|
>>> for s in e_simplified.explain():
|
|
|
|
... print(s)
|
|
|
|
2 + 3 / 2
|
|
|
|
2 / 1 + 3 / 2
|
|
|
|
(2 * 2) / (1 * 2) + 3 / 2
|
|
|
|
4 / 2 + 3 / 2
|
|
|
|
(4 + 3) / 2
|
|
|
|
7 / 2
|
2018-10-10 08:40:40 +00:00
|
|
|
|
2018-10-10 08:13:58 +00:00
|
|
|
>>> e = Expression.from_str("(2/3)^4")
|
|
|
|
>>> e_simplified = e.simplify()
|
|
|
|
>>> print(e_simplified)
|
|
|
|
16 / 81
|
|
|
|
>>> for s in e_simplified.explain():
|
|
|
|
... print(s)
|
|
|
|
(2 / 3)^4
|
|
|
|
2^4 / 3^4
|
|
|
|
16 / 81
|
2018-10-10 08:40:40 +00:00
|
|
|
|
2018-10-10 08:28:38 +00:00
|
|
|
>>> e = Expression.from_str("x^2*x*x^4")
|
|
|
|
>>> e_simplified = e.simplify()
|
|
|
|
>>> print(e_simplified)
|
|
|
|
x^7
|
|
|
|
>>> for s in e_simplified.explain():
|
|
|
|
... print(s)
|
|
|
|
x^2 * x * x^4
|
|
|
|
x^3 * x^4
|
|
|
|
x^(3 + 4)
|
|
|
|
x^7
|
2018-09-17 16:18:29 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from .expression import Expression
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|