
(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 (fma y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= y -1.35e+213)
t_0
(if (<= y -2.75e+131)
(* y z)
(if (<= y -500.0)
t_0
(if (<= y -5.6e-56)
(* y z)
(if (<= y 9.5e-30) x (if (<= y 8.5e+171) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -1.35e+213) {
tmp = t_0;
} else if (y <= -2.75e+131) {
tmp = y * z;
} else if (y <= -500.0) {
tmp = t_0;
} else if (y <= -5.6e-56) {
tmp = y * z;
} else if (y <= 9.5e-30) {
tmp = x;
} else if (y <= 8.5e+171) {
tmp = y * z;
} else {
tmp = t_0;
}
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 = x * -y
if (y <= (-1.35d+213)) then
tmp = t_0
else if (y <= (-2.75d+131)) then
tmp = y * z
else if (y <= (-500.0d0)) then
tmp = t_0
else if (y <= (-5.6d-56)) then
tmp = y * z
else if (y <= 9.5d-30) then
tmp = x
else if (y <= 8.5d+171) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -1.35e+213) {
tmp = t_0;
} else if (y <= -2.75e+131) {
tmp = y * z;
} else if (y <= -500.0) {
tmp = t_0;
} else if (y <= -5.6e-56) {
tmp = y * z;
} else if (y <= 9.5e-30) {
tmp = x;
} else if (y <= 8.5e+171) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -1.35e+213: tmp = t_0 elif y <= -2.75e+131: tmp = y * z elif y <= -500.0: tmp = t_0 elif y <= -5.6e-56: tmp = y * z elif y <= 9.5e-30: tmp = x elif y <= 8.5e+171: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -1.35e+213) tmp = t_0; elseif (y <= -2.75e+131) tmp = Float64(y * z); elseif (y <= -500.0) tmp = t_0; elseif (y <= -5.6e-56) tmp = Float64(y * z); elseif (y <= 9.5e-30) tmp = x; elseif (y <= 8.5e+171) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -1.35e+213) tmp = t_0; elseif (y <= -2.75e+131) tmp = y * z; elseif (y <= -500.0) tmp = t_0; elseif (y <= -5.6e-56) tmp = y * z; elseif (y <= 9.5e-30) tmp = x; elseif (y <= 8.5e+171) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -1.35e+213], t$95$0, If[LessEqual[y, -2.75e+131], N[(y * z), $MachinePrecision], If[LessEqual[y, -500.0], t$95$0, If[LessEqual[y, -5.6e-56], N[(y * z), $MachinePrecision], If[LessEqual[y, 9.5e-30], x, If[LessEqual[y, 8.5e+171], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -1.35 \cdot 10^{+213}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.75 \cdot 10^{+131}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.6 \cdot 10^{-56}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-30}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+171}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.35e213 or -2.74999999999999986e131 < y < -500 or 8.4999999999999995e171 < y Initial program 100.0%
Taylor expanded in x around inf 66.1%
mul-1-neg66.1%
unsub-neg66.1%
Simplified66.1%
Taylor expanded in y around inf 64.3%
mul-1-neg64.3%
distribute-rgt-neg-out64.3%
Simplified64.3%
if -1.35e213 < y < -2.74999999999999986e131 or -500 < y < -5.59999999999999986e-56 or 9.49999999999999939e-30 < y < 8.4999999999999995e171Initial program 100.0%
Taylor expanded in x around 0 68.3%
if -5.59999999999999986e-56 < y < 9.49999999999999939e-30Initial program 100.0%
Taylor expanded in y around 0 73.2%
(FPCore (x y z)
:precision binary64
(if (or (<= x -3.9e-28)
(and (not (<= x -3.9e-212))
(or (<= x -1.45e-222) (not (<= x 1.3e-110)))))
(* x (- 1.0 y))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e-28) || (!(x <= -3.9e-212) && ((x <= -1.45e-222) || !(x <= 1.3e-110)))) {
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 <= (-3.9d-28)) .or. (.not. (x <= (-3.9d-212))) .and. (x <= (-1.45d-222)) .or. (.not. (x <= 1.3d-110))) 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 <= -3.9e-28) || (!(x <= -3.9e-212) && ((x <= -1.45e-222) || !(x <= 1.3e-110)))) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e-28) or (not (x <= -3.9e-212) and ((x <= -1.45e-222) or not (x <= 1.3e-110))): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e-28) || (!(x <= -3.9e-212) && ((x <= -1.45e-222) || !(x <= 1.3e-110)))) 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 <= -3.9e-28) || (~((x <= -3.9e-212)) && ((x <= -1.45e-222) || ~((x <= 1.3e-110))))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e-28], And[N[Not[LessEqual[x, -3.9e-212]], $MachinePrecision], Or[LessEqual[x, -1.45e-222], N[Not[LessEqual[x, 1.3e-110]], $MachinePrecision]]]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-28} \lor \neg \left(x \leq -3.9 \cdot 10^{-212}\right) \land \left(x \leq -1.45 \cdot 10^{-222} \lor \neg \left(x \leq 1.3 \cdot 10^{-110}\right)\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.89999999999999999e-28 or -3.9e-212 < x < -1.4500000000000001e-222 or 1.29999999999999995e-110 < x Initial program 100.0%
Taylor expanded in x around inf 84.1%
mul-1-neg84.1%
unsub-neg84.1%
Simplified84.1%
if -3.89999999999999999e-28 < x < -3.9e-212 or -1.4500000000000001e-222 < x < 1.29999999999999995e-110Initial program 100.0%
Taylor expanded in x around 0 75.9%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-56) (not (<= y 1.4e-29))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-56) || !(y <= 1.4e-29)) {
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 <= (-1.35d-56)) .or. (.not. (y <= 1.4d-29))) 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 <= -1.35e-56) || !(y <= 1.4e-29)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-56) or not (y <= 1.4e-29): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-56) || !(y <= 1.4e-29)) 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 <= -1.35e-56) || ~((y <= 1.4e-29))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-56], N[Not[LessEqual[y, 1.4e-29]], $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 -1.35 \cdot 10^{-56} \lor \neg \left(y \leq 1.4 \cdot 10^{-29}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1.34999999999999997e-56 or 1.4000000000000001e-29 < y Initial program 100.0%
Taylor expanded in y around inf 96.4%
if -1.34999999999999997e-56 < y < 1.4000000000000001e-29Initial program 100.0%
Taylor expanded in x around inf 73.2%
mul-1-neg73.2%
unsub-neg73.2%
Simplified73.2%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-56) (not (<= y 1.3e-30))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-56) || !(y <= 1.3e-30)) {
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 <= (-1.5d-56)) .or. (.not. (y <= 1.3d-30))) 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 <= -1.5e-56) || !(y <= 1.3e-30)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-56) or not (y <= 1.3e-30): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-56) || !(y <= 1.3e-30)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.5e-56) || ~((y <= 1.3e-30))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-56], N[Not[LessEqual[y, 1.3e-30]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-56} \lor \neg \left(y \leq 1.3 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.49999999999999995e-56 or 1.29999999999999993e-30 < y Initial program 100.0%
Taylor expanded in x around 0 51.9%
if -1.49999999999999995e-56 < y < 1.29999999999999993e-30Initial program 100.0%
Taylor expanded in y around 0 73.2%
Final simplification61.3%
(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%
(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%
herbie shell --seed 2024103
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))