
(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 (let* ((t_1 (- (tanh (/ t y)) (tanh (/ x y))))) (if (<= (+ x (* (* y z) t_1)) 2e+305) (fma t_1 (* y z) x) (* z (- t x)))))
double code(double x, double y, double z, double t) {
double t_1 = tanh((t / y)) - tanh((x / y));
double tmp;
if ((x + ((y * z) * t_1)) <= 2e+305) {
tmp = fma(t_1, (y * z), x);
} else {
tmp = z * (t - x);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) tmp = 0.0 if (Float64(x + Float64(Float64(y * z) * t_1)) <= 2e+305) tmp = fma(t_1, Float64(y * z), x); else tmp = Float64(z * Float64(t - x)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x + N[(N[(y * z), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], 2e+305], N[(t$95$1 * N[(y * z), $MachinePrecision] + x), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\
\mathbf{if}\;x + \left(y \cdot z\right) \cdot t\_1 \leq 2 \cdot 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(t\_1, y \cdot z, x\right)\\
\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))))) < 1.9999999999999999e305Initial program 99.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.5
Applied rewrites99.5%
if 1.9999999999999999e305 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 50.2%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
Applied rewrites100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma (- (/ t y) (tanh (/ x y))) (* y z) x)))
(if (<= x -1.4e+81)
t_1
(if (<= x -2.85e-21)
(fma z (* (- (* x (* x x))) (/ 1.0 (fma t t (* x (+ x t))))) x)
(if (<= x 66.0) (fma (- (tanh (/ t y)) (/ x y)) (* y z) x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = fma(((t / y) - tanh((x / y))), (y * z), x);
double tmp;
if (x <= -1.4e+81) {
tmp = t_1;
} else if (x <= -2.85e-21) {
tmp = fma(z, (-(x * (x * x)) * (1.0 / fma(t, t, (x * (x + t))))), x);
} else if (x <= 66.0) {
tmp = fma((tanh((t / y)) - (x / y)), (y * z), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(Float64(t / y) - tanh(Float64(x / y))), Float64(y * z), x) tmp = 0.0 if (x <= -1.4e+81) tmp = t_1; elseif (x <= -2.85e-21) tmp = fma(z, Float64(Float64(-Float64(x * Float64(x * x))) * Float64(1.0 / fma(t, t, Float64(x * Float64(x + t))))), x); elseif (x <= 66.0) tmp = fma(Float64(tanh(Float64(t / y)) - Float64(x / y)), Float64(y * z), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(y * z), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, -1.4e+81], t$95$1, If[LessEqual[x, -2.85e-21], N[(z * N[((-N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]) * N[(1.0 / N[(t * t + N[(x * N[(x + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 66.0], N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision] * N[(y * z), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right), y \cdot z, x\right)\\
\mathbf{if}\;x \leq -1.4 \cdot 10^{+81}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -2.85 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(z, \left(-x \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{\mathsf{fma}\left(t, t, x \cdot \left(x + t\right)\right)}, x\right)\\
\mathbf{elif}\;x \leq 66:\\
\;\;\;\;\mathsf{fma}\left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}, y \cdot z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -1.39999999999999997e81 or 66 < x Initial program 99.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.0
Applied rewrites99.0%
Taylor expanded in t around 0
lower-/.f6470.5
Applied rewrites70.5%
if -1.39999999999999997e81 < x < -2.8499999999999998e-21Initial program 96.2%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6449.3
Applied rewrites49.3%
Applied rewrites44.8%
Taylor expanded in t around 0
Applied rewrites76.7%
if -2.8499999999999998e-21 < x < 66Initial program 93.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6493.0
Applied rewrites93.0%
Taylor expanded in x around 0
lower-/.f6480.9
Applied rewrites80.9%
Final simplification76.8%
(FPCore (x y z t)
:precision binary64
(if (<= y 1.45e-145)
(fma z (- x) x)
(if (<= y 4.5e+181)
(fma (- (/ t y) (tanh (/ x y))) (* y z) x)
(fma z (- t x) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.45e-145) {
tmp = fma(z, -x, x);
} else if (y <= 4.5e+181) {
tmp = fma(((t / y) - tanh((x / y))), (y * z), x);
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 1.45e-145) tmp = fma(z, Float64(-x), x); elseif (y <= 4.5e+181) tmp = fma(Float64(Float64(t / y) - tanh(Float64(x / y))), Float64(y * z), x); else tmp = fma(z, Float64(t - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.45e-145], N[(z * (-x) + x), $MachinePrecision], If[LessEqual[y, 4.5e+181], N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(y * z), $MachinePrecision] + x), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-145}:\\
\;\;\;\;\mathsf{fma}\left(z, -x, x\right)\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+181}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right), y \cdot z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 1.44999999999999992e-145Initial program 95.2%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6452.2
Applied rewrites52.2%
Taylor expanded in t around 0
Applied rewrites46.6%
if 1.44999999999999992e-145 < y < 4.5e181Initial program 98.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.7
Applied rewrites98.7%
Taylor expanded in t around 0
lower-/.f6463.6
Applied rewrites63.6%
if 4.5e181 < y Initial program 83.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6494.5
Applied rewrites94.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (- t x)))) (if (<= z -30.5) t_1 (if (<= z 6.4e+21) (fma z (- x) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * (t - x);
double tmp;
if (z <= -30.5) {
tmp = t_1;
} else if (z <= 6.4e+21) {
tmp = fma(z, -x, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(z * Float64(t - x)) tmp = 0.0 if (z <= -30.5) tmp = t_1; elseif (z <= 6.4e+21) tmp = fma(z, Float64(-x), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -30.5], t$95$1, If[LessEqual[z, 6.4e+21], N[(z * (-x) + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \left(t - x\right)\\
\mathbf{if}\;z \leq -30.5:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{+21}:\\
\;\;\;\;\mathsf{fma}\left(z, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -30.5 or 6.4e21 < z Initial program 91.2%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6444.8
Applied rewrites44.8%
Taylor expanded in z around inf
Applied rewrites44.8%
if -30.5 < z < 6.4e21Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6468.7
Applied rewrites68.7%
Taylor expanded in t around 0
Applied rewrites74.5%
(FPCore (x y z t) :precision binary64 (if (<= t -3e-165) (* z t) (if (<= t 4.8e-163) (* z (- x)) (* z t))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3e-165) {
tmp = z * t;
} else if (t <= 4.8e-163) {
tmp = z * -x;
} else {
tmp = z * t;
}
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 <= (-3d-165)) then
tmp = z * t
else if (t <= 4.8d-163) then
tmp = z * -x
else
tmp = z * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3e-165) {
tmp = z * t;
} else if (t <= 4.8e-163) {
tmp = z * -x;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3e-165: tmp = z * t elif t <= 4.8e-163: tmp = z * -x else: tmp = z * t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3e-165) tmp = Float64(z * t); elseif (t <= 4.8e-163) tmp = Float64(z * Float64(-x)); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -3e-165) tmp = z * t; elseif (t <= 4.8e-163) tmp = z * -x; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3e-165], N[(z * t), $MachinePrecision], If[LessEqual[t, 4.8e-163], N[(z * (-x)), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3 \cdot 10^{-165}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;t \leq 4.8 \cdot 10^{-163}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if t < -2.99999999999999979e-165 or 4.8000000000000001e-163 < t Initial program 95.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6449.2
Applied rewrites49.2%
Taylor expanded in t around inf
Applied rewrites24.2%
if -2.99999999999999979e-165 < t < 4.8000000000000001e-163Initial program 95.4%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6477.8
Applied rewrites77.8%
Taylor expanded in z around inf
Applied rewrites30.7%
Taylor expanded in t around 0
Applied rewrites27.4%
(FPCore (x y z t) :precision binary64 (if (<= y 3e-120) (fma z (- x) x) (fma z (- t x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3e-120) {
tmp = fma(z, -x, x);
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 3e-120) tmp = fma(z, Float64(-x), x); else tmp = fma(z, Float64(t - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 3e-120], N[(z * (-x) + x), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-120}:\\
\;\;\;\;\mathsf{fma}\left(z, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 3.00000000000000011e-120Initial program 95.4%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6450.9
Applied rewrites50.9%
Taylor expanded in t around 0
Applied rewrites46.2%
if 3.00000000000000011e-120 < y Initial program 95.7%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6467.2
Applied rewrites67.2%
(FPCore (x y z t) :precision binary64 (* z (- t x)))
double code(double x, double y, double z, double t) {
return z * (t - 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 = z * (t - x)
end function
public static double code(double x, double y, double z, double t) {
return z * (t - x);
}
def code(x, y, z, t): return z * (t - x)
function code(x, y, z, t) return Float64(z * Float64(t - x)) end
function tmp = code(x, y, z, t) tmp = z * (t - x); end
code[x_, y_, z_, t_] := N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(t - x\right)
\end{array}
Initial program 95.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6456.5
Applied rewrites56.5%
Taylor expanded in z around inf
Applied rewrites29.2%
(FPCore (x y z t) :precision binary64 (* z t))
double code(double x, double y, double z, double t) {
return z * t;
}
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 = z * t
end function
public static double code(double x, double y, double z, double t) {
return z * t;
}
def code(x, y, z, t): return z * t
function code(x, y, z, t) return Float64(z * t) end
function tmp = code(x, y, z, t) tmp = z * t; end
code[x_, y_, z_, t_] := N[(z * t), $MachinePrecision]
\begin{array}{l}
\\
z \cdot t
\end{array}
Initial program 95.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6456.5
Applied rewrites56.5%
Taylor expanded in t around inf
Applied rewrites19.6%
(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 2024220
(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))))))