
(FPCore (x y z) :precision binary64 :pre TRUE (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * y) + (((1) - x) * z) END code
x \cdot y + \left(1 - x\right) \cdot z
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * y) + (((1) - x) * z) END code
x \cdot y + \left(1 - x\right) \cdot z
(FPCore (x y z) :precision binary64 :pre TRUE (fma x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (y - z)) + z END code
\mathsf{fma}\left(x, y - z, z\right)
Initial program 98.0%
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (- y z))))
(if (<= x -14298.649587223466)
t_0
(if (<= x 0.0005660629841236394) (fma x y z) t_0))))double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -14298.649587223466) {
tmp = t_0;
} else if (x <= 0.0005660629841236394) {
tmp = fma(x, y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -14298.649587223466) tmp = t_0; elseif (x <= 0.0005660629841236394) tmp = fma(x, y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -14298.649587223466], t$95$0, If[LessEqual[x, 0.0005660629841236394], N[(x * y + z), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (x * (y - z)) IN LET tmp_1 = IF (x <= (566062984123639448448550570702764161978848278522491455078125e-63)) THEN ((x * y) + z) ELSE t_0 ENDIF IN LET tmp = IF (x <= (-14298649587223466369323432445526123046875e-36)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -14298.649587223466:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.0005660629841236394:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -14298.649587223466 or 5.6606298412363945e-4 < x Initial program 98.0%
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites64.9%
if -14298.649587223466 < x < 5.6606298412363945e-4Initial program 98.0%
Taylor expanded in x around 0
Applied rewrites75.9%
Applied rewrites76.0%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= y -6.742668220036118e+82) (fma x y z) (if (<= y 3.07342713026798e-110) (* z (- 1.0 x)) (fma x y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.742668220036118e+82) {
tmp = fma(x, y, z);
} else if (y <= 3.07342713026798e-110) {
tmp = z * (1.0 - x);
} else {
tmp = fma(x, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -6.742668220036118e+82) tmp = fma(x, y, z); elseif (y <= 3.07342713026798e-110) tmp = Float64(z * Float64(1.0 - x)); else tmp = fma(x, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -6.742668220036118e+82], N[(x * y + z), $MachinePrecision], If[LessEqual[y, 3.07342713026798e-110], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y + z), $MachinePrecision]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (y <= (3073427130267980153005627182190657993395790266346178807683912839381824716108030662403918387306509888781507111484986848945374899460134021774697330315701930108353347326619958155595922805617888049569222363859348691391916452399978367507736953548628895889670962497363109096337741021898182225413620471954345703125e-416)) THEN (z * ((1) - x)) ELSE ((x * y) + z) ENDIF IN LET tmp = IF (y <= (-67426682200361176120268859113156867640057346737471876670647569701482367024229253120)) THEN ((x * y) + z) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -6.742668220036118 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\mathbf{elif}\;y \leq 3.07342713026798 \cdot 10^{-110}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\end{array}
if y < -6.7426682200361176e82 or 3.0734271302679802e-110 < y Initial program 98.0%
Taylor expanded in x around 0
Applied rewrites75.9%
Applied rewrites76.0%
if -6.7426682200361176e82 < y < 3.0734271302679802e-110Initial program 98.0%
Taylor expanded in y around 0
Applied rewrites62.3%
(FPCore (x y z) :precision binary64 :pre TRUE (fma x y z))
double code(double x, double y, double z) {
return fma(x, y, z);
}
function code(x, y, z) return fma(x, y, z) end
code[x_, y_, z_] := N[(x * y + z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * y) + z END code
\mathsf{fma}\left(x, y, z\right)
Initial program 98.0%
Taylor expanded in x around 0
Applied rewrites75.9%
Applied rewrites76.0%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= x -2.8368855981903414e-51) (* x y) (if (<= x 9.957315309628584e-34) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8368855981903414e-51) {
tmp = x * y;
} else if (x <= 9.957315309628584e-34) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-2.8368855981903414d-51)) then
tmp = x * y
else if (x <= 9.957315309628584d-34) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.8368855981903414e-51) {
tmp = x * y;
} else if (x <= 9.957315309628584e-34) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.8368855981903414e-51: tmp = x * y elif x <= 9.957315309628584e-34: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.8368855981903414e-51) tmp = Float64(x * y); elseif (x <= 9.957315309628584e-34) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.8368855981903414e-51) tmp = x * y; elseif (x <= 9.957315309628584e-34) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.8368855981903414e-51], N[(x * y), $MachinePrecision], If[LessEqual[x, 9.957315309628584e-34], z, N[(x * y), $MachinePrecision]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (x <= (995731530962858429324473884117268777133337992305983115666935440622549596510538661930608296535272216942757950164377689361572265625e-162)) THEN z ELSE (x * y) ENDIF IN LET tmp = IF (x <= (-28368855981903414102920337465896913142028897505741484614367286972627935745057502704794255345263793652131194254318143559929623156480593682005064692930318415164947509765625e-220)) THEN (x * y) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -2.8368855981903414 \cdot 10^{-51}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9.957315309628584 \cdot 10^{-34}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
if x < -2.8368855981903414e-51 or 9.9573153096285843e-34 < x Initial program 98.0%
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites41.5%
if -2.8368855981903414e-51 < x < 9.9573153096285843e-34Initial program 98.0%
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites64.9%
Taylor expanded in x around 0
Applied rewrites36.9%
(FPCore (x y z) :precision binary64 :pre TRUE z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = z END code
z
Initial program 98.0%
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites64.9%
Taylor expanded in x around 0
Applied rewrites36.9%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))