2018-01-21 08:26:34 +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-17 14:27:08 +00:00
|
|
|
r"""
|
2018-01-21 08:26:34 +00:00
|
|
|
Abstracts tools for calculs manipulations
|
2018-09-17 14:27:08 +00:00
|
|
|
|
|
|
|
:example:
|
|
|
|
|
|
|
|
>>> t = Tree.from_str("2+3*4")
|
|
|
|
>>> print(t)
|
|
|
|
+
|
|
|
|
> 2
|
|
|
|
> *
|
|
|
|
| > 3
|
|
|
|
| > 4
|
2018-11-19 11:23:37 +00:00
|
|
|
>>> print(t.apply_on_last_level(compute))
|
2018-09-17 14:27:08 +00:00
|
|
|
+
|
|
|
|
> 2
|
|
|
|
> 12
|
|
|
|
>>> tree2txt(t)
|
|
|
|
'2 + 3 * 4'
|
|
|
|
>>> tree2tex(t)
|
|
|
|
'2 + 3 \\times 4'
|
2018-09-24 13:47:47 +00:00
|
|
|
|
|
|
|
>>> t = Tree.from_str("2+3/4")
|
|
|
|
>>> print(t)
|
|
|
|
+
|
|
|
|
> 2
|
|
|
|
> /
|
|
|
|
| > 3
|
|
|
|
| > 4
|
2018-11-19 11:23:37 +00:00
|
|
|
>>> print(t.apply_on_last_level(compute))
|
2018-11-21 08:37:17 +00:00
|
|
|
+
|
|
|
|
> 2
|
|
|
|
> /
|
|
|
|
| > 3
|
|
|
|
| > 4
|
2018-11-19 11:23:37 +00:00
|
|
|
>>> tt = t.apply_on_last_level(typing)
|
|
|
|
>>> print(tt.apply_on_last_level(compute))
|
2018-09-24 13:47:47 +00:00
|
|
|
+
|
2018-12-21 11:20:13 +00:00
|
|
|
> 2 / 1
|
|
|
|
> 3 / 4
|
2018-11-19 11:23:37 +00:00
|
|
|
>>> type(t.right_value)
|
|
|
|
<class 'mapytex.calculus.core.tree.Tree'>
|
|
|
|
>>> type(tt.right_value)
|
|
|
|
<class 'mapytex.calculus.core.MO.fraction.MOFraction'>
|
|
|
|
>>> tt.right_value
|
|
|
|
<MOFraction 3 / 4>
|
2018-09-24 13:47:47 +00:00
|
|
|
|
2018-09-20 16:27:40 +00:00
|
|
|
>>> t = Tree.from_str("2+3x")
|
|
|
|
>>> print(t)
|
|
|
|
+
|
|
|
|
> 2
|
|
|
|
> *
|
|
|
|
| > 3
|
|
|
|
| > x
|
2018-09-17 14:27:08 +00:00
|
|
|
|
2018-01-21 08:26:34 +00:00
|
|
|
"""
|
|
|
|
|
2018-10-01 14:14:04 +00:00
|
|
|
from .tree import Tree, AssocialTree
|
2018-09-17 14:27:08 +00:00
|
|
|
from .compute import compute
|
2018-11-19 11:23:37 +00:00
|
|
|
from .typing import typing, TypingError
|
2018-09-17 14:27:08 +00:00
|
|
|
from .renders import tree2txt, tree2tex
|
2020-08-20 15:36:38 +00:00
|
|
|
from .random import list_generator
|
2018-09-17 14:27:08 +00:00
|
|
|
|
2018-01-21 08:26:34 +00:00
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|