
(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 6 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 -2.3e+81)
t_0
(if (<= y 14000000000000.0)
(+ x (* y z))
(if (or (<= y 1.8e+78) (and (not (<= y 2.15e+251)) (<= y 1.12e+292)))
t_0
(* y z))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -2.3e+81) {
tmp = t_0;
} else if (y <= 14000000000000.0) {
tmp = x + (y * z);
} else if ((y <= 1.8e+78) || (!(y <= 2.15e+251) && (y <= 1.12e+292))) {
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 <= (-2.3d+81)) then
tmp = t_0
else if (y <= 14000000000000.0d0) then
tmp = x + (y * z)
else if ((y <= 1.8d+78) .or. (.not. (y <= 2.15d+251)) .and. (y <= 1.12d+292)) 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 <= -2.3e+81) {
tmp = t_0;
} else if (y <= 14000000000000.0) {
tmp = x + (y * z);
} else if ((y <= 1.8e+78) || (!(y <= 2.15e+251) && (y <= 1.12e+292))) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -2.3e+81: tmp = t_0 elif y <= 14000000000000.0: tmp = x + (y * z) elif (y <= 1.8e+78) or (not (y <= 2.15e+251) and (y <= 1.12e+292)): 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 <= -2.3e+81) tmp = t_0; elseif (y <= 14000000000000.0) tmp = Float64(x + Float64(y * z)); elseif ((y <= 1.8e+78) || (!(y <= 2.15e+251) && (y <= 1.12e+292))) 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 <= -2.3e+81) tmp = t_0; elseif (y <= 14000000000000.0) tmp = x + (y * z); elseif ((y <= 1.8e+78) || (~((y <= 2.15e+251)) && (y <= 1.12e+292))) 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, -2.3e+81], t$95$0, If[LessEqual[y, 14000000000000.0], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.8e+78], And[N[Not[LessEqual[y, 2.15e+251]], $MachinePrecision], LessEqual[y, 1.12e+292]]], t$95$0, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -2.3 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 14000000000000:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+78} \lor \neg \left(y \leq 2.15 \cdot 10^{+251}\right) \land y \leq 1.12 \cdot 10^{+292}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.2999999999999999e81 or 1.4e13 < y < 1.8000000000000001e78 or 2.15e251 < y < 1.12000000000000004e292Initial program 100.0%
Taylor expanded in z around 0 72.2%
associate-*r*72.2%
neg-mul-172.2%
*-commutative72.2%
Simplified72.2%
Taylor expanded in y around inf 72.0%
mul-1-neg72.0%
*-commutative72.0%
distribute-rgt-neg-out72.0%
Simplified72.0%
if -2.2999999999999999e81 < y < 1.4e13Initial program 100.0%
Taylor expanded in z around inf 93.9%
if 1.8000000000000001e78 < y < 2.15e251 or 1.12000000000000004e292 < y Initial program 100.0%
Taylor expanded in z around inf 67.0%
Taylor expanded in x around 0 67.4%
Final simplification84.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -3.9e+63)
t_0
(if (<= y -1.4e-6)
(* y z)
(if (<= y 1.9e-26)
x
(if (<= y 1.26e+250) (* y z) (if (<= y 1e+292) t_0 (* y z))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.9e+63) {
tmp = t_0;
} else if (y <= -1.4e-6) {
tmp = y * z;
} else if (y <= 1.9e-26) {
tmp = x;
} else if (y <= 1.26e+250) {
tmp = y * z;
} else if (y <= 1e+292) {
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 <= (-3.9d+63)) then
tmp = t_0
else if (y <= (-1.4d-6)) then
tmp = y * z
else if (y <= 1.9d-26) then
tmp = x
else if (y <= 1.26d+250) then
tmp = y * z
else if (y <= 1d+292) 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 <= -3.9e+63) {
tmp = t_0;
} else if (y <= -1.4e-6) {
tmp = y * z;
} else if (y <= 1.9e-26) {
tmp = x;
} else if (y <= 1.26e+250) {
tmp = y * z;
} else if (y <= 1e+292) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.9e+63: tmp = t_0 elif y <= -1.4e-6: tmp = y * z elif y <= 1.9e-26: tmp = x elif y <= 1.26e+250: tmp = y * z elif y <= 1e+292: 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 <= -3.9e+63) tmp = t_0; elseif (y <= -1.4e-6) tmp = Float64(y * z); elseif (y <= 1.9e-26) tmp = x; elseif (y <= 1.26e+250) tmp = Float64(y * z); elseif (y <= 1e+292) 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 <= -3.9e+63) tmp = t_0; elseif (y <= -1.4e-6) tmp = y * z; elseif (y <= 1.9e-26) tmp = x; elseif (y <= 1.26e+250) tmp = y * z; elseif (y <= 1e+292) 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, -3.9e+63], t$95$0, If[LessEqual[y, -1.4e-6], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.9e-26], x, If[LessEqual[y, 1.26e+250], N[(y * z), $MachinePrecision], If[LessEqual[y, 1e+292], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3.9 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-6}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.26 \cdot 10^{+250}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 10^{+292}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -3.9e63 or 1.26000000000000006e250 < y < 1e292Initial program 100.0%
Taylor expanded in z around 0 67.9%
associate-*r*67.9%
neg-mul-167.9%
*-commutative67.9%
Simplified67.9%
Taylor expanded in y around inf 67.9%
mul-1-neg67.9%
*-commutative67.9%
distribute-rgt-neg-out67.9%
Simplified67.9%
if -3.9e63 < y < -1.39999999999999994e-6 or 1.90000000000000007e-26 < y < 1.26000000000000006e250 or 1e292 < y Initial program 100.0%
Taylor expanded in z around inf 62.1%
Taylor expanded in x around 0 59.6%
if -1.39999999999999994e-6 < y < 1.90000000000000007e-26Initial program 100.0%
Taylor expanded in z around inf 99.5%
Taylor expanded in x around inf 74.8%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-12) (not (<= z 9e-34))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-12) || !(z <= 9e-34)) {
tmp = x + (y * z);
} else {
tmp = x - (x * 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 <= (-4.5d-12)) .or. (.not. (z <= 9d-34))) then
tmp = x + (y * z)
else
tmp = x - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-12) || !(z <= 9e-34)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.5e-12) or not (z <= 9e-34): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-12) || !(z <= 9e-34)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.5e-12) || ~((z <= 9e-34))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-12], N[Not[LessEqual[z, 9e-34]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-12} \lor \neg \left(z \leq 9 \cdot 10^{-34}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -4.49999999999999981e-12 or 9.00000000000000085e-34 < z Initial program 100.0%
Taylor expanded in z around inf 91.0%
if -4.49999999999999981e-12 < z < 9.00000000000000085e-34Initial program 100.0%
Taylor expanded in z around 0 89.4%
associate-*r*89.4%
neg-mul-189.4%
*-commutative89.4%
Simplified89.4%
Taylor expanded in x around 0 89.4%
+-commutative89.4%
mul-1-neg89.4%
+-commutative89.4%
distribute-rgt-in89.4%
*-lft-identity89.4%
cancel-sign-sub-inv89.4%
Simplified89.4%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.4e-6) (* y z) (if (<= y 2.8e-27) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-6) {
tmp = y * z;
} else if (y <= 2.8e-27) {
tmp = x;
} 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 (y <= (-1.4d-6)) then
tmp = y * z
else if (y <= 2.8d-27) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e-6) {
tmp = y * z;
} else if (y <= 2.8e-27) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.4e-6: tmp = y * z elif y <= 2.8e-27: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.4e-6) tmp = Float64(y * z); elseif (y <= 2.8e-27) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.4e-6) tmp = y * z; elseif (y <= 2.8e-27) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-6], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.8e-27], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-6}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-27}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.39999999999999994e-6 or 2.8e-27 < y Initial program 100.0%
Taylor expanded in z around inf 54.4%
Taylor expanded in x around 0 52.7%
if -1.39999999999999994e-6 < y < 2.8e-27Initial program 100.0%
Taylor expanded in z around inf 99.5%
Taylor expanded in x around inf 74.8%
Final simplification62.9%
(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 z around inf 75.3%
Taylor expanded in x around inf 37.1%
Final simplification37.1%
herbie shell --seed 2023297
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))