
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 99.2%
*-commutative99.2%
distribute-rgt-out--99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
neg-mul-199.2%
associate-+r+99.2%
unsub-neg99.2%
+-commutative99.2%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -8.5e+267)
(* x z)
(if (<= x -7.5e-27)
(* x y)
(if (<= x 3.75e-6)
(- z)
(if (or (<= x 3.7e+121) (and (not (<= x 2.9e+154)) (<= x 1.6e+283)))
(* x y)
(* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.5e+267) {
tmp = x * z;
} else if (x <= -7.5e-27) {
tmp = x * y;
} else if (x <= 3.75e-6) {
tmp = -z;
} else if ((x <= 3.7e+121) || (!(x <= 2.9e+154) && (x <= 1.6e+283))) {
tmp = x * y;
} else {
tmp = x * 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 <= (-8.5d+267)) then
tmp = x * z
else if (x <= (-7.5d-27)) then
tmp = x * y
else if (x <= 3.75d-6) then
tmp = -z
else if ((x <= 3.7d+121) .or. (.not. (x <= 2.9d+154)) .and. (x <= 1.6d+283)) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -8.5e+267) {
tmp = x * z;
} else if (x <= -7.5e-27) {
tmp = x * y;
} else if (x <= 3.75e-6) {
tmp = -z;
} else if ((x <= 3.7e+121) || (!(x <= 2.9e+154) && (x <= 1.6e+283))) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.5e+267: tmp = x * z elif x <= -7.5e-27: tmp = x * y elif x <= 3.75e-6: tmp = -z elif (x <= 3.7e+121) or (not (x <= 2.9e+154) and (x <= 1.6e+283)): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.5e+267) tmp = Float64(x * z); elseif (x <= -7.5e-27) tmp = Float64(x * y); elseif (x <= 3.75e-6) tmp = Float64(-z); elseif ((x <= 3.7e+121) || (!(x <= 2.9e+154) && (x <= 1.6e+283))) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.5e+267) tmp = x * z; elseif (x <= -7.5e-27) tmp = x * y; elseif (x <= 3.75e-6) tmp = -z; elseif ((x <= 3.7e+121) || (~((x <= 2.9e+154)) && (x <= 1.6e+283))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.5e+267], N[(x * z), $MachinePrecision], If[LessEqual[x, -7.5e-27], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.75e-6], (-z), If[Or[LessEqual[x, 3.7e+121], And[N[Not[LessEqual[x, 2.9e+154]], $MachinePrecision], LessEqual[x, 1.6e+283]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{+267}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7.5 \cdot 10^{-27}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.75 \cdot 10^{-6}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{+121} \lor \neg \left(x \leq 2.9 \cdot 10^{+154}\right) \land x \leq 1.6 \cdot 10^{+283}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -8.5000000000000007e267 or 3.70000000000000013e121 < x < 2.89999999999999979e154 or 1.60000000000000005e283 < x Initial program 96.7%
Taylor expanded in y around 0 83.8%
Taylor expanded in x around inf 83.8%
*-commutative83.8%
Simplified83.8%
if -8.5000000000000007e267 < x < -7.50000000000000029e-27 or 3.7500000000000001e-6 < x < 3.70000000000000013e121 or 2.89999999999999979e154 < x < 1.60000000000000005e283Initial program 99.1%
Taylor expanded in y around inf 66.9%
if -7.50000000000000029e-27 < x < 3.7500000000000001e-6Initial program 100.0%
Taylor expanded in x around 0 70.9%
neg-mul-170.9%
Simplified70.9%
Final simplification70.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.06e-28) (not (<= x 3.75e-6))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.06e-28) || !(x <= 3.75e-6)) {
tmp = x * (z + y);
} 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 ((x <= (-1.06d-28)) .or. (.not. (x <= 3.75d-6))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.06e-28) || !(x <= 3.75e-6)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.06e-28) or not (x <= 3.75e-6): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.06e-28) || !(x <= 3.75e-6)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.06e-28) || ~((x <= 3.75e-6))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.06e-28], N[Not[LessEqual[x, 3.75e-6]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.06 \cdot 10^{-28} \lor \neg \left(x \leq 3.75 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.06e-28 or 3.7500000000000001e-6 < x Initial program 98.6%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
Simplified98.7%
if -1.06e-28 < x < 3.7500000000000001e-6Initial program 100.0%
Taylor expanded in x around 0 70.9%
neg-mul-170.9%
Simplified70.9%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-29) (not (<= x 0.46))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-29) || !(x <= 0.46)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-7d-29)) .or. (.not. (x <= 0.46d0))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-29) || !(x <= 0.46)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e-29) or not (x <= 0.46): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e-29) || !(x <= 0.46)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e-29) || ~((x <= 0.46))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-29], N[Not[LessEqual[x, 0.46]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-29} \lor \neg \left(x \leq 0.46\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -6.9999999999999995e-29 or 0.46000000000000002 < x Initial program 98.6%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
Simplified98.7%
if -6.9999999999999995e-29 < x < 0.46000000000000002Initial program 100.0%
Taylor expanded in y around 0 71.9%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e-30) (not (<= x 0.0036))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-30) || !(x <= 0.0036)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - 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 <= (-4d-30)) .or. (.not. (x <= 0.0036d0))) then
tmp = x * (z + y)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-30) || !(x <= 0.0036)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e-30) or not (x <= 0.0036): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e-30) || !(x <= 0.0036)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4e-30) || ~((x <= 0.0036))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e-30], N[Not[LessEqual[x, 0.0036]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-30} \lor \neg \left(x \leq 0.0036\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -4e-30 or 0.0035999999999999999 < x Initial program 98.6%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
Simplified98.7%
if -4e-30 < x < 0.0035999999999999999Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 71.9%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e-30) (+ (* x y) (* x z)) (if (<= x 1.05e-5) (- (* x z) z) (* x (+ z y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e-30) {
tmp = (x * y) + (x * z);
} else if (x <= 1.05e-5) {
tmp = (x * z) - z;
} else {
tmp = x * (z + 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 (x <= (-5.4d-30)) then
tmp = (x * y) + (x * z)
else if (x <= 1.05d-5) then
tmp = (x * z) - z
else
tmp = x * (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e-30) {
tmp = (x * y) + (x * z);
} else if (x <= 1.05e-5) {
tmp = (x * z) - z;
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.4e-30: tmp = (x * y) + (x * z) elif x <= 1.05e-5: tmp = (x * z) - z else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.4e-30) tmp = Float64(Float64(x * y) + Float64(x * z)); elseif (x <= 1.05e-5) tmp = Float64(Float64(x * z) - z); else tmp = Float64(x * Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.4e-30) tmp = (x * y) + (x * z); elseif (x <= 1.05e-5) tmp = (x * z) - z; else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.4e-30], N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.05e-5], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-30}:\\
\;\;\;\;x \cdot y + x \cdot z\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-5}:\\
\;\;\;\;x \cdot z - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if x < -5.39999999999999975e-30Initial program 100.0%
Taylor expanded in x around inf 97.8%
*-commutative97.8%
Simplified97.8%
if -5.39999999999999975e-30 < x < 1.04999999999999994e-5Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 71.9%
if 1.04999999999999994e-5 < x Initial program 96.8%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e-27) (not (<= x 3.75e-6))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-27) || !(x <= 3.75e-6)) {
tmp = x * y;
} 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 ((x <= (-8d-27)) .or. (.not. (x <= 3.75d-6))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-27) || !(x <= 3.75e-6)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e-27) or not (x <= 3.75e-6): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e-27) || !(x <= 3.75e-6)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e-27) || ~((x <= 3.75e-6))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e-27], N[Not[LessEqual[x, 3.75e-6]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-27} \lor \neg \left(x \leq 3.75 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.0000000000000003e-27 or 3.7500000000000001e-6 < x Initial program 98.6%
Taylor expanded in y around inf 58.0%
if -8.0000000000000003e-27 < x < 3.7500000000000001e-6Initial program 100.0%
Taylor expanded in x around 0 70.9%
neg-mul-170.9%
Simplified70.9%
Final simplification63.8%
(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 Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.2%
Taylor expanded in x around 0 33.7%
neg-mul-133.7%
Simplified33.7%
Final simplification33.7%
herbie shell --seed 2024021
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))