
(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 (fma z (* y (- (tanh (/ t y)) (tanh (/ x y)))) x))
double code(double x, double y, double z, double t) {
return fma(z, (y * (tanh((t / y)) - tanh((x / y)))), x);
}
function code(x, y, z, t) return fma(z, Float64(y * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), x) end
code[x_, y_, z_, t_] := N[(z * N[(y * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(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 99.9%
associate-*l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (tanh (/ t y))))
(if (<= t -6e-116)
(+ x (* y (* z t_1)))
(if (<= t 1.1e-210)
(+ x (* (* z y) (- (/ t y) (tanh (/ x y)))))
(fma z (* y t_1) x)))))
double code(double x, double y, double z, double t) {
double t_1 = tanh((t / y));
double tmp;
if (t <= -6e-116) {
tmp = x + (y * (z * t_1));
} else if (t <= 1.1e-210) {
tmp = x + ((z * y) * ((t / y) - tanh((x / y))));
} else {
tmp = fma(z, (y * t_1), x);
}
return tmp;
}
function code(x, y, z, t) t_1 = tanh(Float64(t / y)) tmp = 0.0 if (t <= -6e-116) tmp = Float64(x + Float64(y * Float64(z * t_1))); elseif (t <= 1.1e-210) tmp = Float64(x + Float64(Float64(z * y) * Float64(Float64(t / y) - tanh(Float64(x / y))))); else tmp = fma(z, Float64(y * t_1), x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t, -6e-116], N[(x + N[(y * N[(z * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.1e-210], N[(x + N[(N[(z * y), $MachinePrecision] * N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * t$95$1), $MachinePrecision] + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tanh \left(\frac{t}{y}\right)\\
\mathbf{if}\;t \leq -6 \cdot 10^{-116}:\\
\;\;\;\;x + y \cdot \left(z \cdot t_1\right)\\
\mathbf{elif}\;t \leq 1.1 \cdot 10^{-210}:\\
\;\;\;\;x + \left(z \cdot y\right) \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y \cdot t_1, x\right)\\
\end{array}
\end{array}
if t < -6.00000000000000053e-116Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 10.3%
*-commutative10.3%
associate-/r*10.3%
div-sub10.3%
rec-exp10.3%
rec-exp10.3%
tanh-def-a92.7%
Simplified92.7%
if -6.00000000000000053e-116 < t < 1.09999999999999995e-210Initial program 99.9%
Taylor expanded in t around 0 98.7%
if 1.09999999999999995e-210 < t Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 14.2%
associate-/r*14.2%
div-sub14.2%
rec-exp14.2%
rec-exp14.2%
tanh-def-a87.0%
Simplified87.0%
Final simplification92.4%
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.02e-115) (not (<= t 1.1e-210))) (+ x (* y (* z (tanh (/ t y))))) (+ x (* (* z y) (- (/ t y) (tanh (/ x y)))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.02e-115) || !(t <= 1.1e-210)) {
tmp = x + (y * (z * tanh((t / y))));
} else {
tmp = x + ((z * y) * ((t / y) - tanh((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 ((t <= (-1.02d-115)) .or. (.not. (t <= 1.1d-210))) then
tmp = x + (y * (z * tanh((t / y))))
else
tmp = x + ((z * y) * ((t / y) - tanh((x / y))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.02e-115) || !(t <= 1.1e-210)) {
tmp = x + (y * (z * Math.tanh((t / y))));
} else {
tmp = x + ((z * y) * ((t / y) - Math.tanh((x / y))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -1.02e-115) or not (t <= 1.1e-210): tmp = x + (y * (z * math.tanh((t / y)))) else: tmp = x + ((z * y) * ((t / y) - math.tanh((x / y)))) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.02e-115) || !(t <= 1.1e-210)) tmp = Float64(x + Float64(y * Float64(z * tanh(Float64(t / y))))); else tmp = Float64(x + Float64(Float64(z * y) * Float64(Float64(t / y) - tanh(Float64(x / y))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -1.02e-115) || ~((t <= 1.1e-210))) tmp = x + (y * (z * tanh((t / y)))); else tmp = x + ((z * y) * ((t / y) - tanh((x / y)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.02e-115], N[Not[LessEqual[t, 1.1e-210]], $MachinePrecision]], N[(x + N[(y * N[(z * N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z * y), $MachinePrecision] * N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.02 \cdot 10^{-115} \lor \neg \left(t \leq 1.1 \cdot 10^{-210}\right):\\
\;\;\;\;x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(z \cdot y\right) \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right)\\
\end{array}
\end{array}
if t < -1.02e-115 or 1.09999999999999995e-210 < t Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around 0 12.5%
*-commutative12.5%
associate-/r*12.5%
div-sub12.5%
rec-exp12.5%
rec-exp12.5%
tanh-def-a89.6%
Simplified89.6%
if -1.02e-115 < t < 1.09999999999999995e-210Initial program 99.9%
Taylor expanded in t around 0 98.7%
Final simplification92.4%
(FPCore (x y z t) :precision binary64 (+ x (* y (* z (tanh (/ t y))))))
double code(double x, double y, double z, double t) {
return x + (y * (z * tanh((t / 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))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (z * Math.tanh((t / y))));
}
def code(x, y, z, t): return x + (y * (z * math.tanh((t / y))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * tanh(Float64(t / y))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * tanh((t / y)))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(z * N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)
\end{array}
Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 29.7%
*-commutative29.7%
associate-/r*29.7%
div-sub29.7%
rec-exp29.7%
rec-exp29.7%
tanh-def-a87.4%
Simplified87.4%
Final simplification87.4%
(FPCore (x y z t) :precision binary64 (if (<= y 2700.0) x (+ x (/ y (/ (/ y z) (- t x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2700.0) {
tmp = x;
} else {
tmp = x + (y / ((y / 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 <= 2700.0d0) then
tmp = x
else
tmp = x + (y / ((y / 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 <= 2700.0) {
tmp = x;
} else {
tmp = x + (y / ((y / z) / (t - x)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2700.0: tmp = x else: tmp = x + (y / ((y / z) / (t - x))) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2700.0) tmp = x; else tmp = Float64(x + Float64(y / Float64(Float64(y / z) / Float64(t - x)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2700.0) tmp = x; else tmp = x + (y / ((y / z) / (t - x))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2700.0], x, N[(x + N[(y / N[(N[(y / z), $MachinePrecision] / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2700:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{\frac{y}{z}}{t - x}}\\
\end{array}
\end{array}
if y < 2700Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around 0 70.6%
if 2700 < y Initial program 99.8%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in y around inf 76.7%
associate-/l*76.7%
Simplified76.7%
clear-num76.7%
un-div-inv76.7%
Applied egg-rr76.7%
Final simplification70.8%
(FPCore (x y z t) :precision binary64 (if (<= y 25500.0) x (+ x (* z (- t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 25500.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 <= 25500.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 <= 25500.0) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 25500.0: tmp = x else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 25500.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 <= 25500.0) tmp = x; else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 25500.0], x, N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 25500:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 25500Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around 0 70.6%
if 25500 < y Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 76.7%
Final simplification70.8%
(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 99.9%
+-commutative99.9%
*-commutative99.9%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around 0 70.4%
Final simplification70.4%
(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 2023278
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:herbie-target
(+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))