
(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 8 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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.65e-64)
(* y z)
(if (<= y -2.35e-90)
x
(if (<= y -4.1e-111)
(* y z)
(if (<= y 1.18e-49) x (if (<= y 4.8e+68) (* y z) (* y (- x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-64) {
tmp = y * z;
} else if (y <= -2.35e-90) {
tmp = x;
} else if (y <= -4.1e-111) {
tmp = y * z;
} else if (y <= 1.18e-49) {
tmp = x;
} else if (y <= 4.8e+68) {
tmp = y * z;
} else {
tmp = y * -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.65d-64)) then
tmp = y * z
else if (y <= (-2.35d-90)) then
tmp = x
else if (y <= (-4.1d-111)) then
tmp = y * z
else if (y <= 1.18d-49) then
tmp = x
else if (y <= 4.8d+68) then
tmp = y * z
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-64) {
tmp = y * z;
} else if (y <= -2.35e-90) {
tmp = x;
} else if (y <= -4.1e-111) {
tmp = y * z;
} else if (y <= 1.18e-49) {
tmp = x;
} else if (y <= 4.8e+68) {
tmp = y * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e-64: tmp = y * z elif y <= -2.35e-90: tmp = x elif y <= -4.1e-111: tmp = y * z elif y <= 1.18e-49: tmp = x elif y <= 4.8e+68: tmp = y * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e-64) tmp = Float64(y * z); elseif (y <= -2.35e-90) tmp = x; elseif (y <= -4.1e-111) tmp = Float64(y * z); elseif (y <= 1.18e-49) tmp = x; elseif (y <= 4.8e+68) tmp = Float64(y * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e-64) tmp = y * z; elseif (y <= -2.35e-90) tmp = x; elseif (y <= -4.1e-111) tmp = y * z; elseif (y <= 1.18e-49) tmp = x; elseif (y <= 4.8e+68) tmp = y * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e-64], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.35e-90], x, If[LessEqual[y, -4.1e-111], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.18e-49], x, If[LessEqual[y, 4.8e+68], N[(y * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-64}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.35 \cdot 10^{-90}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -4.1 \cdot 10^{-111}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.18 \cdot 10^{-49}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+68}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -1.65e-64 or -2.35e-90 < y < -4.09999999999999968e-111 or 1.18e-49 < y < 4.80000000000000016e68Initial program 100.0%
Taylor expanded in z around inf 75.0%
Taylor expanded in y around inf 74.2%
Taylor expanded in y around inf 65.1%
if -1.65e-64 < y < -2.35e-90 or -4.09999999999999968e-111 < y < 1.18e-49Initial program 100.0%
Taylor expanded in y around 0 77.8%
if 4.80000000000000016e68 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around 0 57.5%
mul-1-neg57.5%
distribute-lft-neg-out57.5%
*-commutative57.5%
Simplified57.5%
Final simplification68.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z x))))
(if (<= y -6.8e-65)
t_0
(if (<= y -3.6e-88)
(* x (- 1.0 y))
(if (or (<= y -3.7e-112) (not (<= y 1.55e-50))) t_0 x)))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -6.8e-65) {
tmp = t_0;
} else if (y <= -3.6e-88) {
tmp = x * (1.0 - y);
} else if ((y <= -3.7e-112) || !(y <= 1.55e-50)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * (z - x)
if (y <= (-6.8d-65)) then
tmp = t_0
else if (y <= (-3.6d-88)) then
tmp = x * (1.0d0 - y)
else if ((y <= (-3.7d-112)) .or. (.not. (y <= 1.55d-50))) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -6.8e-65) {
tmp = t_0;
} else if (y <= -3.6e-88) {
tmp = x * (1.0 - y);
} else if ((y <= -3.7e-112) || !(y <= 1.55e-50)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -6.8e-65: tmp = t_0 elif y <= -3.6e-88: tmp = x * (1.0 - y) elif (y <= -3.7e-112) or not (y <= 1.55e-50): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -6.8e-65) tmp = t_0; elseif (y <= -3.6e-88) tmp = Float64(x * Float64(1.0 - y)); elseif ((y <= -3.7e-112) || !(y <= 1.55e-50)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -6.8e-65) tmp = t_0; elseif (y <= -3.6e-88) tmp = x * (1.0 - y); elseif ((y <= -3.7e-112) || ~((y <= 1.55e-50))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.8e-65], t$95$0, If[LessEqual[y, -3.6e-88], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -3.7e-112], N[Not[LessEqual[y, 1.55e-50]], $MachinePrecision]], t$95$0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -6.8 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{-88}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;y \leq -3.7 \cdot 10^{-112} \lor \neg \left(y \leq 1.55 \cdot 10^{-50}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.79999999999999973e-65 or -3.5999999999999999e-88 < y < -3.6999999999999998e-112 or 1.5500000000000001e-50 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
Taylor expanded in z around inf 93.1%
if -6.79999999999999973e-65 < y < -3.5999999999999999e-88Initial program 100.0%
Taylor expanded in x around inf 86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
if -3.6999999999999998e-112 < y < 1.5500000000000001e-50Initial program 100.0%
Taylor expanded in y around 0 77.2%
Final simplification86.7%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.35e-64)
(not (or (<= y -5.5e-89) (and (not (<= y -8.4e-111)) (<= y 8e-51)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-64) || !((y <= -5.5e-89) || (!(y <= -8.4e-111) && (y <= 8e-51)))) {
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.35d-64)) .or. (.not. (y <= (-5.5d-89)) .or. (.not. (y <= (-8.4d-111))) .and. (y <= 8d-51))) 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.35e-64) || !((y <= -5.5e-89) || (!(y <= -8.4e-111) && (y <= 8e-51)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-64) or not ((y <= -5.5e-89) or (not (y <= -8.4e-111) and (y <= 8e-51))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-64) || !((y <= -5.5e-89) || (!(y <= -8.4e-111) && (y <= 8e-51)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e-64) || ~(((y <= -5.5e-89) || (~((y <= -8.4e-111)) && (y <= 8e-51))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-64], N[Not[Or[LessEqual[y, -5.5e-89], And[N[Not[LessEqual[y, -8.4e-111]], $MachinePrecision], LessEqual[y, 8e-51]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-64} \lor \neg \left(y \leq -5.5 \cdot 10^{-89} \lor \neg \left(y \leq -8.4 \cdot 10^{-111}\right) \land y \leq 8 \cdot 10^{-51}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.34999999999999993e-64 or -5.50000000000000012e-89 < y < -8.3999999999999995e-111 or 8.0000000000000001e-51 < y Initial program 100.0%
Taylor expanded in z around inf 65.4%
Taylor expanded in y around inf 64.9%
Taylor expanded in y around inf 58.9%
if -1.34999999999999993e-64 < y < -5.50000000000000012e-89 or -8.3999999999999995e-111 < y < 8.0000000000000001e-51Initial program 100.0%
Taylor expanded in y around 0 77.8%
Final simplification66.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -450000000000.0) (not (<= z 4.8e+69))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -450000000000.0) || !(z <= 4.8e+69)) {
tmp = y * z;
} 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 ((z <= (-450000000000.0d0)) .or. (.not. (z <= 4.8d+69))) then
tmp = y * z
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 ((z <= -450000000000.0) || !(z <= 4.8e+69)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -450000000000.0) or not (z <= 4.8e+69): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -450000000000.0) || !(z <= 4.8e+69)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -450000000000.0) || ~((z <= 4.8e+69))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -450000000000.0], N[Not[LessEqual[z, 4.8e+69]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -450000000000 \lor \neg \left(z \leq 4.8 \cdot 10^{+69}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -4.5e11 or 4.8000000000000003e69 < z Initial program 100.0%
Taylor expanded in z around inf 96.2%
Taylor expanded in y around inf 92.9%
Taylor expanded in y around inf 77.6%
if -4.5e11 < z < 4.8000000000000003e69Initial program 100.0%
Taylor expanded in x around inf 82.7%
mul-1-neg82.7%
unsub-neg82.7%
Simplified82.7%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1400000.0) (not (<= y 1.0))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1400000.0) || !(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 <= (-1400000.0d0)) .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 <= -1400000.0) || !(y <= 1.0)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1400000.0) 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 <= -1400000.0) || !(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 <= -1400000.0) || ~((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, -1400000.0], 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 -1400000 \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.4e6 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 99.4%
if -1.4e6 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.5%
Final simplification99.5%
(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 37.6%
Final simplification37.6%
herbie shell --seed 2024095
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))