This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<numeric> nth_root(const ex &f_, const symbol &x, const numeric epsilon = std::numeric_limits<double>::epsilon()){ | |
| ex f = f_; | |
| std::vector<numeric> result; | |
| int deg = f.degree(x); | |
| result.reserve(deg); | |
| ex g = f.diff(x); | |
| numeric xn = deg / 2.0, xm; | |
| for(; ; ){ | |
| xm = xn - ex_to<numeric>(f.subs(x == xn)) / ex_to<numeric>(g.subs(x == xn)); | |
| if(abs(xn - xm) < epsilon){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://gist.github.com/marionette-of-u/cd23016454f22bfb3383/019f24bfbdf60ba9025cd4ea664b051ebe678575 | |
| decl_g関数はBNF規則名を取り規則を保持するscanner::rule_rhsのインスタンスの参照を返す | |
| 中身はstd::map<std::string, scanner::rule_rhs>とほぼ同じ | |
| nt関数は非終端記号を内部処理可能な記号(=term(=int))に変換する | |
| seqクラスはコンストラクタに記号(=term(=int))の初期化リストとセマンティックアクションを取る | |
| 初期化リストはそのままBNF規則の右辺のひとつとして扱える | |
| ASTを構築してあとで解析するのでほとんどのセマンティックアクションはeat(食べる) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://github.com/marionette-of-u/kp19pp/blob/stable/scanner.cpp | |
| フォーマット解説 : | |
| DECL_SEQSマクロでBNF表現ルールを記述 | |
| DECL_SEQS_EPSはε還元を含むルールを追加する以外DECL_SEQSと同機能 | |
| L = Ra1 Ra2 Ra3 [ActA] | Rb1 Rb2 Rb3 [ActB]; | |
| を記述するには始めに左辺Lをマクロの引数に取る | |
| Rはa, bと複数個あるのでここでBOOST_PP_SEQ形式(Ra)(ActA)(Rb)(ActB)の形を取る |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <functional> | |
| #include <utility> | |
| #include <memory> | |
| #include <stdexcept> | |
| #include <iterator> | |
| #include <algorithm> | |
| #include <limits> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef MULTI_PRECISION_INCLUDE_INTEGER_HPP | |
| #define MULTI_PRECISION_INCLUDE_INTEGER_HPP | |
| #include <algorithm> | |
| #include <vector> | |
| #include <iostream> | |
| #include <string> | |
| #include <iterator> | |
| #include <utility> | |
| #include <random> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 疑似言語Tiel・構想 | |
| // カンマ演算子で得た値を再帰的に保存する | |
| class comma<class TypeA, class TypeB>{ | |
| TypeA lhs; | |
| TypeB rhs; | |
| }; | |
| // ブラケット演算子で得た値を保存する | |
| using bracket<class TypeA, class TypeB> = comma<TypeA, TypeB>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exception INVALID_ARGUMENT | |
| let rec nth = | |
| function (x :: _, 0) -> x | |
| | (x :: xs, n) -> nth(xs, n - 1) | |
| | ([], _) -> raise INVALID_ARGUMENT | |
| let null s = | |
| match s with | |
| | [] -> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <algorithm> | |
| #include <vector> | |
| #include <tuple> | |
| #include <functional> | |
| #include <utility> | |
| #include <memory> | |
| #include <boost/variant.hpp> | |
| template<class ValueType, class Less = std::less<ValueType>> | |
| class term_rewriting_system{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <token> token{ | |
| <right>{ unary_minus; } | |
| <left>{ | |
| mul = "\*", div = "\/"; | |
| add = "\+", sub = "-"; | |
| } | |
| left_paren = "\(", right_paren = "\)"; | |
| id<int> = "[a-zA-Z_][a-zA-Z0-9_]*"; | |
| } | |
| <grammar> parser{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ----class/struct | |
| dot | |
| 1ドットを表す構造体 | |
| b1u_t b; //blue | |
| b1u_t g; //green | |
| b1u_t r; //red | |
| b1u_t a; //alpha | |
| logic_error |