Skip to content

Instantly share code, notes, and snippets.

View egisatoshi's full-sized avatar

Satoshi Egi egisatoshi

View GitHub Profile
@egisatoshi
egisatoshi / fun.egi
Last active August 29, 2015 14:13
Egison version of this Prolog program https://gist.github.com/GRGSIBERIA/c61e05f3fbb4332bf81e
(define $worriors
{["nagisa_misumi" "futari_ha" "black"]
["honoka_yukishiro" "futari_ha" "white"]
["hikari_kujo" "max_heart" "luminus"]
["saki_hyuga" "splash_star" "bloom"]
["mai_misho" "splash_star" "eaglette"]
["nozomi_yumehara" "yes" "dream"]
["rin_natsuki" "yes" "rouge"]
["urara_kasugano" "yes" "lemonade"]
["komachi_akimoto" "yes" "mint"]
@egisatoshi
egisatoshi / triangles.egi
Last active August 29, 2015 14:13
Find all triangles
(define $points
{[3 1] [4 5] [7 7] [8 1] [1 9] [3 8] [3 1]})
(define $on-a-line?
(match-lambda [[integer integer] [integer integer] [integer integer]]
{[[[$x1 $y1] [$x2 $y2] [$x3 $y3]]
(eq? (abs (* (- y2 y1) (- x3 x1)))
(abs (* (- y3 y1) (- x2 x1))))]}))
; Enumerate triangles
@egisatoshi
egisatoshi / echo_server.erl
Created April 3, 2015 03:32
Very Simple Echo Sever in Erlang
-module(echo_server).
-export([start/0,stop/1]).
-define(PORT, 12321).
start() ->
Options = [binary, {packet, raw}, {active, true}, {reuseaddr, true}],
case gen_tcp:listen(?PORT, Options) of
{ok, Listen} -> spawn(fun() -> acceptor_loop(Listen) end),
@egisatoshi
egisatoshi / install-egison-to-make-pkg.sh
Last active August 29, 2015 14:24
Egison package for Mac
#!/bin/sh
sudo rm -rf .cabal .ghc /Library/Egison
mkdir .ghc
cabal update
cp my-cabal/config .cabal/config
sudo cabal update
sudo cabal install egison egison-tutorial
sleep 3
sudo rm -rf /Library/Egison/lib/ /Library/Egison/logs/ /Library/Egison/repo-cache/
@egisatoshi
egisatoshi / shell18.egi
Last active September 2, 2015 02:01
shell game 18 q8
cat number | egison -F1s -s '(match-all-lambda (list string) [<cons <join _ <cons $x <cons $y <join $s <cons ,x <cons ,y $t>>>>>> _> [x y (take-while eq? (zip (unpack s) (unpack t)))]])'
@egisatoshi
egisatoshi / maclaurin-expansion.md
Last active April 14, 2016 06:23
MacLaurin expansion on shell
% egison -T -e '(maclaurin-expansion (cos x) x)'                                        
1
0
(/ (* -1 x^2) 2)
0
(/ x^4 24)
0
(/ (* -1 x^6) 720)
0
@egisatoshi
egisatoshi / emacs_egison.el
Last active August 4, 2017 01:22
emacs seting for Egison
;; Egison mode
(load-file "~/egison/elisp/egison-mode.el")
(autoload 'egison-mode "egison-mode" "Major mode for editing Egison code." t)
(setq auto-mode-alist
(cons `("\\.egi$" . egison-mode) auto-mode-alist))
(load-file "~/elisp/xah-math-input/xah-math-input.el")
(global-set-key "\C-q" 'xah-math-input-change-to-symbol)
@egisatoshi
egisatoshi / taylor-expansion.egi
Created May 17, 2016 01:57
Multi variate Taylor Expansion
(define $∇
(lambda [$f $xs]
(generate-tensor
1#(∂/∂ f (nth %1 xs))
{(length xs)})))
(define $nabla ∇)
(define $taylor-expansion2
(lambda [$f $xs $as]
@egisatoshi
egisatoshi / tensor.egi
Last active May 19, 2016 07:16
tensor design
;;
;; Tensor
;;
[| x |]
;=>
x
(+ 1 [|1 2 3|])
;=>
(filter (match-lambda (list something)
{[(& <snoc ,D _>
<join _ <cons ,B <join _ <cons ,C _>>>>
<snoc _ <snoc _ <nioj _ <snoc ,B _>>>>
<join _ <cons ,C <join _ <cons ,A _>>>>)
#t]
[_ #f]})
(match-all {A B C D} (multiset something)
[<cons $a <cons $b <cons $c <cons $d <nil>>>>> {a b c d}]))