
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
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 * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
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 * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (- z (* y (- z x))))
double code(double x, double y, double z) {
return z - (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 = z - (y * (z - x))
end function
public static double code(double x, double y, double z) {
return z - (y * (z - x));
}
def code(x, y, z): return z - (y * (z - x))
function code(x, y, z) return Float64(z - Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = z - (y * (z - x)); end
code[x_, y_, z_] := N[(z - N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - y \cdot \left(z - x\right)
\end{array}
Initial program 97.2%
+-commutative97.2%
+-lft-identity97.2%
cancel-sign-sub97.2%
cancel-sign-sub97.2%
+-lft-identity97.2%
distribute-lft-out--97.2%
*-rgt-identity97.2%
associate-+l-97.2%
distribute-rgt-out--100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- y))))
(if (<= y -3.15e+94)
t_0
(if (<= y -5.9e-5) (* y x) (if (<= y 1.35e-8) z t_0)))))
double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -3.15e+94) {
tmp = t_0;
} else if (y <= -5.9e-5) {
tmp = y * x;
} else if (y <= 1.35e-8) {
tmp = 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 = z * -y
if (y <= (-3.15d+94)) then
tmp = t_0
else if (y <= (-5.9d-5)) then
tmp = y * x
else if (y <= 1.35d-8) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -3.15e+94) {
tmp = t_0;
} else if (y <= -5.9e-5) {
tmp = y * x;
} else if (y <= 1.35e-8) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -y tmp = 0 if y <= -3.15e+94: tmp = t_0 elif y <= -5.9e-5: tmp = y * x elif y <= 1.35e-8: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-y)) tmp = 0.0 if (y <= -3.15e+94) tmp = t_0; elseif (y <= -5.9e-5) tmp = Float64(y * x); elseif (y <= 1.35e-8) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -y; tmp = 0.0; if (y <= -3.15e+94) tmp = t_0; elseif (y <= -5.9e-5) tmp = y * x; elseif (y <= 1.35e-8) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-y)), $MachinePrecision]}, If[LessEqual[y, -3.15e+94], t$95$0, If[LessEqual[y, -5.9e-5], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.35e-8], z, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -3.15 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.9 \cdot 10^{-5}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-8}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.15e94 or 1.35000000000000001e-8 < y Initial program 93.5%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
sub-neg98.4%
Simplified98.4%
Taylor expanded in x around 0 59.3%
associate-*r*59.3%
neg-mul-159.3%
*-commutative59.3%
Simplified59.3%
if -3.15e94 < y < -5.8999999999999998e-5Initial program 100.0%
Taylor expanded in x around inf 59.3%
*-commutative59.3%
Simplified59.3%
if -5.8999999999999998e-5 < y < 1.35000000000000001e-8Initial program 100.0%
Taylor expanded in y around 0 98.6%
Taylor expanded in x around 0 73.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.35e-8))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.35e-8)) {
tmp = y * (x - z);
} else {
tmp = z + (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.0d0)) .or. (.not. (y <= 1.35d-8))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.35e-8)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.35e-8): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.35e-8)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.35e-8))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.35e-8]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.35 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1.35000000000000001e-8 < y Initial program 94.4%
Taylor expanded in y around inf 97.6%
mul-1-neg97.6%
sub-neg97.6%
Simplified97.6%
if -1 < y < 1.35000000000000001e-8Initial program 100.0%
Taylor expanded in y around 0 98.6%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2000000.0) (not (<= y 1.32e-8))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2000000.0) || !(y <= 1.32e-8)) {
tmp = y * (x - z);
} else {
tmp = z * (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 <= (-2000000.0d0)) .or. (.not. (y <= 1.32d-8))) then
tmp = y * (x - z)
else
tmp = z * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2000000.0) || !(y <= 1.32e-8)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2000000.0) or not (y <= 1.32e-8): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2000000.0) || !(y <= 1.32e-8)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2000000.0) || ~((y <= 1.32e-8))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2000000.0], N[Not[LessEqual[y, 1.32e-8]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2000000 \lor \neg \left(y \leq 1.32 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -2e6 or 1.32000000000000007e-8 < y Initial program 94.3%
Taylor expanded in y around inf 98.6%
mul-1-neg98.6%
sub-neg98.6%
Simplified98.6%
if -2e6 < y < 1.32000000000000007e-8Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 74.7%
*-commutative74.7%
Simplified74.7%
Taylor expanded in z around 0 74.7%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e-6) (not (<= y 2.3e-23))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-6) || !(y <= 2.3e-23)) {
tmp = y * (x - z);
} else {
tmp = 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 <= (-9d-6)) .or. (.not. (y <= 2.3d-23))) then
tmp = y * (x - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-6) || !(y <= 2.3e-23)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e-6) or not (y <= 2.3e-23): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e-6) || !(y <= 2.3e-23)) tmp = Float64(y * Float64(x - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9e-6) || ~((y <= 2.3e-23))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e-6], N[Not[LessEqual[y, 2.3e-23]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-6} \lor \neg \left(y \leq 2.3 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -9.00000000000000023e-6 or 2.3000000000000001e-23 < y Initial program 94.7%
Taylor expanded in y around inf 95.5%
mul-1-neg95.5%
sub-neg95.5%
Simplified95.5%
if -9.00000000000000023e-6 < y < 2.3000000000000001e-23Initial program 100.0%
Taylor expanded in y around 0 99.4%
Taylor expanded in x around 0 75.0%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e-8) (not (<= y 3.5e-79))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e-8) || !(y <= 3.5e-79)) {
tmp = y * x;
} else {
tmp = 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.15d-8)) .or. (.not. (y <= 3.5d-79))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e-8) || !(y <= 3.5e-79)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.15e-8) or not (y <= 3.5e-79): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e-8) || !(y <= 3.5e-79)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.15e-8) || ~((y <= 3.5e-79))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e-8], N[Not[LessEqual[y, 3.5e-79]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-8} \lor \neg \left(y \leq 3.5 \cdot 10^{-79}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.15e-8 or 3.5000000000000003e-79 < y Initial program 95.2%
Taylor expanded in x around inf 46.3%
*-commutative46.3%
Simplified46.3%
if -1.15e-8 < y < 3.5000000000000003e-79Initial program 100.0%
Taylor expanded in y around 0 99.3%
Taylor expanded in x around 0 78.5%
Final simplification59.9%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 97.2%
Taylor expanded in y around 0 72.9%
Taylor expanded in x around 0 38.7%
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
return 0.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.0d0
end function
public static double code(double x, double y, double z) {
return 0.0;
}
def code(x, y, z): return 0.0
function code(x, y, z) return 0.0 end
function tmp = code(x, y, z) tmp = 0.0; end
code[x_, y_, z_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 97.2%
Taylor expanded in y around inf 62.1%
mul-1-neg62.1%
sub-neg62.1%
Simplified62.1%
Taylor expanded in x around 0 29.4%
associate-*r*29.4%
neg-mul-129.4%
*-commutative29.4%
Simplified29.4%
add-log-exp21.1%
add-sqr-sqrt21.1%
sqrt-unprod21.1%
exp-prod21.0%
add-sqr-sqrt9.0%
sqrt-unprod9.3%
sqr-neg9.3%
sqrt-unprod4.3%
add-sqr-sqrt4.5%
pow-flip4.5%
exp-prod1.5%
rgt-mult-inverse2.5%
metadata-eval2.5%
metadata-eval2.5%
Applied egg-rr2.5%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((z - x) * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z - ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2024132
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))