
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1e-10)
(and (not (<= x -6.5e-46))
(or (<= x -4.1e-106)
(and (not (<= x 3.5e-159))
(or (<= x 1.65e-91) (not (<= x 4.3e+43)))))))
(* x (- 1.0 y))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-10) || (!(x <= -6.5e-46) && ((x <= -4.1e-106) || (!(x <= 3.5e-159) && ((x <= 1.65e-91) || !(x <= 4.3e+43)))))) {
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 <= (-1d-10)) .or. (.not. (x <= (-6.5d-46))) .and. (x <= (-4.1d-106)) .or. (.not. (x <= 3.5d-159)) .and. (x <= 1.65d-91) .or. (.not. (x <= 4.3d+43))) 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 <= -1e-10) || (!(x <= -6.5e-46) && ((x <= -4.1e-106) || (!(x <= 3.5e-159) && ((x <= 1.65e-91) || !(x <= 4.3e+43)))))) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e-10) or (not (x <= -6.5e-46) and ((x <= -4.1e-106) or (not (x <= 3.5e-159) and ((x <= 1.65e-91) or not (x <= 4.3e+43))))): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e-10) || (!(x <= -6.5e-46) && ((x <= -4.1e-106) || (!(x <= 3.5e-159) && ((x <= 1.65e-91) || !(x <= 4.3e+43)))))) 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 <= -1e-10) || (~((x <= -6.5e-46)) && ((x <= -4.1e-106) || (~((x <= 3.5e-159)) && ((x <= 1.65e-91) || ~((x <= 4.3e+43))))))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e-10], And[N[Not[LessEqual[x, -6.5e-46]], $MachinePrecision], Or[LessEqual[x, -4.1e-106], And[N[Not[LessEqual[x, 3.5e-159]], $MachinePrecision], Or[LessEqual[x, 1.65e-91], N[Not[LessEqual[x, 4.3e+43]], $MachinePrecision]]]]]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-10} \lor \neg \left(x \leq -6.5 \cdot 10^{-46}\right) \land \left(x \leq -4.1 \cdot 10^{-106} \lor \neg \left(x \leq 3.5 \cdot 10^{-159}\right) \land \left(x \leq 1.65 \cdot 10^{-91} \lor \neg \left(x \leq 4.3 \cdot 10^{+43}\right)\right)\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.00000000000000004e-10 or -6.49999999999999966e-46 < x < -4.0999999999999999e-106 or 3.50000000000000002e-159 < x < 1.65000000000000006e-91 or 4.3e43 < x Initial program 100.0%
Taylor expanded in x around inf 87.1%
mul-1-neg87.1%
unsub-neg87.1%
Simplified87.1%
if -1.00000000000000004e-10 < x < -6.49999999999999966e-46 or -4.0999999999999999e-106 < x < 3.50000000000000002e-159 or 1.65000000000000006e-91 < x < 4.3e43Initial program 100.0%
Taylor expanded in x around 0 74.8%
Final simplification81.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* y x))))
(if (<= y -4.3e+83)
(* y z)
(if (<= y -8.8e+21)
t_0
(if (<= y -4.8e-112)
(* y z)
(if (<= y 1.95e-78)
x
(if (or (<= y 5.4e+131) (not (<= y 4e+218))) (* y z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = -(y * x);
double tmp;
if (y <= -4.3e+83) {
tmp = y * z;
} else if (y <= -8.8e+21) {
tmp = t_0;
} else if (y <= -4.8e-112) {
tmp = y * z;
} else if (y <= 1.95e-78) {
tmp = x;
} else if ((y <= 5.4e+131) || !(y <= 4e+218)) {
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 = -(y * x)
if (y <= (-4.3d+83)) then
tmp = y * z
else if (y <= (-8.8d+21)) then
tmp = t_0
else if (y <= (-4.8d-112)) then
tmp = y * z
else if (y <= 1.95d-78) then
tmp = x
else if ((y <= 5.4d+131) .or. (.not. (y <= 4d+218))) 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 = -(y * x);
double tmp;
if (y <= -4.3e+83) {
tmp = y * z;
} else if (y <= -8.8e+21) {
tmp = t_0;
} else if (y <= -4.8e-112) {
tmp = y * z;
} else if (y <= 1.95e-78) {
tmp = x;
} else if ((y <= 5.4e+131) || !(y <= 4e+218)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * x) tmp = 0 if y <= -4.3e+83: tmp = y * z elif y <= -8.8e+21: tmp = t_0 elif y <= -4.8e-112: tmp = y * z elif y <= 1.95e-78: tmp = x elif (y <= 5.4e+131) or not (y <= 4e+218): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * x)) tmp = 0.0 if (y <= -4.3e+83) tmp = Float64(y * z); elseif (y <= -8.8e+21) tmp = t_0; elseif (y <= -4.8e-112) tmp = Float64(y * z); elseif (y <= 1.95e-78) tmp = x; elseif ((y <= 5.4e+131) || !(y <= 4e+218)) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * x); tmp = 0.0; if (y <= -4.3e+83) tmp = y * z; elseif (y <= -8.8e+21) tmp = t_0; elseif (y <= -4.8e-112) tmp = y * z; elseif (y <= 1.95e-78) tmp = x; elseif ((y <= 5.4e+131) || ~((y <= 4e+218))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * x), $MachinePrecision])}, If[LessEqual[y, -4.3e+83], N[(y * z), $MachinePrecision], If[LessEqual[y, -8.8e+21], t$95$0, If[LessEqual[y, -4.8e-112], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.95e-78], x, If[Or[LessEqual[y, 5.4e+131], N[Not[LessEqual[y, 4e+218]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot x\\
\mathbf{if}\;y \leq -4.3 \cdot 10^{+83}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -8.8 \cdot 10^{+21}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-112}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-78}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+131} \lor \neg \left(y \leq 4 \cdot 10^{+218}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.3e83 or -8.8e21 < y < -4.8000000000000001e-112 or 1.9500000000000001e-78 < y < 5.40000000000000008e131 or 4.00000000000000033e218 < y Initial program 100.0%
Taylor expanded in x around 0 63.8%
if -4.3e83 < y < -8.8e21 or 5.40000000000000008e131 < y < 4.00000000000000033e218Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around 0 71.4%
mul-1-neg71.4%
distribute-lft-neg-out71.4%
*-commutative71.4%
Simplified71.4%
if -4.8000000000000001e-112 < y < 1.9500000000000001e-78Initial program 100.0%
Taylor expanded in y around 0 89.8%
Final simplification73.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-112) (not (<= y 0.92))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-112) || !(y <= 0.92)) {
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 <= (-5.2d-112)) .or. (.not. (y <= 0.92d0))) 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 <= -5.2e-112) || !(y <= 0.92)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-112) or not (y <= 0.92): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-112) || !(y <= 0.92)) 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 <= -5.2e-112) || ~((y <= 0.92))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-112], N[Not[LessEqual[y, 0.92]], $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 -5.2 \cdot 10^{-112} \lor \neg \left(y \leq 0.92\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -5.19999999999999983e-112 or 0.92000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf 93.3%
if -5.19999999999999983e-112 < y < 0.92000000000000004Initial program 100.0%
Taylor expanded in x around inf 84.6%
mul-1-neg84.6%
unsub-neg84.6%
Simplified84.6%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-113) (not (<= y 8.6e-75))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-113) || !(y <= 8.6e-75)) {
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 <= (-2.5d-113)) .or. (.not. (y <= 8.6d-75))) 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 <= -2.5e-113) || !(y <= 8.6e-75)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-113) or not (y <= 8.6e-75): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-113) || !(y <= 8.6e-75)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.5e-113) || ~((y <= 8.6e-75))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-113], N[Not[LessEqual[y, 8.6e-75]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-113} \lor \neg \left(y \leq 8.6 \cdot 10^{-75}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.4999999999999999e-113 or 8.5999999999999998e-75 < y Initial program 100.0%
Taylor expanded in x around 0 57.4%
if -2.4999999999999999e-113 < y < 8.5999999999999998e-75Initial program 100.0%
Taylor expanded in y around 0 89.8%
Final simplification68.4%
(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 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 38.2%
Final simplification38.2%
herbie shell --seed 2024020
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))