
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.3e+152)
(* y z)
(if (<= y -1.55e+30)
t_0
(if (<= y -1.4e-7)
(* y z)
(if (<= y 1.0)
x
(if (or (<= y 1.85e+96)
(and (not (<= y 2.45e+194)) (<= y 9.5e+225)))
t_0
(* y z))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.3e+152) {
tmp = y * z;
} else if (y <= -1.55e+30) {
tmp = t_0;
} else if (y <= -1.4e-7) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if ((y <= 1.85e+96) || (!(y <= 2.45e+194) && (y <= 9.5e+225))) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-1.3d+152)) then
tmp = y * z
else if (y <= (-1.55d+30)) then
tmp = t_0
else if (y <= (-1.4d-7)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else if ((y <= 1.85d+96) .or. (.not. (y <= 2.45d+194)) .and. (y <= 9.5d+225)) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.3e+152) {
tmp = y * z;
} else if (y <= -1.55e+30) {
tmp = t_0;
} else if (y <= -1.4e-7) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if ((y <= 1.85e+96) || (!(y <= 2.45e+194) && (y <= 9.5e+225))) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.3e+152: tmp = y * z elif y <= -1.55e+30: tmp = t_0 elif y <= -1.4e-7: tmp = y * z elif y <= 1.0: tmp = x elif (y <= 1.85e+96) or (not (y <= 2.45e+194) and (y <= 9.5e+225)): tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.3e+152) tmp = Float64(y * z); elseif (y <= -1.55e+30) tmp = t_0; elseif (y <= -1.4e-7) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; elseif ((y <= 1.85e+96) || (!(y <= 2.45e+194) && (y <= 9.5e+225))) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -1.3e+152) tmp = y * z; elseif (y <= -1.55e+30) tmp = t_0; elseif (y <= -1.4e-7) tmp = y * z; elseif (y <= 1.0) tmp = x; elseif ((y <= 1.85e+96) || (~((y <= 2.45e+194)) && (y <= 9.5e+225))) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.3e+152], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.55e+30], t$95$0, If[LessEqual[y, -1.4e-7], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, If[Or[LessEqual[y, 1.85e+96], And[N[Not[LessEqual[y, 2.45e+194]], $MachinePrecision], LessEqual[y, 9.5e+225]]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.3 \cdot 10^{+152}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{+30}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+96} \lor \neg \left(y \leq 2.45 \cdot 10^{+194}\right) \land y \leq 9.5 \cdot 10^{+225}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.3e152 or -1.5499999999999999e30 < y < -1.4000000000000001e-7 or 1.84999999999999996e96 < y < 2.45000000000000013e194 or 9.49999999999999957e225 < y Initial program 100.0%
Taylor expanded in z around inf 70.0%
Taylor expanded in x around 0 69.9%
if -1.3e152 < y < -1.5499999999999999e30 or 1 < y < 1.84999999999999996e96 or 2.45000000000000013e194 < y < 9.49999999999999957e225Initial program 100.0%
Taylor expanded in x around inf 67.8%
mul-1-neg67.8%
unsub-neg67.8%
Simplified67.8%
Taylor expanded in y around inf 67.0%
associate-*r*67.0%
mul-1-neg67.0%
Simplified67.0%
if -1.4000000000000001e-7 < y < 1Initial program 100.0%
Taylor expanded in y around 0 76.9%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.12e-86) (not (<= x 6e-117))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e-86) || !(x <= 6e-117)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-1.12d-86)) .or. (.not. (x <= 6d-117))) then
tmp = x * (1.0d0 - y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e-86) || !(x <= 6e-117)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.12e-86) or not (x <= 6e-117): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.12e-86) || !(x <= 6e-117)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.12e-86) || ~((x <= 6e-117))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.12e-86], N[Not[LessEqual[x, 6e-117]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-86} \lor \neg \left(x \leq 6 \cdot 10^{-117}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.12e-86 or 5.99999999999999982e-117 < x Initial program 100.0%
Taylor expanded in x around inf 81.3%
mul-1-neg81.3%
unsub-neg81.3%
Simplified81.3%
if -1.12e-86 < x < 5.99999999999999982e-117Initial program 100.0%
Taylor expanded in z around inf 92.4%
Taylor expanded in x around 0 79.5%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00037) (not (<= y 1.5e-18))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00037) || !(y <= 1.5e-18)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-0.00037d0)) .or. (.not. (y <= 1.5d-18))) then
tmp = y * (z - x)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00037) || !(y <= 1.5e-18)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00037) or not (y <= 1.5e-18): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00037) || !(y <= 1.5e-18)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00037) || ~((y <= 1.5e-18))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00037], N[Not[LessEqual[y, 1.5e-18]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00037 \lor \neg \left(y \leq 1.5 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -3.6999999999999999e-4 or 1.49999999999999991e-18 < y Initial program 100.0%
Taylor expanded in x around 0 94.6%
Taylor expanded in y around inf 98.2%
mul-1-neg98.2%
unsub-neg98.2%
Simplified98.2%
if -3.6999999999999999e-4 < y < 1.49999999999999991e-18Initial program 100.0%
Taylor expanded in x around inf 79.8%
mul-1-neg79.8%
unsub-neg79.8%
Simplified79.8%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.45e+30) (not (<= y 1.0))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+30) || !(y <= 1.0)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-1.45d+30)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e+30) || !(y <= 1.0)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e+30) or not (y <= 1.0): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e+30) || !(y <= 1.0)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.45e+30) || ~((y <= 1.0))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+30], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+30} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.4499999999999999e30 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 94.2%
Taylor expanded in y around inf 99.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.5%
if -1.4499999999999999e30 < y < 1Initial program 100.0%
Taylor expanded in z around inf 98.8%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -8e-7) (not (<= y 7.8e-19))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e-7) || !(y <= 7.8e-19)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-8d-7)) .or. (.not. (y <= 7.8d-19))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8e-7) || !(y <= 7.8e-19)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8e-7) or not (y <= 7.8e-19): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8e-7) || !(y <= 7.8e-19)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8e-7) || ~((y <= 7.8e-19))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8e-7], N[Not[LessEqual[y, 7.8e-19]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-7} \lor \neg \left(y \leq 7.8 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.9999999999999996e-7 or 7.7999999999999999e-19 < y Initial program 100.0%
Taylor expanded in z around inf 57.8%
Taylor expanded in x around 0 56.8%
if -7.9999999999999996e-7 < y < 7.7999999999999999e-19Initial program 100.0%
Taylor expanded in y around 0 79.2%
Final simplification66.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 35.1%
Final simplification35.1%
herbie shell --seed 2023334
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))