
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
double code(double x, double y, double z, double t) {
return x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + (y * (z * (tanh((t / y)) - tanh((x / y)))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
}
def code(x, y, z, t): return x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y))))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
Initial program 94.7%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6497.6%
Applied egg-rr97.6%
Final simplification97.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y))))) (if (<= t_1 5e+304) t_1 (* z (- t x)))))
double code(double x, double y, double z, double t) {
double t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
double tmp;
if (t_1 <= 5e+304) {
tmp = t_1;
} else {
tmp = z * (t - x);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y))
if (t_1 <= 5d+304) then
tmp = t_1
else
tmp = z * (t - x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x + ((Math.tanh((t / y)) - Math.tanh((x / y))) * (z * y));
double tmp;
if (t_1 <= 5e+304) {
tmp = t_1;
} else {
tmp = z * (t - x);
}
return tmp;
}
def code(x, y, z, t): t_1 = x + ((math.tanh((t / y)) - math.tanh((x / y))) * (z * y)) tmp = 0 if t_1 <= 5e+304: tmp = t_1 else: tmp = z * (t - x) return tmp
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y))) tmp = 0.0 if (t_1 <= 5e+304) tmp = t_1; else tmp = Float64(z * Float64(t - x)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y)); tmp = 0.0; if (t_1 <= 5e+304) tmp = t_1; else tmp = z * (t - x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e+304], t$95$1, N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.9999999999999997e304Initial program 97.6%
if 4.9999999999999997e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 51.3%
Taylor expanded in y around inf
/-lowering-/.f64N/A
--lowering--.f6451.3%
Simplified51.3%
Taylor expanded in z around inf
*-lowering-*.f64N/A
--lowering--.f6493.8%
Simplified93.8%
Final simplification97.3%
(FPCore (x y z t)
:precision binary64
(if (<= y 4.6e-68)
x
(if (<= y 1.35e+171)
(+ x (* (* z y) (- (tanh (/ t y)) (/ x y))))
(+ x (* z (- t x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4.6e-68) {
tmp = x;
} else if (y <= 1.35e+171) {
tmp = x + ((z * y) * (tanh((t / y)) - (x / y)));
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 4.6d-68) then
tmp = x
else if (y <= 1.35d+171) then
tmp = x + ((z * y) * (tanh((t / y)) - (x / y)))
else
tmp = x + (z * (t - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4.6e-68) {
tmp = x;
} else if (y <= 1.35e+171) {
tmp = x + ((z * y) * (Math.tanh((t / y)) - (x / y)));
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 4.6e-68: tmp = x elif y <= 1.35e+171: tmp = x + ((z * y) * (math.tanh((t / y)) - (x / y))) else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 4.6e-68) tmp = x; elseif (y <= 1.35e+171) tmp = Float64(x + Float64(Float64(z * y) * Float64(tanh(Float64(t / y)) - Float64(x / y)))); else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 4.6e-68) tmp = x; elseif (y <= 1.35e+171) tmp = x + ((z * y) * (tanh((t / y)) - (x / y))); else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 4.6e-68], x, If[LessEqual[y, 1.35e+171], N[(x + N[(N[(z * y), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.6 \cdot 10^{-68}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+171}:\\
\;\;\;\;x + \left(z \cdot y\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 4.59999999999999994e-68Initial program 96.3%
Taylor expanded in x around inf
Simplified61.8%
if 4.59999999999999994e-68 < y < 1.3499999999999999e171Initial program 97.6%
Taylor expanded in x around 0
/-lowering-/.f6483.7%
Simplified83.7%
if 1.3499999999999999e171 < y Initial program 80.9%
Taylor expanded in y around inf
+-lowering-+.f64N/A
*-lowering-*.f64N/A
--lowering--.f6490.8%
Simplified90.8%
Final simplification68.9%
(FPCore (x y z t) :precision binary64 (if (<= y 1.5e-67) x (+ x (* y (* z (- (tanh (/ t y)) (/ x y)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.5e-67) {
tmp = x;
} else {
tmp = x + (y * (z * (tanh((t / y)) - (x / y))));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.5d-67) then
tmp = x
else
tmp = x + (y * (z * (tanh((t / y)) - (x / y))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.5e-67) {
tmp = x;
} else {
tmp = x + (y * (z * (Math.tanh((t / y)) - (x / y))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.5e-67: tmp = x else: tmp = x + (y * (z * (math.tanh((t / y)) - (x / y)))) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.5e-67) tmp = x; else tmp = Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - Float64(x / y))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.5e-67) tmp = x; else tmp = x + (y * (z * (tanh((t / y)) - (x / y)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.5e-67], x, N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{-67}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right)\right)\\
\end{array}
\end{array}
if y < 1.50000000000000016e-67Initial program 96.3%
Taylor expanded in x around inf
Simplified61.8%
if 1.50000000000000016e-67 < y Initial program 90.7%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f64N/A
tanh-lowering-tanh.f64N/A
/-lowering-/.f6495.9%
Applied egg-rr95.9%
Taylor expanded in x around 0
/-lowering-/.f6486.4%
Simplified86.4%
Final simplification68.8%
(FPCore (x y z t) :precision binary64 (if (<= y 78000000.0) x (+ x (* z (- t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 78000000.0) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 78000000.0d0) then
tmp = x
else
tmp = x + (z * (t - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 78000000.0) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 78000000.0: tmp = x else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 78000000.0) tmp = x; else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 78000000.0) tmp = x; else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 78000000.0], x, N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 78000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 7.8e7Initial program 96.6%
Taylor expanded in x around inf
Simplified62.4%
if 7.8e7 < y Initial program 88.3%
Taylor expanded in y around inf
+-lowering-+.f64N/A
*-lowering-*.f64N/A
--lowering--.f6479.9%
Simplified79.9%
(FPCore (x y z t) :precision binary64 (if (<= y 600000000.0) x (* x (- 1.0 z))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 600000000.0) {
tmp = x;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 600000000.0d0) then
tmp = x
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 600000000.0) {
tmp = x;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 600000000.0: tmp = x else: tmp = x * (1.0 - z) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 600000000.0) tmp = x; else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 600000000.0) tmp = x; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 600000000.0], x, N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 600000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < 6e8Initial program 96.6%
Taylor expanded in x around inf
Simplified62.6%
if 6e8 < y Initial program 88.1%
Taylor expanded in y around inf
/-lowering-/.f64N/A
--lowering--.f6469.4%
Simplified69.4%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6468.0%
Simplified68.0%
(FPCore (x y z t) :precision binary64 (if (<= z -1.35e+232) (* z t) x))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.35e+232) {
tmp = z * t;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-1.35d+232)) then
tmp = z * t
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.35e+232) {
tmp = z * t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.35e+232: tmp = z * t else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.35e+232) tmp = Float64(z * t); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.35e+232) tmp = z * t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.35e+232], N[(z * t), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+232}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35e232Initial program 89.0%
Taylor expanded in y around inf
/-lowering-/.f64N/A
--lowering--.f6456.2%
Simplified56.2%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f6443.6%
Simplified43.6%
if -1.35e232 < z Initial program 95.1%
Taylor expanded in x around inf
Simplified61.3%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 94.7%
Taylor expanded in x around inf
Simplified58.3%
(FPCore (x y z t) :precision binary64 (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
double code(double x, double y, double z, double t) {
return x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + (y * (z * (tanh((t / y)) - tanh((x / y)))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
}
def code(x, y, z, t): return x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y))))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
herbie shell --seed 2024191
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))